Beispiel #1
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);
        }