Exemplo n.º 1
1
        public void Setup()
        {
            var loader = new AttributeConfigurationLoader(
               new string[] { "Glass.Sitecore.Mapper.Tests.HtmlFixtureNS, Glass.Sitecore.Mapper.Tests" }
               );
            _context = new Context(loader, new AbstractSitecoreDataHandler[] { });

            _db = global::Sitecore.Configuration.Factory.GetDatabase("master");
            _sitecore = new SitecoreService(_db);
            _itemId = new Guid("{5864308D-A91A-4E74-B8CA-7F27372CBB73}");
            _item = _db.GetItem(new ID(_itemId));
            _html = new GlassHtml(_sitecore);
            _sltTextOriginal = _item["SingleLineText"];
            _mltTextOriginal = _item["MultiLineText"];
            _intOriginal = _item["Integer"];
            _numberOriginal = _item["Number"];

            using (new SecurityDisabler())
            {
                _item.Editing.BeginEdit();
                _item["SingleLineText"] = _sltContent;
                _item["MultiLineText"] = _mltContent;
                _item["Integer"] = _intContent;
                _item["Number"] = _numberContent;
                _item.Editing.EndEdit();
            }

        }
        public override void SetValue(global::Sitecore.Data.Items.Item item, object value, ISitecoreService service)
        {
            
            switch (InfoType)
            {
                case SitecoreInfoType.DisplayName:
                    if (value is string || value == null)
                        item[Settings.DisplayNameFieldName] = (value ?? string.Empty).ToString();
                    else
                        throw new NotSupportedException("Can't set DisplayName. Value is not of type System.String");
                    break;
                case SitecoreInfoType.Name:
                    if (value is string || value == null)
                    {
                        //if the name is null or empty nothing should happen
                        if ((value ?? string.Empty).ToString().IsNullOrEmpty()) return;
                        
                        if (item.Name != value.ToString())
                        {
                            item.Name = value.ToString();
                        }
                        
                    }
                    else
                        throw new NotSupportedException("Can't set Name. Value is not of type System.String");
                    break;             
                default:
                    throw new NotSupportedException("You can not save SitecoreInfo {0}".Formatted(InfoType));
            }

        }
