示例#1
0
    private static void ParseTask(JSONNode taskJson, ref TaskStrategy task, List <TaskStrategy> strategies)
    {
        task.Name     = taskJson["Name"];
        task.NodeName = taskJson["NodeName"];

        if (taskJson["BeginDate"] == null)
        {
            task.BeginDate = DateTime.Today;
        }
        else
        {
            string   dateString = taskJson["BeginDate"];
            var      culture    = CultureInfo.CreateSpecificCulture("pt-PT");
            var      styles     = DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeLocal;
            DateTime date;
            if (DateTime.TryParse(dateString, culture, styles, out date))
            {
                task.BeginDate = date;
            }
        }

        if (taskJson["DependsOn"] != null)
        {
            for (int i = 0; i < taskJson["DependsOn"].Count; i++)
            {
                foreach (var strategy in strategies)
                {
                    if (string.Equals(strategy.Name, taskJson["DependsOn"][i]))
                    {
                        task.DependsOn.Add(strategy);
                    }
                }
            }
        }
    }
示例#2
0
        public void Run()
        {
            //TaskQueue=Services.GetService<Queue<IProcess>>();
            TaskQueue = new Queue <IProcess>();
            //CurrentSessionParams.Context=Services.GetService<VDContext>();
            TaskStrategy = Services.GetService <TaskStrategy>();
            var serviceAccessor = Services.GetService <Func <ProcessState, ITask> >();

            InitTask       = serviceAccessor(ProcessState.Init);
            CleanTask      = serviceAccessor(ProcessState.Clean);
            DownloadTask   = serviceAccessor(ProcessState.Download);
            UnzipTask      = serviceAccessor(ProcessState.Unzip);
            ImportDataTask = serviceAccessor(ProcessState.Import);

            TaskQueue.Enqueue(new Processable(() => TaskStrategy.ChangeStrategy(InitTask).PerformTask()));
            TaskQueue.Enqueue(new Processable(() => TaskStrategy.ChangeStrategy(CleanTask).PerformTask()));
            TaskQueue.Enqueue(new Processable(() => TaskStrategy.ChangeStrategy(DownloadTask).PerformTask()));
            TaskQueue.Enqueue(new Processable(() => TaskStrategy.ChangeStrategy(UnzipTask).PerformTask()));
            TaskQueue.Enqueue(new Processable(() => TaskStrategy.ChangeStrategy(ImportDataTask).PerformTask()));

            while (TaskQueue.Count > 0)
            {
                TaskQueue.Dequeue().Process();
            }
        }
示例#3
0
 public Task(Action action, TaskStrategy mode) : this()
 {
     if (mode == TaskStrategy.Coroutine)
     {
         throw new ArgumentException("Action tasks may not be coroutines");
     }
     this._action  = action;
     this.Strategy = mode;
 }
示例#4
0
 public Task(IEnumerator action) : this()
 {
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     this._routine = action;
     this.Strategy = TaskStrategy.Coroutine;
 }
示例#5
0
        /// <summary>
        /// Creates a new background task
        /// </summary>
        /// <param name="action"></param>
        public UnityTask(Action action)
        {
            _action = action;
#if UNITY_WEBGL
            Strategy = TaskStrategy.MainThread;
#else
            Strategy = TaskStrategy.BackgroundThread;
#endif
        }
示例#6
0
 public Task(Delegate action, object paramater, TaskStrategy mode) : this()
 {
     if (mode == TaskStrategy.Coroutine)
     {
         throw new ArgumentException("Action tasks may not be coroutines");
     }
     this._action2  = action;
     this.Strategy  = mode;
     this.Paramater = paramater;
 }
示例#7
0
 public Task(IEnumerator action, object param) : this()
 {
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     this._routine  = action;
     this.Strategy  = TaskStrategy.Coroutine;
     this.Paramater = param;
 }
