コード例 #1
0
        private static void PrintParAsDefined(FunBase fun)
        {
            DefinitionAdmin.Fun funDef = DefinitionAdmin.GetFunDefinition(fun.description.GetFunName());
            PrintSubHeading("Possible parameters");

            CompOpt(funDef.GetParList());
            foreach (DefinitionAdmin.ParGroup group in funDef.GetGroupParList())
            {
                RandColor.WriteLine($"{(group.minCount > 0 ? "Compuslory" : "Optional")} group {group.groupName}:", colorHeading);
                CompOpt(group.par, "   ");
            }

            void CompOpt(Dictionary <string, DefinitionAdmin.Par> parList, string space = "")
            {
                RandColor.Write($"{space}Compulsory: ", colorHeading);
                foreach (var par in parList)
                {
                    if (par.Value.minCount > 0)
                    {
                        RandColor.Write($"{par.Key} ", GetSwapColor());
                    }
                }
                RandColor.Write(Environment.NewLine + $"{space}Optional: ", colorHeading);
                foreach (var par in parList)
                {
                    if (par.Value.minCount == 0)
                    {
                        RandColor.Write($"{par.Key} ", GetSwapColor());
                    }
                }
                Console.WriteLine();
            }
        }
コード例 #2
0
        private static List <AddParameterTag> GetFullParList(string funName)
        {
            List <AddParameterTag> pars = new List <AddParameterTag>();

            DefinitionAdmin.Fun fun = DefinitionAdmin.GetFunDefinition(funName, false); if (fun == null)
            {
                return(pars);
            }

            List <AddParameterTag> commonPars = new List <AddParameterTag>(), footnotePars = new List <AddParameterTag>();

            foreach (var p in fun.GetParList())
            {
                AddPar(p);
            }
            foreach (var pg in fun.GetGroupParList())
            {
                foreach (var p in pg.par)
                {
                    AddPar(p, pg);
                }
            }
            pars.AddRange(commonPars); pars.AddRange(footnotePars); // to get parameters in order: fun/common/footnotes
            return(pars);

            void AddPar(KeyValuePair <string, DefinitionAdmin.Par> p, DefinitionAdmin.ParGroup pg = null)
            {
                if (p.Key.ToLower() == DefPar.DefConst.Const_Monetary.ToLower())
                {
                    return;                                                              // Const_Monetary is not allowed, but needs to exist in library, because it is used in some countries (e.g. el, ie)
                }
                string          parName = p.Key.ToUpper() == DefPar.PAR_TYPE.PLACEHOLDER.ToString().ToUpper() ? DefinitionAdmin.ParTypeToString(DefPar.PAR_TYPE.PLACEHOLDER) : p.Key;
                AddParameterTag apt     = new AddParameterTag()
                {
                    _parName = parName, _parDef = p.Value, _parGroup = pg
                };

                if (p.Value.isFootnote)
                {
                    footnotePars.Add(apt);
                }
                else if (p.Value.isCommon)
                {
                    commonPars.Add(apt);
                }
                else
                {
                    pars.Add(apt);
                }
            }
        }
コード例 #3
0
        private int GetMaxGroupUsedByFunction(CountryConfig.FunctionRow functionRow, string groupName)
        {
            int maxGroup = 0; List <string> potentialGroupPars = new List <string>();

            DefinitionAdmin.Fun fun = DefinitionAdmin.GetFunDefinition(functionRow.Name, false);
            if (fun != null)         // find all parameters belonging to this group, e.g. functionRow.Name=BenCalc, groupName=Comp_X:
            {                        // find: Comp_PerTU, Comp_PerElig, Comp_Cond, Comp_LowLim, Comp_UpLim
                var pgs = from pg in fun.GetGroupParList() where pg.groupName.ToLower() == groupName.ToLower() select pg;
                if (pgs.Count() > 0) // this should always be fulfilled (i.e. the function has such a group)
                {
                    foreach (var p in pgs.First().par)
                    {
                        potentialGroupPars.Add(p.Key.ToLower());
                        foreach (string s in p.Value.substitutes)
                        {
                            potentialGroupPars.Add(s);
                        }
                    }
                }
            }
            foreach (CountryConfig.ParameterRow countryConfigParameterRow in functionRow.GetParameterRows())
            {
                if (countryConfigParameterRow.Group == string.Empty || !EM_Helpers.IsNonNegInteger(countryConfigParameterRow.Group))
                {
                    continue; //no group parameter
                }
                if (!potentialGroupPars.Contains(countryConfigParameterRow.Name.ToLower()) && !IsPlaceholderSibling(countryConfigParameterRow, potentialGroupPars))
                {
                    continue; //no sibling
                }
                if (EM_Helpers.SaveConvertToInt(countryConfigParameterRow.Group) > maxGroup)
                {
                    maxGroup = EM_Helpers.SaveConvertToInt(countryConfigParameterRow.Group);
                }
            }
            return(maxGroup);
        }
