Esempio n. 1
0
        private void Deserialize(string path)
        {
            var doc  = XDocument.Load(path);
            var vars = doc.Root.Element("variables");

            if (vars != null)
            {
                foreach (var item in vars.Elements("add"))
                {
                    processor.Parameters.Variables.Add(new Parameter(item.Attribute("key").Value, double.Parse(item.Attribute("value").Value), bool.Parse(item.Attribute("readonly").Value) ? ParameterType.ReadOnly : ParameterType.Normal));
                }
            }

            var funcs = doc.Root.Element("functions");

            if (funcs != null)
            {
                foreach (var item in funcs.Elements("add"))
                {
                    processor.Solve($"{item.Attribute("key").Value}:={item.Attribute("value").Value}");
                }
            }

            var exps = doc.Root.Element("expressions");

            if (exps != null)
            {
                foreach (var item in exps.Elements("expression").Select(exp => exp.Value))
                {
                    mathPresenter.Add(item);
                }
            }
        }
Esempio n. 2
0
        internal void MathExpEnter()
        {
            try
            {
                presenter.Add(mathExpressionBox.Text);
                var count = mathExpsListBox.Items.Count;
                if (count > 0)
                {
                    mathExpsListBox.ScrollIntoView(mathExpsListBox.Items[count - 1]);
                }
                Status = string.Empty;
            }
            catch (LexerException mle)
            {
                Status = mle.Message;
            }
            catch (ParserException mpe)
            {
                Status = mpe.Message;
            }
            catch (ParameterIsReadOnlyException mpiroe)
            {
                Status = mpiroe.Message;
            }
            catch (BinaryParameterTypeMismatchException bptme)
            {
                Status = bptme.Message;
            }
            catch (DifferentParameterTypeMismatchException dptme)
            {
                Status = dptme.Message;
            }
            catch (ParameterTypeMismatchException ptme)
            {
                Status = ptme.Message;
            }
            catch (ResultIsNotSupportedException rinse)
            {
                Status = rinse.Message;
            }
            catch (DivideByZeroException dbze)
            {
                Status = dbze.Message;
            }
            catch (ArgumentNullException ane)
            {
                Status = ane.Message;
            }
            catch (ArgumentException ae)
            {
                Status = ae.Message;
            }
            catch (FormatException fe)
            {
                Status = fe.Message;
            }
            catch (OverflowException oe)
            {
                Status = oe.Message;
            }
            catch (KeyNotFoundException knfe)
            {
                Status = knfe.Message;
            }
            catch (IndexOutOfRangeException)
            {
                Status = Resource.IndexOutOfRangeExceptionError;
            }
            catch (InvalidOperationException ioe)
            {
                Status = ioe.Message;
            }
            catch (NotSupportedException)
            {
                Status = Resource.NotSupportedOperationError;
            }

            mathExpressionBox.Text = string.Empty;
        }