Esempio n. 1
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="orig"></param>
        /// <param name="searchOpen"></param>
        /// <param name="searchClose"></param>
        /// <param name="newOpen"></param>
        /// <param name="newClose"></param>
        /// <param name="convert"></param>
        /// <returns></returns>
        protected TVariant ReplaceVariablesPattern(TVariant orig,
            String searchOpen,
            String searchClose,
            String newOpen,
            String newClose,
            TConvertProc convert)
        {
            int position = 0;
            String resultString = orig.ToString();
            TVariant ReturnValue = null;
            int bracket = resultString.IndexOf(searchOpen, position);

            if (bracket == -1)
            {
                // no brackets, therefore use the original TVariant, so that the type information is not lost
                ReturnValue = orig;
            }

            while (bracket != -1)
            {
                int firstRealChar = bracket + searchOpen.Length;
                int paramEndIdx = resultString.IndexOf(searchClose, firstRealChar);

                if (paramEndIdx <= 0)
                {
                    // missing closing bracket; can happen with e.g. #testdate; should be #testdate#
                    if (resultString.Length > bracket + 20)
                    {
                        throw new Exception("Cannot find closing bracket " + searchClose + " for " + resultString.Substring(bracket, 20));
                    }
                    else
                    {
                        throw new Exception("Cannot find closing bracket " + searchClose + " for " + resultString.Substring(bracket));
                    }
                }

                String parameter = resultString.Substring(firstRealChar, paramEndIdx - firstRealChar);
                bool ParameterExists = false;
                TVariant newvalue;

                if (parameters != null)
                {
                    if (parameter.IndexOf("GLOBAL:") == 0)
                    {
                        newvalue = parameters.Get(parameter.Substring(7), -1, -1, eParameterFit.eExact);
                    }
                    else if (parameter.IndexOf("ALLLEVELS:") == 0)
                    {
                        newvalue = parameters.Get(parameter.Substring(10), -1, depth, eParameterFit.eBestFitEvenLowerLevel);
                    }
                    else
                    {
                        newvalue = parameters.Get(parameter, column, depth, eParameterFit.eBestFitEvenLowerLevel);
                    }

                    ParameterExists = (newvalue.TypeVariant != eVariantTypes.eEmpty);
                }
                else
                {
                    newvalue = new TVariant();
                }

                if (!ParameterExists)
                {
                    // if date is given, use the parameter itself
                    if ((parameter[0] >= '0') && (parameter[0] <= '9'))
                    {
                        newvalue = new TVariant(parameter);
                    }
                    else
                    {
                        int CountWarning = 1;

                        // do not print warning too many times for the same variable
                        if (!VariablesNotFound.ContainsKey(parameter))
                        {
                            VariablesNotFound.Add(parameter, 1);
                        }
                        else
                        {
                            VariablesNotFound[parameter] = VariablesNotFound[parameter] + 1;
                            CountWarning = VariablesNotFound[parameter];
                        }

                        if (CountWarning < 5)
                        {
                            // this can be alright, for empty values; for example method of giving can be empty; for report GiftTransactions
                            TLogging.Log(
                                "Variable " + parameter + " empty or not found (column: " + column.ToString() +
                                "; level: " + depth.ToString() + "). " + resultString);
                        }
                        else if (CountWarning % 20 == 0)
                        {
                            TLogging.Log("20 times: Variable " + parameter + " empty or not found.");
                        }
                    }
                }

                try
                {
                    if (resultString.Length == (searchOpen + parameter + searchClose).Length)
                    {
                        // replace the whole value, return as a TVariant
                        ReturnValue = convert(newvalue);
                    }

                    resultString = resultString.Replace(searchOpen + parameter + searchClose, newOpen + convert(newvalue).ToString() + newClose);
                }
                catch (Exception e)
                {
                    throw new Exception(
                        "While trying to format parameter " + parameter + ", there was a problem with formatting." + Environment.NewLine + e.Message);
                }
                bracket = resultString.IndexOf(searchOpen, position);
            } // while

            if (ReturnValue == null)
            {
                // there has not been just a single value
                ReturnValue = new TVariant(resultString, true); // explicit string
            }

            return ReturnValue;
        }
