Exemplo n.º 1
0
        public void RenderField()
        {
            var    obj      = _sitecore.CreateClass <Super>(false, false, _item);
            string rendered = null;

            using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("website")))
            {
                rendered = _html.Editable <Super>(obj, x => x.MultiLineText);
            }
            Assert.AreEqual(_mltContent, rendered);
        }
        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));
        }
        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));
        }
        /// <summary>
        /// Gets the product model.
        /// </summary>
        /// <param name="productItem">The product item.</param>
        /// <param name="price">The product price.</param>
        /// <param name="stockInformation">The stock information.</param>
        /// <param name="orderableInformation">The pre-orderable information.</param>
        /// <returns>The product model.</returns>
        private ProductModel GetProductModel(Item productItem, decimal price, StockInformation stockInformation, OrderableInformation orderableInformation)
        {
            ISitecoreService glassMapper = GlassMapperService.Current;

            var productModel = glassMapper.CreateClass <ProductModel, decimal, StockInformation, OrderableInformation>(false, false, productItem, price, stockInformation, orderableInformation);

            return(productModel.SetProductResource(this.productService, productItem));
        }
 public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
 {
     if (Id != Guid.Empty)
     {
         var scItem = service.Database.GetItem(new ID(Id));
         return(service.CreateClass(IsLazy, false, Property.Property.PropertyType, scItem));
     }
     else if (!Path.IsNullOrEmpty())
     {
         var scItem = service.Database.GetItem(Path);
         return(service.CreateClass(IsLazy, false, Property.Property.PropertyType, scItem));
     }
     else
     {
         return(null);
     }
 }
 public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
 {
     if (Id != Guid.Empty)
     {
         var scItem = service.Database.GetItem(new ID(Id));
         return service.CreateClass(IsLazy, false, Property.Property.PropertyType, scItem);
     }
     else if (!Path.IsNullOrEmpty())
     {
         var scItem = service.Database.GetItem(Path);
         return service.CreateClass(IsLazy, false, Property.Property.PropertyType, scItem);
     }
     else
     {
         return null;
     }
 }
        public void Intercept(IInvocation invocation)
        {
            //create class
            if (_actual == null)
            {
                _actual = _service.CreateClass(false, _inferType, _type, _item);
            }

            invocation.ReturnValue = invocation.Method.Invoke(_actual, invocation.Arguments);
        }
        public void CreateClass_NullItem_ReturnsNull()
        {
            //Assign
            Item item = null;

            //Act
            var result = _service.CreateClass <InstanceContextFixtureNS.TestClass>(false, false, item);

            //Assert
            Assert.IsNull(result);
        }
        /// <summary>
        /// Gets the sorting items.
        /// </summary>
        /// <returns>The sorting items.</returns>
        protected List <ProductSortingItem> GetSortingItems()
        {
            var result = new List <ProductSortingItem>();

            ISitecoreService glassMapper = GlassMapperService.Current;

            var sortingRoot = Sitecore.Context.Database.GetItem("/sitecore/content/Global/Product Sorting");

            if (sortingRoot != null)
            {
                foreach (Item sortingItem in sortingRoot.Children)
                {
                    result.Add(glassMapper.CreateClass <ProductSortingItem>(false, false, sortingItem));
                }
            }

            return(result);
        }
        public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
        {
            Item target = null;

            if (fieldValue.IsNullOrEmpty()) return null;

            Guid id = Guid.Empty;
            if (Guid.TryParse(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);

        }
        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 ActionResult CategoryFacet(
            [CanBeNull][Bind(Prefix = "category")] string category,
            [CanBeNull][Bind(Prefix = "subCategory")] string subCategory)
        {
            if (string.IsNullOrEmpty(category))
            {
                return(new EmptyResult());
            }

            Item categoryItem = this.productService.GetCategory(category);

            if (ReferenceEquals(categoryItem, null))
            {
                return(new EmptyResult());
            }

            var categories = this.productService.GetRelatedCategories(categoryItem.ID);

            ISitecoreService glassMapper = GlassMapperService.Current;

            var categoryModels = categories.Select(item => glassMapper.CreateClass <CategoryModel>(false, false, item)).ToList();

            var model = new CategoryFacetModel(categoryModels, category, subCategory);

            if (!string.IsNullOrWhiteSpace(subCategory))
            {
                var foundModel = model.Categories.Where(c => c.ExternalID.Equals(subCategory, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                if (foundModel != null)
                {
                    this._catalogService.VisitedCategoryPage(subCategory, foundModel.Name);
                }
            }
            else
            {
                this._catalogService.VisitedCategoryPage(category, categoryItem.Name);
            }

            return(this.View(model));
        }
Exemplo n.º 13
0
        private IList <T> LoadItems()
        {
            Type type     = typeof(T);
            var  itemList = Utility.CreateGenericType(typeof(List <>), new Type[] { type }) as IList <T>;

            if (_getItems == null)
            {
                throw new NullReferenceException("No function to return items");
            }

            var items = _getItems.Invoke();

            if (items != null)
            {
                foreach (Item item in items.Where(x => x != null))
                {
                    var result = _service.CreateClass <T>(_isLazy, _inferType, item);
                    itemList.Add(result);
                }
            }

            return(itemList);
        }
Exemplo n.º 14
0
 public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
 {
     return(service.CreateClass(this.IsLazy, this.InferType, Property.PropertyType, item.Parent));
 }
        public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
        {

            string query = ParseQuery(Query, item);

            if (Property.PropertyType.IsGenericType)
            {
                Type outerType = Utility.GetGenericOuter(Property.PropertyType);

                if (typeof(IEnumerable<>) == outerType)
                {
                    Type genericType = Utility.GetGenericArgument(Property.PropertyType);
                    
                    Func<IEnumerable<Item>> getItems = null;
                    if (IsRelative)
                    {
                        getItems = new Func<IEnumerable<Item>>(() =>
                        {
                            return item.Axes.SelectItems(query);
                        });
                    }
                    else
                    {
                        getItems = new Func<IEnumerable<Item>>(() =>
                        {
                            return item.Database.SelectItems(query);
                        });
                    }

                    return service.CreateClasses(IsLazy, InferType, genericType, getItems);
                }
                else throw new NotSupportedException("Generic type not supported {0}. Must be IEnumerable<>.".Formatted(outerType.FullName));
            }
            else
            {
                Item result = null;
                if (IsRelative)
                {
                    result = item.Axes.SelectSingleItem(query);
                }
                else
                {
                    result = item.Database.SelectSingleItem(query);
                }
                return service.CreateClass(IsLazy, InferType, Property.PropertyType, result);
            }

        }
 public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
 {
     return service.CreateClass(this.IsLazy, this.InferType, Property.PropertyType, item.Parent);
 }
Exemplo n.º 17
0
        public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
        {
            string query = ParseQuery(Query, item);

            if (Property.PropertyType.IsGenericType)
            {
                Type outerType = Utility.GetGenericOuter(Property.PropertyType);

                if (typeof(IEnumerable <>) == outerType)
                {
                    Type genericType = Utility.GetGenericArgument(Property.PropertyType);

                    Func <IEnumerable <Item> > getItems = null;
                    if (IsRelative)
                    {
                        getItems = new Func <IEnumerable <Item> >(() =>
                        {
                            return(item.Axes.SelectItems(query));
                        });
                    }
                    else
                    {
                        getItems = new Func <IEnumerable <Item> >(() =>
                        {
                            if (UseQueryContext)
                            {
                                Query conQuery            = new Query(query);
                                QueryContext queryContext = new QueryContext(item.Database.DataManager);

                                object obj = conQuery.Execute(queryContext);
                                QueryContext[] contextArray = obj as QueryContext[];
                                QueryContext context        = obj as QueryContext;

                                if (contextArray == null)
                                {
                                    contextArray = new QueryContext[] { context }
                                }
                                ;

                                return(contextArray.Select(x => item.Database.GetItem(x.ID)));
                            }
                            else
                            {
                                return(item.Database.SelectItems(query));
                            }
                        });
                    }

                    return(service.CreateClasses(IsLazy, InferType, genericType, getItems));
                }
                else
                {
                    throw new NotSupportedException("Generic type not supported {0}. Must be IEnumerable<>.".Formatted(outerType.FullName));
                }
            }
            else
            {
                Item result = null;
                if (IsRelative)
                {
                    result = item.Axes.SelectSingleItem(query);
                }
                else
                {
                    result = item.Database.SelectSingleItem(query);
                }
                return(service.CreateClass(IsLazy, InferType, Property.PropertyType, result));
            }
        }
        public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
        {

            string query = ParseQuery(Query, item);

            if (Property.PropertyType.IsGenericType)
            {
                Type outerType = Utility.GetGenericOuter(Property.PropertyType);

                if (typeof(IEnumerable<>) == outerType)
                {
                    Type genericType = Utility.GetGenericArgument(Property.PropertyType);
                    
                    Func<IEnumerable<Item>> getItems = null;
                    if (IsRelative)
                    {
                        getItems = new Func<IEnumerable<Item>>(() =>
                        {
                            return item.Axes.SelectItems(query);
                        });
                    }
                    else
                    {
                        getItems = new Func<IEnumerable<Item>>(() =>
                        {
                            if (UseQueryContext)
                            {
                                Query conQuery = new Query(query);
                                QueryContext queryContext = new QueryContext(item.Database.DataManager);

                                object obj = conQuery.Execute(queryContext);
                                QueryContext[] contextArray = obj as QueryContext[];
                                QueryContext context = obj as QueryContext;

                                if (contextArray == null)
                                    contextArray = new QueryContext[] { context };

                                return contextArray.Select(x => item.Database.GetItem(x.ID));
                            }
                            else
                                return item.Database.SelectItems(query);
                        });
                    }

                    return service.CreateClasses(IsLazy, InferType, genericType, getItems);
                }
                else throw new NotSupportedException("Generic type not supported {0}. Must be IEnumerable<>.".Formatted(outerType.FullName));
            }
            else
            {
                Item result = null;
                if (IsRelative)
                {
                    result = item.Axes.SelectSingleItem(query);
                }
                else
                {
                    result = item.Database.SelectSingleItem(query);
                }
                return service.CreateClass(IsLazy, InferType, Property.PropertyType, result);
            }

        }