Ejemplo n.º 1
0
        /// <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;
        }
Ejemplo n.º 2
0
 private CSCloudResponse SendFirstCommand(ICSCloudClient client)
 {
     CSCloudCommand command = new CSCloudCommand();
     command.Code = (CSCloudCommandCode)Enum.Parse(typeof(CSCloudCommandCode), CommandWorkFlow.First(), true);
     return SendCommand(client, command);
 }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
 public CommandSentEventArgs(ICSCloudClient client, CSCloudCommand command)
 {
     this.Client = client;
     this.Command = command;
 }