private void MenuItem_DeleteSpeaker(object sender, RoutedEventArgs e) { var selectedSpeaker = ((SpeakerContainer)SpeakersBox.SelectedValue).Speaker; if (MessageBox.Show(string.Format(Properties.Strings.SpeakersManagerDeleteSpeakerDialogFormat, selectedSpeaker), Properties.Strings.SpeakersManagerDeleteSpeakerDialogQuestion, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (SpeakerProvider.DeferRefresh()) { SpeakerProvider.DeleteSpeaker(selectedSpeaker); _transcription.BeginUpdate(); foreach (TranscriptionParagraph tp in _transcription.EnumerateParagraphs()) { if (tp.Speaker == selectedSpeaker) { tp.Speaker = Speaker.DefaultSpeaker; } } _transcription.EndUpdate(); } SpeakersBox.UnselectAll(); } }
private void Button_Click(object sender, RoutedEventArgs e) { var cleardicts = _pairs.Where(p => p.Speaker2 == null).Count(); if (cleardicts > 0) { if (MessageBox.Show("Chcete v lokální databázi vytvořit nové položky pro všechny nepřiřazené mluvčí?", "automatické vytváření mluvčích", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { foreach (var p in _pairs.Where(pa => pa.Speaker2 == null)) { var n = new SpeakerContainer(p.Speaker1.Speaker.Copy()); n.Speaker.DataBaseType = DBType.User; _speakersDatabase.Add(n.Speaker); p.Speaker2 = n; } } } var pairdict = _pairs.Where(p => p.Speaker2 != null).ToDictionary(p => p.Speaker1.Speaker, p => (p.Speaker2 == null) ? null : p.Speaker2.Speaker); _transcription.BeginUpdate(); foreach (var par in _transcription.EnumerateParagraphs()) { Speaker os; if (pairdict.TryGetValue(par.Speaker, out os)) { par.Speaker = os; } } _transcription.EndUpdate(); foreach (var spe in pairdict.Keys) { _transcription.Speakers.RemoveSpeaker(spe); } this.DialogResult = true; Close(); }
new public static WPFTranscription Deserialize(Stream stream) { //on some remote data storage this can be more effective than lot of small direct reads by XMLTextReader #region copy stream to internal buffer byte[] bfr = new byte[32 * 1024]; int read = 0; int initsize = 500 * 1024; MemoryStream bufferStream; try { initsize = (int)stream.Length; }finally { bufferStream = new MemoryStream(initsize); } while ((read = stream.Read(bfr, 0, bfr.Length)) > 0) { bufferStream.Write(bfr, 0, read); } bufferStream.Seek(0, SeekOrigin.Begin); #endregion #if DEBUG #region validation XmlSchemaSet schemas = new XmlSchemaSet(); XNamespace xNamespace = XNamespace.Get("http://www.ite.tul.cz/TRSXSchema3.xsd"); using (var s = File.Open(FilePaths.TrsxSchemaPath, FileMode.Open, FileAccess.Read, FileShare.Read)) schemas.Add(null, XmlReader.Create(s)); XDocument doc = XDocument.Load(bufferStream); foreach (XElement xElement in doc.Descendants()) { // First make sure that the xmlns-attribute is changed xElement.SetAttributeValue("xmlns", xNamespace.NamespaceName); // Then also prefix the name of the element with the namespace xElement.Name = xNamespace + xElement.Name.LocalName; } doc.Validate(schemas, (o, e) => { System.Diagnostics.Debug.WriteLine(string.Format("{0}", e.Message)); }); //restore stream position bufferStream.Seek(0, SeekOrigin.Begin); #endregion #endif var t = new WPFTranscription(); t.BeginUpdate(); Transcription.Deserialize(bufferStream, t); t.IsOnline = t.Elements.ContainsKey("Online") && t.Elements["Online"] == "True"; t.EndUpdate(); t.ClearUndo(); t.Saved = true; return(t); }
public async Task<bool> NewTranscription() { if (!await TrySaveUnsavedChanges()) return false; var source = new WPFTranscription(); source.BeginUpdate(false); var c = new TranscriptionChapter(Properties.Strings.DefaultChapterText); var s = new TranscriptionSection(Properties.Strings.DefaultSectionText); var p = new TranscriptionParagraph(); p.Add(new TranscriptionPhrase()); c.Add(s); s.Add(p); source.Add(c); Transcription = source; SynchronizeSpeakers(); VirtualizingListBox.ActiveTransctiption = p; TranscriptionList.Clear(); source.ClearUndo(); source.EndUpdate(); Transcription.Saved = true; return true; }
public static new WPFTranscription Deserialize(Stream stream) { //on some remote data storage this can be more effective than lot of small direct reads by XMLTextReader #region copy stream to internal buffer byte[] bfr = new byte[32*1024]; int read = 0; int initsize = 500*1024; MemoryStream bufferStream; try { initsize = (int)stream.Length; }finally { bufferStream = new MemoryStream(initsize); } while((read = stream.Read(bfr,0,bfr.Length)) > 0) bufferStream.Write(bfr,0,read); bufferStream.Seek(0, SeekOrigin.Begin); #endregion #if DEBUG #region validation XmlSchemaSet schemas = new XmlSchemaSet(); XNamespace xNamespace = XNamespace.Get("http://www.ite.tul.cz/TRSXSchema3.xsd"); using (var s = File.Open(FilePaths.TrsxSchemaPath,FileMode.Open,FileAccess.Read,FileShare.Read)) schemas.Add(null, XmlReader.Create(s)); XDocument doc = XDocument.Load(bufferStream); foreach (XElement xElement in doc.Descendants()) { // First make sure that the xmlns-attribute is changed xElement.SetAttributeValue("xmlns", xNamespace.NamespaceName); // Then also prefix the name of the element with the namespace xElement.Name = xNamespace + xElement.Name.LocalName; } doc.Validate(schemas, (o,e) => { System.Diagnostics.Debug.WriteLine(string.Format("{0}", e.Message)); }); //restore stream position bufferStream.Seek(0, SeekOrigin.Begin); #endregion #endif var t = new WPFTranscription(); t.BeginUpdate(); Transcription.Deserialize(bufferStream, t); t.IsOnline = t.Elements.ContainsKey("Online") && t.Elements["Online"] == "True"; t.EndUpdate(); t.ClearUndo(); t.Saved = true; return t; }