/// <summary> /// Send the next command in the server's command workflow /// </summary> /// <param name="client">The client to be sent the command</param> /// <param name="command">The current command</param> /// <returns>The next command to be executed , of the provided command was the last of the command workflow then null is returned</returns> private CSCloudResponse SendNextCommand(ICSCloudClient client, CSCloudCommand command) { CSCloudResponse response = null; int idxCommand = Array.IndexOf(CommandWorkFlow, command.Code.ToString()); if (idxCommand < CommandWorkFlow.Length - 1) { // the command is not the last command in the command workflow var nextCommand = new CSCloudCommand(); nextCommand.Code = (CSCloudCommandCode)Enum.Parse(typeof(CSCloudCommandCode), CommandWorkFlow.ElementAt(idxCommand + 1), true); response = SendCommand(client, nextCommand); } return response; }
private CSCloudResponse SendFirstCommand(ICSCloudClient client) { CSCloudCommand command = new CSCloudCommand(); command.Code = (CSCloudCommandCode)Enum.Parse(typeof(CSCloudCommandCode), CommandWorkFlow.First(), true); return SendCommand(client, command); }
private Command CommandToModel(string clientName, CSCloudCommand command, CSCloudResult result) { var c = new CSCloud.DAL.Command(); c.Date = DateTime.UtcNow; c.Client = new Client { Name = clientName }; c.Code = command.Code.ToString(); c.Result = result.ToString(); return c; }
private CSCloudResponse SendCommand(ICSCloudClient client, CSCloudCommand command) { var request = new CSCloudRequest(); request.ClientName = client.GetName(); request.Command = command; CSCloudResponse response = null; try { LogRequest(request, CSCloudSeverity.INFO, string.Format("Client: {0} has been sent Command: {1}", client.GetName(), request.ToString())); response = client.ExecuteCommand(request); LogResponse(response, CSCloudSeverity.INFO); if (CommandSent != null) CommandSent(this, new CommandSentEventArgs(client, command)); } catch (Exception ex) { LogResponse(response, CSCloudSeverity.ERROR, ex.Message, ex.StackTrace); } return response; }
public CommandSentEventArgs(ICSCloudClient client, CSCloudCommand command) { this.Client = client; this.Command = command; }