Ejemplo n.º 1
0
        public void RegisterCommand(ICommand command, Predicate <object> canExecute, Action <object> execute)
        {
            VerifyArgument(command, "command");
            VerifyArgument(canExecute, "canExecute");
            VerifyArgument(execute, "execute");

            _commandToCallbacksMap[command] = new CommandCallbacks(canExecute, execute);
        }
Ejemplo n.º 2
0
		public void RegisterCommand( ICommand command, Predicate<object> canExecute, Action<object> execute )
		{
			VerifyArgument( command, "command" );
			VerifyArgument( canExecute, "canExecute" );
			VerifyArgument( execute, "execute" );

			_commandToCallbacksMap[command] = new CommandCallbacks( canExecute, execute );
		}
Ejemplo n.º 3
0
 public override void DispatchCommand(CommandModifier active, byte[] inBuf, out byte[] outBuf)
 {
     if (CommandCallbacks != null)
     {
         byte[] tempInBuf;
         CommandCallbacks.PreCallback(inBuf, out tempInBuf);
         if (tempInBuf != null)
         {
             inBuf = tempInBuf;
         }
     }
     Device.DispatchCommand(active, inBuf, out outBuf);
     if (CommandCallbacks != null)
     {
         CommandCallbacks.PostCallback(inBuf, outBuf);
     }
 }
Ejemplo n.º 4
0
        public void ParseInputLine(string line)
        {
            Console.WriteLine($"< '{line}'");

            line = line.Trim();

            if (line.StartsWith("notify") || line.StartsWith("channel"))
            {
                ReceivedEvcent(line);
                return;
            }

            if (CurrentCommand != null)
            {
                if (line.StartsWith("error"))
                {
                    Response = Response.Trim();

                    if (line.EndsWith("ok"))
                    {
                        CurrentCommand.Invoke(null, Response);
                    }
                    else
                    {
                        Console.WriteLine($"Command did not execute successfully (last line '{line}'). Leftover response: {Response}");
                        CommandException = new TeamspeakCommandException($"Command did not execute successfully (last line '{line}'). Leftover response: {Response}");
                        CurrentCommand.Invoke(CommandException, Response);
                    }

                    Response       = "";
                    CurrentCommand = null;
                    if (CommandCallbacks.Count > 0)
                    {
                        (string cmd, Action <Exception, string> callback) = CommandCallbacks.Dequeue();
                        DoSendCommand(cmd, callback);
                    }
                }
                else
                {
                    Response += $"{line}\n\r";
                }
            }
        }
Ejemplo n.º 5
0
        public void SendCommand(string cmd, Action <Exception, string> callback = null)
        {
            string withCallback = callback == null ? "no callback" : "with callback";

            if (callback == null)
            {
                callback = (ex, s) => GenericCallback(cmd, ex, s);
            }


            lock (LastCallLock) {
                if (CurrentCommand != null)
                {
                    CommandCallbacks.Enqueue(Tuple.Create(cmd, callback));
                }
                else
                {
                    DoSendCommand(cmd, callback);
                }
            }
        }