Ejemplo n.º 1
0
        public static string ExecutorCancelPlan()
        {
            BoundCommand bound = new BoundCommand(EXECUTOR_CONTROL_PLAN_CANCEL);

            string result = bound.ToString();

            return(result);
        }
Ejemplo n.º 2
0
        public static string Register(string name)
        {
            BoundCommand bound = new BoundCommand(SRV_REGISTER)
                                 .BindArgument("clientName", name);
            string result = bound.ToString();

            return(result);
        }
Ejemplo n.º 3
0
        public static string WrapToRoute(string targetName, string message)
        {
            BoundCommand bound = new BoundCommand(SRV_ROUTE);

            bound.BindArgument <string>("targetName", targetName);
            bound.BindArgument <string>("message", message);
            string result = bound.ToString();

            return(result);
        }
Ejemplo n.º 4
0
        public static string ServerKillPlan(string planType, Int32 planId)
        {
            if (!IsValidPlanType(planType))
            {
                throw new ArgumentException("Invalid plan type", "planType");
            }

            BoundCommand bound = new BoundCommand(SRV_CONTROL_PLAN_KILL)
                                 .BindArgument("planType", planType)
                                 .BindArgument("planId", planId);

            string result = bound.ToString();

            return(result);
        }
Ejemplo n.º 5
0
        public static string GuiReportOperationProgress(string planType, Int32 planId, GuiReportPlanProgress progress)
        {
            if (!IsValidPlanType(planType))
            {
                throw new ArgumentException("Invalid plan type", "planType");
            }

            BoundCommand bound = new BoundCommand(GUI_REPORT_PLAN_PROGRESS);

            bound.BindArgument <string>("planType", planType);
            bound.BindArgument <Int32>("planId", planId);
            bound.BindArgument <GuiReportPlanProgress>("progress", progress);

            string result = bound.ToString();

            return(result);
        }
Ejemplo n.º 6
0
        public static string GuiReportOperationStatus(string planType, Int32 planId, GuiReportPlanStatus report)
        {
            if (!IsValidPlanType(planType))
            {
                throw new ArgumentException("Invalid plan type", "planType");
            }

            BoundCommand bound = new BoundCommand(GUI_REPORT_PLAN_STATUS);

            bound.BindArgument <string>("planType", planType);
            bound.BindArgument <Int32>("planId", planId);
#if true
            bound.BindArgument <GuiReportPlanStatus>("report", report);
#else
            bound.BindArgument <string>("status", status.ToString());

            string startedAtStr = startedAt.HasValue
                                ? startedAt.Value.ToLocalTime().ToString("o") // Convert to ISO (doesn't contain whitespace)
                                : null;
            string lastRunAtStr = lastRunAt.HasValue
                                ? lastRunAt.Value.ToLocalTime().ToString("o") // Convert to ISO (doesn't contain whitespace)
                                : "Never";
            string lastSuccessfulRunAtStr = lastSuccessfulRunAt.HasValue
                                ? lastSuccessfulRunAt.Value.ToLocalTime().ToString("o") // Convert to ISO (doesn't contain whitespace)
                                : "Never";

            string sourcesStr = EncodeString(sources);

            bound.BindArgument <string>("report", startedAtStr);
            bound.BindArgument <string>("lastRunAt", lastRunAtStr);
            bound.BindArgument <string>("lastSuccessfulRunAt", lastSuccessfulRunAtStr);
            bound.BindArgument <string>("scheduleType", scheduleType);
            bound.BindArgument <string>("sources", sourcesStr);
#endif

            string result = bound.ToString();
            return(result);
        }
Ejemplo n.º 7
0
        private static BoundCommand ParseMessage(Message msg, out string errorMessage, Command[] acceptedCommands, BoundCommand lastCommand = null)
        {
            string currentToken = msg.NextToken();

            if (currentToken == null)
            {
                errorMessage = lastCommand == null ? "Invalid command" : null;
                return(lastCommand);
            }

            Command commandMatch = Array.Find(acceptedCommands, delegate(Command cmd)
            {
                return(currentToken.Equals(cmd.Name, StringComparison.InvariantCulture));
            });

            if (commandMatch == null)
            {
                errorMessage = string.Format("Unknown command: {0}", currentToken);
                return(null);
            }

            BoundCommand boundCommand = new BoundCommand(commandMatch);

            if (commandMatch.HasSubCommands)
            {
                // Find sub-command.
                boundCommand = ParseMessage(msg, out errorMessage, commandMatch.SubCommands.ToArray(), boundCommand);
            }
            else if (commandMatch.HasArguments)
            {
                LinkedList <string> argValues = new LinkedList <string>();

                // Read and validate arguments.
                foreach (DictionaryEntry entry in commandMatch.OrderedArgumentDefinitions)
                {
                    ArgumentDefinition definedArg     = (ArgumentDefinition)entry.Value;
                    string             definedArgName = (string)entry.Key;
                    Type   definedArgType             = definedArg.Type;
                    string passedArgValue             = definedArg.Trailing ? msg.RemainingTokens() : msg.NextToken();

                    try
                    {
                        bool isString = definedArgType.IsSameOrSubclass(typeof(string));
                        if (isString)
                        {
                            boundCommand.BindArgument(definedArgName, passedArgValue);
                        }
                        else
                        {
                            bool isComplex = definedArgType.IsSameOrSubclass(typeof(ComplexArgument));
                            if (isComplex)
                            {
                                dynamic deserializedValue = JsonConvert.DeserializeObject(passedArgValue, definedArgType);
                                boundCommand.BindArgument(definedArgName, deserializedValue);
                            }
                            else
                            {
                                dynamic convertedArgValue = Convert.ChangeType(passedArgValue, definedArgType);
                                boundCommand.BindArgument(definedArgName, convertedArgValue);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                        return(null);
                    }

                    if (definedArg.Trailing)
                    {
                        break;                         // There shouldn't be any arguments after this one.
                    }
                }
            }

            errorMessage = null;
            return(boundCommand);
        }