/// <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); }