public void Start() { if (systemManager == null) { throw new NullReferenceException("Error: BarcodeSystemController has not been assigned to BarCodeSystemUI instance!"); } isRunning = true; systemManager.UserBalanceWarning += DisplayUserBalanceWarning; do { ShowProducts(systemManager.ActiveProducts); Console.Write("> "); string command = Console.ReadLine(); CommandEntered?.Invoke(command); DisplayMessage("\nPress any key to continue."); Console.ReadKey(); Console.Clear(); } while (isRunning); }
private void tsmiKruskalAlgorithm_Click(object sender, EventArgs e) { if (_field.Status == false) { return; } var args = new MSTCommandArgs(500); new Thread(() => { CommandEntered?.Invoke(this, args); if (args.SuccsessOut) { StringBuilder mst = new StringBuilder(); args.MstOut.ForEach(str => mst.AppendLine(str)); mst.AppendLine($"Суммарный вес: {args.SummWeightOut}"); ResultForm result = new ResultForm(args.TaskNameOut, args.AlgorithmNameOut, mst.ToString()); BeginInvoke((MethodInvoker)(() => { result.Owner = this; result.ShowDialog(); if (result.Stream != null) { mst.Clear(); mst.AppendLine(result.TaskName); mst.AppendLine(result.AlgorithmName); mst.AppendLine(result.ResultText); CommandEntered?.Invoke(this, new SaveAlgorithmResultCommandArgs(result.Stream, mst.ToString())); } })); } }).Start(); }
public void Interactive() { string lastline = null; bool quit; do { Console.Write(">"); string line = Console.ReadLine().Trim(); if (line.Length == 0) { line = lastline; } bool processed = false; quit = false; if (CommandEntered != null) { CommandEntered.Invoke(line, ref processed, ref quit); } if (processed) { lastline = line; } else { lastline = ""; } } while (!quit); }
private void tsBtnAddEdge_Click(object sender, EventArgs e) { if (sourceModel == null || stockModel == null || sourceModel.Key == stockModel.Key) { return; } string weight = null; if (_field.IsWeighted) { SetWeightForm window = new SetWeightForm(); window.Owner = this; window.ShowDialog(); if (window.Ok) { weight = window.Weight; } } AEdgeModel edgeModel; if (_field.IsOrgraph) { edgeModel = new OrientEdgeModel(sourceModel, stockModel, weight); } else { edgeModel = new NonOrientEdgeModel(sourceModel, stockModel, weight); } CommandEntered?.Invoke(this, new AddModelCommandArgs(edgeModel)); _field.UnmarkGraphModels(); }
private void HandleInput() { string command = Console.ReadLine(); Console.Clear(); CommandEntered?.Invoke(command); }
private void subDetoursBtnDFS_Click(object sender, EventArgs e) { toolStripStatusLabel.Text = "Выполяется алгоритм обхода в глубину"; _field.UnmarkGraphModels(); new Thread(() => CommandEntered?.Invoke(this, new DFScommandArgs(sourceModel))).Start(); }
public void ShutDown() { _running = false; string command = Console.ReadLine(); CommandEntered?.Invoke(command); Console.ReadLine(); }
private void subShortcutBtnBFS_Click(object sender, EventArgs e) { Text += " - Выполяется алгоритм нахождение кратчайшего пути с помошью построение родительского дерева"; new Thread(() => { CommandEntered?.Invoke(this, new ShortcutBFSCommandArgs(sourceModel, stockModel)); }).Start(); }
private void HandleInput() { Console.WriteLine("Enter Command:"); string command = Console.ReadLine(); Console.Clear(); CommandEntered?.Invoke(command); }
private void tsmiFordBellmanAlgorithm_Click(object sender, EventArgs e) { if (_field.Status == false) { return; } if (_field.MarkedVertexModelCount == 2) { SetWeightForm form = new SetWeightForm("Укажите макс длину L", "Найти"); form.Owner = this; form.ShowDialog(); if (!form.Ok) { return; } bool succsess = int.TryParse(form.Weight, out var l); if (!succsess) { PostErrorMessage("Некорректное число L"); return; } new Thread(() => { var args = new WayNoMoreThenLCommandArgs(sourceModel, stockModel, l); CommandEntered.Invoke(this, args); if (args.SuccsessOut) { if (!args.Exist) { PostMessage($"Пути не больше {l} не существуют!!"); } else { StringBuilder sb = new StringBuilder(); args.OutWays.ForEach(w => sb.AppendLine(w)); ResultForm resform = new ResultForm(args.TaskNameOut, args.AlgorithmNameOut, sb.ToString()); BeginInvoke((MethodInvoker)(() => { resform.Owner = this; resform.ShowDialog(); if (resform.Stream != null) { sb.Clear(); sb.AppendLine(resform.TaskName); sb.AppendLine(resform.AlgorithmName); sb.AppendLine(resform.ResultText); CommandEntered?.Invoke(this, new SaveAlgorithmResultCommandArgs(resform.Stream, sb.ToString())); } })); } } }).Start(); } else { PostWarningMessage("Надо вбрать две вершини!!!"); } }
public void Start() { while (_running) { PrintHello(); string command = Console.ReadLine(); CommandEntered?.Invoke(command); } }
private void tsBtnDeleteGraph_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show(this, "Вы действительно хотите безвозвратно удалить этот граф?", "Удаление Графа", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Yes) { CommandEntered?.Invoke(null, new ACommandArgs(nameof(RemoveGraphCommand))); } }
private void btnSaveAdjList_Click(object sender, EventArgs e) { var window = new StoredGraphNameForm(); window.Owner = this; window.ShowDialog(); if (window.Ok) { CommandEntered?.Invoke(this, new AddCurrentGraphInStoredGraphsCommandArgs(window.ListName)); } }
private void tsBtnCrtGraph_Click(object sender, EventArgs e) { CreateGraphForm window = new CreateGraphForm(); window.Owner = this; window.ShowDialog(); if (window.Ok) { oriented = window.Oriented; weighted = window.Weighted; CommandEntered?.Invoke(this, new CreateGraphCommandArgs(oriented, weighted)); } }
private void tsmiNPeriohery_Click(object sender, EventArgs e) { if (_field.Status == false) { return; } if (_field.MarkedVertexModelCount == 1) { SetWeightForm form = new SetWeightForm("Укажите N", "Найти"); form.Owner = this; form.ShowDialog(); if (!form.Ok) { return; } bool succsess = int.TryParse(form.Weight, out var N); if (!succsess) { PostErrorMessage("Некорректное число N"); return; } new Thread(() => { var args = new NPeripheryCommandArgs(sourceModel, N); CommandEntered.Invoke(this, args); if (args.SuccsessOut) { StringBuilder sb = new StringBuilder(); args.NPeripheryOut.ForEach(w => sb.AppendLine(w)); ResultForm resform = new ResultForm(args.TaskNameOut, args.AlgorithmNameOut, sb.ToString()); BeginInvoke((MethodInvoker)(() => { resform.Owner = this; resform.ShowDialog(); if (resform.Stream != null) { sb.Clear(); sb.AppendLine(resform.TaskName); sb.AppendLine(resform.AlgorithmName); sb.AppendLine(resform.ResultText); CommandEntered?.Invoke(this, new SaveAlgorithmResultCommandArgs(resform.Stream, sb.ToString())); } })); } }).Start(); } else { PostWarningMessage("Надо вбрать одну вершину!!!"); } }
private void tsmiPowVertex_Click(object sender, EventArgs e) { if (_field.MarkedVertexModelCount == 1) { HalfLifeDegreeCommandArgs args = new HalfLifeDegreeCommandArgs(sourceModel); CommandEntered?.Invoke(this, args); string halfWay = _field.IsOrgraph ? "полуисхода" : ""; PostMessage($"Степень {halfWay} вершины {sourceModel.VertexStr} равно {args.OutHalfLifeDegree}"); } else { PostWarningMessage("Отметьте одну и только одну вершину !!!"); } }
public void Start() { while (running) { Stregsystem.UserBalanceWarning += DisplayBalanceWarning; DisplayProducts(Stregsystem.ActiveProducts); var command = Console.ReadLine(); CommandEntered?.Invoke(command); Console.ReadKey(); Console.Clear(); } }
protected override bool ProcessCmdKey(ref Message m, Keys keyData) { if (keyData == Keys.Enter && Text.Trim().Length > 0) { string cmd = Text.Trim(); mCommandHistory.Add(cmd); Clear(); mHistoryIndex = mCommandHistory.Count; CommandEntered?.Invoke(cmd); return(true); } if (keyData == Keys.Up) { if (mHistoryIndex > 0) { mHistoryIndex--; } if (mHistoryIndex >= 0 && mHistoryIndex < mCommandHistory.Count) { Text = mCommandHistory[mHistoryIndex]; SelectionStart = Text.Length; SelectionLength = 0; } return(true); } if (keyData == Keys.Down) { if (mHistoryIndex < mCommandHistory.Count) { mHistoryIndex++; } if (mHistoryIndex >= 0 && mHistoryIndex < mCommandHistory.Count) { Text = mCommandHistory[mHistoryIndex]; SelectionStart = Text.Length; SelectionLength = 0; } return(true); } return(base.ProcessCmdKey(ref m, keyData)); }
private void MainForm_MouseUp(object sender, MouseEventArgs e) { vec2 pos = new vec2(e.X, e.Y); if (mouseDownFL && lastVertexPos != null && middlePos != null) { vec2 helpVector = new vec2(min); Clip.RectangleClip(ref helpVector, ref pos, min, max); CommandEntered?.Invoke(this, new MoveVertexModelCommandArgs(middlePos, lastVertexPos, selectedKey)); selectedKey = null; lastVertexPos = null; _field.UnmarkGraphModels(); } mouseDownFL = false; }
private void DrawCLI() { Console.Clear(); Console.WriteLine("┌────┬─────────────────────────────────────┬──────────┐"); foreach (var product in _lineSystem.ActiveProducts) { Console.WriteLine(product); } Console.WriteLine("└────┴─────────────────────────────────────┴──────────┘"); Console.WriteLine(); Console.WriteLine(_cliInfoMessage + _userBalanceWarning); Console.Write("Quickbuy: "); string enteredCommand = Console.ReadLine(); _userBalanceWarning = string.Empty; if (enteredCommand != string.Empty) CommandEntered?.Invoke(this, enteredCommand.Trim()); }
private void tsbtnOpen_Click(object sender, EventArgs e) { try { if (openGraphFileDialog.ShowDialog() == DialogResult.OK) { using (Stream stream = openGraphFileDialog.OpenFile()) { CommandEntered?.Invoke(this, new OpenGraphInFileCommandArgs(stream)); } } } catch (Exception ex) { PostErrorMessage(ex.Message); } }
private void btnRemoveAdjList_Click(object sender, EventArgs e) { int count; if ((count = listBoxAdjList.SelectedItems.Count) == 0) { return; } string[] names = new string[count]; int i = 0; foreach (var elem in listBoxAdjList.SelectedItems) { names[i++] = (string)elem; } CommandEntered?.Invoke(this, new RemoveStoredGraphCommandArgs(names)); }
private void tsmiDijkstraAlgorithm_Click(object sender, EventArgs e) { if (_field.Status == false) { return; } new Thread(() => { DijkstraCommandArgs args = null; if (_field.MarkedVertexModelCount == 1) { args = new DijkstraCommandArgs(sourceModel); CommandEntered.Invoke(this, args); if (args.SuccsessOut) { if (args.OutWays.Count == 0) { PostMessage("Пути к данной вершини отсутсвуют!!!"); } else { StringBuilder sb = new StringBuilder(); args.OutWays.ForEach(w => sb.AppendLine(w)); ResultForm resform = new ResultForm(args.TaskNameOut, args.AlgorithmNameOut, sb.ToString()); BeginInvoke((MethodInvoker)(() => { resform.Owner = this; resform.ShowDialog(); if (resform.Stream != null) { sb.Clear(); sb.AppendLine(resform.TaskName); sb.AppendLine(resform.AlgorithmName); sb.AppendLine(resform.ResultText); CommandEntered?.Invoke(this, new SaveAlgorithmResultCommandArgs(resform.Stream, sb.ToString())); } })); } } } else { PostWarningMessage("Надо вбрать одну вершину!!!"); } }).Start(); }
private void tsbtnSaveGraph_Click(object sender, EventArgs e) { try { if (saveGraphFileDialog.ShowDialog() == DialogResult.OK) { using (Stream stream = saveGraphFileDialog.OpenFile()) { CommandEntered?.Invoke(this, new SaveGraphToFileCommandArgs(stream)); PostMessage("Граф успешно сохранен"); } } } catch (Exception ex) { PostErrorMessage(ex.Message); } }
public void Start() { Console.SetWindowSize(idStrLength + productStrLength + priceStrLength + 10, windowHeight); DrawMenu(); stayAlive = true; while (stayAlive) { try { CommandEntered?.Invoke(Console.ReadLine()); } catch (Exception ex) { DrawMenu(); Debug.WriteLine(ex); } } }
private void tsmiEdmondsKarp_Click(object sender, EventArgs e) { if (_field.Status == false) { return; } if (_field.MarkedVertexModelCount == 2) { new Thread(() => { try { var args = new EdmondsKarpCommandArgs(sourceModel, stockModel); CommandEntered.Invoke(this, args); if (args.SuccsessOut) { ResultForm resform = new ResultForm(args.TaskNameOut, args.AlgorithmNameOut, args.MaxFlowOut.ToString()); BeginInvoke((MethodInvoker)(() => { resform.Owner = this; resform.ShowDialog(); if (resform.Stream != null) { StringBuilder sb = new StringBuilder(); sb.AppendLine(resform.TaskName); sb.AppendLine(resform.AlgorithmName); sb.AppendLine(resform.ResultText); CommandEntered?.Invoke(this, new SaveAlgorithmResultCommandArgs(resform.Stream, sb.ToString())); } })); } } catch (Exception ex) { PostErrorMessage(ex.Message); } }).Start(); } else { PostWarningMessage("Надо вбрать две вершини!!!"); } }
private void tsmiConnectedComponents_Click(object sender, EventArgs e) { if (_field.Status == false) { return; } new Thread(() => { var args = new ConnectedComponentsCommandArgs(); CommandEntered?.Invoke(this, args); StringBuilder components = new StringBuilder(); components.AppendLine($"Алгоритм: \"{args.AlgorithmNameOut}\""); for (int i = 0; i < args.ComponentsOut.Count; i++) { components.Append($"Компонента {i + 1}: "); args.ComponentsOut[i].ForEach(v => components.Append($"{v}, ")); components.Append("\r\n"); } MessageBox.Show(components.ToString(), args.ConnectedTypeOut, MessageBoxButtons.OK, MessageBoxIcon.None); }).Start(); }
private void btnUnion_Click(object sender, EventArgs e) { int count; if ((count = listBoxAdjList.SelectedItems.Count) == 0) { return; } string[] names = new string[count]; int i = 0; foreach (var elem in listBoxAdjList.SelectedItems) { names[i++] = (string)elem; } var window = new StoredGraphNameForm(); window.Owner = this; window.ShowDialog(); if (window.Ok) { CommandEntered?.Invoke(this, new GraphUnionCommandArgs(names, window.ListName)); } }
private void GetInput() { CommandEntered?.Invoke(Console.ReadLine()); }
protected virtual void OnCommandEntered(string command) { CommandEntered?.Invoke(this, command); }