コード例 #1
0
 public Variable(string id, int indxStart, int indxEnd,
                 IGetAchives achives = null, object userTag2 = null, bool isCalculateBetweenIndexes = true)
 {
     Id         = id;
     Achives    = achives;
     UserTag2   = userTag2;
     _indxStart = indxStart;
     _indxEnd   = indxEnd;
     _isCalculateBetweenIndexes = isCalculateBetweenIndexes;
 }
コード例 #2
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);
        }