コード例 #4
0
        /// <summary> check for compulsory parameters </summary>
        private void CheckForCompleteness(Dictionary <string, ExeXml.Par> xmlParList, DefinitionAdmin.Fun funDef)
        {
            // check if compulsory non-group parameters are available
            foreach (var p in funDef.GetParList())
            {
                string parName = p.Key; DefinitionAdmin.Par parDef = p.Value;
                if (parDef.minCount == 0)
                {
                    continue;                       // optional parameter (e.g. Allocate's Share_Between)
                }
                // (note that footnote-parameters are always optional)
                bool found = false;
                if (parDef.maxCount == 1) // check for unique compulsory parameter (e.g. ArithOp's Formula)
                {
                    if (GetUniquePar <ParBase>(parName) != null)
                    {
                        found = true;
                    }
                    else // could still be available as substitute (e.g. output_var not available, but output_add_var)
                    {
                        foreach (string substitute in parDef.substitutes)
                        {
                            if (GetUniquePar <ParBase>(substitute) != null)
                            {
                                found = true; break;
                            }
                        }
                        ;
                    }
                }
                if (parDef.maxCount > 1) // check for non-unique parameter, where at least one must be defined (e.g. SetDefault's Dataset)
                {
                    if (GetNonUniquePar <ParBase>(parName).Count > 0)
                    {
                        found = true;
                    }
                    else // unlikely, but could still be available as substitute
                    {
                        foreach (string substitute in parDef.substitutes)
                        {
                            if (GetNonUniquePar <ParBase>(substitute).Count > 0)
                            {
                                found = true; break;
                            }
                        }
                        ;
                    }
                }

                if (!found)
                {
                    infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                    {
                        isWarning = false, message = $" {description.Get()}: compulsory parameter {parName} is missing"
                    });
                }
            }

            // check if compulsory groups, and compulsory parameter within groups are available
            foreach (var groupDef in funDef.GetGroupParList())
            {
                if (groupDef.minCount > 0) // check for compulsory group, e.g. BenCalc's Comp_X-group
                {
                    if (!groupPar.ContainsKey(groupDef.groupName))
                    {
                        infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                        {
                            isWarning = false, message = $" {description.Get()}: compulsory group {groupDef.groupName} is missing"
                        });
                    }
                }

                // whether or not the group is compulsory it can (if existent) ask for completeness, i.e. have compulsory parts
                if (!groupPar.ContainsKey(groupDef.groupName))
                {
                    continue;                   // no such group exists
                }
                foreach (var p in groupDef.par) // loop over the group-definition's parameters (e.g. Comp_Cond, Comp_perTU, Comp_LowLim, ...)
                {
                    string parName = p.Key; DefinitionAdmin.Par parDef = p.Value;
                    if (parDef.minCount == 0)
                    {
                        continue;                       // optional parameter (e.g. Comp_LowLim)
                    }
                    // check for compulsory parameter (e.g. Comp_Cond)
                    foreach (var g in GetParGroups(groupDef.groupName)) // loop over all existent groups
                    {                                                   // (e.g. all components of an actual BenCalc)
                        int groupNo = g.Key; List <ParBase> groupPar = g.Value;
                        int found = 0;
                        if (parDef.maxCount == 1) // check for unique compulsory group-parameter (e.g. BenCalc's Comp_Cond)
                        {
                            if (GetUniqueGroupPar <ParBase>(parName, groupPar) != null)
                            {
                                ++found;
                            }
                            foreach (string substitute in parDef.substitutes)
                            {
                                if (GetUniqueGroupPar <ParBase>(substitute.ToLower(), groupPar) != null)
                                {
                                    ++found;
                                }
                            }
                            if (found > 1)
                            {
                                infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                                {
                                    isWarning = false, message = $" {description.Get()}: double definition of group-parameter {parName} (group {groupNo})"
                                });
                            }
                        }
                        if (parDef.maxCount > 1) // check for non-unique compulsory group-parameter (e.g. Uprate's AggVarPart)
                        {
                            if (GetNonUniqueGroupPar <ParBase>(parName, groupPar).Count > 0)
                            {
                                ++found;
                            }
                            foreach (string substitute in parDef.substitutes)
                            {
                                if (GetNonUniqueGroupPar <ParBase>(substitute.ToLower(), groupPar).Count > 0)
                                {
                                    ++found;
                                }
                            }
                        }
                        if (found == 0)
                        {
                            infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                            {
                                isWarning = false, message = $" {description.Get()}: compulsory group-parameter {parName} (group {groupNo}) is missing"
                            });
                        }
                    }
                }
            }
        }
