示例#1
0
        /// <summary>
        /// Processes the items.
        /// </summary>
        /// <returns>IEnumerable{`0}.</returns>
        public virtual List <T> ProcessItems()
        {
            if (_service == null)
            {
                throw new NullReferenceException("SitecoreService has not been set");
            }

            var items = _options.GetItems(_service.Database);



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

            items = items.ToArray();

            var results = new List <T>();

            var options = new GetItemByItemOptions();

            options.Copy(_options);
            //we have to copy these properties to the sub item because
            //normally they are not applied to the whole graph
            options.TemplateId      = _options.TemplateId;
            options.EnforceTemplate = _options.EnforceTemplate;


            foreach (Item child in items)
            {
                options.Item = child;
                var obj = _service.GetItem(options) as T;

                if (obj == null)
                {
                    continue;
                }

                results.Add(obj);
            }

            //release the service after full enumeration
            _service = null;

            return(results);
        }
        public virtual T CreateModel <T>(NameValueCollection parameters, ID renderParametersTemplateId) where T : class
        {
            var item = Utilities.CreateFakeItem(null, renderParametersTemplateId, _sitecoreService.Database, "renderingParameters");

            using (new SecurityDisabler())
            {
                using (new EventDisabler())
                {
                    if (parameters != null)
                    {
                        item.Editing.BeginEdit();
                        item.RuntimeSettings.Temporary = true;
                        foreach (var key in parameters.AllKeys)
                        {
                            var fld = item.Fields[key];
                            if (fld != null)
                            {
                                fld.SetValue(parameters[key], true);
                            }
                        }
                    }

                    var options = new GetItemByItemOptions
                    {
                        Item = item,
                        //this must be only reference properties to force the fake item to be read before it is deleted
                        //it isn't possible lazy load the top level
                        Lazy         = LazyLoading.OnlyReferenced,
                        VersionCount = false
                    };
                    T obj = _sitecoreService.GetItem <T>(options);

                    item.Editing.CancelEdit();

                    if (_sitecoreService.Config.DeleteRenderingParameterItems)
                    {
                        item.Delete(); //added for clean up
                    }

                    return(obj);
                }
            }
        }
        /// <summary>
        /// Processes the items.
        /// </summary>
        /// <returns>IEnumerable{`0}.</returns>
        public virtual List <T> ProcessItems()
        {
            if (_service == null)
            {
                throw new NullReferenceException("SitecoreService has not been set");
            }

            var items = _options.GetItems(_service.Database);



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

            items = items.ToArray();

            var results = new List <T>();

            var options = new GetItemByItemOptions();

            options.Copy(_options);

            foreach (Item child in items)
            {
                options.Item = child;
                var obj = _service.GetItem(options) as T;

                if (obj == null)
                {
                    continue;
                }

                results.Add(obj);
            }

            //release the service after full enumeration
            _service = null;

            return(results);
        }