/// <summary> /// Save the configuration of the Sync SQLite Database /// </summary> /// <param name="configuration">Sync Configuration </param> internal void SaveConfiguration(SQLiteConfiguration configuration) { XElement xScopeInfoTable = new XElement("ScopeInfoTable"); // Create Types xml doc. foreach (var t in configuration.Types) { xScopeInfoTable.Add(new XElement("Types", t)); } XDocument doc = new XDocument(xScopeInfoTable); var scopeInfoTable = new ScopeInfoTable { ScopeName = configuration.ScopeName, ServiceUri = configuration.ServiceUri.AbsoluteUri, Configuration = doc.ToString(), AnchorBlob = configuration.AnchorBlob, LastSyncDate = configuration.LastSyncDate }; // Saving Configuration using (var connection = SQLitePCL.pretty.SQLite3.Open(localFilePath)) { try { string tableScope = connection.Query(SQLiteConstants.ScopeExist).Select(r => r[0].ToString()).FirstOrDefault(); bool scopeTableExist = tableScope == "ScopeInfoTable"; if (scopeTableExist) { String commandSelect = "Select * From ScopeInfoTable Where ScopeName = ?;"; var exist = connection.Query(commandSelect, SQLiteHelper.P(configuration.ScopeName)).Select(r => true).Any(); string stmtText = exist ? "Update ScopeInfoTable Set ServiceUri = ?, LastSyncDate = ?, Configuration = ?, AnchorBlob = ? Where ScopeName = ?;" : "Insert into ScopeInfoTable (ServiceUri, LastSyncDate, Configuration, AnchorBlob, ScopeName) Values (?, ?, ?, ?, ?);"; connection.Execute(stmtText, SQLiteHelper.P(scopeInfoTable.ServiceUri), SQLiteHelper.P(scopeInfoTable.LastSyncDate), SQLiteHelper.P(scopeInfoTable.Configuration), SQLiteHelper.P(scopeInfoTable.AnchorBlob), SQLiteHelper.P(scopeInfoTable.ScopeName)); } } catch (Exception ex) { throw new Exception("Impossible to save Sync Configuration", ex); } } }
/// <summary> /// Save the configuration of the Sync SQLite Database /// </summary> /// <param name="configuration">Sync Configuration </param> internal void SaveConfiguration(SQLiteConfiguration configuration) { XElement xScopeInfoTable = new XElement("ScopeInfoTable"); // Create Types xml doc. foreach (var t in configuration.Types) { xScopeInfoTable.Add(new XElement("Types", t)); } XDocument doc = new XDocument(xScopeInfoTable); var scopeInfoTable = new ScopeInfoTable { ScopeName = configuration.ScopeName, ServiceUri = configuration.ServiceUri.AbsoluteUri, Configuration = doc.ToString(), AnchorBlob = configuration.AnchorBlob, LastSyncDate = configuration.LastSyncDate }; // Saving Configuration using (var connection = new SQLiteConnection(localFilePath)) { try { String tableScope = null; using (var sqlCommand = connection.Prepare(SQLiteConstants.ScopeExist)) { if (sqlCommand.Step() == SQLiteResult.ROW) { tableScope = sqlCommand[0] as string; } } bool scopeTableExist = tableScope == "ScopeInfoTable"; if (scopeTableExist) { String commandSelect = "Select * From ScopeInfoTable Where ScopeName = ?;"; using (var stmtSelect = connection.Prepare(commandSelect)) { stmtSelect.Bind(1, configuration.ScopeName); var exist = stmtSelect.Step() == SQLiteResult.ROW; string stmtText = exist ? "Update ScopeInfoTable Set ServiceUri = ?, LastSyncDate = ?, Configuration = ?, AnchorBlob = ? Where ScopeName = ?;" : "Insert into ScopeInfoTable (ServiceUri, LastSyncDate, Configuration, AnchorBlob, ScopeName) Values (?, ?, ?, ?, ?);"; using (var stmt = connection.Prepare(stmtText)) { SQLiteHelper.BindParameter(stmt, 1, scopeInfoTable.ServiceUri); SQLiteHelper.BindParameter(stmt, 2, scopeInfoTable.LastSyncDate); SQLiteHelper.BindParameter(stmt, 3, scopeInfoTable.Configuration); SQLiteHelper.BindParameter(stmt, 4, scopeInfoTable.AnchorBlob); SQLiteHelper.BindParameter(stmt, 5, scopeInfoTable.ScopeName); stmt.Step(); } } } } catch (Exception ex) { throw new Exception("Impossible to save Sync Configuration", ex); } } }
/// <summary> /// Read Internal Configuration /// </summary> internal SQLiteConfiguration ReadConfiguration(string databaseScopeName) { SQLiteConfiguration configuration = new SQLiteConfiguration(); using (var connection = new SQLiteConnection(localFilePath)) { string s = null; List <String> t = new List <string>(); bool scopeInfoTableFounded; DateTime d = new DateTime(1900, 1, 1); Byte[] blob = null; try { string name = databaseScopeName; ScopeInfoTable scopeInfoTable = null; // Check if Scope Table Exist String tableScope = null; using (var sqlCommand = connection.Prepare(SQLiteConstants.ScopeExist)) { if (sqlCommand.Step() == SQLiteResult.ROW) { tableScope = sqlCommand[0] as String; } } bool scopeTableExist = tableScope == "ScopeInfoTable"; if (scopeTableExist) { String commandSelect = "Select * From ScopeInfoTable Where ScopeName = ?;"; using (var stmtSelect = connection.Prepare(commandSelect)) { stmtSelect.Bind(1, name); var exist = stmtSelect.Step() == SQLiteResult.ROW; if (exist) { scopeInfoTable = new ScopeInfoTable(); scopeInfoTable.ScopeName = (String)SQLiteHelper.ReadCol(stmtSelect, 0, typeof(String)); scopeInfoTable.ServiceUri = (String)SQLiteHelper.ReadCol(stmtSelect, 1, typeof(String)); scopeInfoTable.LastSyncDate = (DateTime)SQLiteHelper.ReadCol(stmtSelect, 2, typeof(DateTime)); scopeInfoTable.AnchorBlob = (Byte[])SQLiteHelper.ReadCol(stmtSelect, 3, typeof(Byte[])); scopeInfoTable.Configuration = (String)SQLiteHelper.ReadCol(stmtSelect, 4, typeof(String)); } } } if (scopeInfoTable == null) { return(null); } XDocument document = XDocument.Parse(scopeInfoTable.Configuration); s = scopeInfoTable.ServiceUri; t = (from tt in document.Descendants() where tt.Name == "Types" select tt.Value).ToList(); d = scopeInfoTable.LastSyncDate; blob = scopeInfoTable.AnchorBlob; scopeInfoTableFounded = true; } catch { scopeInfoTableFounded = false; } if (!scopeInfoTableFounded) { return(null); } // Configure Configuration en return it configuration.ScopeName = databaseScopeName; configuration.ServiceUri = new Uri(s); configuration.Types = t; configuration.LastSyncDate = d; configuration.AnchorBlob = blob; } return(configuration); }
/// <summary> /// Read Internal Configuration /// </summary> internal SQLiteConfiguration ReadConfiguration(string databaseScopeName) { SQLiteConfiguration configuration = new SQLiteConfiguration(); using (var connection = SQLitePCL.pretty.SQLite3.Open(localFilePath)) { string s = null; List <String> t = new List <string>(); bool scopeInfoTableFounded; DateTime d = new DateTime(1900, 1, 1); Byte[] blob = null; try { string name = databaseScopeName; ScopeInfoTable scopeInfoTable = null; // Check if Scope Table Exist string tableScope = connection.Query(SQLiteConstants.ScopeExist).Select(r => r[0].ToString()).FirstOrDefault(); bool scopeTableExist = tableScope == "ScopeInfoTable"; if (scopeTableExist) { String commandSelect = "Select * From ScopeInfoTable Where ScopeName = ?;"; foreach (var row in connection.Query(commandSelect, SQLiteHelper.P(name))) { scopeInfoTable = new ScopeInfoTable(); scopeInfoTable.ScopeName = (String)SQLiteHelper.ReadCol(row, 0, typeof(String)); scopeInfoTable.ServiceUri = (String)SQLiteHelper.ReadCol(row, 1, typeof(String)); scopeInfoTable.LastSyncDate = (DateTime)SQLiteHelper.ReadCol(row, 2, typeof(DateTime)); scopeInfoTable.AnchorBlob = (Byte[])SQLiteHelper.ReadCol(row, 3, typeof(Byte[])); scopeInfoTable.Configuration = (String)SQLiteHelper.ReadCol(row, 4, typeof(String)); } } if (scopeInfoTable == null) { return(null); } XDocument document = XDocument.Parse(scopeInfoTable.Configuration); s = scopeInfoTable.ServiceUri; t = (from tt in document.Descendants() where tt.Name == "Types" select tt.Value).ToList(); d = scopeInfoTable.LastSyncDate; blob = scopeInfoTable.AnchorBlob; scopeInfoTableFounded = true; } catch { scopeInfoTableFounded = false; } if (!scopeInfoTableFounded) { return(null); } // Configure Configuration en return it configuration.ScopeName = databaseScopeName; configuration.ServiceUri = new Uri(s); configuration.Types = t; configuration.LastSyncDate = d; configuration.AnchorBlob = blob; } return(configuration); }