示例#1
0
        private void ReadCacheFromDisk()
        {
            logger.Trace("ReadCacheFromDisk Path:{0}", cachePath.ToString());

            ConnectionCacheItem[] connections = null;

            if (cachePath.FileExists())
            {
                var json = cachePath.ReadAllText();
                try
                {
                    connections = SimpleJson.DeserializeObject <ConnectionCacheItem[]>(json);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error deserializing connection cache: {0}", cachePath);
                    cachePath.Delete();
                }
            }

            if (connections != null)
            {
                connectionCache =
                    connections.Select(item => new Connection {
                    Host = new UriString(item.Host), Username = item.Username
                })
                    .ToDictionary(connection => connection.Host);
            }
            else
            {
                connectionCache = new Dictionary <UriString, Connection>();
            }
        }
示例#2
0
        public UsageStore Load(string userId)
        {
            UsageStore result = null;
            string     json   = null;

            if (path.FileExists())
            {
                try
                {
                    json   = path.ReadAllText(Encoding.UTF8);
                    result = json?.FromJson <UsageStore>(lowerCase: true);
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.Warning(ex, "Error Loading Usage: {0}; Deleting File", path);
                    try
                    {
                        path.DeleteIfExists();
                    }
                    catch { }
                }
            }

            if (result == null)
            {
                result = new UsageStore();
            }

            if (String.IsNullOrEmpty(result.Model.Guid))
            {
                result.Model.Guid = userId;
            }

            return(result);
        }
示例#3
0
文件: Utils.cs 项目: willofd02/Unity
        public static bool VerifyFileIntegrity(NPath file, NPath md5file)
        {
            var expected = md5file.ReadAllText();
            var actual   = file.CalculateMD5();

            return(expected.Equals(actual, StringComparison.InvariantCultureIgnoreCase));
        }
示例#4
0
        private UsageStore LoadUsage()
        {
            UsageStore result = null;
            string     json   = null;

            if (storePath.FileExists())
            {
                Logger.Trace("LoadUsage: \"{0}\"", storePath);

                try
                {
                    json = storePath.ReadAllText(Encoding.UTF8);
                    if (json != null)
                    {
                        result = SimpleJson.DeserializeObject <UsageStore>(json);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Warning(ex, "Error Loading Usage: {0}; Deleting File", storePath);

                    try
                    {
                        storePath.DeleteIfExists();
                    }
                    catch {}
                }
            }

            if (result == null)
            {
                result = new UsageStore();
            }

            if (String.IsNullOrEmpty(result.Model.Guid))
            {
                result.Model.Guid = guid;
            }

            return(result);
        }
示例#5
0
 private void LoadConnectionsFromDisk()
 {
     if (cachePath.FileExists())
     {
         var json = cachePath.ReadAllText();
         try
         {
             var conns = json.FromJson <Connection[]>();
             UpdateConnections(conns);
         }
         catch (IOException ex)
         {
             logger.Error(ex, "Error reading connection cache: {0}", cachePath);
         }
         catch (Exception ex)
         {
             logger.Error(ex, "Error deserializing connection cache: {0}", cachePath);
             // try to fix the corrupted file with the data we have
             SaveConnectionsToDisk(raiseChangedEvent: false);
         }
     }
 }
示例#6
0
文件: Keychain.cs 项目: snaami/Unity
 private void LoadConnectionsFromDisk()
 {
     //logger.Trace("ReadCacheFromDisk Path:{0}", cachePath.ToString());
     if (cachePath.FileExists())
     {
         var json = cachePath.ReadAllText();
         try
         {
             var conns = SimpleJson.DeserializeObject <Connection[]>(json);
             UpdateConnections(conns);
         }
         catch (IOException ex)
         {
             logger.Error(ex, "Error reading connection cache: {0}", cachePath);
         }
         catch (Exception ex)
         {
             logger.Error(ex, "Error deserializing connection cache: {0}", cachePath);
             // try to fix the corrupted file with the data we have
             SaveConnectionsToDisk(raiseChangedEvent: false);
         }
     }
 }