コード例 #1
0
ファイル: formulasparser.cs プロジェクト: Kobuntu/ProryvARM
        private void WriteFormulaData(FORMULA f, XmlWriter xml_writer)
        {
            xml_writer.WriteStartElement("FORMULA");

            xml_writer.WriteAttributeString("F_CLASS", f.F_CLASS.ToString());
            xml_writer.WriteAttributeString("F_INFO", f.F_INFO);
            xml_writer.WriteAttributeString("F_TYPE", f.F_TYPE.ToString());
            xml_writer.WriteAttributeString("F_ID", f.F_ID);
            xml_writer.WriteAttributeString("F_RESULT_TYPE", f.F_RESULT_TYPE);
            xml_writer.WriteAttributeString("F_MODE", f.F_MODE.ToString());

            System.Globalization.CultureInfo provider = new System.Globalization.CultureInfo("en-US");
            provider.NumberFormat.NumberDecimalSeparator = ".";

            xml_writer.WriteAttributeString("HIGHT_LIMIT", f.HIGHT_LIMIT.ToString(provider));
            xml_writer.WriteAttributeString("LOWER_LIMIT", f.LOWER_LIMIT.ToString(provider));

            if (f.F_OPERATORS != null)
            {
                for (int i = 0; i < f.F_OPERATORS.Count; i++)
                {
                    WriteFormulaOperator(xml_writer, f.F_OPERATORS[i]);
                }
            }
            xml_writer.WriteEndElement();
        }
コード例 #2
0
ファイル: formulasparser.cs プロジェクト: Kobuntu/ProryvARM
        private FORMULA ReadFormulaData(XmlReader xml_reader)
        {
            var fclass = Convert.ToInt32(xml_reader.GetAttribute("F_CLASS"));
            var f      = new FORMULA(xml_reader.GetAttribute("F_ID"));

            f.F_CLASS       = fclass;
            f.F_RESULT_TYPE = xml_reader.GetAttribute("F_RESULT_TYPE");
            f.F_TYPE        = Convert.ToInt32(xml_reader.GetAttribute("F_TYPE"));
            f.F_INFO        = xml_reader.GetAttribute("F_INFO");

            string temp_str = xml_reader.GetAttribute("F_MODE");

            if (!string.IsNullOrEmpty(temp_str))
            {
                f.F_MODE = Convert.ToInt32(temp_str);
            }

            System.Globalization.CultureInfo provider = new System.Globalization.CultureInfo("en-US");
            provider.NumberFormat.NumberDecimalSeparator = ".";


            temp_str = xml_reader.GetAttribute("HIGHT_LIMIT");
            if (temp_str != null)
            {
                f.HIGHT_LIMIT = Convert.ToSingle(temp_str, provider);
            }

            temp_str = xml_reader.GetAttribute("LOWER_LIMIT");
            if (temp_str != null)
            {
                f.LOWER_LIMIT = Convert.ToSingle(temp_str, provider);
            }


            if (xml_reader.IsEmptyElement == true)
            {
                return(f);
            }

            while (xml_reader.Read())
            {
                if (xml_reader.NodeType == XmlNodeType.Element && xml_reader.Name == "F_OPERATOR")
                {
                    f.F_OPERATORS.Add(ReadOperator(xml_reader, f));
                }
                else if (xml_reader.NodeType == XmlNodeType.EndElement && xml_reader.Name == "FORMULA")
                {
                    break;
                }
            }
            f.F_OPERATORS.Sort(SortOperatorsByOrder);
            return(f);
        }
コード例 #3
0
ファイル: formulasparser.cs プロジェクト: Kobuntu/ProryvARM
        private F_OPERATOR ReadOperator(XmlReader xml_reader, FORMULA f)
        {
            var oper = new F_OPERATOR
            {
                AFTER_OPERANDS = xml_reader.GetAttribute("AFTER_OPERANDS"),
                OPER_ID        = xml_reader.GetAttribute("OPER_ID"),
                OPER_ORDER     = Convert.ToInt32(xml_reader.GetAttribute("OPER_ORDER")),
                OPER_TYPE      = (F_OPERATOR.F_OPERAND_TYPE)Convert.ToInt32(xml_reader.GetAttribute("OPER_TYPE")),
                PRE_OPERANDS   = xml_reader.GetAttribute("PRE_OPERANDS"),
            };

            if (oper.OPER_TYPE == F_OPERATOR.F_OPERAND_TYPE.TI_channel)
            {
                oper.TI_CHANNEL = Convert.ToByte(xml_reader.GetAttribute("TI_CHANNEL"));
            }
            else
            {
                oper.TI_CHANNEL = null;
            }

            oper.INNER_FORMULA = f;

            return(oper);
        }
