예제 #1
0
        protected override void PrepareNonCommonPar()
        {
            path = GetParBaseValueOrDefault(DefFun.DefInput, DefPar.DefInput.path);     // compulsory
            file = GetParBaseValueOrDefault(DefFun.DefInput, DefPar.DefInput.file);     // compulsory

            ParVar parRowMergeVar = GetUniquePar <ParVar>(DefPar.DefInput.RowMergeVar); // compulsory

            if (parRowMergeVar != null)
            {
                rowMergeVar = new VarSpec()
                {
                    name = parRowMergeVar.name
                }
            }
            ;
            ParVar parColMergeVar = GetUniquePar <ParVar>(DefPar.DefInput.ColMergeVar);

            if (parColMergeVar != null)
            {
                colMergeVar = new VarSpec()
                {
                    name = parColMergeVar.name
                }
            }
            ;
            ParVar parInputVar = GetUniquePar <ParVar>(DefPar.DefInput.InputVar);

            if (parInputVar != null)
            {
                inputVar = new VarSpec()
                {
                    name = parInputVar.name
                }
            }
            ;

            if ((colMergeVar != null && inputVar == null) || (colMergeVar == null && inputVar != null))
            {
                infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                {
                    isWarning = false,
                    message   = $"{description.Get()}: if {DefPar.DefInput.ColMergeVar} is defined {DefPar.DefInput.InputVar} must be defined too, and vice-versa"
                });
            }
            lookUpMode = colMergeVar != null;

            repByEMPath         = GetParBaseValueOrDefault(DefFun.DefInput, DefPar.DefInput.RepByEMPath);
            ignoreNRows         = (int)GetParNumberValueOrDefault(DefFun.DefInput, DefPar.DefInput.IgnoreNRows);
            ignoreNCols         = (int)GetParNumberValueOrDefault(DefFun.DefInput, DefPar.DefInput.IgnoreNCols);
            doRanges            = GetParBoolValueOrDefault(DefFun.DefInput, DefPar.DefInput.DoRanges);
            parDefaultIfNoMatch = GetUniquePar <ParNumber>(DefPar.DefInput.DefaultIfNoMatch);

            // * * *   T O D O   * * *
            // consider parameters that allow defining and initialising variables
            // currently all input-variables need to be defined with DefVar or, if they are defined in variables-file, initialised with SetDefault
        }
        protected override void PrepareNonCommonPar()
        {
            ParVar fv = GetUniquePar <ParVar>(DefPar.AddHHMembers.FlagVar);

            if (fv != null)
            {
                flagVar = new VarSpec()
                {
                    name = fv.name
                }
            }
            ;

            foreach (var g in GetParGroups(DefPar.AddHHMembers.GROUP_MAIN))
            {
                var            group = g.Value; int groupNo = g.Key;
                AddInstruction addInstruction = new AddInstruction();

                // first find out whether we are adding children or partners or other persons ...
                ParCateg parWho = GetUniqueGroupPar <ParCateg>(DefPar.AddHHMembers.Add_Who, group); if (parWho == null)
                {
                    continue;                                                                                                    // compulsory parameter, error already issued
                }
                addInstruction.addWho = parWho.GetCateg();

                // ... depending on that, check the add-condition
                ParCond parParent = GetUniqueGroupPar <ParCond>(DefPar.AddHHMembers.ParentCond, group);
                ParCond parPartner = GetUniqueGroupPar <ParCond>(DefPar.AddHHMembers.PartnerCond, group);
                ParCond parOther = GetUniqueGroupPar <ParCond>(DefPar.AddHHMembers.HHCond, group);
                string  missing = string.Empty; string tooMuch = string.Empty;
                switch (addInstruction.addWho)
                {
                case DefPar.Value.ADDHHMEMBERS_CHILD:
                    if (parParent != null)
                    {
                        addInstruction.cond = parParent;
                    }
                    else
                    {
                        missing = DefPar.AddHHMembers.ParentCond;
                    }
                    if (parPartner != null)
                    {
                        tooMuch = DefPar.AddHHMembers.PartnerCond + " ";
                    }
                    if (parOther != null)
                    {
                        tooMuch = DefPar.AddHHMembers.HHCond;
                    }
                    ParBool parIsPP = GetUniqueGroupPar <ParBool>(DefPar.AddHHMembers.IsPartnerParent, group);
                    if (parIsPP != null)
                    {
                        addInstruction.isPartnerParent = parIsPP.GetBoolValue();
                    }
                    break;

                case DefPar.Value.ADDHHMEMBERS_PARTNER:
                    if (parParent != null)
                    {
                        tooMuch = DefPar.AddHHMembers.ParentCond + " ";
                    }
                    if (parPartner != null)
                    {
                        addInstruction.cond = parPartner;
                    }
                    else
                    {
                        missing = DefPar.AddHHMembers.PartnerCond;
                    }
                    if (parOther != null)
                    {
                        tooMuch = DefPar.AddHHMembers.HHCond;
                    }
                    break;

                case DefPar.Value.ADDHHMEMBERS_OTHER:
                    if (parParent != null)
                    {
                        tooMuch = DefPar.AddHHMembers.ParentCond + " ";
                    }
                    if (parPartner != null)
                    {
                        tooMuch = DefPar.AddHHMembers.PartnerCond;
                    }
                    if (parOther != null)
                    {
                        addInstruction.cond = parOther;
                    }
                    else
                    {
                        missing = DefPar.AddHHMembers.HHCond;
                    }
                    break;

                default: continue;     // error is caught by general error handling
                }
                if (missing != string.Empty)
                {
                    infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                    {
                        isWarning = false,
                        message   = $"{description.Get()} (group {groupNo}): {DefPar.AddHHMembers.Add_Who}={addInstruction.addWho} requires parameter {missing}"
                    });
                }
                if (tooMuch != string.Empty)
                {
                    infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                    {
                        isWarning = true,
                        message   = $"{description.Get()} (group {groupNo}): {DefPar.AddHHMembers.Add_Who}={addInstruction.addWho} does not require {tooMuch}"
                    });
                }

                // here we are only gathering the variables that are to be set, but do not evaluate whether they exist
                // note: this function does not "register" variables, i.e. if a variable is not used anywhere else, it cannot be set
                foreach (ParFormula parVarDefinition in GetPlaceholderGroupPar <ParFormula>(group))
                {
                    string varName = parVarDefinition.description.GetParName();
                    if (addInstruction.prepVarDefinitions.ContainsKey(varName))
                    {
                        infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                        {
                            isWarning = false,
                            message   = $"{parVarDefinition.description.Get()}: double definition of variable {varName}"
                        });
                        continue;
                    }
                    if (varName == DefVarName.IDHH || varName == DefVarName.IDPERSON || varName == DefVarName.DWT || varName == DefVarName.DCT)
                    {
                        infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                        {
                            isWarning = false,
                            message   = $"{parVarDefinition.description.Get()}: variable {varName} is system-set and cannot be changed"
                        });
                        continue;
                    }
                    addInstruction.prepVarDefinitions.Add(varName, parVarDefinition);
                }
                addInstructions.Add(addInstruction);
            }
        }