示例#1
0
        public override void Process(GetModelArgs args)
        {
            if (args.Result != null)
            {
                return;
            }

            Type modelType = this.GetModelVromViewPath(args.Rendering, args);

            if (modelType == null || !typeof(IGlassBase).IsAssignableFrom(modelType))
            {
                return;
            }


            var        sitecoreContext = this.SitecoreContext();
            IGlassBase createdInstance = GetInstanceFromContext(args.Rendering, sitecoreContext);

            if (modelType.IsInstanceOfType(createdInstance))
            {
                args.Result = createdInstance;
            }

            // else if model type is not type of created instance.

            args.AbortPipeline();
        }
        private string GetKeyName(ITaxonomy_Item item)
        {
            IGlassBase parent = item._Parent;

            while (!parent._TemplateId.Equals(_dependencies.ItemReferences.FolderTemplate) || parent._Name.ToLower().Equals("content"))
            {
                parent = parent._Parent;
            }

            if (parent._Id.Equals(_dependencies.ItemReferences.DeviceAreasTaxonomyFolder))
            {
                return("deviceareas");
            }
            else if (parent._Id.Equals(_dependencies.ItemReferences.TherapyAreasTaxonomyFolder))
            {
                return("areas");
            }
            else if (parent._Id.Equals(_dependencies.ItemReferences.SubjectsTaxonomyFolder))
            {
                return("subjects");
            }
            else if (parent._Id.Equals(_dependencies.ItemReferences.RegionsTaxonomyFolder))
            {
                return("regions");
            }
            else
            {
                return("value");
            }
        }
示例#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 Setup()
        {
            _rendering                  = Substitute.For <Rendering>();
            _renderingContext           = Substitute.ForPartsOf <RenderingContext>();
            _renderingContext.Rendering = _rendering;

            _disposableRenderingContext = ContextService.Get().Push(_renderingContext);

            _directDatasource     = Substitute.For <IGlassBase>();
            _staticItemDatasource = Substitute.For <IGlassBase>();
            _nestedItemDatasource = Substitute.For <IGlassBase>();
            _contextItem          = Substitute.For <IGlassBase>();

            _directDatasource._Id.Returns(Guid.NewGuid());
            _staticItemDatasource._Id.Returns(Guid.NewGuid());
            _nestedItemDatasource._Id.Returns(Guid.NewGuid());
            _contextItem._Id.Returns(Guid.NewGuid());

            var mockGlassHtml = Substitute.For <IGlassHtml>();

            _sitecoreContext = Substitute.For <ISitecoreContext>();

            // SUT
            _renderingService = new RenderingContextService(mockGlassHtml, _sitecoreContext);
        }
示例#5
0
        public Guid ReturnSourceID(IGlassBase i)
        {
            if (i == null)
            {
                return(Guid.Empty);
            }

            Item itm = _dependencies.SitecoreServiceMaster.GetItem <Item>(i._Id);

            if (itm == null)
            {
                return(Guid.Empty);
            }

            Field f = itm.Fields[Sitecore.FieldIDs.Source];

            if (f == null)
            {
                return(Guid.Empty);
            }

            if (!ItemUri.IsItemUri(f.Value))
            {
                return(Guid.Empty);
            }

            return(ItemUri.Parse(f.Value).ItemID.Guid);
        }
示例#6
0
        public IEnumerable <IGlassBase> GetValidLinkTargets(IGlassBase glassItem)
        {
            var item = _service.GetItem <Item>(glassItem._Id, glassItem._Language);

            var links = item.Links.GetValidLinks();

            return(links.Select(link => link.GetTargetItem().GlassCast <IGlassBase>(inferType: true)));
        }
示例#7
0
        public T GetItem <T>(IGlassBase model) where T : class
        {
            var implType = GetItemFromInterface(model, typeof(T));

            return(implType != null
                                ? _factory.Create <T, IGlassBase>(implType, model)
                                : default(T));
        }
示例#8
0
        public override object GetFieldValue(IGlassBase glassItem)
        {
            var model = _interfaceFactory.GetItem <T>(glassItem);

            return(model == null
                                ? null
                                : GetFieldValue(model));
        }