Exemplo n.º 3
0
        public static T Save <T>(this T obj, IGlassBase parent, ISitecoreService service) where T : class, IHasExternalId
        {
            if (obj.HasIDTableEntry())
            {
                if (obj.IsUpdateRequired())
                {
                    //      Any data manipulation can go hear before
                    //      updating the database once again
                    //      This case will never be hit in this sample
                    using (new SecurityDisabler())
                    {
                        service.Save(obj);
                    }
                }
                obj = service.GetItem <T>(obj.GetItemIdFromIDTableEntry().Guid);
            }
            else
            {
                obj.Name = ItemUtil.ProposeValidItemName(obj.Name).ToLower().Replace(" ", "-");
                using (new SecurityDisabler())
                {
                    service.Create(parent, obj);
                }
            }

            return(obj);
        }
 public  void ReadFromItem(ISitecoreService service, object target, Item item, SitecoreClassConfig config)
 {
     foreach (var handler in config.DataHandlers)
     {
         handler.SetProperty(target, item, service);
     }
 }
 public PlaceholderRenderer(ICompositeViewEngine viewEngine, IViewComponentHelper viewComponentHelper, ISitecoreService sitecoreService, IOptions <ApiSettings> apiSettings)
 {
     _viewEngine          = viewEngine;
     _viewComponentHelper = viewComponentHelper;
     _sitecoreService     = sitecoreService;
     _baseAddress         = new Uri(new Uri(apiSettings.Value.BaseUrl), apiSettings.Value.PageDataApiPath);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SitecoreDataMappingContext"/> class.
 /// </summary>
 /// <param name="obj">The obj.</param>
 /// <param name="item">The item.</param>
 /// <param name="service">The service.</param>
 public SitecoreDataMappingContext(object obj, Item item, ISitecoreService service, GetItemOptions getModelOptions)
     : base(obj, getModelOptions)
 {
     //TODO: ME - should we assert that these are not null
     this.Item = item;
     Service   = service;
 }
        public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
        {
            Item target = null;

            if (fieldValue.IsNullOrEmpty())
            {
                return(null);
            }

            try
            {
                Guid id = Guid.Empty;
                id     = new Guid(fieldValue);
                target = item.Database.GetItem(new ID(id));
            }
            catch (Exception ex)
            {
                target = item.Database.GetItem(fieldValue);
            }

            if (target == null)
            {
                return(null);
            }
            return(service.CreateClass(IsLazy, InferType, Property.PropertyType, target));
        }
        public override string SetFieldValue(object value, ISitecoreService service)
        {
            if (value is TriState)
            {
                TriState state = (TriState)value;
                switch (state)
                {
                case TriState.Default:
                    return("");

                case TriState.No:
                    return("0");

                case TriState.Yes:
                    return("1");

                default:
                    return("");
                }
            }
            else
            {
                throw new MapperException("Value is not of type {0}".Formatted(typeof(TriState).FullName));
            }
        }
Exemplo n.º 9
0
        public static T CreateItem <T>(this ISitecoreService service, object parent, T model, Action <CreateItemByModelBuilder> config) where T : class
        {
            var builder = new CreateItemByModelBuilder().Model(model).Parent(parent);

            config(builder);
            return(service.CreateItem <T>(builder));
        }
Exemplo n.º 10
0
 public ChildrenCast(ISitecoreService service, Item item, bool isLazy, bool inferType)
 {
     _service   = service;
     _item      = item;
     _isLazy    = isLazy;
     _inferType = inferType;
 }
Exemplo n.º 11
0
 public DuplicateRenderingsFactory(
     IDuplicateRenderingsFactoryConfiguration configuration,
     ISitecoreService sitecoreService)
 {
     Configuration   = configuration;
     SitecoreService = sitecoreService;
 }
 public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
 {
     if (fieldValue.IsNullOrEmpty()) return 0d;
     double dValue = 0;
     if (double.TryParse(fieldValue, out dValue)) return dValue;
     else throw new MapperException("Could not convert value to double");
 }
        public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
        {
            Type type = Property.PropertyType;
            //Get generic type
            Type pType = Utility.GetGenericArgument(type);

            if (EnumSubHandler == null)
            {
                EnumSubHandler = GetSubHandler(pType, service);
            }

            //The enumerator only works with piped lists
            IEnumerable <string> parts = fieldValue.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            //replace any pipe encoding with an actual pipe
            parts = parts.Select(x => x.Replace(Settings.PipeEncoding, "|")).ToArray();



            IEnumerable <object> items = parts.Select(x => EnumSubHandler.GetFieldValue(x, item, service)).ToArray();
            var list = Utility.CreateGenericType(typeof(List <>), new Type[] { pType });

            Utility.CallAddMethod(items, list);

            return(list);
        }
 public ProxyClassInterceptor(Type type, ISitecoreService service, Item item, bool inferType)
 {
     _service   = service;
     _item      = item;
     _type      = type;
     _inferType = inferType;
 }
Exemplo n.º 15
0
        public SiteSettingsProviderTests()
        {
            this.siteDefinitionsProvider = Substitute.For <ISiteDefinitionsProvider>();
            this.sitecoreService         = Substitute.For <ISitecoreService>();

            this.provider = new SiteSettingsProvider(this.siteDefinitionsProvider, this.sitecoreService);
        }
 public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
 {
     if (fieldValue.IsNullOrEmpty()) return (float)0.0;
     float fValue = 0.0f;
     if (float.TryParse(fieldValue, out fValue)) return fValue;
     else throw new MapperException("Could not convert value to float");
 }
Exemplo n.º 17
0
        /// <summary>
        /// Processes the items.
        /// </summary>
        /// <returns>IEnumerable{`0}.</returns>
        public IEnumerable <T> ProcessItems()
        {
            if (_service == null)
            {
                throw new NullReferenceException("SitecoreService has not been set");
            }

            var items = _getItems();

            if (items == null)
            {
                items = new Item[] {};
            }

            foreach (Item child in items)
            {
                var obj = _service.CreateType(
                    _type,
                    child,
                    _service.Config.UseProxiesForLazyEnumerables && _isLazy,
                    _inferType, null) as T;

                if (obj == null)
                {
                    continue;
                }
                yield return(obj);
            }

            //release the service after full enumeration
            _service = null;
        }
Exemplo n.º 18
0
        public static T CreateItem <T>(this ISitecoreService service, object parent, string name, Action <CreateItemByNameBuilder> config) where T : class
        {
            var builder = new CreateItemByNameBuilder().Name(name).Parent(parent).Type(typeof(T));

            config(builder);
            return(service.CreateItem <T>(builder));
        }
 public void ReadFromItem(ISitecoreService service, object target, Item item, SitecoreClassConfig config)
 {
     foreach (var handler in config.DataHandlers)
     {
         handler.SetProperty(target, item, service);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SitecoreDataMappingContext"/> class.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="item">The item.</param>
        /// <param name="service">The service.</param>
        public SitecoreDataMappingContext(object obj, Item item, ISitecoreService service):base(obj)
        {

            //TODO: ME - should we assert that these are not null
            this.Item = item;
            Service = service;
        }
Exemplo n.º 21
0
        /// <summary>
        /// This is a search implementatation where you want to pass the database name along with the filter.
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="database"></param>
        /// <returns></returns>
        public IArticleSearchResults SearchCustomDatabase(IArticleSearchFilter filter, string database)
        {
            using (var context = SearchContextFactory.Create(database))
            {
                var query = context.GetQueryable <ArticleSearchResultItem>()
                            .Filter(i => i.TemplateId == IArticleConstants.TemplateId)
                            .FilterTaxonomies(filter, ItemReferences, GlobalService)
                            .ExcludeManuallyCurated(filter)
                            .FilteryByArticleNumbers(filter)
                            .FilteryByEScenicID(filter)
                            .ApplyDefaultFilters();

                if (filter.PageSize > 0)
                {
                    query = query.Page(filter.Page > 0 ? filter.Page - 1 : 0, filter.PageSize);
                }

                query = query.OrderByDescending(i => i.ActualPublishDate);
                ISitecoreService localSearchContext = SitecoreFactory(database);
                var results = query.GetResults();
                return(new ArticleSearchResults
                {
                    Articles = results.Hits.Select(h => localSearchContext.GetItem <IArticle>(h.Document.ItemId.Guid))
                });
            }
        }
 public override object GetFieldValue(string fieldValue, Item item,  ISitecoreService service)
 {
     if (fieldValue.IsNullOrEmpty()) return 0;
     int iValue = 0;
     if (int.TryParse(fieldValue, out iValue)) return iValue;
     else throw new MapperException("Could not convert value to integer.");
 }
Exemplo n.º 23
0
        public void Setup()
        {
            var loader = new AttributeConfigurationLoader(
                new string[] { "Glass.Sitecore.Mapper.Tests.HtmlFixtureNS, Glass.Sitecore.Mapper.Tests" }
                );

            _context = new Context(loader, new AbstractSitecoreDataHandler[] { });

            _db              = global::Sitecore.Configuration.Factory.GetDatabase("master");
            _sitecore        = new SitecoreService(_db);
            _itemId          = new Guid("{5864308D-A91A-4E74-B8CA-7F27372CBB73}");
            _item            = _db.GetItem(new ID(_itemId));
            _html            = new GlassHtml(_sitecore);
            _sltTextOriginal = _item["SingleLineText"];
            _mltTextOriginal = _item["MultiLineText"];
            _intOriginal     = _item["Integer"];
            _numberOriginal  = _item["Number"];

            using (new SecurityDisabler())
            {
                _item.Editing.BeginEdit();
                _item["SingleLineText"] = _sltContent;
                _item["MultiLineText"]  = _mltContent;
                _item["Integer"]        = _intContent;
                _item["Number"]         = _numberContent;
                _item.Editing.EndEdit();
            }
        }
Exemplo n.º 24
0
        public void Setup()
        {
            var dependencies = Substitute.For <NlmExportService.IDependencies>();
            var mockLogger   = Substitute.For <ILog>();

            _mockService       = Substitute.For <ISitecoreService>();
            _mockReferences    = Substitute.For <IItemReferences>();
            _mockSearchService = Substitute.For <IArticleSearchService>();

            // May as well use real dependencies for testing; more of a system test
            var builder = new ContainerBuilder();

            builder.RegisterModule(new AutomapperModule("Informa.Library"));
            builder.Register(c => _mockService).As <ISitecoreService>();
            builder.Register(c => _mockReferences).As <IItemReferences>();
            builder.Register(c => _mockSearchService).As <IArticleSearchService>();
            var container = builder.Build();

            AutofacConfig.ServiceLocator = container;

            dependencies.Mapper.Returns(c => container.Resolve <IMapper>());
            dependencies.Serializer.Returns(c => new NlmSerializer());

            _exportService = new NlmExportService(dependencies, mockLogger);
        }
        public override void SetValue(global::Sitecore.Data.Items.Item item, object value, ISitecoreService service)
        {

            File  file = value as File;
            FileField field = new FileField(item.Fields[FieldName]);

            if (file == null)
            {
                field.Clear();
                return;
            }

            if (field.MediaID.Guid != file.Id)
            {
                if (file.Id == Guid.Empty)
                {
                    ItemLink link = new ItemLink(item.Database.Name, item.ID, field.InnerField.ID, field.MediaItem.Database.Name, field.MediaID, field.MediaItem.Paths.FullPath);
                    field.RemoveLink(link);
                }
                else
                {
                    ID newId = new ID(file.Id);
                    Item target = item.Database.GetItem(newId);
                    if (target != null)
                    {
                        field.MediaID = newId;
                        ItemLink link = new ItemLink(item.Database.Name, item.ID, field.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath);
                        field.UpdateLink(link);
                    }
                    else throw new MapperException("No item with ID {0}. Can not update File Item field".Formatted(newId));
                }
            }

        }
Exemplo n.º 26
0
 public ChildrenCast(ISitecoreService service, Item item, GetItemOptions getModelOptions, LazyLoadingHelper lazyLoadingHelper)
 {
     _service           = service;
     _item              = item;
     _getModelOptions   = getModelOptions;
     _lazyLoadingHelper = lazyLoadingHelper;
 }
        public override string SetFieldValue(object value, ISitecoreService service)
        {
            Type pType = Utility.GetGenericArgument(Property.PropertyType);


            if (EnumSubHandler == null)
                EnumSubHandler = GetSubHandler(pType, service);

            IEnumerable list = value as IEnumerable;

            if (list == null) return "";

            List<string> sList = new List<string>();
                       

            foreach (object obj in list)
            {
                string result = EnumSubHandler.SetFieldValue(obj, service);
                if (!result.IsNullOrEmpty())
                    sList.Add(result);
            }

            StringBuilder sb = new StringBuilder();
            sList.ForEach(x => sb.AppendFormat("{0}|", x.Replace("|", Settings.PipeEncoding)));
            if (sb.Length > 1) 
                sb.Remove(sb.Length - 1, 1);

            return sb.ToString();
        }
        public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
        {
            Type type = Property.PropertyType;
            //Get generic type
            Type pType = Utility.GetGenericArgument(type);

            if (EnumSubHandler == null) EnumSubHandler = GetSubHandler(pType, service);
            
            //The enumerator only works with piped lists
            IEnumerable<string> parts = fieldValue.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            //replace any pipe encoding with an actual pipe
            parts = parts.Select(x => x.Replace(Settings.PipeEncoding, "|")).ToArray();

                      

            IEnumerable<object> items = parts.Select(x => EnumSubHandler.GetFieldValue(x, item, service)).ToArray();
            var list = Utility.CreateGenericType(typeof(List<>), new Type[] { pType }) ;
            Utility.CallAddMethod(items, list);

            return list;
            


        }
Exemplo n.º 29
0
        public static T GetItem <T>(this ISitecoreService service, Guid id, Action <GetItemByIdBuilder> config) where T : class
        {
            var builder = new GetItemByIdBuilder().Id(id);

            config(builder);
            return(service.GetItem <T>(builder));
        }
        public override object GetValue(global::Sitecore.Data.Items.Item item,  ISitecoreService service)
        {
            var itemField = item.Fields[FieldName];

            if (itemField == null) return null;

            Image img = new Image();
            ImageField scImg = new ImageField(itemField);

            int height = 0;
            int.TryParse(scImg.Height, out height);
            int width = 0;
            int.TryParse(scImg.Width, out width);
            int hSpace = 0;
            int.TryParse(scImg.HSpace, out hSpace);
            int vSpace = 0;
            int.TryParse(scImg.VSpace, out vSpace);

            img.Alt = scImg.Alt;
            img.Border = scImg.Border;
            img.Class = scImg.Class;
            img.Height = height;
            img.HSpace = hSpace;
            img.MediaId = scImg.MediaID.Guid;
            if(scImg.MediaItem != null)
                img.Src = MediaManager.GetMediaUrl(scImg.MediaItem);
            img.VSpace = vSpace;
            img.Width = width;

            return img;
        }
Exemplo n.º 31
0
        public override void SetValue(Item item, object value, ISitecoreService service)
        {
            var field = base.GetField(item);

            if (field == null)
            {
                return;
            }
            else if (field.Type.StartsWith("Rich Text") && Setting != SitecoreFieldSettings.RichTextRaw)
            {
                throw new NotSupportedException("It is not possible to save data from a rich text field when the data isn't raw."
                                                + "Set the SitecoreFieldAttribute setting property to SitecoreFieldSettings.RichTextRaw for property {0} on type {1}".Formatted(Property.Name, Property.ReflectedType.FullName));
            }
            else
            {
                if (value != null)
                {
                    string fieldValue = value.ToString();
                    field.Value = fieldValue;
                }
                else
                {
                    field.Value = string.Empty;
                }
            }
        }
Exemplo n.º 32
0
 public ProductColorsContextExtension(
     ISitecoreService sitecoreService,
     IConfigurationResolver configurationResolver)
     : base(configurationResolver)
 {
     this.sitecoreService = sitecoreService;
 }
        public override object GetValue(global::Sitecore.Data.Items.Item item,  ISitecoreService service)
        {
                int numChildren = item.Children.Count;
                Type genericType = Utility.GetGenericArgument(Property.PropertyType);


              
                    var getItems = new Func<IEnumerable<Item>>(() =>
                    {

                        switch (Options)
                        {
                            case SitecoreLinkedOptions.All:
                                var itemLinks1 = global::Sitecore.Configuration.Factory.GetLinkDatabase().GetReferences(item);
                                var itemLinks2 = global::Sitecore.Configuration.Factory.GetLinkDatabase().GetReferrers(item);
                                return itemLinks1.Select(x => x.GetTargetItem()).Union(itemLinks2.Select(x=>x.GetSourceItem()));
                                break;
                            case SitecoreLinkedOptions.References:
                                var itemLinks3 = global::Sitecore.Configuration.Factory.GetLinkDatabase().GetReferences(item);
                                return itemLinks3.Select(x => x.GetTargetItem());
                                break;
                            case SitecoreLinkedOptions.Referrers:
                                var itemLinks4 = global::Sitecore.Configuration.Factory.GetLinkDatabase().GetReferrers(item);
                                return itemLinks4.Select(x => x.GetSourceItem());
                                break;
                            default:
                                return new List<Item>();
                        }
                        
                    });

                return service.CreateClasses(IsLazy, InferType,  genericType, getItems);
        }
 public Enumerable(Func <IEnumerable <Item> > getItems, ISitecoreService service, bool isLazy, bool inferType)
 {
     _getItems  = getItems;
     _service   = service;
     _isLazy    = isLazy;
     _inferType = inferType;
 }
        public void Setup()
        {
            _handler = new SitecoreLinkedHandler();
            _database = global::Sitecore.Configuration.Factory.GetDatabase("master");
            _target = _database.GetItem("/sitecore/content/Glass/ItemLinksTest");

            SitecoreProperty idProperty =  new SitecoreProperty(){
                            Attribute = new SitecoreIdAttribute(),
                            Property = typeof(SitecoreLinkedHandlerFixtureNS.LinkedTestClass).GetProperty("Id")
                        };
            SitecoreIdDataHandler idHandler = new SitecoreIdDataHandler();
            idHandler.ConfigureDataHandler(idProperty);
                 

            var context = new InstanceContext(
              (new SitecoreClassConfig[]{
                   new SitecoreClassConfig(){
                       ClassAttribute = new SitecoreClassAttribute(),
                       Properties = new SitecoreProperty[]{
                           idProperty                       
                       },
                       Type = typeof(SitecoreLinkedHandlerFixtureNS.LinkedTestClass),
                       DataHandlers = new AbstractSitecoreDataHandler []{
                            idHandler
                       }
                   }
               }).ToDictionary(), new AbstractSitecoreDataHandler[] { });


        

            _service = new SitecoreService(_database, context);

        }
Exemplo n.º 36
0
 public InterfaceMethodInterceptor(SitecoreClassConfig config, Item item, ISitecoreService service)
 {
     _config  = config;
     _item    = item;
     _service = service;
     _values  = new Dictionary <string, object>();
 }
Exemplo n.º 37
0
        public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
        {
            var itemField = base.GetField(item);

            if (itemField == null)
            {
                return(null);
            }

            FileField field = new FileField(itemField);
            File      file  = new File();

            if (field.MediaItem != null)
            {
                MediaItem mediaItem = new MediaItem(field.MediaItem);

                file.Src       = HttpUtility.UrlPathEncode(MediaManager.GetMediaUrl(field.MediaItem));
                file.Size      = mediaItem.Size;
                file.Title     = mediaItem.Title;
                file.Extension = mediaItem.Extension;
            }
            file.Id = field.MediaID.Guid;

            return(file);
        }
 public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
 {
     if (fieldValue.IsNullOrEmpty()) return 0;
     long lValue = 0;
     if (long.TryParse(fieldValue, NumberStyles.Any, CultureInfo.InvariantCulture, out lValue)) return lValue;
     throw new MapperException("Could not convert value to long.");
 }
        public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
        {
            Item target = null;

            if (fieldValue.IsNullOrEmpty())
            {
                return(null);
            }

            Guid id = Guid.Empty;

            if (Utility.GuidTryParse(fieldValue, out id))
            {
                target = item.Database.GetItem(new ID(id), item.Language);
            }
            else
            {
                target = item.Database.GetItem(fieldValue, item.Language);
            }

            if (target == null)
            {
                return(null);
            }
            return(service.CreateClass(IsLazy, InferType, Property.PropertyType, target));
        }
Exemplo n.º 40
0
 public HeaderController(IMvcContext mvccontext,
                         IRequestContext requestContext, ISitecoreService sitecoreService)
 {
     this.mvccontext      = mvccontext;
     this.requestContext  = requestContext;
     this.sitecoreService = sitecoreService;
 }
Exemplo n.º 41
0
        public static T GetItem <T>(this ISitecoreService service, Item item, Action <GetItemByItemBuilder> config) where T : class
        {
            var builder = new GetItemByItemBuilder().Item(item);

            config(builder);
            return(service.GetItem <T>(builder));
        }
Exemplo n.º 42
0
        public static T GetItem <T>(this ISitecoreService service, string path, Action <GetItemByPathBuilder> config) where T : class
        {
            var builder = new GetItemByPathBuilder().Path(path);

            config(builder);
            return(service.GetItem <T>(builder));
        }
 public CommentsController(
     ISitecoreContext context,
     ISitecoreService master)
 {
     _context = context;
     _master = master;
 }
        public override void SetValue( Item item, object value, ISitecoreService service)
        {
            var field = base.GetField(item);

            if (field == null)
            {
                return;
            }
            else if (field.Type.StartsWith("Rich Text") && Setting != SitecoreFieldSettings.RichTextRaw)
            {
                throw new NotSupportedException("It is not possible to save data from a rich text field when the data isn't raw."
                    + "Set the SitecoreFieldAttribute setting property to SitecoreFieldSettings.RichTextRaw for property {0} on type {1}".Formatted(Property.Name, Property.ReflectedType.FullName));
            }
            else
            {
                if (value != null)
                {
                    string fieldValue = value.ToString();
                    field.Value = fieldValue;
                }
                else
                {
                    field.Value = string.Empty;
                }
            }
        }
Exemplo n.º 45
0
        public static T GetItem <T>(this ISitecoreService service, Query query, Action <GetItemByQueryBuilder> config) where T : class
        {
            var builder = new GetItemByQueryBuilder().Query(query.Value);

            config(builder);
            return(service.GetItem <T>(builder));
        }
Exemplo n.º 46
0
 public SiteRootsContext(
     ISitecoreService sitecoreService,
     ICrossSiteCacheProvider cacheProvider)
 {
     SitecoreService = sitecoreService;
     CacheProvider   = cacheProvider;
 }
        public override object GetValue(global::Sitecore.Data.Items.Item item,  ISitecoreService service)
        {

            var itemField = base.GetField(item);

            if (itemField == null || itemField.Value.Trim().IsNullOrEmpty()) return null;
            
            

            Link link = new Link();
            LinkField field = new LinkField(itemField);

            switch (field.LinkType)
            {
                case "anchor":
                    link.Url = field.Anchor;
                    link.Type = LinkType.Anchor;
                    break;
                case "external":
                    link.Url = field.Url;
                    link.Type = LinkType.External;
                    break;
                case "mailto":
                    link.Url = field.Url;
                    link.Type = LinkType.MailTo;
                    break;
                case "javascript":
                    link.Url = field.Url;
                    link.Type = LinkType.JavaScript;
                    break;
                case "media":
                    global::Sitecore.Data.Items.MediaItem media = new global::Sitecore.Data.Items.MediaItem(field.TargetItem);
                    link.Url = global::Sitecore.Resources.Media.MediaManager.GetMediaUrl(media);
                    link.Type = LinkType.Media;
                    link.TargetId = field.TargetID.Guid;

                    break;
                case "internal":
                    if (field.TargetItem == null) link.Url = string.Empty;
                    else link.Url = LinkManager.GetItemUrl(field.TargetItem);
                    link.Type = LinkType.Internal;
                    link.TargetId = field.TargetID.Guid;

                    break;
                default:
                    return null;
                    break;

            }
            

            link.Anchor = field.Anchor;
            link.Class = field.Class;
            link.Text = field.Text;
            link.Title = field.Title;
            link.Target = field.Target;
            link.Query = field.QueryString;

            return link;
        }
 public ProxyClassInterceptor(Type type, ISitecoreService service, Item item, bool inferType)
 {
     _service = service;
     _item = item;
     _type = type;
     _inferType = inferType;
     
 }
 public void Setup()
 {
     _handler = new SitecoreFieldIEnumerableHandler();
     var context = new InstanceContext(
         new Dictionary<Type, SitecoreClassConfig>(),
         new AbstractSitecoreDataHandler[] { new SitecoreFieldIntegerHandler() });
     _service = new SitecoreService("master");
 }
        /// <summary>
        /// Sets the property on the target object using data from the Sitecore Item
        /// </summary>
        /// <param name="target">The object to set the value on</param>
        /// <param name="item">The item to pull the data from</param>
        /// <param name="context">The current instance context</param>
        public void SetProperty(object target, Item item, ISitecoreService service)
        {
            object value = null;

            value = this.GetValue(item, service);
            if(value != null)
                Property.SetValue(target, value, null);
        }
        public override  object GetValue(Item item, ISitecoreService service)
        {
            var field = GetField(item);

            string fieldValue = field == null ? string.Empty : field.Value ;

            return GetFieldValue(fieldValue, item, service);
        }
        public override object GetFieldValue(string fieldValue, Item item,  ISitecoreService service)
        {
            if (fieldValue.IsNullOrEmpty()) return 0M;

            decimal dValue = 0;
            if (decimal.TryParse(fieldValue, NumberStyles.Float, CultureInfo.InvariantCulture, out dValue)) return dValue;
            else throw new MapperException("Could not convert value to decimal");
        }
        public RateBaconController(
            ISitecoreContext context,
            ISitecoreService service

            ):base(context, new GlassHtml(context))
        {
            _service = service;
        }
        public override void SetValue(Item item, object value, ISitecoreService service)
        {
            if (value == null) return;
         
            Field field = item.Fields[FieldName];

            field.SetBlobStream(value as Stream);
        }
        public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
        {
            if (string.IsNullOrWhiteSpace(fieldValue))
            {
                return null;
            }

            return global::Sitecore.DateUtil.IsoDateToDateTime(fieldValue);
        }
        public override string SetFieldValue(object value, ISitecoreService service)
        {

            if (value is Guid)
            {
                return ((Guid)value).ToString("B");
            }
            else throw new MapperException("The value is not of type System.Guid");
        }
        public void Setup()
        {
            _context = new Context(
                new AttributeConfigurationLoader("Glass.Sitecore.Mapper.Tests.GlassHtmlFixtureNs, Glass.Sitecore.Mapper.Tests")
                );

            _service = new SitecoreService("master");
            _editablePath = "/sitecore/content/GlassHtml/Editable";
        }
 public override string SetFieldValue(object value, ISitecoreService service)
 {
     if (value is double)
     {
         return value.ToString();
     }
     else
         throw new MapperException("The value is not of type System.Double");
 }
 public override string SetFieldValue(object value, ISitecoreService service)
 {
     if (value is DateTime)
     {
         DateTime date = (DateTime)value;
         return global::Sitecore.DateUtil.ToIsoDate(date);
     }
     else
         throw new MapperException("The value is not of type System.DateTime");
 }
        public void Setup()
        {
            _handler = new SitecoreFieldIEnumerableHandler();
            Context context = new Context(
                new AttributeConfigurationLoader(
                    "Glass.Sitecore.Mapper.Tests.Data.SitecoreChildrenHandlerFixture,  Glass.Sitecore.Mapper.Tests",
                    "Glass.Sitecore.Mapper.Tests.Domain,  Glass.Sitecore.Mapper.Tests"));

            _service = new SitecoreService("master");
        }