Commits

Igor Fesenko  committed 75cfadf

[+] add not implemented FluentTask<TResult> and FluentTask<T,TResult>

  • Participants
  • Parent commits fe9fbeb

Comments (0)

Files changed (1)

File FluentTasks/FluentTask.cs

         private Action<Exception> onExceptionAction;
         private Dispatcher activeDispatcher; 
         private TimeSpan operationTimeout = new TimeSpan(0); 
+        private TimeSpan runAfter = new TimeSpan(0); 
 
         public FluentTask DoWork(Action action)
         {
             return this;
         }
 
+        public FluentTask StartAfter(TimeSpan duration)
+        {
+            runAfter = duration;
+            return this;
+        }
+
         #region Running
 
         public void RunSynchronously()
             {
                 if (doWorkAction != null)
                 {
+                    if(runAfter.Ticks != 0)
+                    {
+                        Thread.Sleep(runAfter);
+                    }
+
                     if(activeDispatcher != null)
                     {
                         if(!activeDispatcher.CheckAccess())
 
         #endregion
     }
+
+    public class FluentTask<TResult>
+    {
+        private Func<Action<string, int>, TResult> doWorkActionWithProgress;
+        private Action<TResult> onCompleteAction;
+        private Action<Exception> onExceptionAction;
+        private Action<string, int> onProgressChangedAction;
+
+        public FluentTask<TResult> DoWork(Func<TResult> action)
+        {
+            if (action == null)
+            {
+                throw new ArgumentNullException();
+            }
+            doWorkActionWithProgress = onprogress => action();
+            return this;
+        }
+
+        public FluentTask<TResult> DoWork(Func<Action<string, int>, TResult> action)
+        {
+            if (action == null)
+            {
+                throw new ArgumentNullException();
+            }
+            doWorkActionWithProgress = action;
+            return this;
+        }
+
+        public FluentTask<TResult> OnComplete(Action<TResult> action)
+        {
+            if (action == null)
+            {
+                throw new ArgumentNullException();
+            }
+            onCompleteAction = action;
+            return this;
+        }
+
+        public FluentTask<TResult> OnException(Action<Exception> action)
+        {
+            if (action == null)
+            {
+                throw new ArgumentNullException();
+            }
+            onExceptionAction = action;
+            return this;
+        }
+
+        public FluentTask<TResult> OnProgress(Action<string, int> action)
+        {
+            if (action == null)
+            {
+                throw new ArgumentNullException();
+            }
+            onProgressChangedAction = action;
+            return this;
+        }
+
+        #region Running
+
+        public TResult RunSynchronously()
+        {
+            throw new NotImplementedException();
+        }
+
+        public TResult RunAsync()
+        {
+            return Task<TResult>.Factory.StartNew(RunSynchronously).Result;
+        }
+
+
+        #endregion
+    }
+
+
+    public class FluentTask<T, TResult>
+    {
+        private Func<T, Action<T, string, int>, TResult> doWorkAction;
+        private Action<T, TResult> onCompleteAction;
+        private Action<T, Exception> onExceptionAction;
+        private Action<T, string, int> onProgressChangedAction;
+
+        public FluentTask<T, TResult> DoWork(Func<T, Action<T, string, int>, TResult> action)
+        {
+            if (action == null)
+            {
+                throw new ArgumentNullException();
+            }
+            doWorkAction = action;
+            return this;
+        }
+
+        public FluentTask<T, TResult> OnComplete(Action<T, TResult> action)
+        {
+            if (action == null)
+            {
+                throw new ArgumentNullException();
+            }
+            onCompleteAction = action;
+            return this;
+        }
+
+        public FluentTask<T, TResult> OnException(Action<T, Exception> action)
+        {
+            if (action == null)
+            {
+                throw new ArgumentNullException();
+            }
+            onExceptionAction = action;
+            return this;
+        }
+
+        public FluentTask<T, TResult> OnProgress(Action<T, string, int> action)
+        {
+            if (action == null)
+            {
+                throw new ArgumentNullException();
+            }
+            onProgressChangedAction = action;
+            return this;
+        }
+
+
+        #region Running
+
+        public TResult RunSynchronously(T arg)
+        {
+            throw new NotImplementedException();
+        }
+
+        public TResult RunAsync(T arg)
+        {
+            throw new NotImplementedException();
+        }
+
+        #endregion
+    }
 }