private async Task <bool> TrySaveSpeaker(SpeakerContainer spk) { if (NewSpeaker == spk.Speaker) { if (await TestName(spk)) { bool reselect = spk == SpeakersBox.SelectedItem; using (SpeakerProvider.DeferRefresh()) { spk.ApplyChanges(); SpeakerProvider.DeleteSpeaker(spk.Speaker); if (spk.IsOnline) { SpeakerProvider.AddOnlineSpeaker((ApiSynchronizedSpeaker)spk.Speaker); } else { SpeakerProvider.AddLocalSpeaker(spk.Speaker); } NewSpeaker = null; } if (reselect) { var ss = SpeakerProvider.GetContainerForSpeaker(spk.Speaker); SpeakersBox.SelectedValue = ss; } } else { return(false); //do not apply or save - name is invalid } } spk.ApplyChanges(); if (spk.IsOnline) { using (var wc = new WaitCursor()) { ApiSynchronizedSpeaker ss = spk.Speaker as ApiSynchronizedSpeaker; if (ss == null) { return(false); } if (ss.IsSaved) { return(await _transcription.Api.UpdateSpeaker(ss)); } else { return(await _transcription.Api.AddSpeaker(ss)); } } } return(true);; }
private void SpeakerSmall_Drop(object sender, DragEventArgs e) { if (sender != null && e.AllowedEffects.HasFlag(DragDropEffects.Copy) && e.Data.GetData(typeof(SpeakerContainer)) != null) { SpeakerSmall ss = (sender as UIElement).VisualFindChild <SpeakerSmall>(); e.Effects = DragDropEffects.Copy; SpeakerContainer cont = (SpeakerContainer)e.Data.GetData(typeof(SpeakerContainer)); (ss.DataContext as SpeakerPair).Speaker2 = cont; e.Handled = true; } }
internal async Task <Speaker[]> FindSimilar(SpeakerContainer spk) { List <Speaker> all = new List <Speaker>(); if (IsOnline) { var result = await _api.SimpleSearch(spk.FullName); all.AddRange(result); } all.AddRange(_allSpeakers.Where(s => s.FullName == spk.FullName).Select(c => c.Speaker).Except(_temp)); return(Deduplicate(all).ToArray()); }
private async void SpeakerDetails_RevertSpeakerRequest(SpeakerContainer spk) { if (spk.IsOnline) { using (var wc = new WaitCursor()) { var s = await _transcription.Api.GetSpeaker(spk.Speaker.DBID); Speaker.MergeFrom(spk.Speaker, s); spk.ReloadSpeaker(); } } else { spk.DiscardChanges(); } }
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(); }
private async Task <bool> TestName(SpeakerContainer spk) { if (string.IsNullOrWhiteSpace(spk.FullName.Replace("-", ""))) { MessageBox.Show(string.Format(Properties.Strings.SpeakersManagerSpeakerNameConflictForbiddenQuestionFormat, spk.FullName), Properties.Strings.SpeakersManagerSpeakerNameConflictCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation); return(false); } else { var similar = await SpeakerProvider.FindSimilar(spk); if (similar.Length > 0) { if (MessageBox.Show(string.Format(Properties.Strings.SpeakersManagerSpeakerNameConflictQuestionFormat, string.Join(",", similar.Take((similar.Length > 3) ? 3 : similar.Length).Select(s => s.FullName))), Properties.Strings.SpeakersManagerSpeakerNameConflictCaption, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) { return(false); } } } return(true); }
private bool FilterItems(object item) { SpeakerContainer cont = item as SpeakerContainer; bool res = false; if (cont == null) { return(false); } if (_showDocument && _document.Contains(cont.Speaker)) { res = true; } if (_showLocal && cont.IsLocal) { res = true; } if (_showOnline && cont.IsOnline) { res = true; } if (!string.IsNullOrWhiteSpace(_filterstring)) { string flover = _filterstring.ToLower(); res &= (cont.FullName.ToLower().Contains(flover) | cont.DegreeBefore.ToLower().Contains(flover) | cont.DegreeAfter.ToLower().Contains(flover) | cont.Language.ToLower().Contains(flover)); } return(res); }
private MessageBoxResult CheckChanges(SpeakerContainer sc) { if (!sc.Changed) { return(MessageBoxResult.OK); } var result = MessageBox.Show(string.Format(Properties.Strings.SpeakersManagerSpeakerApplyChangesDialogFormat, sc.FullName), Properties.Strings.SpeakersManagerSpeakerApplyChangesDialogQuestion, MessageBoxButton.YesNoCancel, MessageBoxImage.Question); var ss = sc.Speaker; if (result == MessageBoxResult.Yes) { bool saved = AsyncHelpers.RunSync(() => TrySaveSpeaker(sc)); if (!saved) { result = MessageBoxResult.No; } else { return(MessageBoxResult.Yes); } } if (result == MessageBoxResult.No) { if (NewSpeaker == sc.Speaker) { NewSpeaker = null; SpeakerProvider.DeleteSpeaker(ss); } sc.ReloadSpeaker(); return(MessageBoxResult.No); } return(MessageBoxResult.Cancel); }
private async void SpeakerDetails_SaveSpeakerClick(SpeakerContainer spk) { using (new WaitCursor()) await TrySaveSpeaker(spk); }
private async Task<bool> TrySaveSpeaker(SpeakerContainer spk) { bool retval = false; if (NewSpeaker == spk.Speaker) { if (await TestName(spk)) { using (SpeakerProvider.DeferRefresh()) { spk.ApplyChanges(); SpeakerProvider.DeleteSpeaker(spk.Speaker); if (spk.IsOnline) SpeakerProvider.AddOnlineSpeaker((ApiSynchronizedSpeaker)spk.Speaker); else SpeakerProvider.AddLocalSpeaker(spk.Speaker); NewSpeaker = null; retval = true; } } else { return false; //do not apply or save - name is invalid } } spk.ApplyChanges(); if (spk.IsOnline) { using (var wc = new WaitCursor()) { ApiSynchronizedSpeaker ss = spk.Speaker as ApiSynchronizedSpeaker; if (ss == null) return false; if (ss.IsSaved) return await _transcription.Api.UpdateSpeaker(ss); else return await _transcription.Api.AddSpeaker(ss); } } return retval; }
private async Task<bool> TestName(SpeakerContainer spk) { if (string.IsNullOrWhiteSpace(spk.FullName.Replace("-", ""))) { MessageBox.Show(string.Format(Properties.Strings.SpeakersManagerSpeakerNameConflictForbiddenQuestionFormat, spk.FullName), Properties.Strings.SpeakersManagerSpeakerNameConflictCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation); return false; } else { var similar = await SpeakerProvider.FindSimilar(spk); if (similar.Length > 0) { if (MessageBox.Show(string.Format(Properties.Strings.SpeakersManagerSpeakerNameConflictQuestionFormat, string.Join(",", similar.Take((similar.Length > 3) ? 3 : similar.Length).Select(s => s.FullName))), Properties.Strings.SpeakersManagerSpeakerNameConflictCaption, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) { return false; } } } return true; }
private bool CheckChanges(SpeakerContainer sc) { if (!sc.Changed) return true; var result = MessageBox.Show(string.Format(Properties.Strings.SpeakersManagerSpeakerApplyChangesDialogFormat, sc.FullName), Properties.Strings.SpeakersManagerSpeakerApplyChangesDialogQuestion, MessageBoxButton.YesNo, MessageBoxImage.Question); ApiSynchronizedSpeaker ss = sc.Speaker as ApiSynchronizedSpeaker; if (result == MessageBoxResult.Yes) { bool saved = AsyncHelpers.RunSync(() => TrySaveSpeaker(sc)); if (!saved) { return false; } } else { if (NewSpeaker == sc.Speaker) { NewSpeaker = null; SpeakerProvider.DeleteSpeaker(ss); } sc.ReloadSpeaker(); return false; } return true; }
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(); }
private MessageBoxResult CheckChanges(SpeakerContainer sc) { if (!sc.Changed) return MessageBoxResult.OK; var result = MessageBox.Show(string.Format(Properties.Strings.SpeakersManagerSpeakerApplyChangesDialogFormat, sc.FullName), Properties.Strings.SpeakersManagerSpeakerApplyChangesDialogQuestion, MessageBoxButton.YesNoCancel, MessageBoxImage.Question); var ss = sc.Speaker; if (result == MessageBoxResult.Yes) { bool saved = AsyncHelpers.RunSync(() => TrySaveSpeaker(sc)); if (!saved) { result = MessageBoxResult.No; }else return MessageBoxResult.Yes; } if (result == MessageBoxResult.No) { if (NewSpeaker == sc.Speaker) { NewSpeaker = null; SpeakerProvider.DeleteSpeaker(ss); } sc.ReloadSpeaker(); return MessageBoxResult.No; } return MessageBoxResult.Cancel; }