コード例 #5
0
        internal override void PerformAction()
        {
            TreeListNode policyNode = _senderNode;

            if (_senderNode.ParentNode != null)
            {
                policyNode = _senderNode.ParentNode;
            }

            int newFunctionNodeIndex = -1;
            List <CountryConfig.FunctionRow> newFunctionRows = new List <CountryConfig.FunctionRow>();

            foreach (CountryConfig.PolicyRow policyRow in (policyNode.Tag as PolicyTreeListTag).GetPolicyRows()) //loop over systems
            {
                CountryConfig.FunctionRow newFunctionRow = null;

                //(1) add function
                //if the sender node is a policy node: insert as last function ('Add Function' was called from policy node or 'Add Function After' was called from last function node in policy)
                if (_senderNode == policyNode)
                {
                    newFunctionRow = CountryConfigFacade.AddFunctionRowAtTail(_functionName, policyRow,
                                                                              // the switch of a function inside an extension-policy cannot be changed, therefore add as on (otherwise one would need to remove the policy from the extension to be able to change the switch to on)
                                                                              ExtensionAndGroupManager.ShowExtensionSwitchEditor(policyRow) ? DefPar.Value.ON : DefPar.Value.NA);
                }

                //if the sender node is a function node: insert before ('Add Function Before' was called from function node)
                else
                {
                    CountryConfig.FunctionRow neighbourFunction = (_senderNode.Tag as FunctionTreeListTag).GetFunctionRowOfSystem(policyRow.SystemRow.ID);
                    newFunctionRow = CountryConfigFacade.AddFunctionRow(_functionName, neighbourFunction, true,
                                                                        ExtensionAndGroupManager.ShowExtensionSwitchEditor(policyRow) ? DefPar.Value.ON : DefPar.Value.NA); // see comment above
                    newFunctionNodeIndex = _mainForm.treeList.GetNodeIndex(_senderNode);
                }
                _addedFunctionsIDs.Add(newFunctionRow.ID);

                //(2) add compulsory parameters
                DefinitionAdmin.Fun fun = DefinitionAdmin.GetFunDefinition(_functionName, false);
                if (fun != null)
                {
                    for (short doCommon = 0; doCommon < 2; ++doCommon) // add function-specific parameters before common
                    {
                        foreach (var p in fun.GetParList())
                        {
                            AddPar(p, false);
                        }
                        foreach (var pg in fun.GetGroupParList())
                        {
                            if (pg.minCount > 0)
                            {
                                foreach (var p in pg.par)
                                {
                                    AddPar(p, true);
                                }
                            }
                        }

                        void AddPar(KeyValuePair <string, DefinitionAdmin.Par> p, bool group)
                        {
                            string parName = p.Key.ToUpper() == DefPar.PAR_TYPE.PLACEHOLDER.ToString().ToUpper() ? DefinitionAdmin.ParTypeToString(DefPar.PAR_TYPE.PLACEHOLDER) : p.Key;

                            DefinitionAdmin.Par parDef = p.Value;
                            if (parDef.minCount > 0 && ((doCommon == 0 && !parDef.isCommon) || (doCommon == 1 && parDef.isCommon)))
                            {
                                CountryConfigFacade.AddParameterRowAtTail(newFunctionRow, parName, parDef, group ? "1" : string.Empty);
                            }
                        }
                    }
                }
                newFunctionRows.Add(newFunctionRow);
            }

            _mainForm.GetTreeListBuilder().InsertFunctionNode(newFunctionRows, policyNode, newFunctionNodeIndex);
        }