Ejemplo n.º 1
0
 void CompleteSession(APICommand command)
 {
     if (OnSessionEnded != null)
     {
         OnSessionEnded.Invoke(this);
     }
 }
Ejemplo n.º 2
0
 public APIAnswer(APICommand command, object answer, Exception exception = null)
 {
     if ((Command = command) == null)
     {
         throw new ArgumentNullException(nameof(command));
     }
     Exception = exception;
 }
Ejemplo n.º 3
0
        void GetAPICommands(APICommand command)
        {
            var dict = new Dictionary <string, Type[]>();

            foreach (var f in apiCommands)
            {
                dict.Add(f.Key, (f.Value.Method.GetCustomAttributes(typeof(APICommandAttr), true)[0] as APICommandAttr).InputParams);
            }
            SendObject(new APIAnswer(command, dict));
        }
Ejemplo n.º 4
0
        void Perform(APICommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (apiCommands.TryGetValue(command.Command, out Action <APICommand> method))
            {
                Task t;
                var  prms     = command.Params;
                var  attrPrms = (method.Method.GetCustomAttributes(typeof(APICommandAttr), true)[0] as APICommandAttr).InputParams;
                if (prms.Length != attrPrms.Length)
                {
                    SendObject(new APIAnswer(command, null,
                                             new NotImplementedException("Current API command, named " + command.Command + " must have " + attrPrms.Length + " parameters")));
                    return;
                }
                for (int i = 0; i < prms.Length; i++)
                {
                    if (prms[i].GetType() != attrPrms[i])
                    {
                        string msg = "Current API command, named " + command.Command + " must have " + attrPrms.Length + " parameters of type: ";
                        foreach (var f in attrPrms)
                        {
                            msg += "[" + f.GetType() + "]";
                        }
                        SendObject(new APIAnswer(command, null,
                                                 new NotImplementedException("Current API command, named " + command.Command + " must have " + attrPrms.Length + " parameters")));
                        return;
                    }
                }
                t = Task.Run(() => method(command));
            }
            else
            {
                SendObject(new APIAnswer(command, null,
                                         new NotImplementedException("Current API haven't command, named " + command.Command)));
            }
        }
Ejemplo n.º 5
0
 void GetAPIType(APICommand command)
 {
     SendObject(new APIAnswer(command, GetType()));
 }