Example #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);
            }
        }
Example #2
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));
 }