示例#8
0
        /// <summary>
        /// Creates a new background task with a parameter
        /// </summary>
        /// <param name="action"></param>
        /// <param name="paramater"></param>
        public UnityTask(Delegate action, object paramater)
            : this()
        {
            _action2 = action;
#if UNITY_WEBGL
            Strategy = TaskStrategy.MainThread;
#else
            Strategy = TaskStrategy.BackgroundThread;
#endif
            Paramater = paramater;
        }
示例#9
0
        private bool SaveCollSettings()
        {
            int newGrCollCycle;

            try
            {
                newGrCollCycle = int.Parse(this.txtGRCollCycle.Text.Trim());
            }
            catch
            {
                MsgBox.Show("采集周期必须输入数字");
                return(false);
            }

            if (newGrCollCycle < MIN_COLL_CYCLE)
            {
                MsgBox.Show("采集周期不能小于" + MIN_COLL_CYCLE + "分钟");
                return(false);
            }
            if (newGrCollCycle > MAX_COLL_CYCLE)
            {
                MsgBox.Show("采集周期不能大于" + MIN_COLL_CYCLE + "分钟");
                return(false);
            }

            XGConfig.Default.GrRealDataCollCycle = newGrCollCycle;

            // refresh task coll cycle
            //
            TasksCollection tasks = Singles.S.TaskScheduler.Tasks;

            foreach (Task t in tasks)
            {
                TaskStrategy s   = t.TaskStrategy;
                CommCmdBase  cmd = t.CommCmd;


                if (s is CycleTaskStrategy && cmd is GRCtrl.GRRealDataCommand)
                {
                    CycleTaskStrategy cyc = s as CycleTaskStrategy;
                    cyc.Cycle = GetCycle(newGrCollCycle);
                }
            }

            // TODO: update app.config file
            //


            return(true);
        }
示例#10
0
        private void SetCollCycle()
        {
            TasksCollection tasks = Singles.S.TaskScheduler.Tasks;

            foreach (Task t in tasks)
            {
                TaskStrategy s = t.TaskStrategy;
                if (s is CycleTaskStrategy)
                {
                    CycleTaskStrategy cyc = s as CycleTaskStrategy;
                    cyc.Cycle = GetCycle();
                }
            }
        }
示例#11
0
        /// <summary>
        /// Creates a new task with a specific strategy
        /// </summary>
        public UnityTask(Func <TResult> function, TaskStrategy mode)
            : this()
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            if (mode == TaskStrategy.Coroutine)
            {
                throw new ArgumentException("Mode can not be coroutine");
            }

            _function = function;
            Strategy  = mode;
        }
示例#12
0
        /// <summary>
        /// Creates a new task with a specific strategy
        /// </summary>
        public UnityTask(Delegate function, object param, TaskStrategy mode)
            : this()
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            if (mode == TaskStrategy.Coroutine)
            {
                throw new ArgumentException("Mode can not be coroutine");
            }

            _function2 = function;
            Paramater  = param;
            Strategy   = mode;
        }
示例#13
0
    public static List <TaskStrategy> FromJson(JSONNode json)
    {
        var strategies = new List <TaskStrategy>();

        foreach (var tasksPair in json["Tasks"].AsArray)
        {
            var          taskJson = tasksPair.Value.AsObject;
            TaskStrategy task     = new TaskStrategy();
            ParseTask(taskJson, ref task, strategies);
            strategies.Add(task);
        }

        foreach (var tasksPair in json["OnceADaysTasks"].AsArray)
        {
            var          taskJson = tasksPair.Value.AsObject;
            TaskStrategy task     = new OnceADayTaskStrategy();
            ParseTask(taskJson, ref task, strategies);
            strategies.Add(task);
        }

        return(strategies);
    }
示例#14
0
 /// <summary>
 /// Creates a new background task
 /// </summary>
 /// <param name="action"></param>
 public AsyncTask(Action action)
 {
     _action  = action;
     Strategy = TaskStrategy.BackgroundThread;
 }
