Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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);
                }
            }
        }