예제 #1
0
 public virtual T CachedUserGet <T>()
     where T : class
 {
     try
     {
         ICacheFileStore fileStore = this.GetFileStore();
         string          path      = GenerateUserLocation(USER_CACHE_FILENAME);
         if (fileStore.Exists(path))
         {
             string protectedString = string.Empty;
             fileStore.TryReadTextFile(path, out protectedString);
             if (!string.IsNullOrEmpty(protectedString))
             {
                 string unProtectedString = protectedString;
                 return(JsonConvert.DeserializeObject <T>(unProtectedString, new JsonSerializerSettings
                 {
                     TypeNameHandling = TypeNameHandling.All,
                 }));
             }
         }
         return(null);
     }
     catch (Exception ex)
     {
         base.LogError(ex, "CachedUserGet");
         return(null);
     }
 }
예제 #2
0
        public virtual bool PersistentDataSet <T>(bool secure, string fileName, T item)
        {
            try
            {
                ICacheFileStore fileStore = this.GetFileStore();
                string          path      = GeneratePersistentCacheLocation(fileName);

                string unProtectedString = JsonConvert.SerializeObject(item);
                string protectedString   = unProtectedString;
                if (secure)
                {
                    if (!string.IsNullOrEmpty(unProtectedString))
                    {
                        protectedString = unProtectedString;
                    }
                }
                lock (_persistLock)
                {
                    fileStore.EnsureFolderExists(Path.GetDirectoryName(path));
                    fileStore.WriteFile(path, protectedString);
                }
                return(true);
            }
            catch (Exception ex)
            {
                this.LogError(ex, "PersistentDataSet");
                return(false);
            }
        }
예제 #3
0
 /// <summary>
 /// Not the standard IoC, but it'll work just fine
 /// </summary>
 public static void RegisterDependencies(ICacheFileStore cacheStore, ICacheHost cacheHost, IEscapeApp escapeApp, IViewPlatform platform)
 {
     Container.ViewPlatform = platform;
     Container.EscapeApp    = escapeApp;
     Container.CacheStore   = cacheStore;
     Container.CacheHost    = cacheHost;
     Container.ViewPlatform = platform;
 }
예제 #4
0
        public virtual void CachedUserClear()
        {
            ICacheFileStore fileStore = this.GetFileStore();
            string          path      = GenerateUserLocation(USER_CACHE_FILENAME);

            if (fileStore.Exists(path))
            {
                fileStore.DeleteFile(path);
            }
        }
예제 #5
0
 public virtual void CachedDataClear()
 {
     try
     {
         ICacheFileStore fileStore = this.GetFileStore();
         string          path      = GenerateDataCacheLocation("ignore");
         lock (_persistLock)
         {
             if (fileStore.FolderExists(Path.GetDirectoryName(path)))
             {
                 fileStore.DeleteFolder(Path.GetDirectoryName(path), true);
             }
         }
     }
     catch (Exception ex)
     {
         this.LogError(ex, "CachedDataClear");
     }
 }
예제 #6
0
        public virtual void CachedUserSet <T>(T user)
            where T : class
        {
            try
            {
                ICacheFileStore fileStore = this.GetFileStore();
                string          path      = GenerateUserLocation(USER_CACHE_FILENAME);

                string unProtectedString = JsonConvert.SerializeObject(user);
                string protectedString   = string.Empty;
                if (!string.IsNullOrEmpty(unProtectedString))
                {
                    protectedString = unProtectedString;
                }
                fileStore.EnsureFolderExists(Path.GetDirectoryName(path));
                fileStore.WriteFile(path, protectedString);
            }
            catch (Exception ex)
            {
                base.LogError(ex, "CachedUserSet");
            }
        }
예제 #7
0
        public virtual T PersistentDataGet <T>(bool secured, string fileName)
        {
            try
            {
                ICacheFileStore fileStore = this.GetFileStore();
                string          path      = GeneratePersistentCacheLocation(fileName);

                string protectedString = string.Empty;
                lock (_persistLock)
                {
                    if (fileStore.Exists(path))
                    {
                        fileStore.TryReadTextFile(path, out protectedString);
                    }
                }
                if (!string.IsNullOrEmpty(protectedString))
                {
                    string unProtectedString = protectedString;
                    if (secured)
                    {
                        unProtectedString = protectedString;
                    }
                    if (!string.IsNullOrEmpty(unProtectedString))
                    {
                        return(JsonConvert.DeserializeObject <T>(unProtectedString, new JsonSerializerSettings
                        {
                            TypeNameHandling = TypeNameHandling.All,
                        }));
                    }
                }
                return(default(T));
            }
            catch (Exception ex)
            {
                this.LogError(ex, "PersistentDataGet");
                return(default(T));
            }
        }