示例#1
0
        /// <summary>
        /// Create an <see cref="TimeExpressionEntity"/> instance from the specified <paramref name="timeTranscoding"/>
        /// </summary>
        /// <param name="timeTranscoding">
        /// The Mapping store Time Transcoding
        /// </param>
        /// <returns>
        /// An <see cref="TimeExpressionEntity"/>
        /// </returns>
        public static TimeExpressionEntity CreateExpression(TimeTranscodingEntity timeTranscoding)
        {
            var   expr  = new TimeExpressionEntity();
            Match match = TimeExpressionRegex.Match(timeTranscoding.Expression);

            expr.Freq             = TimeFormat.GetTimeFormatFromCodeId(timeTranscoding.FrequencyValue).EnumType;
            expr.IsDateTime       = match.Groups["datetime"].Value.Equals("1");
            expr.TranscodingRules = timeTranscoding.TranscodingRules;

            if (!expr.IsDateTime)
            {
                expr.YearStart  = Convert.ToInt32(match.Groups["year_start"].Value, CultureInfo.InvariantCulture);
                expr.YearLength = Convert.ToInt32(match.Groups["year_len"].Value, CultureInfo.InvariantCulture);
                if (expr.YearLength == 0)
                {
                    expr.YearLength = 4;
                }

                expr.YearColumnSysId   = timeTranscoding.YearColumnId;
                expr.PeriodStart       = 0;
                expr.PeriodLength      = 0;
                expr.PeriodColumnSysId = 0;
                if (expr.Freq != TimeFormatEnumType.Year)
                {
                    expr.PeriodColumnSysId = timeTranscoding.PeriodColumnId;
                    expr.PeriodStart       = Convert.ToInt32(match.Groups["period_start"].Value, CultureInfo.InvariantCulture);
                    expr.PeriodLength      = Convert.ToInt32(match.Groups["period_len"].Value, CultureInfo.InvariantCulture);
                    expr.OneColumnMapping  = expr.YearColumnSysId == expr.PeriodColumnSysId;
                }
                else
                {
                    expr.OneColumnMapping = true;
                }
            }
            else
            {
                expr.DateColumnSysId = timeTranscoding.DateColumnId;
            }

            return(expr);
        }
        /// <summary>
        /// Create an <see cref="TimeExpressionEntity"/> instance from the specified <paramref name="timeTranscoding"/>
        /// </summary>
        /// <param name="timeTranscoding">
        /// The Mapping store Time Transcoding
        /// </param>
        /// <returns>
        /// An <see cref="TimeExpressionEntity"/>
        /// </returns>
        public static TimeExpressionEntity CreateExpression(TimeTranscodingEntity timeTranscoding)
        {
            var expr = new TimeExpressionEntity();
            Match match = TimeExpressionRegex.Match(timeTranscoding.Expression);
            expr.Freq = TimeFormat.GetTimeFormatFromCodeId(timeTranscoding.FrequencyValue).EnumType;
            expr.IsDateTime = match.Groups["datetime"].Value.Equals("1");
            expr.TranscodingRules = timeTranscoding.TranscodingRules;

            if (!expr.IsDateTime)
            {
                expr.YearStart = Convert.ToInt32(match.Groups["year_start"].Value, CultureInfo.InvariantCulture);
                expr.YearLength = Convert.ToInt32(match.Groups["year_len"].Value, CultureInfo.InvariantCulture);
                if (expr.YearLength == 0)
                {
                    expr.YearLength = 4;
                }

                expr.YearColumnSysId = timeTranscoding.YearColumnId;
                expr.PeriodStart = 0;
                expr.PeriodLength = 0;
                expr.PeriodColumnSysId = 0;
                if (expr.Freq != TimeFormatEnumType.Year)
                {
                    expr.PeriodColumnSysId = timeTranscoding.PeriodColumnId;
                    expr.PeriodStart = Convert.ToInt32(match.Groups["period_start"].Value, CultureInfo.InvariantCulture);
                    expr.PeriodLength = Convert.ToInt32(match.Groups["period_len"].Value, CultureInfo.InvariantCulture);
                    expr.OneColumnMapping = expr.YearColumnSysId == expr.PeriodColumnSysId;
                }
                else
                {
                    expr.OneColumnMapping = true;
                }
            }
            else
            {
                expr.DateColumnSysId = timeTranscoding.DateColumnId;
            }

            return expr;
        }
        /// <summary>
        /// Create time dimension mapping with transcoding 
        /// </summary>
        /// <param name="mapping">
        ///     The mapping entity<see cref="MappingEntity"/> of the Time Dimension component
        /// </param>
        /// <param name="databaseType">
        ///     The dissemination database vendor. Is needed to generate the correct SQL query where conditions
        /// </param>
        /// <param name="timeTranscoding">
        /// The Mapping Store <c>TIME_TRANSCODING</c> object
        /// </param>
        /// <exception cref="TranscodingException">
        /// Incomplete/Invalid mapping or expression
        /// </exception>
        /// <returns>
        /// An Time Dimension Transcoding object<see cref="ITimeDimension"/>
        /// </returns>
        private static ITimeDimensionMapping CreateTranscodedTimeDimensionMapping(MappingEntity mapping, string databaseType, TimeTranscodingEntity timeTranscoding)
        {
            ITimeDimensionMapping timeDimensionTranscoding;
            TimeExpressionEntity expr = TimeExpressionEntity.CreateExpression(timeTranscoding);

            if (!expr.IsDateTime)
            {
                if (!expr.OneColumnMapping)
                {
                    timeDimensionTranscoding = new TimeDimension2Column(mapping, expr, databaseType);
                }
                else
                {
                    if (expr.YearLength != 4)
                    {
                        throw new TranscodingException(ErrorMessages.TimeDimensionYearNo4Digits);
                    }

                    if (expr.Freq != TimeFormatEnumType.Year)
                    {
                        if (expr.PeriodLength <= 0 && expr.YearStart > expr.PeriodStart)
                        {
                            throw new TranscodingException(ErrorMessages.TimeDimensionVariableLenPeriodNotFirst);
                        }

                        if (((expr.YearStart + expr.YearLength) > expr.PeriodStart && expr.YearStart < expr.PeriodStart)
                            ||
                            ((expr.PeriodStart + expr.PeriodLength) > expr.YearStart
                             && expr.YearStart > expr.PeriodStart) || expr.PeriodStart == expr.YearStart)
                        {
                            throw new TranscodingException(ErrorMessages.TimeDimensionYearPeriodOverlap);
                        }
                    }

                    timeDimensionTranscoding = new TimeDimension1Column(mapping, expr, databaseType);
                }
            }
            else
            {
                timeDimensionTranscoding = new TimeDimensionDateType(mapping, expr, databaseType);
            }

            return timeDimensionTranscoding;
        }