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; }
public async Task<bool> SaveTranscription(bool useSaveDialog, string jmenoSouboru) { try { string savePath = Transcription.FileName; if (useSaveDialog) { Microsoft.Win32.SaveFileDialog fileDialog = new Microsoft.Win32.SaveFileDialog(); fileDialog.Title = Properties.Strings.FileDialogSaveTranscriptionTitle; fileDialog.Filter = Properties.Strings.FileDialogSaveTranscriptionFilter; fileDialog.FilterIndex = 1; fileDialog.OverwritePrompt = true; fileDialog.RestoreDirectory = true; if (fileDialog.ShowDialog() == true) { savePath = fileDialog.FileName; Transcription.Saved = true; } else return false; } if (Transcription.IsOnline && !useSaveDialog) { using (var wc = new WaitCursor()) { var onl = await _api.UploadTranscription(Transcription); Transcription.Saved = onl; return onl; } } else if (Transcription.Serialize(savePath, Settings.Default.SaveWholeSpeaker)) { this.Title = Const.APP_NAME + " [" + Transcription.FileName + "]"; Transcription.Saved = true; return true; } return false; } catch (Exception ex) { MessageBox.Show(Properties.Strings.MessageBoxSaveTranscriptionError + ex.Message, Properties.Strings.MessageBoxErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error); } return false; }
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(); } }