コード例 #1
0
ファイル: WebTaskRunner.cs プロジェクト: tisonet/webtasks
        private void RunWebTaskWithContext(Func <IWebTaskActionContext, WebTaskResult> action, WebTask webTask)
        {
            WebTaskController controller = CreateAndStoreWebTaskController(webTask);

            Task.Factory.StartNew <WebTaskResult>(RunWithContext, Tuple.Create(controller, action), controller.CancellationToken)
            .ContinueWith(tpl => FinishWithContext(tpl));
        }
コード例 #2
0
ファイル: WebTaskRunner.cs プロジェクト: tisonet/webtasks
        private WebTaskController CreateAndStoreWebTaskController(WebTask webTask)
        {
            WebTaskController controller = new WebTaskController(webTask);

            _taskControllers.TryAdd(webTask.Id, controller);

            return(controller);
        }
コード例 #3
0
ファイル: WebTaskRunner.cs プロジェクト: tisonet/webtasks
        private void FinishWithContext(Task <WebTaskResult> tpl)
        {
            var conf = (Tuple <WebTaskController, Func <IWebTaskActionContext, WebTaskResult> >)tpl.AsyncState;

            WebTaskController controller = conf.Item1;

            SetWebTaskStateOnController(tpl, controller);
        }
コード例 #4
0
ファイル: WebTaskRunner.cs プロジェクト: tisonet/webtasks
        private WebTaskResult RunWithContext(object state)
        {
            var conf = (Tuple <WebTaskController, Func <IWebTaskActionContext, WebTaskResult> >)state;

            WebTaskController controller = conf.Item1;
            Func <IWebTaskActionContext, WebTaskResult> action = conf.Item2;

            controller.Started();

            WebTaskResult result = action(controller);

            return(result);
        }
コード例 #5
0
ファイル: WebTaskRunner.cs プロジェクト: tisonet/webtasks
 private static void SetWebTaskStateOnController(Task <WebTaskResult> tpl, WebTaskController controller)
 {
     if (tpl.Status == TaskStatus.Faulted)
     {
         controller.Faulted(tpl.Exception.InnerException ?? tpl.Exception);
     }
     else if (tpl.Status == TaskStatus.Canceled)
     {
         controller.Canceled();
     }
     else if (tpl.IsCompleted)
     {
         controller.Completed(tpl.Result);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }