Esempio n. 1
0
        public override void Run()
        {
            StringBuilder msg = new StringBuilder("Threre are " + this.Commands.Count <CommandSketch>() + " commands: \r\n");

            foreach (CommandSketch description in this.Commands)
            {
                msg.AppendLine("[" + ParseTools.GetCommandName(description.CommandType) + "] - " + description.Attribute.Description);
                ArgumentDescription[] descriptionArray = (from a in description.Arguments
                                                          where !a.Attribute.Optional
                                                          select a).ToArray <ArgumentDescription>();
                if (descriptionArray.Length > 0)
                {
                    msg.AppendLine("neccessary: ");
                    foreach (ArgumentDescription description2 in descriptionArray)
                    {
                        this.fillArgDescription(msg, description2);
                    }
                }
                ArgumentDescription[] descriptionArray2 = (from a in description.Arguments
                                                           where a.Attribute.Optional
                                                           select a).ToArray <ArgumentDescription>();
                if (descriptionArray2.Length > 0)
                {
                    msg.AppendLine("optional: ");
                    foreach (ArgumentDescription description2 in descriptionArray2)
                    {
                        this.fillArgDescription(msg, description2);
                    }
                }
            }
            this.Log.WriteMessage(msg.ToString());
        }
Esempio n. 2
0
        public Instruction Create(List <string> args)
        {
            string cmdName = ParseTools.ExtractCommandName(args);

            var description = library.GetOrNull(cmdName);

            if (description == null)
            {
                throw new UnknownCommandNameException(cmdName);
            }

            var intervalArgumentsDescription
                = ReflectionTools.GetArgumentsDescription(typeof(CommandScheduleSettings));
            var intervalSettingsValues = ReflectionTools.ExtractAndParse(args, intervalArgumentsDescription, typeof(CommandScheduleSettings));
            var intervalSettings       = new CommandScheduleSettings();

            ReflectionTools.Configurate(intervalSettings, intervalSettingsValues);

            var commandConfiguration = ReflectionTools.ExtractAndParse(args, description.Arguments, description.CommandType);

            if (args.Count != 0)
            {
                throw new UnknownArgumentsException(args.ToArray());
            }

            return(new Instruction {
                Locator = new CommandLocator(description.GetRawInstance, commandConfiguration),
                ScheduleSettings = intervalSettings,
            });
        }
Esempio n. 3
0
 public override void Run()
 {
     for (ulong i = 0; i < iterationsCount; i++)
     {
         var cmd = locator.GetReadyToGoInstance();
         Log.WriteMessage("\"" + ParseTools.GetCommandName(cmd.GetType()) + "\"'s iteration " + i + " of " + iterationsCount);
         executor.Run(cmd);
     }
     Log.WriteMessage("Cycle finished");
 }
Esempio n. 4
0
        void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            TaskPlan[] plansArray = null;

            lock (_locker) {
                plansArray = this._plans
                             .Where(p => p.PlannedTime <= DateTime.Now)
                             .ToArray();
            }
            foreach (var plan in plansArray)
            {
                if (IsKilled)
                {
                    break;
                }

                var exemplar = plan.Instruction.Locator.GetReadyToGoInstance();

                Log.WriteMessage("Regular task \""
                                 + ParseTools.GetCommandName(exemplar.GetType())
                                 + "\". Executed: " + (plan.ExecutedCount + 1)
                                 + (plan.Instruction.ScheduleSettings.Count.HasValue ? (" of " + plan.Instruction.ScheduleSettings.Count.Value) : "") + ". "
                                 + (plan.Instruction.ScheduleSettings.Every.HasValue ? ("Interval: " + (plan.Instruction.ScheduleSettings.Every.Value)) : ""));

                if (plan.Instruction.ScheduleSettings.Every.HasValue)
                {
                    plan.PlannedTime += plan.Instruction.ScheduleSettings.Every.Value;
                }

                this._executor.Run(exemplar);
                plan.ExecutedCount++;

                if (plan.Instruction.ScheduleSettings.Count.HasValue &&
                    plan.ExecutedCount >= plan.Instruction.ScheduleSettings.Count)
                {
                    bool hasOtherTasks = false;
                    lock (_locker)
                    {
                        _plans.Remove(plan);
                        hasOtherTasks = _plans.Any();
                    }
                    Log.WriteMessage("Regular task \"" + ParseTools.GetCommandName(exemplar.GetType()) + "\" were finished.");
                    if (!hasOtherTasks)
                    {
                        _tasksDone.Set();
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Searching for the property value in the args list
        /// </summary>
        /// <returns>value, if value have founded, null false otherwise</returns>
        static object SearchExactAndGetValue(List <string> args, ArgumentDescription property, IEnumerable <ArgumentDescription> otherProperties, Type type)
        {
            var propertyName = property.Attribute.ShortAlias.ToLower();

            for (int i = 0; i < args.Count; i++)
            {
                if (propertyName == ParseTools.NormalizeCommandArgName(args[i]))
                {
                    //match!
                    var propertyType = ReflectionTools.GetNonNullType(property.Property.PropertyType);
                    var hasMore      = (i < args.Count - 1);
                    if (propertyType == typeof(bool))    //It can be flag!
                    {
                        if (!hasMore || otherProperties.Any(p => p.Attribute.ShortAlias.ToLower() == args[i + 1]))
                        {
                            args.RemoveAt(i);
                            return(true);   //it means flag value
                        }
                        else
                        {
                            var value = ParseTools.Convert(args[i + 1], propertyType, property.Attribute.ShortAlias);
                            args.RemoveAt(i);     //extract the name and the value from the list
                            args.RemoveAt(i);
                            return(value);
                        }
                    }
                    else
                    {
                        if (!hasMore)
                        {
                            throw new InvalidArgumentException(type, "", property.Attribute.ShortAlias);
                        }
                        var nonBoolValue = ParseTools.Convert(args[i + 1], propertyType, property.Attribute.ShortAlias);
                        args.RemoveAt(i);     //extract the name and the value from the list
                        args.RemoveAt(i);
                        return(nonBoolValue);
                    }
                }
            }
            return(null);
        }
Esempio n. 6
0
 /// <summary>
 /// Parses and executes the command by input string
 /// </summary>
 public void Execute(string inputString)
 {
     Execute(ParseTools.SmartSplit(inputString));
 }
Esempio n. 7
0
        void Registrate(CommandSketch sketch)
        {
            string key = ParseTools.GetCommandName(sketch.CommandType).ToLower();

            this.commands.Add(key, sketch);
        }