Exemple #1
0
        private void ProcessInput()
        {
            if (this.init != null)
            {
                this.init.Wait();
                this.init = null;
            }

            var newSource = new CancellationTokenSource();
            var source    = Interlocked.Exchange(ref this.cancelSource, newSource);

            if (source != null)
            {
                source.Cancel();
                source.Dispose();
            }

            StringObjectLogger logger = new StringObjectLogger(this.cancelSource.Token);

            logger.MaximumLoops = MaximumLoops;

            new Timer(o =>
            {
                var cancel = Interlocked.Exchange(ref this.cancelSource, null);
                if (cancel != null)
                {
                    cancel.Cancel();
                    cancel.Dispose();
                }
            }, null, ExecutionTimeout, Timeout.Infinite);

            Task.Factory.StartNew(s =>
            {
                string code = (string)s;
                if (code == null)
                {
                    return;
                }

                SyntaxNode root = Syntax.ParseCompilationUnit(code);

                var logRewriter = new LoggingRewriter();
                root            = logRewriter.Visit(root);

                if (DebugTree)
                {
                    LogSyntaxTree(root);
                }

                try
                {
                    Session session = Session.Create(logger);

                    this.scripting.Execute(root.ToString(), session);
                }
                catch (CompilationErrorException cex)
                {
                    if (ShowCompilerErrors)
                    {
                        Output = this.lastOutput + Environment.NewLine + cex.ToString();
                    }

                    return;
                }
                catch (OutOfMemoryException)
                {
                    return;
                }
                catch (Exception ex)
                {
                    this.lastOutput = logger.Output;
                    Output          = logger.Output + Environment.NewLine + ex.ToString();
                    return;
                }

                string o = logger.Output;
                if (!String.IsNullOrWhiteSpace(o))
                {
                    Output          = o;
                    this.lastOutput = o;
                }
            }, Input, this.cancelSource.Token)
            .ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    t.Exception.ToString();
                }
            });
        }
Exemple #2
0
        private void ProcessInput()
        {
            if (this.init != null)
            {
                this.init.Wait();
                this.init = null;
            }

            var newSource = new CancellationTokenSource();
            var source = Interlocked.Exchange (ref this.cancelSource, newSource);

            if (source != null)
            {
                source.Cancel();
                source.Dispose();
            }

            StringObjectLogger logger = new StringObjectLogger (this.cancelSource.Token);
            logger.MaximumLoops = MaximumLoops;

            new Timer (o =>
            {
                var cancel = Interlocked.Exchange (ref this.cancelSource, null);
                if (cancel != null)
                {
                    cancel.Cancel();
                    cancel.Dispose();
                }
            }, null, ExecutionTimeout, Timeout.Infinite);

            Task.Factory.StartNew (s =>
            {
                string code = (string) s;
                if (code == null)
                    return;

                SyntaxNode root = Syntax.ParseCompilationUnit (code);

                var logRewriter = new LoggingRewriter();
                root = logRewriter.Visit (root);

                if (DebugTree)
                    LogSyntaxTree (root);

                try
                {
                    Session session = Session.Create (logger);

                    this.scripting.Execute (root.ToString(), session);
                }
                catch (CompilationErrorException cex)
                {
                    if (ShowCompilerErrors)
                        Output = this.lastOutput + Environment.NewLine + cex.ToString();

                    return;
                }
                catch (OutOfMemoryException)
                {
                    return;
                }
                catch (Exception ex)
                {
                    this.lastOutput = logger.Output;
                    Output = logger.Output + Environment.NewLine + ex.ToString();
                    return;
                }

                string o = logger.Output;
                if (!String.IsNullOrWhiteSpace (o))
                {
                    Output = o;
                    this.lastOutput = o;
                }

            }, Input, this.cancelSource.Token)
            .ContinueWith(t =>
            {
                if (t.IsFaulted)
                    t.Exception.ToString();
            });
        }