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); } } }
public void SaveText(string path, string text) { try { File.WriteAllText(path, text); } catch (Exception ex) { X1LogHelper.Error(ex.Message); } }
void OnAuthError(object sender, AuthenticatorErrorEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } X1LogHelper.Error(e.Message); }
public Stream LoadEntiry(string id) { try { return(LoadContent(GetEntityPath(id))); } catch (Exception ex) { X1LogHelper.Error(ex.Message); } return(null); }
public long GetFileLength(string path) { try { return(new FileInfo(path).Length); } catch (Exception ex) { X1LogHelper.Error(ex.Message); } return(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); }
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); }
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); }
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); }
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; } } }
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); }