/// <summary> /// sends the command to the server /// <param name="commandEnum"> represents the command</param> /// <param name="handler">the handler to remove</param> /// </summary> public void SendCommandToServer(CommandsEnum commandEnum, string handler) { string[] args = new string[1]; args[0] = handler; client.sendCommand((int)CommandsEnum.RemoveDirCommand, args); //CommandReceivedEventArgs e = new CommandReceivedEventArgs((int)CommandsEnum.GetConfigCommand, args, "Empty"); }
/// <summary> /// Performs a series of check to ensure the call is legal, and return a Command object /// </summary> /// <param name="httpRequest"></param> /// <returns></returns> private Tuple <Command, HttpStatusCode> GetCommandFromRequest(HttpRequest httpRequest) { //Check the authentication if (!httpRequest.Headers.ContainsKey("authorization") || httpRequest.Headers["authorization"] != SecretManager.PortalPasswordBase64) { return(new Tuple <Command, HttpStatusCode>(Command.CreateErrorCommand("Unauthorized."), HttpStatusCode.Unauthorized)); } //if Encryption is enabled, the device will expect a request with encrypted header if (SecretManager.IsEncryptionEnabled && !httpRequest.Headers.ContainsKey(EdisonEncryptHeader)) { return(new Tuple <Command, HttpStatusCode>(Command.CreateErrorCommand("Encryption is enabled on the device."), HttpStatusCode.Unauthorized)); } //Listen to /edison/ endpoints only if (!httpRequest.Query.ToLower().StartsWith("/edison/")) { return(new Tuple <Command, HttpStatusCode>(Command.CreateErrorCommand("Not found."), HttpStatusCode.NotFound)); } //Retrieve the command from the endpoint string commandString = httpRequest.Query.Replace("/edison/", ""); if (!Enum.TryParse(typeof(CommandsEnum), commandString, true, out object commandResult)) { return(new Tuple <Command, HttpStatusCode>(Command.CreateErrorCommand($"The command '{commandString}' was not found."), HttpStatusCode.NotFound)); } //Decrypt the message if (httpRequest.Headers.ContainsKey(EdisonEncryptHeader)) { httpRequest.Body = CommandParserHelper.DecryptMessage(httpRequest.Body, SecretManager.EncryptionKey); } //Generate the command object CommandsEnum command = (CommandsEnum)commandResult; if (httpRequest.Method == "GET" && commandString.StartsWith("get")) { return(new Tuple <Command, HttpStatusCode>(new Command() { BaseCommand = command }, HttpStatusCode.OK)); } else if (httpRequest.Method == "POST" && !commandString.StartsWith("get")) { //If the request is POST, ensure that the content-type header is application/json if (httpRequest.Headers.ContainsKey("content-type") && httpRequest.Headers["content-type"] == "application/json") { return(new Tuple <Command, HttpStatusCode>(new Command() { BaseCommand = command, Data = httpRequest.Body }, HttpStatusCode.OK)); } return(new Tuple <Command, HttpStatusCode>(Command.CreateErrorCommand($"The body content must be a json string."), HttpStatusCode.BadRequest)); } //Method is not GET or POST, return unsupported error return(new Tuple <Command, HttpStatusCode>(Command.CreateErrorCommand($"Method {httpRequest.Method} {command} not supported."), HttpStatusCode.BadRequest)); }
private int abstractRegister; // в случае если вторым параметром является число, а не номер регистра public Operation(CommandsEnum command, int ferstRegistr = 0, int secondRegistr = 0, int abstractRegister = 0) { this.command = command; this.ferstRegistr = ferstRegistr; this.secondRegistr = secondRegistr; this.abstractRegister = abstractRegister; }
public async Task <T> SendCommand <T>(CommandsEnum requestCommandType, string passkey) where T : ResultCommand, new() { Command requestCommand = new Command() { BaseCommand = requestCommandType, Data = null }; return(await SendCommand <T>(requestCommand, passkey)); }
public async Task <U> SendCommand <T, U>(CommandsEnum requestCommandType, T parameters, string passkey) where T : RequestCommand where U : ResultCommand, new() { Command requestCommand = new Command() { BaseCommand = requestCommandType, Data = JsonConvert.SerializeObject(parameters) }; return(await SendCommand <U>(requestCommand, passkey)); }
/// <summary> /// Checks if the command exists in the <see cref="Page.commands"/> /// </summary> /// <param name="cmd"></param> /// <returns></returns> public static bool PageContainsCommand(CommandsEnum cmd) { return(pageManager.activePage.commands.Contains(cmd)); }
/// <summary> /// Gets the string that describes a command /// </summary> /// <param name="cmd">a <see cref="CommandsEnum"/> representing a valid command within the application.</param> /// <returns>string from dictionary</returns> /// <remarks> command needs validated before returning. </remarks> public static string CommandText(CommandsEnum cmd) { return(pageManager.commandsDict[cmd]); }
public bool Run(string stringcommand) { try { try { CommandsEnum command = ParserCommand.ParseMainCommand(stringcommand); if (command == CommandsEnum.Stop) { return(false); } if (command == CommandsEnum.Create) { DatabaseWorker.Create(ParserCommand.ParseData(stringcommand)); } else if (command == CommandsEnum.Exit) { DatabaseWorker.Exit(); } else if (command == CommandsEnum.Delete) { DatabaseWorker.Delete(ParserCommand.ParseData(stringcommand)); } else if (command == CommandsEnum.Edit) { DatabaseWorker.Edit(ParserCommand.ParseData(stringcommand), ParserCommand.ParseNewData(stringcommand)); } else if (command == CommandsEnum.Select) { DatabaseWorker.Select(ParserCommand.ParseData(stringcommand)); } else if (command == CommandsEnum.Save) { DatabaseWorker.Save(); } else if (command == CommandsEnum.Difference) { DatabaseWorker.Difference(ParserCommand.ParseData(stringcommand), ParserCommand.ParseNewData(stringcommand)); } if (command == CommandsEnum.GetData) { DatabaseWorker.GetData(); } else { DatabaseWorker.GetData(); } } catch (TargetInvocationException tie) { throw tie.InnerException; } } catch (NotEqualsColumnsException) { ConsoleWriter.Write("Can't get difference between tables, becouse tables columns aren't equals"); } catch (MethodAccessException) { ConsoleWriter.Write("Method cannot be called in this level in"); } catch (InvalidOperationException) { ConsoleWriter.Write("Invalid operation"); } catch (ArgumentException) { ConsoleWriter.Write("Invalid argument"); } catch (KeyNotFoundException) { ConsoleWriter.Write("Object not found"); } catch (RepetableNameException) { ConsoleWriter.Write("Repetable name"); } catch (System.Exception e) { ConsoleWriter.Write("Unexpected error"); } return(true); }
public CommandsStruct(string word, CommandsEnum commandEnum, CommandsTypeEnum typeEnum) { this.commandEnum = commandEnum; this.word = word; this.typeEnum = typeEnum; }
public ICommand GetCommand(CommandsEnum actionCommand) { var command = commands.Where(a => a.ActionCommand == actionCommand).FirstOrDefault(); return(command); }
public void ExecuteCommand(CommandsEnum command) { _commands[(int)command].Execute(); }