private void ExecuteOnOffCommands() { // Make sure to raise the right command, depending on the IsOn state. // Also ensure that each command is executable. if (IsOn && OnCommand != null && OnCommand.CanExecute(OnCommandParameter)) { this.TraceVerbose("Executing OnCommand."); OnCommand.Execute(OnCommandParameter); } if (!IsOn && OffCommand != null && OffCommand.CanExecute(OffCommandParameter)) { this.TraceVerbose("Executing OffCommand."); OffCommand.Execute(OffCommandParameter); } }
protected void RegisteCommand(int command, OnCommand commandHandler) { List <OnCommand> commandList = null; if (commandDic.TryGetValue(command, out commandList)) { commandList.Add(commandHandler); } else { commandList = new List <OnCommand>(); commandList.Add(commandHandler); commandDic.Add(command, commandList); } }
internal void SubscribeOnCommand(string command, OnCommand handler) { command = command.ToLower(); if (_handlers == null) { _handlers = new Dictionary <string, List <OnCommand> >(); } if (!_handlers.ContainsKey(command)) { _handlers.Add(command, new List <OnCommand>()); } _handlers[command].Add(handler); }
private void CheckForKeys(Event _event) { if (allowEnterKey && (chatInputField.Trim().Length > 0) && EnterPressed(_event)) { string message = chatInputField.Trim(); chatInputField = ""; allowEnterKey = false; GUIUtility.keyboardControl = 0; if (message.StartsWith(VRCTools.ModPrefs.GetString(prefSection, "cmdprefix"))) { Utils.Log("OnCommand " + message); OnCommand?.Invoke(new ChatCommand(message)); } else { Utils.Log("OnMessage " + message); object Sender; if (APIUser.CurrentUser is null) { Sender = "You"; } else { Sender = APIUser.CurrentUser; } var msg = new ChatMessage(content: message, timestamp: DateTime.Now, sender: Sender); #if UNITY_EDITOR HandleMessage(msg, DateTime.Now, "Me"); #else HandleMessage(msg); #endif OnMessage?.Invoke(msg); } } else { allowEnterKey = GUI.GetNameOfFocusedControl() == "chatInputField"; } if (allowEnterKey && Event.current.keyCode == KeyCode.Escape) { GUIUtility.keyboardControl = 0; } }
private void MonitorMethod() { while (true) { var Api = Helper.Api; var server = Api.Groups.GetLongPollServer(_groupId); var poll = Api.Groups.GetBotsLongPollHistory(new BotsLongPollHistoryParams() { Server = server.Server, Key = server.Key, Ts = server.Ts, Wait = 25 }); if (poll?.Updates == null) { continue; } foreach (var e in poll.Updates) { if (e.Type == GroupUpdateType.MessageNew) { if (e.Message.Text.IndexOf("/") == 0) { var inputString = e.Message.Text.Trim().ToLower(); var StrCmdList = inputString.Split('"').Select((element, index) => index % 2 == 0 ? element.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { element }).SelectMany(element => element).ToList(); var CmdName = StrCmdList[0]; StrCmdList.Remove(CmdName); var res = Commands.GetCommand(CmdName.Remove(0, 1)); if (res != null) { OnCommand?.Invoke(this, new CommandEventArgs(e.Message, res, inputString, StrCmdList.ToArray())); } else { OnCommandNotFound?.Invoke(this, new CommandEventArgs(e.Message, res, inputString, StrCmdList.ToArray())); } break; } NewMessage?.Invoke(this, new NewMessageEventArgs(e.Message)); break; } } } }
protected void UnRegisteCommand(int command, OnCommand commandHandler) { List <OnCommand> commandList = null; if (commandDic.TryGetValue(command, out commandList)) { if (commandList.Contains(commandHandler)) { commandList.Remove(commandHandler); } else { ZLog.Error("no commandHandler with " + command + " named " + commandHandler.Method.Name); } } else { ZLog.Error("no command in " + ToString() + " named " + command); } }
public static void Main(string[] args) { // our application will need some reveiver object Television device = new Television(); // our application will need an invoker object, which // in turns relies on concrete command objects: ICommand on = new OnCommand(device); // command to switch device on ICommand off = new OffCommand(device); // command to switch device off ICommand up = new UpCommand(device); // command to turn volume up ICommand down = new DownCommand(device);// command to turn volume down // now we are ready to create our invoker object which // we should think of as some sort of application menu. RemoteControl menu = new RemoteControl(on, off, up, down); // client code is now able to access the invoker object menu.SwitchPowerOn(); menu.RaiseVolume(); menu.RaiseVolume(); menu.RaiseVolume(); menu.LowerVolume(); menu.SwitchPowerOff(); }
static void Main(string[] args) { string input = Console.ReadLine(); ISwitchable device = new Lamp(); ICommand onCommand = new OnCommand(device); ICommand offCommand = new OffCommand(device); Switch @switch = new Switch(onCommand, offCommand); switch (input) { case "On": @switch.On(); break; case "Off": @switch.Off(); break; } }
public static void InvokeCommand(ref string query, ref CommandSender sender, ref bool allow) { OnCommand adminCommandEvent = RemoteAdminCommandEvent; if (adminCommandEvent == null) { return; } RACommandEvent ev = new RACommandEvent() { Allow = allow, Command = query, Sender = sender }; adminCommandEvent?.Invoke(ref ev); query = ev.Command; sender = ev.Sender; allow = ev.Allow; }
public async Task LockWrite(Func <Task> Action) { var Done = AsyncTaskMethodBuilder.Create(); Func <Task> Waiter = async() => { try { await Action(); } finally { Done.SetResult(); } }; lock (this) { WriteQueue.Insert(Waiter); OnCommand?.Invoke(); } await Done.Task; }
public void Run() { while (IsRunning) { if (!string.IsNullOrWhiteSpace(Prompt)) { console.Write(Level.None, Prompt); } while (IsRunning) { ConsoleKeyInfo keyInfo = Console.ReadKey(true); char keyChar = keyInfo.KeyChar; if (keyInfo.Key == ConsoleKey.Enter) { break; } switch (keyInfo.Key) { case ConsoleKey.Backspace: if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control)) { Clear(); } else { Backspace(); } break; case ConsoleKey.Delete: if (MoveCaretRight()) { Backspace(); } break; case ConsoleKey.UpArrow: ShowHistory(-1); break; case ConsoleKey.DownArrow: ShowHistory(1); break; case ConsoleKey.LeftArrow: MoveCaretLeft(); break; case ConsoleKey.RightArrow: MoveCaretRight(); break; case ConsoleKey.Tab: AttemptAutocomplete(); break; default: if (char.IsWhiteSpace(keyChar) || char.IsPunctuation(keyChar) || char.IsSymbol(keyChar) || char.IsLetterOrDigit(keyChar)) { InsertChar(keyChar); } break; } } console.WriteLine(Level.None); string cmd = sb.ToString().Trim(); if (!string.IsNullOrWhiteSpace(cmd)) { commandHistory.Add(cmd); } historyIndex = commandHistory.Count; if (commandHistory.Count > MaxCommandHistory) { commandHistory.RemoveAt(0); } OnCommand?.Invoke(this, cmd); sb.Clear(); caretIndex = 0; } }
public static void RegisterPlugIn( OnCommand cmd, string name, string desc, string helpDesc ) { PlugIns[name] = cmd; ArrayList List = new ArrayList(); List.Add( name ); List.Add( desc ); List.Add( helpDesc ); PlugInsList.Add( List ); PlugInsList.Sort( new PlugInSorter() ); }
public CommandResult Execute(CommandContext command) { return(OnCommand.Invoke(command)); }
/** * The On Command * * @return the Task<CommandResult> command result Task */ public Task <CommandResult> OnCommand() { OnCommand command = new OnCommand(); return(Send(command)); }
internal void OnAssetState(AssetState state) { State = state; OnCommand?.Invoke(this, this); }
public void RegisterCommand(string commandName, string description, OnCommand callback) { commands.Add(commandName, callback); }
public static void InvokeCommand(CommandEventArgs e) { OnCommand?.Invoke(e); }
public void FireCommand(object command) { OnCommand?.Invoke(command); }
private void menuItem_Click(object sender, EventArgs e) { MenuItem menuItem = sender as MenuItem; OnCommand.Call(menuItem.Tag.ToString()); }
public void Command(CommandEventArgs e) => OnCommand?.Invoke(this, e);
public void PressOnButton() { OnCommand.Execute(); }
internal static void RunCommand(string command) => OnCommand?.Invoke(command);
internal static void InvokeOnCommand(Command cmd) { OnCommand?.Invoke(cmd); }
private void HandleReceiveBuffer2(Socket socket) { // TODO - Refactor HandleReceiveBuffer2 // 1: best-case scenario: er staat een geheel bericht in buffer // 2: meerdere berichten in buffer // 3: deelbericht in buffer // 4: kapotte buffer //System.Diagnostics.Debug.Print(DateTime.Now.ToString("HH:mm:ss.fffff") + ":HandleReceiveBuffer2:" + _receiveBuffer.Length); var msgs = Protocol.ParseBuffer(ref _receiveBuffer); if (msgs == null) { return; } foreach (MsgPack.MessagePackObject msg in msgs) { //if (OnMessage != null) //{ // OnMessage(this, new KeyConductorRawCommandEventArgs(msg)); // this is the raw message from the KeyConductorLite //} // handle the message // first key/pair = KCID // second key/pair = CommandType // rest is based on commandtype var dicMessage = msg.AsDictionary(); // Generic parameters string kcid = "000000000000"; // default kcid Protocol.CommandType commandType = Protocol.CommandType.Undefined; Protocol.ReturnValues returnValue = Protocol.ReturnValues.Undefined; string paramData = ""; // Specific parameters byte position = 0; //Protocol.Capabilities capabilities = Protocol.Capabilities.None; Protocol.EventType eventType = Protocol.EventType.Undefined; Protocol.FileName fileName = Protocol.FileName.Undefined; uint fileChecksum = 0; byte[] fileContents = new byte[] { }; foreach (var dc in dicMessage) { if ((byte)dc.Key == (byte)Protocol.Parameter.KCID) // always first parameter { kcid = Convert.ToString((UInt32)dc.Value, 16); } else if ((byte)dc.Key == (byte)Protocol.Parameter.CommandType) // always second parameter { commandType = (Protocol.CommandType)(byte) dc.Value; switch (commandType) { case Protocol.CommandType.GetInfo: OnLogMessage?.Invoke(this, new LogMessageEventArgs("GetInfo request")); ReturnInfo(); break; case Protocol.CommandType.PutFile: case Protocol.CommandType.RemoteRelease: case Protocol.CommandType.SetDateTime: case Protocol.CommandType.RemoteReturn: OnLogMessage?.Invoke(this, new LogMessageEventArgs(string.Format("Command:{0} request", commandType))); ReturnOk(commandType); break; } } else if ((byte)dc.Key == (byte)Protocol.Parameter.Position) { position = (byte)dc.Value; } else // rest of the parameters depends on type of command/event { switch (commandType) { case Protocol.CommandType.GetFile: { if ((byte)dc.Key == (byte)Protocol.Parameter.FileName) { fileName = (Protocol.FileName)(byte) dc.Value; OnLogMessage?.Invoke(this, new LogMessageEventArgs(string.Format("Command:GetFile {0} request", fileName))); ReturnDummyFile(fileName); } } break; case Protocol.CommandType.OnEvent: { if ((byte)dc.Key == (byte)Protocol.Parameter.EventType) { eventType = (Protocol.EventType)(byte) dc.Value; } else if ((byte)dc.Key == (byte)Protocol.Parameter.EventData) { // depends on eventType switch (eventType) { // Standalone events: case Protocol.EventType.RemoteAuthentication: { //case Protocol.EventType.KeyBoardPress: // ter simulatie string userCode = "0000"; string pinCode = "0000"; string userData = ""; // bytes[0] + bytes[1]: userCode of pinCode // bytes[2] + bytes[3]: pinCode // bytes[rest]: userData (optional) paramData = BitConverter.ToString((byte[])dc.Value).Replace("-", ""); // Note that both UserCode and Pincode are byte-rotated; 1234 -> 3412 if (paramData.Length == 4) { pinCode = paramData.Substring(2, 2) + paramData.Substring(0, 2); } else if (paramData.Length >= 8) { userCode = paramData.Substring(2, 2) + paramData.Substring(0, 2); pinCode = paramData.Substring(6, 2) + paramData.Substring(4, 2); } if (paramData.Length > 8) { for (int i = 8; i < paramData.Length; i++) { userData += (char)paramData[i]; // Convert.ToString(paramData[i], 10); } } var evtArg = new RemoteAuthenticationEventArgs(kcid, userCode, pinCode, userData); OnRemoteAuthentication?.Invoke(this, evtArg); } break; case Protocol.EventType.Login: case Protocol.EventType.Logout: { string userCode = "0000"; string pinCode = "0000"; string userData = ""; // bytes[0] + bytes[1]: userCode of pinCode // bytes[2] + bytes[3]: pinCode // bytes[rest]: userData (optional) byte[] tmpAuthData = (byte[])dc.Value; paramData = BitConverter.ToString(tmpAuthData).Replace("-", ""); // Note that both UserCode and Pincode are NOT byte-rotated if (paramData.Length == 4) { pinCode = paramData.Substring(0, 4); } else if (paramData.Length >= 8) { userCode = paramData.Substring(0, 4); pinCode = paramData.Substring(4, 4); } if (paramData.Length > 8) { for (int i = 8; i < paramData.Length; i++) { userData += (char)paramData[i]; // Convert.ToString(paramData[i], 10); } } var evtArg = new OnEventUserEventArgs(kcid, userCode, pinCode, userData); if (eventType == Protocol.EventType.Login) { OnEventLogin?.Invoke(this, evtArg); } else { OnEventLogout?.Invoke(this, evtArg); } } break; case Protocol.EventType.DoorOpen: case Protocol.EventType.DoorClosed: { string userCode = "0000"; // bytes[0] + bytes[1]: userCode of pinCode paramData = BitConverter.ToString((byte[])dc.Value).Replace("-", ""); // Note that both UserCode and Pincode are NOT byte-rotated if (paramData.Length == 4) { userCode = paramData; } var evtArg = new OnEventDoorEventArgs(kcid, userCode, 0x00); if (eventType == Protocol.EventType.DoorOpen) { OnEventDoorOpen?.Invoke(this, evtArg); } else { OnEventDoorClosed?.Invoke(this, evtArg); } } break; case Protocol.EventType.KeyReturned: case Protocol.EventType.KeyPicked: { string userCode = "0000"; ushort slot = 0; // bytes[0] + bytes[1]: userCode // V2: bytes[2]: slot // V3: bytes[2] + bytes[3]: slot (ushort) byte[] data = (byte[])dc.Value; paramData = BitConverter.ToString(data).Replace("-", ""); // Note that both UserCode and Pincode are byte-rotated; 1234 -> 3412 userCode = paramData.Substring(2, 2) + paramData.Substring(0, 2); if (data.Length == 3) { // Firmware 2 slot = data[2]; } else if (data.Length == 4) { // Firmware 3 slot = (ushort)(data[2] * 256 + data[3]); } var evtArg = new OnEventKeyEventArgs(kcid, userCode, slot); if (eventType == Protocol.EventType.KeyReturned) { OnEventKeyReturned?.Invoke(this, evtArg); } else { OnEventKeyPicked?.Invoke(this, evtArg); } } break; case Protocol.EventType.Timeout: case Protocol.EventType.Warning: case Protocol.EventType.ExternalAlarm: case Protocol.EventType.ExternalAlarmCleared: case Protocol.EventType.Startup: case Protocol.EventType.MainsVoltageLost: case Protocol.EventType.MainsVoltageConnected: { string userCode = "0000"; // bytes[0] + bytes[1]: userCode byte[] data = (byte[])dc.Value; paramData = BitConverter.ToString(data).Replace("-", ""); // Note that both UserCode is NOT byte-rotated userCode = paramData; var evtArg = new OnEventWarningEventArgs(kcid, userCode, eventType); switch (eventType) { case Protocol.EventType.Warning: OnEventWarning?.Invoke(this, evtArg); break; case Protocol.EventType.Timeout: OnEventTimeout?.Invoke(this, evtArg); break; case Protocol.EventType.ExternalAlarm: OnEventAlarm?.Invoke(this, evtArg); break; case Protocol.EventType.ExternalAlarmCleared: OnEventAlarmCleared?.Invoke(this, evtArg); break; case Protocol.EventType.Startup: OnEventStartUp?.Invoke(this, evtArg); break; case Protocol.EventType.MainsVoltageLost: OnEventMainsVoltageLost?.Invoke(this, evtArg); break; case Protocol.EventType.MainsVoltageConnected: OnEventMainsVoltageConnected?.Invoke(this, evtArg); break; } } break; } } else if ((byte)dc.Key == (byte)Protocol.Parameter.Result_Code) // n-th parameter { // dit komt niet voor bij events !! } } break; default: { if ((byte)dc.Key == (byte)Protocol.Parameter.Result_Code) // n-th parameter { returnValue = (Protocol.ReturnValues)(byte) dc.Value; var evtArg = new KeyConductorBaseReplyEventArgs(kcid, commandType, returnValue); OnCommand?.Invoke(this, evtArg); // raise event for individual functions switch (commandType) { case Protocol.CommandType.Unknown: OnUnknownCommand?.Invoke(this, evtArg); break; case Protocol.CommandType.PutFile: OnPutFile?.Invoke(this, evtArg); break; case Protocol.CommandType.SetDateTime: OnSetDateTime?.Invoke(this, evtArg); break; case Protocol.CommandType.RemoteRelease: OnRemoteRelease?.Invoke(this, evtArg); break; case Protocol.CommandType.RemoteReturn: OnRemoteReturn?.Invoke(this, evtArg); break; case Protocol.CommandType.RemoteReboot: OnRemoteReboot?.Invoke(this, evtArg); break; } } // if parameter = resultcode } break; } // /Switch commandType } //Else parameter } // foreach dc in dicMessage } // foreach msg in msgs } // /HandleReceiveBuffer
public void HandleCommand(string command, string[] arguments) => OnCommand?.Invoke(command, arguments);