示例#9
0
        private Type GetItemFromInterface(IGlassBase item, Type interfaceType)           // interfaceType: this will be non-generic type, ie. IListable
        {
            if (item == null || interfaceType == null)
            {
                return(null);
            }

            return(_templateCache.GetImplementingTypeForItem(item, interfaceType));
        }
示例#10
0
        public IEnumerable <IGlassBase> GetReferrers(IGlassBase glassItem)
        {
            var item = _service.GetItem <Item>(glassItem._Id, glassItem._Language);

            var links          = Globals.LinkDatabase.GetReferrers(item);
            var linkReferences = links.Select(i => _service.GetItem <IGlassBase>(i.SourceItemID.Guid, i.SourceItemLanguage, inferType: true)).Where(i => i != null);

            return(linkReferences);
        }
        public static Item ToItem(this IGlassBase entity)
        {
            if (entity == null)
            {
                return(null);
            }

            return(Context.Database.GetItem(new ID(entity.Id)));
        }
        public static String AttachFieldRender(this IGlassBase content, string fieldName)
        {
            // Experience Editor support
            if (Sitecore.Context.PageMode.IsExperienceEditorEditing)
            {
                var relatedItem = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(content.Id));
                return(FieldRenderer.Render(relatedItem, fieldName));
            }

            return(string.Empty);
        }
        private static Parameter[] GetModelConstructorParams(Type glassModelType, IGlassBase glassModel, Type renderingModelType = null, object renderingModel = null)
        {
            var parameterArray = glassModel == null || glassModelType == null
                ? new Parameter[0]
                : new Parameter[] { new TypedParameter(glassModelType, glassModel) };

            return(renderingModelType == null || renderingModel == null
                ? parameterArray
                : parameterArray
                   .Concat(new[] { new TypedParameter(renderingModelType, renderingModel) })
                   .ToArray());
        }
示例#14
0
        public static T Crawl <T>(this IGlassBase item, Func <IGlassBase, bool> func) where T : class
        {
            if (item == null)
            {
                return(default(T));
            }

            if (item is T && (func == null || func(item)))
            {
                return(item as T);
            }

            return(item._Parent.Crawl <T>(func));
        }
示例#15
0
        public static IEnumerable <T> GetAncestors <T>(this IGlassBase item) where T : class, IGlassBase
        {
            if (item == null)
            {
                yield break;
            }

            for (IGlassBase parent = item._Parent; parent != null; parent = parent._Parent)
            {
                var navItem = parent as T;
                if (navItem != null)
                {
                    yield return(navItem);
                }
            }
        }
示例#16
0
        private void Initialize(IGlassBase page, ISearchRuleParser ruleParser)
        {
            RuleParser = ruleParser;

            _listConfig  = new Lazy <I_Listing_Configuration>(() => page as I_Listing_Configuration);
            _sortOptions = new Lazy <IEnumerable <ISort> >(() => ListingConfiguration.Available_Sort_Options);

            var refineConfig = page as ISearch_Refinements;

            _refinementOptions = new Lazy <IEnumerable <I_Refinement> >(() =>
            {
                if (refineConfig != null)
                {
                    return(refineConfig.Refinements);
                }

                return(new I_Refinement[0]);
            });
        }
