Beispiel #1
0
        /// <summary>
        /// 执行构建流程
        /// </summary>
        /// <returns>如果成功返回TRUE,否则返回FALSE</returns>
        public static bool Run(List <IBuildTask> pipeline, BuildContext context)
        {
            if (pipeline == null)
            {
                throw new ArgumentNullException("pipeline");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool succeed = true;

            for (int i = 0; i < pipeline.Count; i++)
            {
                IBuildTask task = pipeline[i];
                try
                {
                    var taskAttribute = task.GetType().GetCustomAttribute <TaskAttribute>();
                    Log($"---------------------------------------->{taskAttribute.Desc}");
                    task.Run(context);
                }
                catch (Exception e)
                {
                    Debug.LogError($"Build task {task.GetType().Name} failed !");
                    Debug.LogError($"Build error : {e}");
                    succeed = false;
                    break;
                }
            }

            // 返回运行结果
            return(succeed);
        }
Beispiel #2
0
        static ReturnCode RunTask <T>(params IContextObject[] args) where T : IBuildTask
        {
            IBuildContext context  = new BuildContext(args);
            IBuildTask    instance = Activator.CreateInstance <T>();

            ContextInjector.Inject(context, instance);
            var result = instance.Run();

            ContextInjector.Extract(context, instance);
            return(result);
        }
            public void Run()
            {
                while (!mAbort)
                {
                    IBuildTask task = null;

                    lock (mSemaphore)
                    {
                        if (mTask != null && mTask.TaskState == BuildTaskState.Inactive)
                        {
                            task  = mTask;
                            mTask = null;
                        }
                    }

                    if (task == null)
                    {
                        Thread.Sleep(100);
                    }
                    else
                    {
                        // Have to re-check.  State may have changed.
                        if (task.TaskState == BuildTaskState.Inactive)
                        {
                            /*
                             * Design note:
                             *
                             * This is a trade-off to deal with poorly written tasks. Technically,
                             * the task is responsible for catching and reporting its own
                             * exceptions.  But if it doesn't it can bring down the processor
                             * thread.
                             *
                             * This method forces the task to abort so the main manager can detect
                             * and discard it.  But if the task is so poorly written that the
                             * abort doesn't work, or throws another exception, then the processor
                             * will become a zombie, unresponsive to new requests from the manager.
                             */
                            try
                            {
                                task.Run();
                            }
                            catch (Exception ex)
                            {
                                task.Abort("Exception detected by processor: " + ex.Message);
                            }
                        }
                    }
                }
            }
        public static void Run(List <IBuildTask> pipeline, BuildContext context)
        {
            if (pipeline == null)
            {
                throw new ArgumentNullException("pipeline");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            for (int i = 0; i < pipeline.Count; i++)
            {
                IBuildTask task = pipeline[i];
                try
                {
                    task.Run(context);
                }
                catch (Exception e)
                {
                    throw new Exception($"Build task {task.GetType().Name} failed : {e}");
                }
            }
        }