private void SaveButton_Click(object sender, RoutedEventArgs e) { if (CacheService.Instance.MachineId == -1) { List <String> lpath = new List <String>(); foreach (ListenPath lp in paths) { lpath.Add(lp.Path); } MachineResult mr = mf.AddMachine(MachineUtil.GetMac(), (int)this.labList.SelectedValue, this.pathText.Text.ToString(), lpath); if (mr != null) { if (mr.code == "200") { LSMessageBox.Show("提示", "配置成功"); CacheService.Instance.SetMachineConf(mr); this.Close(); this.Owner.Show(); } else { LSMessageBox.Show("配置异常", mr.message); } } else { LSMessageBox.Show("网络错误", "网络异常"); } } else { List <String> lpath = new List <String>(); foreach (ListenPath lp in paths) { lpath.Add(lp.Path); } MachineResult mr = mf.UpdateMachine(CacheService.Instance.MachineId, MachineUtil.GetMac(), (int)this.labList.SelectedValue, this.pathText.Text.ToString(), lpath); if (mr != null) { if (mr.code == "200") { LSMessageBox.Show("提示", "更新成功"); CacheService.Instance.SetMachineConf(mr); this.Close(); this.Owner.Show(); } else { LSMessageBox.Show("配置异常", mr.message); } } else { LSMessageBox.Show("网络错误", "网络异常"); } } }
public void SetMachineConf(MachineResult mr) { machineId = mr.data.id; mac = mr.data.macAddress; lab = mr.data.lab; launchPath = mr.data.launchPath; listenPath.Clear(); foreach (String p in mr.data.listenPath) { listenPath.Add(new ListenPath { Path = p }); } NotifyPropertyChanged("Lab"); }
async Task CleanUpPool(List <WorkerResource> filteredMachines, WorkerPoolResource poolResource) { commandOutputProvider.Information("Found {MachineCount} machines in {WorkerPool:l} with the status {Status:l}", filteredMachines.Count, poolResource.Name, GetStateFilterDescription()); if (filteredMachines.Any(m => m.WorkerPoolIds.Count > 1)) { commandOutputProvider.Information("Note: Some of these machines belong to multiple pools. Instead of being deleted, these machines will be removed from the {WorkerPool:l} pool.", poolResource.Name); } foreach (var machine in filteredMachines) { var result = new MachineResult { Machine = machine }; // If the machine belongs to more than one pool, we should remove the machine from the pool rather than delete it altogether. if (machine.WorkerPoolIds.Count > 1) { commandOutputProvider.Information("Removing {Machine:l} {Status} (ID: {Id:l}) from {WorkerPool:l}", machine.Name, machine.Status, machine.Id, poolResource.Name); machine.WorkerPoolIds.Remove(poolResource.Id); await Repository.Workers.Modify(machine).ConfigureAwait(false); result.Action = MachineAction.RemovedFromPool; } else { commandOutputProvider.Information("Deleting {Machine:l} {Status} (ID: {Id:l})", machine.Name, machine.Status, machine.Id); await Repository.Workers.Delete(machine).ConfigureAwait(false); result.Action = MachineAction.Deleted; } commandResults.Add(result); } }
private async Task CleanUpEnvironment(List <MachineResource> filteredMachines, EnvironmentResource environmentResource) { commandOutputProvider.Information("Found {MachineCount} machines in {Environment:l} with the status {Status:l}", filteredMachines.Count, environmentResource.Name, GetStateFilterDescription()); if (filteredMachines.Any(m => m.EnvironmentIds.Count > 1)) { commandOutputProvider.Information("Note: Some of these machines belong to multiple environments. Instead of being deleted, these machines will be removed from the {Environment:l} environment.", environmentResource.Name); } foreach (var machine in filteredMachines) { MachineResult result = new MachineResult { Machine = machine }; // If the machine belongs to more than one environment, we should remove the machine from the environment rather than delete it altogether. if (machine.EnvironmentIds.Count > 1) { commandOutputProvider.Information("Removing {Machine:l} {Status} (ID: {Id:l}) from {Environment:l}", machine.Name, machine.Status, machine.Id, environmentResource.Name); machine.EnvironmentIds.Remove(environmentResource.Id); await Repository.Machines.Modify(machine).ConfigureAwait(false); result.Action = MachineAction.RemovedFromEnvironment; } else { commandOutputProvider.Information("Deleting {Machine:l} {Status} (ID: {Id:l})", machine.Name, machine.Status, machine.Id); await Repository.Machines.Delete(machine).ConfigureAwait(false); result.Action = MachineAction.Deleted; } this.commandResults.Add(result); } }
protected override void OnStartup(StartupEventArgs e) { MachineResult mr = mf.GetMachine(MachineUtil.GetMac()); if (mr != null) { if (mr.code == "200") { if (mr.data != null) { CacheService.Instance.SetMachineConf(mr); } MainWindow mainWindow = new MainWindow(); mainWindow.Show(); } else if (mr.code == "402") { LSMessageBox.Show("提示", "当前机器没有配置"); MainWindow mainWindow = new MainWindow(); mainWindow.Show(); } else { LSMessageBox.Show("获取配置错误", "网络异常,请确认网络连接并重新打开"); this.Shutdown(); } } else { LSMessageBox.Show("网络错误", "获取机器配置错误,请确认网络连接并重新打开"); this.Shutdown(); //MainWindow mainWindow = new MainWindow(); //mainWindow.Show(); } base.OnStartup(e); }
/// <summary> /// Writes a message about what caused the machine to stop to the MessageList /// </summary> /// <param name="result">The result to write a message about.</param> /// <returns>The unedited input value.</returns> private MachineResult MessageWrapper(MachineResult result) { if (Messages != null) { #region Write a message about what caused the machine to stop if (result == MachineResult.HALT) Messages.Add("The Turing machine reached a defined end. (HALT)"); else if (result == MachineResult.NO_RULE) Messages.Add("Turing machine stopped. There is no instruction for the current state."); else if (result == MachineResult.ABORTED) Messages.Add("The execution of the Turing machine has been stopped."); #endregion } return result; }
/// <summary> /// Stops the machine and provides a message about what caused the stop /// </summary> /// <param name="result">The last step's result.</param> private void Stop(MachineResult result) { _timer.Stop(); IsRunning = false; }