コード例 #1
0
ファイル: DesultoryTask.cs プロジェクト: teerta/Biu
        protected void Init(DesultoryBlock finishedItem, DesultoryBlock errorItem)
        {
            if (null != finishedItem)
            {
                _finishedItem           = finishedItem;
                _finishedItem.Desultory = this;
                _finishedItem.Deep      = 1;
            }

            if (null != errorItem)
            {
                _errorItem           = errorItem;
                _errorItem.Desultory = this;
                _errorItem.Deep      = 1;
            }

            if (null == _finishedItem)
            {
                _finishedItem = new DesultoryBlock((arg) =>
                {
                    var argDTI = arg as DesultoryBlock;

                    DesultoryTaskManager.Instance.Remove(argDTI.Desultory.ID);
                }, this.CTSource.Token);
            }
            else
            {
                _finishedItem.Task.ContinueWith((argTask, arg) =>
                {
                    var dtask = arg as DesultoryTask;

                    DesultoryTaskManager.Instance.Remove(dtask.ID);
                }, this, this.CTSource.Token);
            }
        }
コード例 #2
0
ファイル: DesultoryTask.cs プロジェクト: teerta/Biu
        /// <summary>
        /// Dispatch this task (run it).
        ///
        /// U should call this method after a series of creations.
        /// This methid also initializes finished-item and error-item.
        /// </summary>
        /// <param name="finishedAction"></param>
        /// <param name="errorAction"></param>
        /// <param name="finishedState"></param>
        /// <param name="errorState"></param>
        public void Dispatch(Action <object> finishedAction = null, Action <object> errorAction = null, object finishedState = null, object errorState = null)
        {
            try
            {
                DesultoryBlock finishedItem = null;
                DesultoryBlock errorItem    = null;
                if (null != finishedAction)
                {
                    finishedItem = new DesultoryBlock(finishedAction, this.CTSource.Token)
                    {
                        Desultory = this,
                        State     = finishedState
                    };
                }

                if (null != errorAction)
                {
                    errorItem = new DesultoryBlock(errorAction, this.CTSource.Token)
                    {
                        Desultory = this,
                        State     = errorState
                    };
                }

                Init(finishedItem, errorItem);

                DesultoryTaskManager.Instance.Add(this.ID, this);
            }
            catch
            {
                throw;
            }
        }
コード例 #3
0
ファイル: DesultoryTask.cs プロジェクト: teerta/Biu
        /// <summary>
        /// Create a DesultoryBlock and add it to this task.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="state"></param>
        /// <param name="nextCondition"></param>
        /// <returns></returns>
        public DesultoryTask WithBlock(Action <object> action, object state = null,
                                       Func <DesultoryStatementBase, object, DesultoryTaskNextFunction> nextCondition = null)
        {
            var block = new DesultoryBlock(action, this.CTSource.Token)
            {
                Desultory     = this,
                Deep          = 1,
                State         = state,
                NextCondition = nextCondition
            };

            _items.Add(block);

            return(this);
        }
コード例 #4
0
ファイル: DesultoryTask.cs プロジェクト: teerta/Biu
        public void Create(IEnumerable <DesultoryStatementBase> items, DesultoryBlock finishedItem = null, DesultoryBlock errorItem = null)
        {
            try
            {
                foreach (var item in items)
                {
                    item.Desultory = this;
                    item.Deep      = 1;
                    _items.Add(item);
                }

                Init(finishedItem, errorItem);
            }
            catch
            {
                throw;
            }
        }