Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using umbraco.cms.businesslogic.datatype;
  6. using System.Collections;
  7.  
  8. namespace Kyber.Entities
  9. {
  10.     public class CropFormats
  11.     {
  12.         private List<CropFormat> _lCropFormats = new List<CropFormat>();
  13.  
  14.         public CropFormats()
  15.         {
  16.             Guid _g = new Guid("7a2d436c-34c2-410f-898f-4a23b3d79f54"); // Guid of the imgage cropper datatype            
  17.             DataTypeDefinition _dtdImageCropper = DataTypeDefinition.GetByDataTypeId(_g);
  18.             SortedList _sortedList = PreValues.GetPreValues(_dtdImageCropper.Id);
  19.             if (_sortedList != null && _sortedList.Count > 0)
  20.             {
  21.                 PreValue _preValue = (PreValue)_sortedList[0];
  22.                 this.ParseImageCropperPreValueString(_preValue.Value.ToString());
  23.             }
  24.         }
  25.  
  26.         public List<CropFormat> AvailableCropFormats
  27.         {
  28.             get
  29.             {
  30.                 return this._lCropFormats;
  31.             }
  32.         }
  33.  
  34.         private void ParseImageCropperPreValueString(String _sImageCropperPrevalue)
  35.         {
  36.             // Example string umbracoFile,1,1|Hovedbilde,660,286,1,CM;Oversiktsbilde,170,135,1,CM;test,200,200,1,LT
  37.             String[] _aSplitByPipe = _sImageCropperPrevalue.Split('|');
  38.             if (_aSplitByPipe.Length > 1) // two lines
  39.             {
  40.                 if (!String.IsNullOrEmpty(_aSplitByPipe[1]))
  41.                 {
  42.                     String[] _aCropTypes = _aSplitByPipe[1].Split(';');
  43.                     foreach (String _sCropType in _aCropTypes)
  44.                     {
  45.                         String[] _aCropTypeProperties = _sCropType.Split(',');
  46.                         String _sCropName = _aCropTypeProperties[0];
  47.                         String _sWidth = _aCropTypeProperties[1];
  48.                         String _sHeight = _aCropTypeProperties[2];
  49.                         String _sBKeepAspectRatio = _aCropTypeProperties[3];
  50.                         String _sDefaultPosition = _aCropTypeProperties[4];
  51.  
  52.                         _lCropFormats.Add(new CropFormat(_sCropName, _sWidth, _sHeight, _sBKeepAspectRatio, _sDefaultPosition));
  53.                     }
  54.                 }
  55.             }
  56.  
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement