Пример #1
0
        public bool AddNewFormula(ParserFormula formula)
        {
            //проверка на совподении имени
            foreach (var v in Formulas)
            {
                if (v.Name == formula.Name)
                {
                    return(false);
                }
            }
            //регистрируем функцию
            switch (formula.variables.Count)
            {
            case 0: Log.SetMessage("Количество параметров = 0, " + formula.Name); break;

            case 1: Parser.DefineFun(formula.Name, new Parser.Fun1Delegate(formula.Eval)); break;

            case 2: Parser.DefineFun(formula.Name, new Parser.Fun2Delegate(formula.Eval)); break;

            case 3: Parser.DefineFun(formula.Name, new Parser.Fun3Delegate(formula.Eval)); break;

            case 4: Parser.DefineFun(formula.Name, new Parser.Fun4Delegate(formula.Eval)); break;

            case 5: Parser.DefineFun(formula.Name, new Parser.Fun5Delegate(formula.Eval)); break;

            default: Log.SetMessage("Первышено количество параметров, " + formula.Name); return(false);
            }
            //если все прошло успешно
            Formulas.Add(formula);

            return(true);
        }
Пример #2
0
        private Analizator()
        {
            Formulas = new List <IParserFormula>();
            Parser   = new Parser();
            string path = Path.Combine(Directory.GetCurrentDirectory(), "Formulas");

            if (Directory.Exists(path))
            {
                var fs = Directory.GetFiles(path, "*.mf", SearchOption.TopDirectoryOnly);
                foreach (var f in fs)
                {
                    Stream          TestFileStream = File.OpenRead(f);
                    BinaryFormatter deserializer   = new BinaryFormatter();
                    ParserFormula   formula        = (ParserFormula)deserializer.Deserialize(TestFileStream, null);
                    var             fl             = new ParserFormula(formula.Name, formula.Expression, formula.variables.GetVariables().ToArray());
                    TestFileStream.Dispose();
                    AddNewFormula(fl);
                }
            }
            AddSysFormulas();
        }