Esempio n. 2
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="orig"></param>
        /// <param name="searchOpen"></param>
        /// <param name="searchClose"></param>
        /// <param name="newOpen"></param>
        /// <param name="newClose"></param>
        /// <param name="convert"></param>
        /// <returns></returns>
        protected TVariant ReplaceVariablesPattern(TVariant orig,
                                                   String searchOpen,
                                                   String searchClose,
                                                   String newOpen,
                                                   String newClose,
                                                   TConvertProc convert)
        {
            int      position     = 0;
            String   resultString = orig.ToString();
            TVariant ReturnValue  = null;
            int      bracket      = resultString.IndexOf(searchOpen, position);

            if (bracket == -1)
            {
                // no brackets, therefore use the original TVariant, so that the type information is not lost
                ReturnValue = orig;
            }

            while (bracket != -1)
            {
                int firstRealChar = bracket + searchOpen.Length;
                int paramEndIdx   = resultString.IndexOf(searchClose, firstRealChar);

                if (paramEndIdx <= 0)
                {
                    // missing closing bracket; can happen with e.g. #testdate; should be #testdate#
                    if (resultString.Length > bracket + 20)
                    {
                        throw new Exception("Cannot find closing bracket " + searchClose + " for " + resultString.Substring(bracket, 20));
                    }
                    else
                    {
                        throw new Exception("Cannot find closing bracket " + searchClose + " for " + resultString.Substring(bracket));
                    }
                }

                String   parameter       = resultString.Substring(firstRealChar, paramEndIdx - firstRealChar);
                bool     ParameterExists = false;
                TVariant newvalue;

                if (parameters != null)
                {
                    if (parameter.IndexOf("GLOBAL:") == 0)
                    {
                        newvalue = parameters.Get(parameter.Substring(7), -1, -1, eParameterFit.eExact);
                    }
                    else if (parameter.IndexOf("ALLLEVELS:") == 0)
                    {
                        newvalue = parameters.Get(parameter.Substring(10), -1, depth, eParameterFit.eBestFitEvenLowerLevel);
                    }
                    else
                    {
                        newvalue = parameters.Get(parameter, column, depth, eParameterFit.eBestFitEvenLowerLevel);
                    }

                    ParameterExists = (newvalue.TypeVariant != eVariantTypes.eEmpty);
                }
                else
                {
                    newvalue = new TVariant();
                }

                if (!ParameterExists)
                {
                    // if date is given, use the parameter itself
                    if ((parameter[0] >= '0') && (parameter[0] <= '9'))
                    {
                        newvalue = new TVariant(parameter);
                    }
                    else
                    {
                        int CountWarning = 1;

                        // do not print warning too many times for the same variable
                        if (!VariablesNotFound.ContainsKey(parameter))
                        {
                            VariablesNotFound.Add(parameter, 1);
                        }
                        else
                        {
                            VariablesNotFound[parameter] = VariablesNotFound[parameter] + 1;
                            CountWarning = VariablesNotFound[parameter];
                        }

                        if (CountWarning < 5)
                        {
                            // this can be alright, for empty values; for example method of giving can be empty; for report GiftTransactions
                            TLogging.Log(
                                "Variable " + parameter + " empty or not found (column: " + column.ToString() +
                                "; level: " + depth.ToString() + "). " + resultString);
                        }
                        else if (CountWarning % 20 == 0)
                        {
                            TLogging.Log("20 times: Variable " + parameter + " empty or not found.");
                        }
                    }
                }

                try
                {
                    if (resultString.Length == (searchOpen + parameter + searchClose).Length)
                    {
                        // replace the whole value, return as a TVariant
                        ReturnValue = convert(newvalue);
                    }

                    resultString = resultString.Replace(searchOpen + parameter + searchClose, newOpen + convert(newvalue).ToString() + newClose);
                }
                catch (Exception e)
                {
                    throw new Exception(
                              "While trying to format parameter " + parameter + ", there was a problem with formatting." + Environment.NewLine + e.Message);
                }
                bracket = resultString.IndexOf(searchOpen, position);
            } // while

            if (ReturnValue == null)
            {
                // there has not been just a single value
                ReturnValue = new TVariant(resultString, true); // explicit string
            }

            return(ReturnValue);
        }