private void sendWordToServer(DictionaryItem dItem) { String jsonObj = "{\"id\":" + dItem.Id + ",\"word\":" + "\"" + dItem.Word + "\"" + ",\"translation\":" + "\"" + dItem.Translation + "\"" + ",\"correct_answers\":" + dItem.CorrectAnswers + ",\"iteration\":" + dItem.Iteration; DateTime nextDate = dItem.NextShowDate; if (!Object.Equals(nextDate, default(DateTime))) //if date != null { string nextDateStr = nextDate.ToString("yyyy-MM-dd HH:mm:ss"); jsonObj = jsonObj + ",\"next_show_date\":" + "\"" + nextDateStr + "\""; } else { jsonObj = jsonObj + ",\"next_show_date\":" + "null"; } DateTime currentDate = DateTime.Now; string updateDateStr = currentDate.ToString("yyyy-MM-dd HH:mm:ss"); jsonObj = jsonObj + ",\"last_update_date\":" + "\"" + updateDateStr + "\"" + "}";; String jsonStr = "{\"words\": [" + jsonObj + "] }"; logger.Info("JsonStr: " + jsonStr); if (config.Synchronization == Const.SYNC_ON) { Synchronizator.sendRequestAsync(jsonStr); } }
private async void GetFromServerMenuItemClick(object sender, RoutedEventArgs e) { logger.Info("getting all data from server as json"); try { String jsonStr = await Synchronizator.getJsonAsync(); logger.Info("got json from server, length: " + jsonStr.Length); if (jsonStr.Length > 0) { String currentDir = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); String syncDir = currentDir + "\\sync"; bool exists = System.IO.Directory.Exists(syncDir); if (!exists) { logger.Info("creating directory: " + syncDir); System.IO.Directory.CreateDirectory(syncDir); } String bkpDir = currentDir + "\\bkp"; exists = System.IO.Directory.Exists(bkpDir); if (!exists) { logger.Info("creating directory: " + bkpDir); System.IO.Directory.CreateDirectory(bkpDir); } String dateExt = DateTime.Now.ToString("yyyy_MM_dd"); String oldPath = currentDir + "\\WordsDatabase.db"; String newPath = bkpDir + "\\WordsDatabase_" + dateExt + ".db"; logger.Info("copying database from path: " + oldPath + " to path: " + newPath); File.Copy(oldPath, newPath, true); logger.Info("Database file was copied. Replace old file with synchronized one"); //String syncPath = syncDir + "\\WordsDatabase_sync.db"; String syncPath = currentDir + "\\WordsDatabase.db"; dbHandler.createDatabaseFileBasedOnJson(jsonStr, syncPath); } else { logger.Info("got empty json from server"); } } catch (Exception ex) { logger.Error("exception while getting data from server: " + ex.Message); } }
private void SendToServerMenuItemClick(object sender, RoutedEventArgs e) { logger.Info("getting all data from db as json"); MessageBoxResult askResult = MessageBox.Show("Send data to server? It will rewrite server state completely", "Info", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly); if (askResult == MessageBoxResult.Yes) { String jsonStr = dbHandler.getAllDataAsJson(); jsonStr = "{\"words\": " + jsonStr + " }"; logger.Info("sending data to server, data length is " + jsonStr.Length); if (jsonStr.Length > 0) { Synchronizator.sendRequestAsync(jsonStr); } } }
protected virtual void Setup() { SyncManager = new Synchronizator(new SyncableActorsFactory()); SyncManager.AddRemote(); }