/// <summary> /// EV3との接続を開始する /// </summary> /// <param name="portName">Port名 (COM3等)</param> /// <returns>接続結果</returns> public bool Start(string portName) { if (serialPort.IsOpen == true) { Close(); return(false); } MessageDialog dialog = new MessageDialog("接続中", null, "EV3と接続しています."); dialog.Show(); dialog.Refresh(); SetUpSerialPort(portName); try { serialPort.Open(); } catch (Exception ex) { dialog.Close(); MessageBox.Show(ex.Message); return(false); } dialog.Close(); _section = null; return(true); }
private async Task ReadMagEncodeData() { MessageDialog insertCardDialog = null; viewModel.Track1Data = ""; viewModel.Track2Data = ""; viewModel.Track3Data = ""; JobStatusControl.ClearLog(); Console.SetOut(new TextBoxTextWriter(JobStatusControl.JobStatusLog)); await printerManager.PerformAction("Reading mag encode data...", (zebraCardPrinter, connection) => { if (printerManager.IsPrinterReady(zebraCardPrinter, JobStatusControl)) { Console.WriteLine(); // Start logging on new line after printer ready check CardSource cardSource = (CardSource)Enum.Parse(typeof(CardSource), viewModel.SelectedSource); Dictionary <string, string> jobSettings = new Dictionary <string, string>(); jobSettings.Add(ZebraCardJobSettingNames.CARD_SOURCE, cardSource.ToString()); jobSettings.Add(ZebraCardJobSettingNames.CARD_DESTINATION, viewModel.SelectedDestination.ToString()); zebraCardPrinter.SetJobSettings(jobSettings); if (cardSource == CardSource.ATM) { insertCardDialog = DialogHelper.ShowInsertCardDialog(); } MagTrackData magTrackData = zebraCardPrinter.ReadMagData(DataSource.Track1 | DataSource.Track2 | DataSource.Track3, true); if (string.IsNullOrEmpty(magTrackData.Track1) && string.IsNullOrEmpty(magTrackData.Track2) && string.IsNullOrEmpty(magTrackData.Track3)) { Console.WriteLine("No data read from card."); } Application.Current.Dispatcher.Invoke(() => { viewModel.Track1Data = magTrackData.Track1; viewModel.Track2Data = magTrackData.Track2; viewModel.Track3Data = magTrackData.Track3; }); } }, (exception) => { string errorMessage = $"Error reading mag encode data: {exception.Message}"; MessageBoxHelper.ShowError(errorMessage); Console.WriteLine(errorMessage); }); if (insertCardDialog != null) { insertCardDialog.Close(); } StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()); streamWriter.AutoFlush = true; Console.SetOut(streamWriter); }
protected override void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { try { Task.WorkerCompleteAction?.Invoke(); if (Task.Exception == null) { Write(TaskMessageCompleted); Flush(); if (Task.IsWarning == false) { WMessageDialog.Close(); } } else { if (Task.Exception is TaskCanceledException) { Write(TaskMessageCanceled); Flush(); WMessageDialog.Close(); return; } Write(TaskMessageErrorOccurred); WriteLine(Task.Exception.Message); WriteLine(Task.Exception.StackTrace); Flush(); } } finally { if (IsClearTaskMessageTerminated == true) { TaskMessageCompleted = DefaultTaskMessageCompleted; TaskMessageCanceled = DefaultTaskMessageCanceled; TaskMessageErrorOccurred = DefaultTaskMessageErrorOccurred; } Task.IsCompleted = true; IsProcessMode = DMessageDialog.IsProcessMode = false; CompleteProgress(); Task = null; } }
private void SetAgentEnvironment() { MessageDialog messageDialog = new MessageDialog( "Environment Setup", "Please wait while the environment is being set up for the Agent.", false); try { messageDialog.Topmost = true; messageDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen; messageDialog.Show(); // Set Environment Variable Path SetEnvironmentVariable(); // Create Settings File CreateSettingsFile(); // Install Default Packages for the First Time NugetPackageManager.SetupFirstTimeUserEnvironment(Environment.UserDomainName, Environment.UserName, SystemForms.Application.ProductVersion); messageDialog.CloseManually = true; messageDialog.Close(); } catch (Exception ex) { messageDialog.CloseManually = true; messageDialog.Close(); ShowErrorDialog("An error occurred while setting up environment for the Agent.", "", ex.Message, Application.Current.MainWindow); ShutDownApplication(); } }