コード例 #4
0
ファイル: formulasparser.cs プロジェクト: Kobuntu/ProryvARM
        //public FORMULAS_EXPRESSIONS Parse(string FilePath)
        //{
        //    PrvFileStream file_str = null;
        //    try
        //    {
        //        // открываем файл и копируем данные в память
        //        file_str = new PrvFileStream(FilePath, FileModeEx.OpenExisting, FileAccessEx.Read, FileShareEx.Read);
        //        byte[] data = new byte[(int)file_str.Length];
        //        file_str.Read(data, 0, data.Length);

        //        return Parse(data);
        //    }
        //    finally
        //    {
        //        if (file_str != null)
        //            file_str.Close();
        //    }

        //}

        public FORMULAS_EXPRESSIONS Parse(byte[] data)
        {
            XmlReaderSettings Xml_set;

            Xml_set = new XmlReaderSettings();
            Xml_set.ConformanceLevel = ConformanceLevel.Document;
            Xml_set.IgnoreWhitespace = true;
            Xml_set.IgnoreComments   = true;

            XmlReader    xml_reader = null;
            MemoryStream memory_str = null;

            try
            {
                memory_str = new MemoryStream();
                memory_str.Write(data, 0, data.Length);
                memory_str.Position = 0;

                xml_reader = XmlReader.Create(memory_str, Xml_set);

                //List<FORMULA> f_list = f_list = new List<FORMULA>(); // дабы не было сообщений от недовольных
                FORMULAS_EXPRESSIONS result;
                result.FORMULAS_LIST = new SortedList <string, FORMULA>();
                FORMULA fmla = null;
                while (xml_reader.Read())
                {
                    if (xml_reader.NodeType == XmlNodeType.Element && xml_reader.Name == "FORMULAS_EXPRESSIONS")
                    {
                        continue;
                    }
                    else if (xml_reader.NodeType == XmlNodeType.Element && xml_reader.Name == "FORMULA")
                    {
                        fmla = ReadFormulaData(xml_reader);
                        if (!result.FORMULAS_LIST.ContainsKey(fmla.F_ID))
                        {
                            result.FORMULAS_LIST.Add(fmla.F_ID, fmla);
                        }
                        //f_list.Add(ReadFormulaData(xml_reader));
                    }
                    else if (xml_reader.NodeType == XmlNodeType.EndElement && xml_reader.Name == "FORMULAS_EXPRESSIONS")
                    {
                        break;
                    }
                }


                //result.FORMULAS_LIST = f_list;

                return(result);
            }
            finally
            {
                if (memory_str != null)
                {
                    memory_str.Close();
                }

                if (xml_reader != null)
                {
                    xml_reader.Close();
                }
            }
        }
