aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-04-21 14:21:19 +0300
committerAvi Levkovich <avi@twine-s.com>2020-04-21 14:21:19 +0300
commitcd728bf3a7d1db76747cb18bcfe396c83d690e86 (patch)
tree99347262eef3f175a7ff1441b6c5a031be74d26f /Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs
parent7fe23e68512e2462de107e76ae3a92ddd381ac77 (diff)
parent97a784b6ce43960bdb92465b08f26d3562a4f202 (diff)
downloadTango-cd728bf3a7d1db76747cb18bcfe396c83d690e86.tar.gz
Tango-cd728bf3a7d1db76747cb18bcfe396c83d690e86.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs')
-rw-r--r--Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs65
1 files changed, 65 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs
new file mode 100644
index 000000000..565949402
--- /dev/null
+++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Scripting.Basic
+{
+ public class ProjectSession
+ {
+ private Action _abortAction;
+ private TaskCompletionSource<object> _completion;
+
+ public event EventHandler<ProjectSessionStateChangedEventArgs> StateChanged;
+
+ public ProjectSessionState State { get; set; }
+
+ public Project Project { get; set; }
+
+ public ProjectSession(Project project, Action abortAction)
+ {
+ _completion = new TaskCompletionSource<object>();
+ Project = project;
+ _abortAction = abortAction;
+ }
+
+ public void Abort()
+ {
+ _abortAction();
+ State = ProjectSessionState.Aborted;
+ _completion.SetException(new OperationCanceledException("Project execution aborted."));
+ RaiseStateChanged();
+ }
+
+ internal void Failed(Exception ex)
+ {
+ State = ProjectSessionState.Failed;
+ _completion.SetException(ex);
+ RaiseStateChanged(null, ex);
+ }
+
+ internal void Completed(object returnValue)
+ {
+ State = ProjectSessionState.Completed;
+ _completion.SetResult(returnValue);
+ RaiseStateChanged(returnValue, null);
+ }
+
+ private void RaiseStateChanged(object returnValue = null, Exception ex = null)
+ {
+ StateChanged?.Invoke(this,
+ new ProjectSessionStateChangedEventArgs()
+ {
+ ReturnValue = returnValue,
+ State = State,
+ Exception = ex
+ });
+ }
+
+ public Task<Object> WaitForCompletion()
+ {
+ return _completion.Task;
+ }
+ }
+}