/// <summary> /// This method overwites all existing data in the database with data from synchronization request /// </summary> /// <param name = "containerData">Contains DTO object to save. Note! It's caller's responsibility to ensure that containerData is not null when calling this method.</param> public static void FullSync(SynchronizationDataContainer containerData) { Debug.Assert(containerData != null, "FullSync method requires containerData to not be null"); #if DEBUG Stopwatch sw = new Stopwatch(); sw.Start(); #endif lock (databaseWriteLocker) { try { using (var connection = OpenConnectionReadWrite()) { try { connection.BeginTransaction(); CreateTablesIfNotExist(connection); ReplaceRecords(connection, containerData); connection.Commit(); } catch (Exception ex) { // try catch for dev purpose / easier debuging Debug.WriteLine("Message: " + ex.Message); Debug.WriteLine("Stack: " + ex.StackTrace); Debug.WriteLine("Source: " + ex.Source); } } } catch (Exception e) { throw e; } } #if DEBUG sw.Stop(); long microseconds = sw.ElapsedTicks / (Stopwatch.Frequency / (1000L * 1000L)) / 1000; Debug.WriteLine("-----> DB Task completed in : {0} ms", microseconds); #endif }
private static void ReplaceRecords(SQLiteConnection connection, SynchronizationDataContainer containerData) { DatabaseHelper.ReplaceAll(containerData.Users,connection); DatabaseHelper.ReplaceAll(containerData.ProductGroups,connection); DatabaseHelper.ReplaceAll(containerData.Arguments,connection); }