public void Add(HistoricalDocDto d) { var key = Base64UrlTextEncoder.Encode( new DocumentAggregateKey { HanziCanonical = d.HanziCanonical, Initial = d.Initial, Final = d.Final, Tone = d.Tone } .ToByteArray()); if (!documents.ContainsKey(key)) { documents[key] = new HistoricalDocument() { Id = key }; } documents[key].Initial = d.Initial; documents[key].Final = d.Final; documents[key].Tone = d.Tone; documents[key].HanziCanonical = d.HanziCanonical; documents[key].Buc = d.Buc; documents[key].Yngping = YngpingBekinUtil.FanqieToYngping(d.Initial, d.Final, d.Tone); documents[key].YngpingModern = CikLingUtil.ToYngPingHokchew(GetInitial(d.Initial), GetFinal(d.Final), GetTone(d.Tone)); var altA = documents[key].HanziAlternatives; var altB = d.HanziAlternatives; var altMerged = altA.Union(altB).Distinct().ToList(); documents[key].HanziAlternatives.Clear(); documents[key].HanziAlternatives.AddRange(altMerged); var mA = documents[key].HanziMatchable; var mB = d.HanziMatchable; var mMerged = mA.Union(mB).Distinct().ToList(); documents[key].HanziMatchable.Clear(); documents[key].HanziMatchable.AddRange(mMerged); if (d is CikLingDto) { var c = d as CikLingDto; documents[key].CiklinSource = c.CikLinSourceInfo; if (!string.IsNullOrEmpty(c.ZingzeuId)) { documents[key].ZingzeuId = c.ZingzeuId; } } if (d is DfdDto) { documents[key].DfdSource = (d as DfdDto).DFDSourceInfo; } }
public RichTextNode ToRichTextNode(HistoricalDocument doc) { var sources = new List <string>(); if (doc.CiklinSource != null) { sources.Add(zc.tM("戚林八音校注")); } if (doc.DfdSource != null) { sources.Add("榕腔注音辞典·目录"); } var children = new List <RichTextNode>(); children.Add(SectionHeader(zc.tH(HanziUtils.HanziToString(doc.HanziCanonical)))); children.Add(Label(zc.tM("音韵地位(戚林八音)"))); children.Add(SimpleText(PhonologyUtils.ToHanzi(doc.Initial, doc.Final, doc.Tone))); children.Add(Label(zc.tM("榕拼(八音)"))); children.Add(SimpleText(doc.Yngping)); children.Add(Label(zc.tM("教会罗马字"))); children.Add(SimpleText(doc.Buc)); if (!string.IsNullOrEmpty(doc.CiklinSource?.ExplanationCik)) { children.Add(Label(zc.tM("戚书释义"))); children.Add(SimpleText(zc.tM(doc.CiklinSource.ExplanationCik))); } if (!string.IsNullOrEmpty(doc.CiklinSource?.ExplanationLing)) { children.Add(Label(zc.tM("林书释义"))); children.Add(SimpleText(zc.tM(doc.CiklinSource.ExplanationLing))); } children.Add(Source(zc.tM("来源:" + string.Join(", ", sources)))); return(new RichTextNode() { VerticalContainer = new RichTextNode.Types.VerticalContainerNode() { Children = { children } } }); }
private async void SaveSessionHistoryToolStripMenuItem_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count != 1) { return; } int selectedIndex = this.listView1.SelectedIndices[0]; HistoricalDocument document = new HistoricalDocument() { SessionName = this.listView1.Items[selectedIndex].SubItems[0].Text, Branch = this.listView1.Items[selectedIndex].SubItems[1].Text, NumSnapshots = int.Parse(this.listView1.Items[selectedIndex].SubItems[2].Text), LastModified = this.listView1.Items[selectedIndex].SubItems[3].Text, IsExpired = bool.Parse(this.listView1.Items[selectedIndex].SubItems[4].Text), ActivityId = this.listView1.Items[selectedIndex].SubItems[5].Text, }; string eToken = await ToolAuthentication.GetDevTokenSilentlyAsync(this.tbScid.Text, this.tbSandbox.Text); this.lblExplanation.Text = "Downloading change history for the selected session..."; Tuple <SessionHistoryDocumentResponse, string> queryResponse = await this.QueryForDocSessionHistoryAsync(eToken, document.SessionName, document.Branch); if (queryResponse.Item2 != null) { this.downloadPanel.Hide(); MessageBox.Show(string.Format("{0}\n\nThe server may have been busy.\nPlease try again.", queryResponse.Item2), "Error!"); return; } string errMsg = null; if (queryResponse.Item1 != null) { foreach (var item in queryResponse.Item1.Results) { Tuple <string, string> getSnapshotResponse = await this.QueryForDocSessionHistoryChangeAsync(document.SessionName, document.Branch, item.ChangeNumber); string snapshotBody = getSnapshotResponse.Item1; errMsg = getSnapshotResponse.Item2; if (errMsg != null) { break; } DocumentStateSnapshot snapshot = new DocumentStateSnapshot() { Change = item.ChangeNumber, ModifiedByXuids = item.ChangedBy, Timestamp = item.Timestamp, TitleId = item.TitleId, ServiceId = item.ServiceId, CorrelationId = item.CorrelationId, ChangeDetails = item.Details, Body = snapshotBody != null ? snapshotBody : string.Empty }; document.DocumentSnapshots.Add(snapshot); } } this.downloadPanel.Hide(); if (errMsg != null) { MessageBox.Show(string.Format("{0}\n\nPlease try again.", errMsg), "Error"); } else { // serialize the HistoricalDocument to json string testString = JsonConvert.SerializeObject(document); var saveDialog = new SaveFileDialog() { Filter = SessionHistoryFileFilter, FileName = string.Format("{0}~{1}", document.SessionName, document.Branch) }; if (saveDialog.ShowDialog() == DialogResult.OK) { using (StreamWriter sw = new StreamWriter(saveDialog.FileName)) { sw.Write(testString); } } } }
private void LoadSessionHistoryToolStripMenuItem_Click(object sender, EventArgs e) { HistoricalDocument document = null; var openFileDialog = new OpenFileDialog() { Filter = SessionHistoryFileFilter }; if (openFileDialog.ShowDialog() == DialogResult.OK) { using (StreamReader sr = new StreamReader(openFileDialog.FileName)) { string fileContents = sr.ReadToEnd(); try { document = JsonConvert.DeserializeObject <HistoricalDocument>(fileContents); } catch (JsonSerializationException) { MessageBox.Show("Could not deserialize the file to a\nHistorical Document.", "Load Document Error"); } } } if (document != null) { this.listView1.Items.Clear(); this.InitViews(); string[] arr = new string[QueryResultColumnCount] { document.SessionName, document.Branch, document.NumSnapshots.ToString(), document.LastModified, document.IsExpired.ToString(), document.ActivityId }; ListViewItem lvi = new ListViewItem(arr); this.listView1.Items.Add(lvi); foreach (DocumentStateSnapshot snapshot in document.DocumentSnapshots) { string hashKey = this.snapshotCache.GetHashString( document.SessionName, document.Branch, snapshot.Change); string snapshotBody; if (snapshot.Change != SessionHistory.MaxChangeValue) { if (!this.snapshotCache.TryGetSnapshot(hashKey, out snapshotBody)) { snapshotBody = snapshot.Body; this.snapshotCache.AddSnapshotToCache(hashKey, snapshot.Body); } } string[] lv2arr = new string[DocumentMetadataColumnCount] { snapshot.Change == SessionHistory.MaxChangeValue ? "expired" : snapshot.Change.ToString(), snapshot.ModifiedByXuids, snapshot.Timestamp.ToString(), snapshot.TitleId, snapshot.ServiceId, snapshot.CorrelationId, snapshot.ChangeDetails }; ListViewItem lvi2 = new ListViewItem(lv2arr); this.listView2.Items.Add(lvi2); } this.lblDocCount.Text = "1 document [offline]"; this.DisplayChangesInfo(); this.showingOfflineSession = true; this.saveSessionHistoryToolStripMenuItem.Visible = false; } }