示例#17
0
        public SearchPageParser(string pageId, ISitecoreContext context, ISearchRuleParser ruleParser)
        {
            IGlassBase page = null;

            if (!string.IsNullOrEmpty(pageId))
            {
                page = context.GetItem <IGlassBase>(pageId, inferType: true);
            }

            if (page == null)
            {
                page = context.GetCurrentItem <IGlassBase>(inferType: true);
            }

            if (!(page is I_Listing_Configuration) && RenderingContext.CurrentOrNull != null)
            {
                page = context.GetItem <IGlassBase>(RenderingContext.Current.Rendering.DataSource, inferType: true);
            }

            Initialize(page, ruleParser);
        }
        protected void GenerateEntry(GetTranslationArgs args)
        {
            //Move to reference or config
            IDictionary_Domain generated =
                SitecoreService.GetItem <IDictionary_Domain>(ItemReferences.GeneratedDictionary);

            if (generated == null)
            {
                return;
            }

            var key           = args.Key;
            var dictionaryKey = key.Split('.');

            IGlassBase        lastItem = generated;
            IDictionary_Entry newEntry = null;
            int total = dictionaryKey.Length;

            using (new SecurityDisabler())
            {
                int i = 0;
                foreach (var k in dictionaryKey)
                {
                    i++;
                    var lookup = lastItem._ChildrenWithInferType.FirstOrDefault(x => x._Name == k);
                    if (lookup is IDictionary_Entry)
                    {
                        var entry  = (lookup as IDictionary_Entry);
                        var phrase = entry.Phrase;

                        if (string.IsNullOrEmpty(phrase))
                        {
                            phrase       = key;
                            entry.Phrase = phrase;
                            SitecoreService.Save(entry);
                        }

                        args.Result = string.IsNullOrEmpty(phrase) ? key : phrase;
                        return;
                    }
                    if (lookup != null)
                    {
                        lastItem = lookup;
                    }
                    else
                    {
                        if (i < total)
                        {
                            lastItem = SitecoreService.Create <IDictionary_Folder, IGlassBase>(lastItem, k);
                        }
                        else
                        {
                            newEntry = SitecoreService.Create <IDictionary_Entry, IGlassBase>(lastItem, k);
                        }
                    }
                }

                if (newEntry == null)
                {
                    return;
                }

                newEntry.Key    = key;
                newEntry.Phrase = key;
                SitecoreService.Save(newEntry);
            }
            args.Result = key;
            return;
        }
示例#19
0
 public SearchPageParser(IGlassBase page, ISearchRuleParser ruleParser)
 {
     Initialize(page, ruleParser);
 }
示例#20
0
 public IEnumerable <INavigation_Link> GetChildLinkItems(IGlassBase item)
 {
     return(item._ChildrenWithInferType.OfType <INavigation_Link>());
 }
示例#21
0
 /// <summary>
 /// Return base Item object from glass interface
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public static Item GetItem(this IGlassBase item) => Context.Database.GetItem(item.Id);
示例#22
0
 public static T Crawl <T>(this IGlassBase item) where T : class
 {
     return(item.Crawl <T>(null));
 }
示例#23
0
 public AccountNavViewModel(ISitecoreContext sitecoreContext)
 {
     _currentItem    = sitecoreContext.GetCurrentItem <IGlassBase>();
     NavigationItems = _currentItem._Parent._ChildrenWithInferType.OfType <I___BasePage>();
 }
示例#24
0
 public static T Parent <T>(this IGlassBase item) where T : class
 {
     return(HelperFactory().Parent <T>(item));
 }
示例#25
0
        public bool HasPresentation(IGlassBase glassItem)
        {
            var item = _service.GetItem <Item>(glassItem._Id, glassItem._Language);

            return(item != null && item[Sitecore.FieldIDs.LayoutField] != string.Empty);
        }
示例#26
0
 public static T FirstChild <T>(this IGlassBase item) where T : class
 {
     return(HelperFactory().FirstChild <T>(item));
 }
示例#27
0
        public IEnumerable <IGlassBase> GetAncestors(IGlassBase glassItem)
        {
            var item = _service.GetItem <Item>(glassItem._Id, glassItem._Language);

            return(item.Axes.GetAncestors().Select(sItem => _service.GetItem <IGlassBase>(sItem.ID.Guid, inferType: true)));
        }
 public Type GetImplementingTypeForItem(IGlassBase item, Type interfaceType)
 {
     return(GetImplementingTypeForTemplate(item._TemplateId, interfaceType));
 }
示例#29
0
        public bool IsMediaItem(IGlassBase glassItem)
        {
            var item = _service.GetItem <Item>(glassItem._Id, glassItem._Language);

            return(item != null && item.Paths.IsMediaItem);
        }
示例#30
0
 public string GetMediaUrl(IGlassBase glassItem) => glassItem != null?GetMediaUrl(glassItem._Id) : null;