コード例 #1
0
 public void InitDB()
 {
     lock (_dbLock)
     {
         int reTry = 3;
         X1LogHelper.Log($"InitDB [{_dbName}] [{typeof(T).FullName}]");
         Exception ex = null;
         while (reTry-- > 0)
         {
             try
             {
                 Connection = PersistentDataHelper.Instance.GetConnection(_isGlobal, _dbName);
                 Connection?.CreateTable <T>();
                 return;
             }
             catch (Exception e)
             {
                 ex = e;
             }
         }
         X1LogHelper.Error("InitDB failed");
         if (ex != null)
         {
             X1LogHelper.Exception(ex);
         }
     }
 }
コード例 #2
0
 public void SaveText(string path, string text)
 {
     try
     {
         File.WriteAllText(path, text);
     }
     catch (Exception ex)
     {
         X1LogHelper.Error(ex.Message);
     }
 }
コード例 #3
0
        void OnAuthError(object sender, AuthenticatorErrorEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;

            if (authenticator != null)
            {
                authenticator.Completed -= OnAuthCompleted;
                authenticator.Error     -= OnAuthError;
            }
            X1LogHelper.Error(e.Message);
        }
コード例 #4
0
 public Stream LoadEntiry(string id)
 {
     try
     {
         return(LoadContent(GetEntityPath(id)));
     }
     catch (Exception ex)
     {
         X1LogHelper.Error(ex.Message);
     }
     return(null);
 }
コード例 #5
0
        public long GetFileLength(string path)
        {
            try
            {
                return(new FileInfo(path).Length);
            }
            catch (Exception ex)
            {
                X1LogHelper.Error(ex.Message);
            }

            return(0);
        }
コード例 #6
0
 public string LoadText(string path)
 {
     try
     {
         if (File.Exists(path))
         {
             return(File.ReadAllText(path));
         }
     }
     catch (Exception ex)
     {
         X1LogHelper.Error(ex.Message);
     }
     return(string.Empty);
 }
コード例 #7
0
 public Stream LoadContent(string path)
 {
     try
     {
         if (File.Exists(path))
         {
             return(new FileStream(path, FileMode.Open, FileAccess.Read));
         }
     }
     catch (Exception ex)
     {
         X1LogHelper.Error(ex.Message);
     }
     return(null);
 }
コード例 #8
0
 public bool DeleteEntiry(string id)
 {
     try
     {
         var path = GetEntityPath(id);
         if (File.Exists(path))
         {
             File.Delete(path);
         }
     }
     catch (Exception ex)
     {
         X1LogHelper.Error(ex.Message);
     }
     return(false);
 }
コード例 #9
0
 public bool SaveEntiry(string id, Stream data)
 {
     try
     {
         using (var stream = new FileStream(GetEntityPath(id), FileMode.Create))
         {
             data.Position = 0;
             data.CopyTo(stream);
             return(true);
         }
     }
     catch (Exception ex)
     {
         X1LogHelper.Error(ex.Message);
     }
     return(false);
 }
コード例 #10
0
 public SQLiteConnectionWithLock GetConnection(bool isGlobal, string dbName)
 {
     lock (_connectionLock)
     {
         try
         {
             string connectionKey = GetDataBasePath(isGlobal, dbName);
             SQLiteConnectionWithLock connection;
             if (!_connections.TryGetValue(connectionKey, out connection))
             {
                 connection = new SecureSqLiteConnectionWithLock(
                     new SQLiteConnectionString(connectionKey, true, connectionKey), SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.Create);
                 _connections[connectionKey] = connection;
             }
             return(connection);
         }
         catch (TypeInitializationException e)
         {
             X1LogHelper.Exception(e);
             X1LogHelper.Error("Please try to rebuild entire service package when this happens");
             throw;
         }
     }
 }
コード例 #11
0
 public bool SaveContent(string path, Stream data)
 {
     try
     {
         using (var stream = new FileStream(path, FileMode.Create))
         {
             try
             {
                 data.Position = 0;
             }
             catch (Exception ex)
             {
                 X1LogHelper.Error(ex.Message);
             }
             data.CopyTo(stream);
             return(true);
         }
     }
     catch (Exception ex)
     {
         X1LogHelper.Exception(ex);
     }
     return(false);
 }