コード例 #5
0
        private Polskaya ComposeExpressionPolskaya(FORMULA f, PolskaParams polskaParams
                                                   , int indxStart, int indxEnd, int numbersHalfHours, bool isCalculateBetweenIndexes = true)
        {
            var parser = new Polskaya(polskaParams, _nameInterface, _formulaArchivesPrecalculator, _variablesDict);

            if (_recursionCallStack.Contains(f.F_ID))
            {
                throw new FormulaParseException("Обнаружена рекурсия формулы\n[" + GetOperNameFromDB(f.F_ID, F_OPERATOR.F_OPERAND_TYPE.Formula, null) + "]");
            }
            _recursionCallStack.Add(f.F_ID);

            foreach (F_OPERATOR operators in f.F_OPERATORS)
            {
                switch (operators.OPER_TYPE)
                {
                case F_OPERATOR.F_OPERAND_TYPE.Section:
                case F_OPERATOR.F_OPERAND_TYPE.TP_channel:
                case F_OPERATOR.F_OPERAND_TYPE.ContrTI_Chanel:
                case F_OPERATOR.F_OPERAND_TYPE.Integral_Channel:
                case F_OPERATOR.F_OPERAND_TYPE.TI_channel:
                case F_OPERATOR.F_OPERAND_TYPE.FormulaConstant:
                case F_OPERATOR.F_OPERAND_TYPE.UANode:

                    if (!parser.ContainsVariable(operators.Name))
                    {
                        Variable var;
                        if (Archives == null)
                        {
                            // режим поиска параметров и проверки правильности
                            var = new Variable(operators.Name, indxStart, indxEnd, isCalculateBetweenIndexes: isCalculateBetweenIndexes);
                        }
                        else
                        {
                            IGetAchives data = Archives.GetArchiveByOperandType(operators);
                            if (data == null && !Archives.IsArchTech)
                            {
                                if (operators.OPER_TYPE == F_OPERATOR.F_OPERAND_TYPE.TP_channel)
                                {
                                    throw new FormulaParseException("Расчет формулы невозможен. Не найдено значение для ТП \"" +
                                                                    GetOperNameFromDB(operators.OPER_ID, operators.OPER_TYPE, operators.TI_CHANNEL) + "\"\nНе описан канал или не найдена для него формула.");
                                }

                                throw new FormulaParseException("Расчет формулы невозможен. Отсутствуют значения для \"" +
                                                                GetOperNameFromDB(operators.OPER_ID, operators.OPER_TYPE, operators.TI_CHANNEL) + "\"\n из формулы <" + GetOperNameFromDB(f.F_ID, F_OPERATOR.F_OPERAND_TYPE.Formula, null) + ">");
                            }

                            var = new Variable(operators.Name, indxStart, indxEnd, data, operators.TI_CHANNEL, isCalculateBetweenIndexes);
                        }

                        parser.CreateVariable(var);
                    }

                    parser.Expression.Append(operators.PRE_OPERANDS ?? "").Append(operators.Name).Append(operators.AFTER_OPERANDS ?? "");
                    break;

                case F_OPERATOR.F_OPERAND_TYPE.Formula:
                    parser.Expression.Append(operators.PRE_OPERANDS ?? "").Append(operators.Name).Append(operators.AFTER_OPERANDS ?? "");
                    if (!parser.ContainsVariable(operators.Name))
                    {
                        var innerFId = GetFormulaByID(operators.OPER_ID);
                        if (innerFId != null)
                        {
                            var p = new PolskaParams(innerFId.F_ID, _formulasTable, polskaParams.StartDateTime, polskaParams.EndDateTime, polskaParams.DiscreteType,
                                                     numbersHalfHours, innerFId.UnitDigit);
                            var formulaExpression = ComposeExpressionPolskaya(innerFId, p, indxStart, indxEnd, numbersHalfHours, isCalculateBetweenIndexes);

                            //Время дейстаия внутренней формулы берем из основной
                            var var = new Variable(operators.Name, indxStart, indxEnd, formulaExpression, isCalculateBetweenIndexes);
                            parser.CreateVariable(var);
                        }
                        else
                        {
                            parser.CreateVariable(new Variable(operators.Name, -1, -1));
                        }
                    }
                    break;

                case F_OPERATOR.F_OPERAND_TYPE.Constanta:
                    parser.Expression.Append(operators.PRE_OPERANDS).Append(operators.AFTER_OPERANDS ?? "");
                    break;

                case F_OPERATOR.F_OPERAND_TYPE.None:
                    if (string.IsNullOrEmpty(operators.PRE_OPERANDS) && string.IsNullOrEmpty(operators.AFTER_OPERANDS))
                    {
                        throw new FormulaParseException("Формула не описана!");
                    }
                    parser.Expression.Append(operators.PRE_OPERANDS ?? "").Append(operators.AFTER_OPERANDS ?? "");
                    break;

                default:
                    throw new FormulaParseException("Неизвестный тип оператора!");
                }
            }

            _recursionCallStack.Remove(f.F_ID);

            return(parser);
        }