示例#15
0
 /// <summary>
 /// Creates a new Task in a Faulted state
 /// </summary>
 /// <param name="ex"></param>
 public AsyncTask(Exception ex)
 {
     Exception = ex;
     Strategy  = TaskStrategy.Custom;
     Status    = TaskStatus.Faulted;
 }
示例#16
0
 /// <summary>
 /// Creates a new task
 /// </summary>
 public AsyncTask(TaskStrategy mode)
 {
     Strategy = mode;
 }
示例#17
0
        /// <summary>
        /// Creates a new Coroutine Task
        /// </summary>
        /// <param name="action"></param>
        public UnityTask(IEnumerator action)
            : this()
        {
            if (action == null)
                throw new ArgumentNullException("action");

            _routine = action;
            Strategy = TaskStrategy.Coroutine;
        }
示例#18
0
        /// <summary>
        /// Creates a new Task 
        /// </summary>
        /// <param name="action"></param>
        /// <param name="mode"></param>
        public UnityTask(Action action, TaskStrategy mode)
            : this()
        {
            if (mode == TaskStrategy.Coroutine)
                throw new ArgumentException("Action tasks may not be coroutines");

            _action = action;
            Strategy = mode;
        }
示例#19
0
        /// <summary>
        /// Creates a new background task
        /// </summary>
        /// <param name="action"></param>
        public UnityTask(Action action)
        {
            _action = action;
#if UNITY_WEBGL
            Strategy = TaskStrategy.MainThread;
#else
            Strategy = TaskStrategy.BackgroundThread;
#endif
        }
示例#20
0
 /// <summary>
 /// Creates a new Task in a Faulted state
 /// </summary>
 /// <param name="ex"></param>
 public UnityTask(Exception ex)
 {
     Exception = ex;
     Strategy = TaskStrategy.Custom;
     Status = TaskStatus.Faulted;
 }
示例#21
0
 /// <summary>
 /// Creates a new task
 /// </summary>
 public UnityTask(TaskStrategy mode)
 {
     Strategy = mode;
 }
示例#22
0
 public Task(TaskStrategy mode) : this()
 {
     this.Strategy = mode;
 }
示例#23
0
 /// <summary>
 /// Creates a new task
 /// </summary>
 public UnityTask(TaskStrategy mode)
     : this()
 {
     Strategy = mode;
 }
