Exemplo n.º 1
0
        /// <summary>
        /// Run the interpreter and dispose everything
        /// </summary>
        private bool Run(StreamReader stream, List <IDisposable> disposables, int postscriptVersion, out GraphicGroup graph)
        {
            bool success = true;

            graph = null;

            try
            {
                var interpreter = new EpsInterpreter();
                graph = interpreter.Run(stream, postscriptVersion);
            }
            catch
            {
                success = false;
            }
            finally
            {
                foreach (var disposable in disposables)
                {
                    disposable.Dispose();
                }
            }

            return(success);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Run the given formula with the given parameters
        /// </summary>
        /// <param name="script"></param>
        public List <double> RunFormula(string script, List <double> parameters)
        {
            List <double> results = null;

            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(script);
            var    ms    = new MemoryStream(bytes);

            var scriptStream = new StreamReader(ms);

            try
            {
                var interpreter  = new EpsInterpreter();
                var operandStack = interpreter.OperandStack;

                foreach (var parameter in parameters)
                {
                    operandStack.Push(new RealOperand(parameter));
                }

                interpreter.Run(scriptStream, 3);

                results = new List <double>();

                while (operandStack.Count > 0)
                {
                    results.Add(operandStack.PopRealValue());
                }

                results.Reverse();
            }
            catch
            {
            }

            scriptStream.Dispose();
            ms.Dispose();

            return(results);
        }