Пример #1
0
        // all tasks that are to be executed from a message must follow the format of "_task_{taskname}"
        public void _task_count_by_seconds(DistributedTask task)
        {
            var required_params = new string[1] {
                "seconds"
            };
            bool missing_params = !TaskIncludesRequiredParams(required_params, task);


            if (missing_params)
            {
                return;
            }

            int seconds = int.Parse(task.taskparams["seconds"].ToString());

            if (seconds > 120)
            {
                Console.WriteLine("120 seconds is maximum count time.");
                return;
            }
            WorkerTaskStatus status = new WorkerTaskStatus(task.task_id, "Queued");

            for (var x = 1; x < seconds + 1; x++)
            {
                var newstatus = String.Format("{0}/{1} counted.", x, seconds);
                status.UpdateStatus(newstatus);
                Thread.Sleep(1000);
                Console.WriteLine(x);
            }
            Console.WriteLine("done");
        }
Пример #2
0
        public string ReceiveTaskFromJson(string taskdata)
        {
            var task = DistributedTask.FromJson(taskdata);

            Console.WriteLine(task);
            return(this.ReceiveTask(task));
        }
Пример #3
0
        private bool TaskIncludesRequiredParams(string[] required_params, DistributedTask task)
        {
            bool success = true;

            foreach (string p in required_params)
            {
                Console.WriteLine(p);
                if (!task.taskparams.ContainsKey(p))
                {
                    Console.WriteLine("key {0} is missing!", p);
                    success = false;
                    break;
                }
            }
            return(success);
        }
Пример #4
0
        public string ReceiveTask(DistributedTask task)
        {
            Type       thisType   = this.GetType();
            MethodInfo taskmethod = thisType.GetMethod("_task_" + task.taskname);

            if (taskmethod == null)
            {
                Console.WriteLine("Could not route task: {0}", task.taskname);
                return("nondeliverable");
            }
            Console.WriteLine("Performing task: {0}", task.taskname);
            Object[] tparams = new Object[1];
            tparams[0] = task;
            taskmethod.Invoke(this, tparams);
            return(task.task_id);
        }