void CompleteSession(APICommand command) { if (OnSessionEnded != null) { OnSessionEnded.Invoke(this); } }
public APIAnswer(APICommand command, object answer, Exception exception = null) { if ((Command = command) == null) { throw new ArgumentNullException(nameof(command)); } Exception = exception; }
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)); }
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))); } }
void GetAPIType(APICommand command) { SendObject(new APIAnswer(command, GetType())); }