private void AddToFormattedFile(string filename, TranslationsList translationsList) { TranslationsList original = ReadFormattedFile(filename); original = PutTwoInOne(original, translationsList); WriteFormattedFile(filename, original); }
public TranslationsList ReadNonFormattedFile(string filename) { string file = File.ReadAllText(filename); List <Translation> translationList = JsonConvert.DeserializeObject <List <Translation> >(file); TranslationsList translations = ToFormatted(translationList); return(translations); }
private TranslationsList ToFormatted(List <Translation> translationList) { TranslationsList translations = new TranslationsList(); foreach (Translation translation in translationList) { TranslationsHolder translationsHolder = new TranslationsHolder(); translationsHolder.AddTranslation(translation); translations.translations.Add(translationsHolder); } return(translations); }
public TranslationsList ReadFormattedFile(string filename) { filename = MakeWorkFile(filename); if (!File.Exists(filename)) { File.Create(filename); filename = UnWorkFile(filename); TranslationsList translations = ReadNonFormattedFile(filename); WriteFormattedFile(filename, translations); return(translations); } else { string file = File.ReadAllText(filename); return(StringToFormatted(file)); } }
internal void SendFile(string filename, TranslationsList translations) { if (translations == null) { Console.WriteLine("{0} send null", filename); return; } ConnectToServer(); if (netStream == null) { throw new NullReferenceException(); } byte[] bytesFile = System.Text.Encoding.UTF8.GetBytes(filename); SendData(bytesFile, netStream, 3); //TranslationsList translations = fileUtils.ReadFormattedFile(filename); string translationsStr = fileUtils.FormattedToString(translations); byte[] bytesTrans = System.Text.Encoding.UTF8.GetBytes(translationsStr); SendDataOnly(bytesTrans, netStream); }
public bool CompareFileWithServer(string filename, Client client) { int versionBuffer; if (!File.Exists(filename)) { File.Create(filename); try { TranslationsList tL = StringToFormatted(client.GetFile(filename)); WriteFormattedFile(filename, tL); } catch (NullReferenceException ex) { return(false); } } else { //if (fileInfo.Length == client.GetServersideFileSize(filename)) return false; try { if (client.versions[filename] != (versionBuffer = client.AskVersion(filename))) { AddToFormattedFile(filename, StringToFormatted(client.GetFile(filename))); client.versions[filename] = versionBuffer; } else { return(false); } } catch (NullReferenceException ex) { return(false); } } return(true); }
private TranslationsList PutTwoInOne(TranslationsList original, TranslationsList translationsList) { foreach (TranslationsHolder tH in original.translations) { foreach (TranslationsHolder tH2 in translationsList.translations) { if (tH.translations[0].ch.Equals(tH2.translations[0].ch)) { foreach (Translation t2 in tH2.translations) { if (t2 == null) { continue; } bool found = false; foreach (Translation t in tH.translations) { if (t == null) { continue; } if (t.ru == t2.ru) { found = true; break; } } if (!found) { tH.translations.Add(t2); } } } } } return(original); }
private void buttonOpenFile_Click(object sender, EventArgs e) { if (listBoxFiles.SelectedIndex == -1) { MessageBox.Show("Сначала выберите файл", "Открытие файла"); return; } if (tabPageFile.Text != "null") { fileUtils.WriteFormattedFile(tabPageFile.Text, chosenTranslationList); } labelTranslationNumber.Text = "-1"; string filename = (string)listBoxFiles.Items[listBoxFiles.SelectedIndex]; try { if (fileUtils.CompareFileWithServer(filename, client)) { Console.WriteLine("File {0} downloaded from server", filename); } } catch { Console.WriteLine("Can't connect to server"); } chosenTranslationList = fileUtils.ReadFormattedFile(filename); buttonTranslationPageForward.Visible = true; buttonTranslationPageForward.Enabled = true; labelTranslationPage.Text = "0"; UpdateTranslationsOnScreen(); tabPageFile.Text = filename; }
public String FormattedToString(TranslationsList v) { return(JsonConvert.SerializeObject(v)); }
public void WriteFormattedFile(string filename, TranslationsList translations) { filename = MakeWorkFile(filename); File.WriteAllText(filename, JsonConvert.SerializeObject(translations).Replace("},", "},\n")); }
public void WriteNonFormattedFile(string filename, TranslationsList translations) { }