Esempio n. 1
0
        /// <inheritdoc/>
        /// <remarks>
        /// Handles the following event types: CloseSessionMessage, ChatMessage, 
        /// ExecutionResultMessage.
        /// </remarks>
        protected override void ApplicationConnectionReceived(object sender, ReceivedEventArgs e)
        {
            if (e.Message is CloseSessionMessage)
            {
                session.Reset();
            }
            else if (e.Message is ChatMessage)
            {
                session.OnReceiveChatMessage(new ReceiveChatMessageEventArgs((ChatMessage)e.Message));
            }
            else if (e.Message is ExecutionResultMessage)
            {
                ExecutionResultMessage erm = (ExecutionResultMessage)e.Message;

                ExecutionResult result = new ExecutionResult();

                session.OnStartedExecution(new StartedExecutionEventArgs((int)session.ApplicationConnection.Tag, result));

                result.OnExecutionChanged(new ExecutionChangedEventArgs(erm.StandardOut));
                result.OnFinishedExecution(new FinishedExecutionEventArgs(0, erm.StandardOut));
            }
            else
            {
                Logger.WarnFormat("Received unsupported message on application connection: {0}", e.Message.GetType().Name);
                base.ApplicationConnectionReceived(sender, e);
            }
        }
Esempio n. 2
0
 public void SetUp()
 {
     result = new ExecutionResult();
     result.ExecutionChanged += ResultExecutionChanged;
     result.FinishedExecution += ResultFinishedExecution;
     finishedExecution = false;
     stdout = "";
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the ExecutionViewForm with an 
 /// ExecutionResult.
 /// </summary>
 /// <param name="executionResult"></param>
 public ExecutionViewForm(ExecutionResult executionResult)
 {
     InitializeComponent();
     this.executionResult = executionResult;
     executionResult.ExecutionChanged += ExecutionResultChanged;
 }
Esempio n. 4
0
        /// <summary>
        /// Executes the document associated with the session.
        /// </summary>
        public void Execute()
        {
            ExecutionResult result = new ExecutionResult();

            OnStartedExecution(new StartedExecutionEventArgs(SiteId, result));

            FileType.Execute(Context.Data, result);

            // When execution is finished, propagate result to other users
            result.FinishedExecution += delegate(object o, FinishedExecutionEventArgs fe)
            {
                if (State == SessionStates.Connected)
                {
                    ApplicationConnection.Send(new Messaging.ExecutionResultMessage(fe.ReturnCode, fe.StandardOut));
                }
            };
        }
Esempio n. 5
0
 public void TearDown()
 {
     result.ExecutionChanged -= ResultExecutionChanged;
     result.FinishedExecution -= ResultFinishedExecution;
     result = null;
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the StartedExecutionEventArgs class.
 /// </summary>
 /// <param name="siteId">See <see cref="SiteId">SiteId</see>.</param>
 /// <param name="executionResult">See <see cref="ExecutionResult">ExecutionResult</see>.</param>
 public StartedExecutionEventArgs(int siteId, ExecutionResult executionResult)
 {
     ExecutionResult = executionResult;
     SiteId = siteId;
 }
Esempio n. 7
0
 /// <summary>
 /// Spawns a new thread that performs the execution of the content.
 /// </summary>
 /// <param name="content">Source code to be executed.</param>
 /// <param name="result">ExecutionResult instance that fires events according to the execution state.</param>
 public void Execute(string content, ExecutionResult result)
 {
     ThreadStart ts = new ThreadStart((Action) delegate { DoExecute(content, result); });
     Thread t = new Thread(ts);
     t.Name = "Python execution thread";
     t.Start();
 }
Esempio n. 8
0
 private void DoExecute(string content, ExecutionResult result)
 {
     var writer = new PythonStringWriter();
     string standardOut = "";
     writer.Write += delegate(object sender, WriteEventArgs e)
     {
         standardOut += e.Text.Replace("\n", Environment.NewLine);
         result.OnExecutionChanged(new ExecutionChangedEventArgs(e.Text.Replace("\n", Environment.NewLine)));
     };
     interpreter.ExecuteCode(content, writer);
     result.OnFinishedExecution(new FinishedExecutionEventArgs(0, standardOut));
 }
Esempio n. 9
0
 /// <inheritdoc/>
 public void Execute(string content, ExecutionResult stdout)
 {
 }