private void ShowChildren(object sender, RoutedEventArgs e) { rightPanel.Children.Clear(); ListBox childrenList = new(); rightPanel.Children.Add(new Label() { Content = "Список детей", VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(10, 10, 0, 0), FontWeight = FontWeights.Bold }); using (SqlConnection conn = new SqlConnection(connection)) { conn.Open(); SqlDataAdapter sda = new SqlDataAdapter($"select [surname],[name],[fathers_name] from [dbo].[children] where [children].[squad_id] = {squadId}", conn); workDS.Tables["children"]?.Clear(); sda.Fill(workDS, "children"); squadsList.SelectionChanged += new SelectionChangedEventHandler(SquadSelect); for (int i = 0; i < workDS.Tables["children"].Rows.Count; i++) { childrenList.Items.Add($"{i+1}. {workDS.Tables["children"].Rows[i].ItemArray[0]} {workDS.Tables["children"].Rows[i].ItemArray[1]} {workDS.Tables["children"].Rows[i].ItemArray[2]}"); } conn.Close(); } childrenList.Margin = new Thickness(10, 10, 10, 10); childrenList.VerticalAlignment = VerticalAlignment.Center; rightPanel.Children.Add(childrenList); lastCommand = ShowChildren; lastArgs = e; lastSender = sender; }
public override bool ProcessCommand(string commandLine) { // If an input state machine is running, send commandLine to machine if (CurrentStateMachine != null && !CurrentStateMachine.IsFinalStateReached) { CurrentStateMachine.ProcessInput(this, commandLine); return(true); } else { CurrentStateMachine = null; // reset current state machine if not currently running one // ! means repeat last command (only when last command was not delete) if (commandLine != null && commandLine.Length >= 1 && commandLine[0] == '!') { if (LastCommand?.ToLowerInvariant() == "delete") { Send("Cannot use '!' to repeat 'delete' command"); _deletionConfirmationNeeded = false; // reset delete confirmation return(false); } commandLine = LastCommand; LastCommandTimestamp = DateTime.Now; } else { LastCommand = commandLine; LastCommandTimestamp = DateTime.Now; } // Extract command and parameters bool extractedSuccessfully = CommandHelpers.ExtractCommandAndParameters(Aliases, commandLine, out string command, out string rawParameters, out CommandParameter[] parameters, out bool forceOutOfGame);
private void GetTodaySchedule(object sender, RoutedEventArgs e) { rightPanel.Children.Clear(); DataGrid schedule = new() { IsReadOnly = true }; rightPanel.Children.Add(new Label() { Content = "Расписание", VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(10, 10, 0, 0), FontWeight = FontWeights.Bold }); using (SqlConnection conn = new SqlConnection(connection)) { conn.Open(); SqlDataAdapter sda = new SqlDataAdapter($"exec [dbo].[getTodaySchedule] {groupId}", conn); workDS.Tables["schedule"]?.Clear(); sda.Fill(workDS, "schedule"); schedule.ItemsSource = workDS.Tables["schedule"].DefaultView; conn.Close(); } schedule.Margin = new Thickness(10, 10, 10, 10); rightPanel.Children.Add(schedule); lastCommand = GetTodaySchedule; lastArgs = e; lastSender = sender; } }
private void RxWaitCallback(object o) { if (TxQueue.Count == 0) { LastCommand = eCommands.Idle; CrestronConsole.PrintLine("rx timeout, nothing in queue"); } else { LastCommand = TxQueue.Dequeue(); CrestronConsole.PrintLine("rx timeout, sending {0}", LastCommand.ToString()); //if (LastCommand == eCommands.VolumeChange) //{ // _com.Send(GetVolumeString()); // RxWaitTimer.Reset(500); //} //else //{ _com.Send(CommandStrings[LastCommand]); RxWaitTimer.Reset(500); //} } CrestronConsole.PrintLine("There are {0} commands in queue", TxQueue.Count); }
private async void ScheduleTimeout() { try { await Task.Delay(100, _cts.Token); } catch (TaskCanceledException) { return; } TaskCompletionSource <CommandError> ctl = null; var isSending = false; //spin lock while (Interlocked.CompareExchange(ref _taskLockTag, CASHelper.LockUsed, CASHelper.LockFree) != CASHelper.LockFree) { } if (_lastCommand != null) { isSending = true; _lastCommand = null; ctl = _currentTaskCtl; _currentTaskCtl = null; } //free lock Interlocked.CompareExchange(ref _taskLockTag, CASHelper.LockFree, CASHelper.LockUsed); if (!isSending) { return; } ctl?.SetResult(CommandError.Timeout); }
protected override void OnModelChanged() { NextCommand.RaiseCanExecuteChanged(); PreviousCommand.RaiseCanExecuteChanged(); FirstCommand.RaiseCanExecuteChanged(); LastCommand.RaiseCanExecuteChanged(); RaisePropertyChanged(nameof(TotalPages)); }
private void NewObject() { LastCommand?.Deactivate(Application.Current.MainWindow); var o = CurrentScene.CreateNew(); LastCommand = new CreateNewObject(Application.Current.MainWindow, o); SelectedObject = o; CurrentScene.Redraw(); }
private void ScaleObject() { LastCommand?.Deactivate(Application.Current.MainWindow); LastCommand = new ScaleCommand(Application.Current.MainWindow, SelectedObject); LastCommand.OnApply += () => { LastCommand.Deactivate(Application.Current.MainWindow); LastCommand = null; }; }
public int GetCommand(Guid username) { if (LastCommand.ContainsKey(username)) { return(LastCommand[username]); } else { return(-1); } }
public void SetLastCommand(LastCommand info) { _lastResult = ParseResult.Complete; _state = State.Init; _stateText = ""; rawCount = info.rawCount; move = info.move; moveChar = info.moveChar; action = info.action; register = info.register; shortcut = info.shortcut; }
public LastCommand GetLastCommand() { LastCommand info = new LastCommand(); info.rawCount = rawCount; info.move = move; info.moveChar = moveChar; info.action = action; info.register = register; info.shortcut = shortcut; return(info); }
public void CommitResponse(ArraySegment <byte> data) { if (data.Array == null) { AppLogger.Error("invalid data"); return; } if (data.Count <= 0) { AppLogger.Error("invalid data"); return; } var funcId = data.Array[data.Offset]; LastCommand task = null; TaskCompletionSource <CommandError> ctl = null; //spin lock while (Interlocked.CompareExchange(ref _taskLockTag, CASHelper.LockUsed, CASHelper.LockFree) != CASHelper.LockFree) { } if (_lastCommand != null && _lastCommand.FuncId == funcId) { task = _lastCommand; _lastCommand = null; ctl = _currentTaskCtl; _currentTaskCtl = null; } //free lock Interlocked.CompareExchange(ref _taskLockTag, CASHelper.LockFree, CASHelper.LockUsed); if (task == null) { return; } _cts.Cancel(); _cts = new CancellationTokenSource(); if (!_cmdhandler.TryGetValue(task.Cmd, out var handler)) { ctl.SetResult(CommandError.Failed); return; } if (handler.ReponseHasErrorFlag) { var success = data.Array[data.Offset + 1] == 0; ctl.SetResult(success ? CommandError.Success : CommandError.Failed); return; } ctl.SetResult(CommandError.Success); }
private void Model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == nameof(Model.MaximumRows) || e.PropertyName == nameof(Model.StartRowIndex) || e.PropertyName == nameof(Model.Count)) { OnPropertyChanged(nameof(CurrentPage)); OnPropertyChanged(nameof(CountOfPages)); OnPropertyChanged(nameof(StringCountOfPages)); FirstCommand.RiseCanExecute(); PreviousCommand.RiseCanExecute(); NextCommand.RiseCanExecute(); LastCommand.RiseCanExecute(); } }
/// <inheritdoc cref="object.ToString" /> public override string ToString() { return(string.Format ( "Number: {0}, IPAddress: {1}, " + "Name: {2}, ID: {3}, Workstation: {4}, " + "Started: {5}, LastCommand: {6}, " + "CommandNumber: {7}, ProcessID: {8}, " + "State: {9}", Number.ToVisibleString(), IPAddress.ToVisibleString(), Name.ToVisibleString(), ClientID.ToVisibleString(), Workstation.ToVisibleString(), Started.ToVisibleString(), LastCommand.ToVisibleString(), CommandNumber.ToVisibleString(), ProcessID.ToVisibleString(), State.ToVisibleString() )); }
public void SetCommand(UndoRedoWrapper command) { if (LastCommand.ContainsKey(command.Command.Username)) { int position = 0; for (int i = Counter; i >= 0; i--) { if (command == Commands[i]) { position = i; } } LastCommand[command.Command.Username] = position; } else { LastCommand.Add(command.Command.Username, Counter); } }
private void Watcher_Changed(object sender, FileSystemEventArgs e) { if (e.ChangeType == WatcherChangeTypes.Changed) { try { LastCommand = File.ReadAllText(e.FullPath); switch (LastCommand.ToLower().GetValue()) { case CONFIG_CLOSE_COMMAND1: case CONFIG_CLOSE_COMMAND2: case CONFIG_CLOSE_COMMAND3: case CONFIG_CLOSE_COMMAND4: case CONFIG_CLOSE_COMMAND5: case CONFIG_CLOSE_COMMAND6: case CONFIG_CLOSE_COMMAND7: Close(); break; case CONFIG_UP_COMMAND: ComeOnUp(); break; default: // it means the command is unknown to us. Debug.Print(UnknownCommandError + LastCommand.GetValue()); break; } } catch (Exception _e) { // it means there was an error here .. // so, never mind it and just continue the game :| Debug.Print(_e.Message); return; } } }
private void DeleteObject() { LastCommand?.Deactivate(Application.Current.MainWindow); LastCommand = null; var index = CurrentScene.Objects.IndexOf(SelectedObject); CurrentScene.Objects.RemoveAt(index); if (CurrentScene.Objects.Count > 0) { SelectedObject = index < CurrentScene.Objects.Count ? CurrentScene.Objects[index] : CurrentScene.Objects[--index]; } else { SelectedObject = null; } CurrentScene.Redraw(); }
private static void Main() { Console.WriteLine("Welcome to PayParking!"); Console.WriteLine("Commands: enter <registration>, leave <registration>, list, price, quit"); Garage = new Garage(10); while (!LastCommand.Equals("quit", StringComparison.OrdinalIgnoreCase)) { try { Console.WriteLine("Waiting for user input..."); LastCommand = Console.ReadLine(); if (LastCommand.Length == 0) { continue; } GetActionFromCommand(LastCommand)(); } catch (Exception ex) when(ex is System.IO.IOException || ex is OutOfMemoryException) { } } }
/// <summary> /// 输出日志 /// </summary> /// <param name="args"></param> private void CmdLog(byte[][] args) { var sb = new StringBuilder(); foreach (var arg in args) { if (sb.Length > 0) { sb.Append(" "); } sb.Append(arg.FromUtf8Bytes()); } LastCommand = sb.ToString(); if (LastCommand.Length > 100) { LastCommand = LastCommand.Substring(0, 100) + "..."; } s_Logger.Debug("S: " + LastCommand); }
/// <summary> Parses a message on behalf of this player. </summary> /// <param name="rawMessage"> Message to parse. </param> /// <param name="fromConsole"> Whether the message originates from console. </param> /// <exception cref="ArgumentNullException"> rawMessage is null. </exception> public void ParseMessage([NotNull] string rawMessage, bool fromConsole) { if (rawMessage == null) { throw new ArgumentNullException("rawMessage"); } // handle canceling selections and partial messages if (rawMessage.StartsWith("/nvm", StringComparison.OrdinalIgnoreCase) || rawMessage.StartsWith("/cancel", StringComparison.OrdinalIgnoreCase)) { if (partialMessage != null) { MessageNow("Partial message cancelled."); partialMessage = null; } else if (IsMakingSelection) { SelectionCancel(); MessageNow("Selection cancelled."); } else { MessageNow("There is currently nothing to cancel."); } return; } if (partialMessage != null) { rawMessage = partialMessage + rawMessage; partialMessage = null; } // replace %-codes with &-codes if (Can(Permission.UseColorCodes)) { rawMessage = Chat.ReplacePercentColorCodes(rawMessage, true); } // replace emotes if (Can(Permission.UseEmotes)) { rawMessage = Chat.ReplaceEmoteKeywords(rawMessage); } rawMessage = Chat.UnescapeBackslashes(rawMessage); switch (Chat.GetRawMessageType(rawMessage)) { case RawMessageType.Chat: HandleChatMessage(rawMessage); break; case RawMessageType.Command: HandleCommandMessage(rawMessage, fromConsole); break; case RawMessageType.PrivateChat: HandlePrivateChatMessage(rawMessage); break; case RawMessageType.RankChat: HandleRankChatMessage(rawMessage); break; case RawMessageType.RepeatCommand: if (LastCommand == null) { Message("No command to repeat."); } else { if (Info.IsFrozen && (LastCommand.Descriptor == null || !LastCommand.Descriptor.UsableByFrozenPlayers)) { MessageNow("&WYou cannot use this command while frozen."); return; } LastCommand.Rewind(); Logger.Log(LogType.UserCommand, "{0} repeated: {1}", Name, LastCommand.RawMessage); Message("Repeat: {0}", LastCommand.RawMessage); SendToSpectators(LastCommand.RawMessage); CommandManager.ParseCommand(this, LastCommand, fromConsole); } break; case RawMessageType.Confirmation: if (Info.IsFrozen) { MessageNow("&WYou cannot use any commands while frozen."); return; } if (ConfirmCallback != null) { if (DateTime.UtcNow.Subtract(ConfirmRequestTime) < ConfirmationTimeout) { Logger.Log(LogType.UserCommand, "{0}: /ok", Name); SendToSpectators("/ok"); ConfirmCallback(this, ConfirmParameter, fromConsole); ConfirmCancel(); } else { MessageNow("Confirmation timed out. Enter the command again."); } } else { MessageNow("There is no command to confirm."); } break; case RawMessageType.PartialMessage: partialMessage = rawMessage.Substring(0, rawMessage.Length - 1); MessageNow("Partial: &F{0}", partialMessage); break; case RawMessageType.Invalid: MessageNow("Could not parse message."); break; } }
/// <summary> /// Handles the Click event of the settingsToolStripMenuItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev05, 2007-08-06</remarks> private void settingsToolStripMenuItem_Click(object sender, EventArgs e) { Application.DoEvents(); //necessary to enable immediate repainting SettingsForm settingsForm = new SettingsForm(settings, numPadControl, dictionaryManager); bool mediaFileAvailableOld = numPadControl.MediaFileAvailable; numPadControl.MediaFileAvailable = true; settingsForm.ShowDialog(); numPadControl.MediaFileAvailable = mediaFileAvailableOld; settings.Save(CONSTANTS.SETTINGS_FILENAME); numPadControl.PresenterActivated = settings.PresenterActivated; lastCommand = (lastCommand == LastCommand.Next) ? LastCommand.Back : LastCommand.Next; RefreshListView(); UpdateSettings(); }
public async Task <CommandError> ExecCmd(DevCommandEnum cmd, params object[] args) { if (!_cmdhandler.TryGetValue(cmd, out var handler)) { AppLogger.Error("Device Command Not Found:"); return(CommandError.CommandNotFound); } var task = new LastCommand { Cmd = cmd, FuncId = handler.FuncId }; if (handler.DontCheckResponse) { task = null; } var isSending = false; //spin lock while (Interlocked.CompareExchange(ref _taskLockTag, CASHelper.LockUsed, CASHelper.LockFree) != CASHelper.LockFree) { } if (_lastCommand != null) { isSending = true; } else { _lastCommand = task; } //free lock Interlocked.CompareExchange(ref _taskLockTag, CASHelper.LockFree, CASHelper.LockUsed); if (isSending) { return(CommandError.SendingCommand); } var buf = new RecycleBuffer(handler.CntSize, _bufMgr); var buffer = buf.Buffer; var cmdState = handler.FillCnt(buffer, args); buffer[0] = handler.FuncId; if (handler.DontCheckResponse) { _clientFrameSender.OnNext(buf.AsDisposableValue()); handler.HandlerSuccessAsync(cmdState); return(CommandError.Success); } _currentTaskCtl = new TaskCompletionSource <CommandError>(); var loclCtl = _currentTaskCtl; _clientFrameSender.OnNext(buf.AsDisposableValue()); #if !DisableDevTimeout if (_enableTimeout) { ScheduleTimeout(); } #endif try { var waitingTask = loclCtl.Task; var result = await waitingTask; if (result == CommandError.Success) { handler.HandlerSuccessAsync(cmdState); } return(result); } catch (Exception ex) { AppLogger.Error(ex.Message); return(CommandError.Failed); } }
public async Task <CommandError> ExecCmd(DevCommandEnum cmd, params object[] args) { if (!_cmdhandler.TryGetValue(cmd, out var handler)) { AppLogger.Error("Device Command Not Found:"); return(CommandError.CommandNotFound); } var task = new LastCommand { Cmd = cmd, FuncId = handler.FuncId }; if (handler.DontCheckResponse) { task = null; } var isSending = false; //spin lock while (Interlocked.CompareExchange(ref _taskLockTag, CASHelper.LockUsed, CASHelper.LockFree) != CASHelper.LockFree) { } if (_lastCommand != null) { isSending = true; } else { _lastCommand = task; } //free lock Interlocked.CompareExchange(ref _taskLockTag, CASHelper.LockFree, CASHelper.LockUsed); if (isSending) { return(CommandError.SendingCommand); } var buf = new RecycleBuffer(handler.CntSize, _bufMgr); var buffer = buf.Buffer; handler.FillCnt(buffer, args); buffer[0] = handler.FuncId; if (handler.DontCheckResponse) { _clientFrameSender.OnNext(DisposableValue.Create(new ArraySegment <byte>(buffer), buf)); return(CommandError.Success); } _currentTaskCtl = new TaskCompletionSource <CommandError>(); _clientFrameSender.OnNext(DisposableValue.Create(new ArraySegment <byte>(buffer), buf)); #if !DisableDevTimeout ScheduleTimeout(); #endif return(await _currentTaskCtl.Task); }
/// <summary> /// Handles the AfterSelect event of the treeViewCards control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Forms.TreeViewEventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev05, 2007-08-09</remarks> private void treeViewCards_AfterSelect(object sender, TreeViewEventArgs e) { if (treeViewCards.SelectedNode != null && !updating) { if (treeViewCards.SelectedNode.Tag is string && (string)treeViewCards.SelectedNode.Tag == "Card") { lastCommand = LastCommand.Next; settings.ActualStep = 0; settings.ActualCard = treeViewCards.SelectedNode.Index; } else settings.ActualStep = treeViewCards.SelectedNode.Index; } if (treeViewCards.SelectedNode != null) treeViewCards.SelectedNode.ForeColor = treeViewCards.SelectedNode.BackColor; if (!updating) UpdateSettings(); }
/// <summary> /// Go to the next card. /// </summary> /// <remarks>Documented by Dev05, 2007-08-03</remarks> private void Next() { numPadControl.UninstallHook(); if (settings.ActualCard == dictionaryManager.CardCount - 1 && settings.ActualStep == settings.RecordingOrder.Length - 1) { if (!multiselecting && MessageBox.Show(Resources.JUMP_TO_OTHER_END_TEXT, Resources.JUMP_TO_OTHER_END_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { settings.ActualStep = -1; settings.ActualCard = 0; } else { if (!treeViewCards.Nodes[treeViewCards.Nodes.Count - 1].Checked) Back(); return; } } lastCommand = LastCommand.Next; if (settings.ActualStep + 1 < settings.RecordingOrder.Length) settings.ActualStep++; else { if (settings.ActualCard + 1 < dictionaryManager.CardCount) { settings.ActualCard++; settings.ActualStep = 0; while (settings.ActualCard + 1 < dictionaryManager.CardCount && !treeViewCards.Nodes[settings.ActualCard].Checked) settings.ActualCard++; } } settings.Save(CONSTANTS.SETTINGS_FILENAME); UpdateSettings(); numPadControl.InstallHook(); }
public static bool TryCommand(string Data) { string[] FullCommandWithArguments; FullCommandWithArguments = Data.Split(null); switch (FullCommandWithArguments[0]) { case "about": About.Command(); return(true); case "%execution.path%": ExecutionPaths.Command(); return(true); case "copy": FileCopy.Command(FullCommandWithArguments); return(true); case "exit": Exit.Command(FullCommandWithArguments); return(true); case "stacktolog": StackToLog.Command(); return(true); case "vars": Vars.Command(FullCommandWithArguments); return(true); case "clear": ClearScreen.Command(); return(true); case "lastcommand": LastCommand.Command(); return(true); case "cd": Cd.Command(FullCommandWithArguments); return(true); case "collectgarbage": Functions.AppOnlyScope.Disposal.RunCleanup(); return(true); case "ls": Ls.Command(FullCommandWithArguments); return(true); case "ping": Ping.Command(FullCommandWithArguments); return(true); case "ipinfo": IpInfo.Command(FullCommandWithArguments); return(true); case "commands": CommandList.Command(); return(true); case "help": CommandList.Command(); return(true); case "download": Download.Command(FullCommandWithArguments); return(true); case "start": Run.Command(FullCommandWithArguments); return(true); case "run": Run.Command(FullCommandWithArguments); return(true); default: return(false); } }