Example #1
0
 internal AsyncTask(int noOfThreads, DoTask TaskDelegate)
 {
     m_doTask      = TaskDelegate;
     m_taskQueue   = new ActivityQueue("AsyncTask Queue");
     m_noOfThreads = noOfThreads;
     StartThreads();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="groupTitle"></param>
 /// <param name="taskTitle"></param>
 /// <param name="level"></param>
 /// <param name="doTask"></param>
 public TaskPaneData(string groupTitle, string taskTitle, int level, DoTask doTask)
 {
     m_groupTitle = groupTitle;
     m_taskTitle = taskTitle;
     m_level = level;
     m_doTask = doTask;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="groupTitle"></param>
 /// <param name="taskTitle"></param>
 /// <param name="level"></param>
 /// <param name="doTask"></param>
 public TaskPaneData(string groupTitle, string taskTitle, int level, DoTask doTask)
 {
     m_groupTitle = groupTitle;
     m_taskTitle  = taskTitle;
     m_level      = level;
     m_doTask     = doTask;
 }
Example #4
0
        public ITargetInternal Do(Action <ITaskContextInternal> targetAction, Action <DoTask> taskAction = null, TaskGroup taskGroup = null)
        {
            var task = new DoTask(targetAction);

            taskAction?.Invoke(task);
            AddTaskToTaskGroup(taskGroup, task, TaskExecutionMode.Synchronous);
            return(this);
        }
Example #5
0
        public ITarget DoAsync(Action <ITaskContextInternal> targetAction, Action <DoTask> taskAction = null)
        {
            var task = new DoTask(targetAction);

            taskAction?.Invoke(task);
            Tasks.Add(new Tuple <ITask, TaskExecutionMode>(task, TaskExecutionMode.Parallel));
            return(this);
        }
Example #6
0
        public void WorkProcess()
        {
            try
            {
                // the transaction timeout should be long enough to handle all of orders in the batch
                TimeSpan tsTimeout = TimeSpan.FromSeconds(Convert.ToDouble(transactionTimeout * batchSize));

                var bsBll   = new BarcodeScanAsyn();
                var taskBll = new DoTask();

                while (true)
                {
                    // queue timeout variables
                    TimeSpan datetimeStarting = new TimeSpan(DateTime.Now.Ticks);
                    double   elapsedTime      = 0;

                    var listBarcode = new List <BarcodeTypeInfo>();

                    for (int j = 0; j < batchSize; j++)
                    {
                        try
                        {
                            //only receive more queued orders if there is enough time
                            if ((elapsedTime + queueTimeout + transactionTimeout) < tsTimeout.TotalSeconds)
                            {
                                listBarcode.Add(bsBll.ReceiveFromQueue(queueTimeout));
                            }
                            else
                            {
                                j = batchSize;   // exit loop
                            }

                            //update elapsed time
                            elapsedTime = new TimeSpan(DateTime.Now.Ticks).TotalSeconds - datetimeStarting.TotalSeconds;
                        }
                        catch (TimeoutException)
                        {
                            //exit loop because no more messages are waiting
                            j = batchSize;
                        }
                    }

                    if (listBarcode.Count > 0)
                    {
                        taskBll.DoBarcode(listBarcode);
                    }
                }
            }
            catch (Exception ex)
            {
                new CustomException(string.Format("来自{0}异常:{1}", "BarcodeScan", ex.Message), ex);
            }
        }
Example #7
0
        private async Task LaunchTask(DoTask task, int index)
        {
            var range = Memories.GetRange(index, task.Length);

            foreach (var m in range)
            {
                m.Color    = task.Color;
                m.Occupied = true;
                m.Task     = task;
            }
            task.MemoryId  = index;
            task.TaskState = DoTask.State.INSTALLED;
        }
Example #8
0
 public ActionResult AddTask(DoTask account)
 {
     if (ModelState.IsValid)
     {
         using (DbTasks dbt = new DbTasks())
         {
             dbt.TaskAccount.Add(account);
             dbt.SaveChanges();
         }
         ModelState.Clear();
         ViewBag.Message = "Succesfully added task.";
     }
     return(View());
 }
Example #9
0
        public void WorkProcess()
        {
            try
            {
                TimeSpan tsTimeout = TimeSpan.FromSeconds(Convert.ToDouble(transactionTimeout * batchSize));

                var bll     = new RunQueueAsyn();
                var taskBll = new DoTask();

                while (true)
                {
                    TimeSpan datetimeStarting = new TimeSpan(DateTime.Now.Ticks);
                    double   elapsedTime      = 0;

                    var list = new List <RunQueueInfo>();

                    for (int j = 0; j < batchSize; j++)
                    {
                        try
                        {
                            if ((elapsedTime + queueTimeout + transactionTimeout) < tsTimeout.TotalSeconds)
                            {
                                list.Add(bll.ReceiveFromQueue(queueTimeout));
                            }
                            else
                            {
                                j = batchSize;
                            }

                            elapsedTime = new TimeSpan(DateTime.Now.Ticks).TotalSeconds - datetimeStarting.TotalSeconds;
                        }
                        catch (TimeoutException)
                        {
                            j = batchSize;
                        }
                    }

                    if (list.Count > 0)
                    {
                        taskBll.DoRunQueue(list);
                    }
                }
            }
            catch (Exception ex)
            {
                new CustomException(string.Format("来自{0}异常:{1}", "RunQueue", ex.Message), ex);
            }
        }
Example #10
0
        private async Task RemoveTask(DoTask task)
        {
            if (task == null)
            {
                return;
            }
            var range = Memories.GetRange(Memories.IndexOf(Memories.FirstOrDefault(x => x.Task == task)), task.Length);

            foreach (var m in range)
            {
                m.Occupied = false;
                m.Color    = "Transparent";
                m.Task     = null;
            }
            task.MemoryId  = -1;
            task.TaskState = DoTask.State.UNINSTALLED;
        }
Example #11
0
        private async Task Swap(DoTask task)
        {
            string op    = string.Empty;
            var    index = -1;

            op += "Removed: ";
            while (index == -1)
            {
                var tuple = await FindFreeUnits(task);
                await RemoveTask(tuple.Item2);

                op   += tuple.Item2 == null ? "null " : tuple.Item2.Id.ToString() + " ";
                index = tuple.Item1;
            }
            op     += "Launched: " + task.Id;
            Op.Text = op;
            await LaunchTask(task, index);
        }
Example #12
0
        public ITarget OverrideDo(Action <ITaskContextInternal> targetAction)
        {
            var tasks   = Tasks.Select(x => x.Item1);
            var doTasks = tasks.OfType <DoTask>().ToList();

            if (doTasks.Count == 0)
            {
                return(this);
            }

            if (doTasks.Count > 1)
            {
                throw new NotSupportedException("You can not override do when there are specified more than 1 do in target.");
            }

            doTasks[0] = new DoTask(targetAction);

            return(this);
        }
Example #13
0
        private static int ChgCatchStatus(DoTask method, string siteName = null)
        {
            var ret = 0;

            if (string.IsNullOrEmpty(siteName) || siteName == "全部")
            {
                foreach (var pair in ArrSites)
                {
                    if (method(pair.Key))
                    {
                        ret++;
                    }
                }
            }
            else
            {
                if (method(siteName))
                {
                    ret++;
                }
            }
            return(ret);
        }
Example #14
0
        /// <summary>
        /// Find a space which launching task fits most.
        /// </summary>
        /// <param name="task"></param>
        /// <returns>Index of free units and removing task. If no enough space, return index -1.</returns>
        private async Task <Tuple <int, DoTask> > FindFreeUnits(DoTask task)
        {
            // Have enough free units.
            var index = -1;
            var count = 0;

            for (int i = 0; i < 32; i++)
            {
                if (!Memories[i].Occupied)
                {
                    count++;
                    index = i + 1;
                    if (count == task.Length)
                    {
                        return(new Tuple <int, DoTask>(index - count, null));
                    }
                }
                else
                {
                    count = 0;
                }
            }

            // Need to swap.
            index = -1;
            List <DoTask> tasks = new List <DoTask>();

            foreach (var m in Memories)
            {
                if (m.Task != null && !tasks.Contains(m.Task))
                {
                    tasks.Add(m.Task);
                }
            }

            // Tuple<index, length, removingtask>.
            List <Tuple <int, int, DoTask> > tuples = new List <Tuple <int, int, DoTask> >();

            foreach (var t in tasks)
            {
                var i   = t.MemoryId;
                var len = 0;
                for (; i > -1 && !Memories[i].Occupied; i--)
                {
                    ;
                }
                for (int tmp = i; tmp < 32 && (!Memories[tmp].Occupied || Memories[tmp].Task == t); tmp++)
                {
                    len++;
                }
                tuples.Add(new Tuple <int, int, DoTask>(i, len, t));
            }

            var rt      = (DoTask)null;
            var ordered = tuples.OrderBy(x => x.Item2);
            var order   = ordered.FirstOrDefault(x => x.Item2 >= task.Length);

            if (order != null)
            {
                index = order.Item1;
                rt    = order.Item3;
            }
            else
            {
                rt = ordered.FirstOrDefault().Item3;
            }
            return(new Tuple <int, DoTask>(index, rt));
        }