示例#1
0
        public static IList <T> LoadAll <T>(this RepositoryData item, SchemaPurpose[] schemaPurposesToInclude = null) where T : RepositoryLocalObjectData
        {
            Logger.Debug("Loading {0} for {1}", typeof(T).Name, item.Title);

            string filename  = string.Format("{0} - {1}.txt", typeof(T).Name, item.Title);
            var    subFolder = "Instances";
            var    items     = FileCache.LoadFromFile <IList <T> >(filename, subFolder);

            if (items == null)
            {
                items = TridionCoreServiceFactory.GetList <T>(item.Id, new RepositoryItemsFilterData
                {
                    BaseColumns    = ListBaseColumns.Extended,
                    ItemTypes      = new[] { ItemTypeResolver.GetItemType(typeof(T)) },
                    Recursive      = true,
                    SchemaPurposes = schemaPurposesToInclude,
                    ShowNewItems   = true
                });

                //Remove Local Copies
                items = items.Where(x => x.BluePrintInfo.IsShared == false || x.BluePrintInfo.IsLocalized == true).ToList();
                Logger.Debug("Found {0} {1} for {2}", items.Count, typeof(T).Name, item.Title);
                FileCache.SaveToFile(filename, items, subFolder);
            }
            else
            {
                Logger.Debug("Loading {0} {1} for {2} from cache", items.Count(), typeof(T).Name, item.Title);
                Logger.Debug("CACHE: {0},{1},{2}", items.Count(), typeof(T).Name, item.Title);
            }
            return(items);
        }
示例#2
0
        public static IList <T> GetAllUsages <T>(this IdentifiableObjectData item, Expression <Func <T, bool> > filterPredicate = null, UsingItemsFilterData filter = null) where T : IdentifiableObjectData
        {
            Logger.Debug("Loading usages of {0} for {1}", typeof(T).Name, item.Title);

            string filename  = string.Format("{0} - {1} - {2}.txt", item.GetType().Name, typeof(T).Name, item.Title);
            var    subFolder = "Usages";
            var    items     = FileCache.LoadFromFile <IList <T> >(filename, subFolder);

            if (items == null)
            {
                if (filter == null)
                {
                    filter = new UsingItemsFilterData
                    {
                        ItemTypes          = new[] { ItemTypeResolver.GetItemType(typeof(T)) },
                        IncludedVersions   = VersionCondition.OnlyLatestAndCheckedOutVersions,
                        IncludeLocalCopies = false,
                        BaseColumns        = ListBaseColumns.Extended
                    };
                }
                items = TridionCoreServiceFactory.GetList <T>(item.Id, filter);
                Logger.Debug("Found {0} {1} for {2}", items.Count, typeof(T).Name, item.Title);
                FileCache.SaveToFile(filename, items, subFolder);
            }
            else
            {
                Logger.Debug("Loading usages of {0} for {1} from cache", typeof(T).Name, item.Title);
            }

            if (filterPredicate != null)
            {
                items = items.AsQueryable().Where(filterPredicate).ToList();
            }

            return(items);
        }