Beispiel #1
0
        internal void GetArchivedTemplate(TemplateData fileAccessor, T item)
        {
            string typeName     = typeof(T).Name;
            Type   templateType = typeof(T);

            if (typeof(T).IsInterface)
            {
                typeName     = typeName.Substring(1);
                templateType = typeof(EntityPartial).Assembly.GetTypes().SingleOrDefault(x => !x.IsAbstract && x.GetInterfaces().Contains(typeof(T)));
            }

            DirectoryInfo archiveDir = new DirectoryInfo(fileAccessor.BaseDirectory + fileAccessor.ArchiveDirectoryName + ArchivePath + "/" + typeName + "/");

            FileInfo[] potentialFiles = archiveDir.GetFiles(item.Id + "." + typeName);

            if (potentialFiles.Any())
            {
                DataTemplate = (T)fileAccessor.ReadEntity(potentialFiles.First(), templateType);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Dumps everything of a single type into the cache from the filesystem for BackingData
        /// </summary>
        /// <typeparam name="T">the type to get and store</typeparam>
        /// <returns>full or partial success</returns>
        public static bool LoadAllToCache(Type objectType)
        {
            if (!objectType.GetInterfaces().Contains(typeof(IKeyedData)))
            {
                return(false);
            }

            TemplateData fileAccessor  = new TemplateData();
            string       typeDirectory = fileAccessor.BaseDirectory + fileAccessor.CurrentDirectoryName + objectType.Name + "/";

            if (!fileAccessor.VerifyDirectory(typeDirectory, false))
            {
                return(false);
            }

            DirectoryInfo filesDirectory = new DirectoryInfo(typeDirectory);

            foreach (FileInfo file in filesDirectory.EnumerateFiles())
            {
                try
                {
                    IKeyedData entity = fileAccessor.ReadEntity(file, objectType);

                    if (entity != null)
                    {
                        entity.PersistToCache();
                    }
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                    //Let it keep going
                }
            }

            return(true);
        }