示例#24
0
 public Task(Delegate action, object paramater) : this()
 {
     this._action2  = action;
     this.Strategy  = TaskStrategy.BackgroundThread;
     this.Paramater = paramater;
 }
        public override void InitStrategy(int robotId, int teamId)
        {
            //Initialisation des taches de la stratégie

            //Taches de bas niveau
            taskBrasGauche = new TaskBrasGauche();
            taskBrasGauche.OnHerkulexPositionRequestEvent += OnHerkulexPositionRequestForwardEvent;
            taskBrasGauche.OnPilotageVentouseEvent        += OnSetSpeedConsigneToMotorEvent;
            OnMotorCurrentReceiveForwardEvent             += taskBrasGauche.OnMotorCurrentReceive;

            taskBrasDroit = new TaskBrasDroit();
            taskBrasDroit.OnHerkulexPositionRequestEvent += OnHerkulexPositionRequestForwardEvent;
            taskBrasDroit.OnPilotageVentouseEvent        += OnSetSpeedConsigneToMotorEvent;
            OnMotorCurrentReceiveForwardEvent            += taskBrasDroit.OnMotorCurrentReceive;

            taskBrasCentre = new TaskBrasCentre();
            taskBrasCentre.OnHerkulexPositionRequestEvent += OnHerkulexPositionRequestForwardEvent;
            taskBrasCentre.OnPilotageVentouseEvent        += OnSetSpeedConsigneToMotorEvent;
            OnMotorCurrentReceiveForwardEvent             += taskBrasCentre.OnMotorCurrentReceive;

            taskBrasDrapeau = new TaskBrasDrapeau();
            taskBrasDrapeau.OnHerkulexPositionRequestEvent += OnHerkulexPositionRequestForwardEvent;
            taskBrasDrapeau.OnPilotageVentouseEvent        += OnSetSpeedConsigneToMotorEvent;
            OnMotorCurrentReceiveForwardEvent += taskBrasDrapeau.OnMotorCurrentReceive;

            taskBalade = new TaskBalade(this);
            OnMotorCurrentReceiveForwardEvent  += taskBalade.OnMotorCurrentReceive;
            taskBalade.OnPilotageVentouseEvent += OnSetSpeedConsigneToMotorEvent;

            taskDepose = new TaskDepose(this);
            OnMotorCurrentReceiveForwardEvent  += taskDepose.OnMotorCurrentReceive;
            taskDepose.OnPilotageVentouseEvent += OnSetSpeedConsigneToMotorEvent;

            taskWindFlag = new TaskWindFlag(this);
            taskWindFlag.OnHerkulexPositionRequestEvent += OnHerkulexPositionRequestForwardEvent;
            OnMotorCurrentReceiveForwardEvent           += taskWindFlag.OnMotorCurrentReceive;
            taskWindFlag.OnPilotageVentouseEvent        += OnSetSpeedConsigneToMotorEvent;

            taskStrategy                    = new TaskStrategy(this);
            OnIOValuesFromRobotEvent       += taskStrategy.OnIOValuesFromRobotEvent;
            taskStrategy.OnMirrorModeEvent += OnMirrorMode;

            taskFinDeMatch = new TaskFinDeMatch(this);
            taskFinDeMatch.OnHerkulexPositionRequestEvent += OnHerkulexPositionRequestForwardEvent;
            OnMotorCurrentReceiveForwardEvent             += taskFinDeMatch.OnMotorCurrentReceive;
            taskFinDeMatch.OnPilotageVentouseEvent        += OnSetSpeedConsigneToMotorEvent;

            taskPhare = new TaskPhare(this);
            taskPhare.OnHerkulexPositionRequestEvent += OnHerkulexPositionRequestForwardEvent;
            OnMotorCurrentReceiveForwardEvent        += taskPhare.OnMotorCurrentReceive;
            taskPhare.OnPilotageVentouseEvent        += OnSetSpeedConsigneToMotorEvent;

            taskDistributeur = new TaskDistributeur(this);
            taskDistributeur.OnHerkulexPositionRequestEvent += OnHerkulexPositionRequestForwardEvent;
            taskDistributeur.OnPilotageVentouseEvent        += OnSetSpeedConsigneToMotorEvent;
            OnMotorCurrentReceiveForwardEvent += taskDistributeur.OnMotorCurrentReceive;

            //On initialisae le timer de réglage récurrent
            //Il permet de modifier facilement les paramètre des asservissement durant l'exécution
            configTimer          = new System.Timers.Timer(1000);
            configTimer.Elapsed += ConfigTimer_Elapsed;
            configTimer.Start();

            //Config Eurobot des paramètre embarqués
            OnOdometryPointToMeter(1.211037464120243e-06);
            On4WheelsAngleSet(Toolbox.DegToRad(72), Toolbox.DegToRad(144), Toolbox.DegToRad(216), Toolbox.DegToRad(288));
            On4WheelsToPolarSet(-3.967532e-01, -2.720655e-01, +2.720655e-01, 3.967532e-01,
                                +3.776278e-01, -3.776278e-01, -3.776278e-01, 3.776278e-01,
                                +2.106947e+00, +1.341329e+00, +1.341329e+00, +2.106947e+00);

            OnEnableDisableMotorCurrentData(true);
        }
示例#26
0
 public Task(Exception ex)
 {
     this.Exception = ex;
     this.Strategy  = TaskStrategy.Custom;
     this.Status    = TaskStatus.Faulted;
 }
示例#27
0
 public Task(Action action) : this()
 {
     this._action  = action;
     this.Strategy = TaskStrategy.BackgroundThread;
 }