Пример #1
0
        public override CodeSourceCollection CreateSources(string aFileName)
        {
            SIImage image = SIImage.New(base.Tracer, aFileName);

            if (image == null)
            {
                throw new NotSupportedException("The specified image file is not supported");
            }

            // We need to make a source and (single) collection for each content object within the image.
            // This enables relocation support when an image is actually used (i.e. read & decompress code
            // on demand, rather than up front).
            CodeSourceCollection sources = new CodeSourceCollection();

            //
            foreach (SIContent content in image)
            {
                CodeCollection collection = CodeCollection.New(base.IdAllocator, aFileName, content.FileName);
                collection.IsRelocatable = content.IsRelocationSupported;

                // The URI must be unique
                string    uri    = string.Format("{0} [{1}]", aFileName, content.FileName);
                ImgSource source = new ImgSource(uri, this, collection, content);
                sources.Add(source);
            }
            //
            return(sources);
        }
Пример #2
0
 public CodeCollectionViewModel(Boolean isInDesignMode)
 {
     this._model = new CodeCollection()
     {
         new Code()
         {
             Id           = "default",
             Title        = "(Default)",
             Description  = new Lazy <String>(() => "Default empty code."),
             OriginalBody = new Lazy <String>(() => ""),
             Output       = "YACQ Silverlight Runner (version " + YacqServices.Version + ")",
         }
     };
     this._model.ForEach(c => this.Add(new CodeViewModel(c)));
     this._model.CollectionChanged += (s, e) =>
     {
         switch (e.Action)
         {
         case NotifyCollectionChangedAction.Add:
             if (!isInDesignMode)
             {
                 DispatcherHelper.UIDispatcher.BeginInvoke(() =>
                                                           this.Add(new CodeViewModel(e.NewItems.OfType <Code>().Single()))
                                                           );
             }
             break;
         }
     };
     this.Fetch = new RelayCommand(() => this._model.Fetch(), () => true);
 }
 internal CodeSourceAndCollection(CodeSource aSource, CodeCollection aCollection)
 {
     System.Diagnostics.Debug.Assert(aSource != null && aCollection != null);
     //
     iSource     = aSource;
     iCollection = aCollection;
 }
Пример #4
0
        public ImgSource(string aURI, CodeSourceProvider aProvider, CodeCollection aCollection, SIContent aImageContent)
            : base(aURI, aProvider)
        {
            iImageContent = aImageContent;

            // Make sure we receive any requests from the collection object for code.
            aCollection.IfaceInstructionConverter = this;
            aCollection.IsRelocatable             = aImageContent.IsRelocationSupported;

            // XIP content should be read during priming.
            TTimeToRead timeToRead = TTimeToRead.EReadWhenPriming;

            if (aImageContent.IsRelocationSupported)
            {
                timeToRead = TTimeToRead.EReadWhenNeeded;
            }
            else
            {
                // If the image is fixed, then so is the collection base address
                aCollection.Relocate(aImageContent.RelocationAddress);
            }

            // Must add the collection *after* setting it's properties
            base.TimeToRead = timeToRead;
            base.Add(aCollection);
        }
Пример #5
0
        /// <summary>
        /// Build where clauses in the form of : (year and (periodA or periodB or ... ) and write them
        /// to a specified StringBuilder
        /// </summary>
        /// <param name="ret">The StringBuilder to write the output</param>
        /// <param name="yearStr">The year string</param>
        /// <param name="firstPeriod">The first period</param>
        /// <param name="lastPeriod">The last period</param>
        /// <param name="periodicity">The periodicity.</param>
        /// <param name="timeExpressionEntity">The time expression entity.</param>
        /// <returns>
        /// The position of the last clause inside the StringBuilder
        /// </returns>
        private int BuildPeriodWhere(StringBuilder ret, string yearStr, int firstPeriod, int lastPeriod, IPeriodicity periodicity, TimeExpressionEntity timeExpressionEntity)
        {
            var queryCode = new CodeCollection();

            ret.Append("( ");
            ret.AppendFormat(this._yearOnlyWhereFormat, yearStr);
            int lastClause = ret.Length;

            ret.Append(" and ");
            ret.Append("( ");
            for (int x = firstPeriod; x <= lastPeriod; x++)
            {
                string periodStr = x.ToString(periodicity.Format, _formatProvider);
                queryCode.Clear();
                queryCode.Add(periodStr);
                string periodCode = timeExpressionEntity.TranscodingRules.GetLocalCodes(queryCode)[0][0];
                ret.AppendFormat(CultureInfo.InvariantCulture, this._whereFormat, periodCode);
                lastClause = ret.Length;
                ret.Append(" or ");
            }

            ret.Length = lastClause;
            ret.Append(") ");
            ret.Append(") ");
            lastClause = ret.Length;
            ret.Append(" or ");
            return(lastClause);
        }
Пример #6
0
        /// <summary>
        /// Transcodes the time period returned by the local database to SDMX Time period
        /// </summary>
        /// <param name="reader">
        /// The data reader reading the Dissemination database
        /// </param>
        /// <returns>
        /// The transcoded time period, as in SDMX Time period type
        /// </returns>
        public string MapComponent(IDataReader reader)
        {
            string ret;

            this._fieldOrdinals.BuildOrdinal(reader);

            string yearperiod = DataReaderHelper.GetString(reader, this._fieldOrdinals.YearOrdinal);

            if (this.Expression.YearStart + this.Expression.YearLength > yearperiod.Length)
            {
                return(null);
            }

            string year    = yearperiod.Substring(this.Expression.YearStart, this.Expression.YearLength);
            var    rowFreq = this.Expression.Freq;

            if (rowFreq != TimeFormatEnumType.Year)
            {
                if (this.Expression.PeriodStart >= yearperiod.Length)
                {
                    return(null);
                }

                string period;
                if (this.Expression.PeriodLength > 0)
                {
                    int rowPeriodLen = this.Expression.PeriodLength;
                    if (this.Expression.PeriodLength + this.Expression.PeriodStart > yearperiod.Length)
                    {
                        rowPeriodLen = yearperiod.Length - this.Expression.PeriodStart;
                    }

                    period = yearperiod.Substring(this.Expression.PeriodStart, rowPeriodLen);
                }
                else
                {
                    period = yearperiod.Substring(this.Expression.PeriodStart);
                }

                this._periodLocalCode.Clear();
                this._periodLocalCode.Add(period);
                CodeCollection periodDsdCode =
                    this.Expression.TranscodingRules.GetDsdCodes(this._periodLocalCode);
                if (periodDsdCode == null)
                {
                    return(null); // MAT-495

                    // periodDsdCode = periodLocalCode;
                }

                ret = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", year, periodDsdCode[0]);
            }
            else
            {
                ret = year.ToString(FormatProvider);
            }

            return(ret);
        }
Пример #7
0
 public ActionResult Save(Bam.Net.Presentation.Unicode.Code[] values)
 {
     try
     {
         CodeCollection saver = new CodeCollection();
         saver.AddRange(values);
         saver.Save();
         return(Json(new { Success = true, Message = "", Dao = "" }));
     }
     catch (Exception ex)
     {
         return(GetErrorResult(ex));
     }
 }
Пример #8
0
        public CodeCollection Activate(CodeSegDefinition aCodeSegment)
        {
            CodeCollection ret = null;

            // Find the corresponding Code seg
            CodeSourceAndCollection pair = SourceManager[aCodeSegment];

            if (pair != null)
            {
                CodeCollection col = pair.Collection;
                if (col.IsFixed)
                {
                    // Cannot activate a fixed Code segment - TODO: should this return "true", i.e. already activated?
                }
                else
                {
                    bool safe = CheckSafeToActivate(aCodeSegment);
                    if (safe)
                    {
                        // Deep copy the collection
                        CodeCollection dupe = CodeCollection.NewCopy(iPlugin.ProvisioningManager.IdAllocator, col);

                        // Set new process-specific relocated base address. This causes the underlying code to be
                        // decompressed/read if not already done so.
                        dupe.Relocate(aCodeSegment.Base);

                        // At this point, the code owned by 'col' will have definitely been read (if available)
                        // and that means col.IsCodeAvailable is probably true. However, dupe.IsCodeAvailable
                        // is almost certainly false so we may need to copy the code over...
                        if (dupe.IsCodeAvailable == false && col.IsCodeAvailable == true)
                        {
                            dupe.Code = col.Code;
                        }
                        System.Diagnostics.Debug.Assert(dupe.IsCodeAvailable == col.IsCodeAvailable);

                        // Save so that we can unload it later
                        pair = new CodeSourceAndCollection(pair, dupe);
                        AddToActivationList(pair, aCodeSegment);

                        // We managed to activate a binary, so return the collection
                        ret = dupe;

                        iPlugin.Trace("[C] ACTIVATE - {0}", aCodeSegment);
                    }
                }
            }
            //
            return(ret);
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TimeDimension1Column"/> class.
        /// </summary>
        /// <param name="mapping">
        /// The time dimension mapping
        /// </param>
        /// <param name="expression">
        /// The TRANSCODING.EXPRESSION contents
        /// </param>
        /// <param name="databaseType">
        /// The dissemination database vendor from  DB_CONNECTION.DB_TYPE at Mapping Store database. It is used to determine the substring command to use
        /// </param>
        /// <exception cref="TranscodingException">
        /// Occurs when transcoding cannot performed due to incorrect mapping store data
        /// </exception>
        public TimeDimension1Column(MappingEntity mapping, TimeExpressionEntity expression, string databaseType)
            : base(mapping, expression, databaseType)
        {
            this._periodLocalCode = new CodeCollection();
            string yearPeriodColumn = GetColumnName(mapping, expression.YearColumnSysId);
            string yearOnlyStart    = this.CreateSubStringClause(yearPeriodColumn, expression.YearStart + 1, expression.YearLength, ">=");
            string yearOnlyEnd      = this.CreateSubStringClause(yearPeriodColumn, expression.YearStart + 1, expression.YearLength, "<=");

            string whereFormat = this.CreateSubStringClause(yearPeriodColumn, expression.PeriodStart + 1, expression.PeriodLength, "=");

            string yearOnlyWhereFormat = this.CreateSubStringClause(yearPeriodColumn, expression.YearStart + 1, expression.YearLength, "=");

            this._whereBuilder  = new TimeTranscodingWhereBuilder(this.Periodicity, this.Expression, whereFormat, yearOnlyEnd, yearOnlyStart, yearOnlyWhereFormat);
            this._fieldOrdinals = new TimeTranscodingFieldOrdinal(mapping, this.Expression);
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TimeDimension1Column"/> class. 
        /// </summary>
        /// <param name="mapping">
        /// The time dimension mapping
        /// </param>
        /// <param name="expression">
        /// The TRANSCODING.EXPRESSION contents
        /// </param>
        /// <param name="databaseType">
        /// The dissemination database vendor from  DB_CONNECTION.DB_TYPE at Mapping Store database. It is used to determine the substring command to use
        /// </param>
        /// <exception cref="TranscodingException">
        /// Occurs when transcoding cannot performed due to incorrect mapping store data
        /// </exception>
        public TimeDimension1Column(MappingEntity mapping, TimeExpressionEntity expression, string databaseType)
            : base(mapping, expression, databaseType)
        {
            this._periodLocalCode = new CodeCollection();
            string yearPeriodColumn = GetColumnName(mapping, expression.YearColumnSysId);
            string yearOnlyStart = this.CreateSubStringClause(yearPeriodColumn, expression.YearStart + 1, expression.YearLength, ">=");
            string yearOnlyEnd = this.CreateSubStringClause(yearPeriodColumn, expression.YearStart + 1, expression.YearLength, "<=");

            string whereFormat = this.CreateSubStringClause(yearPeriodColumn, expression.PeriodStart + 1, expression.PeriodLength, "=");

            string yearOnlyWhereFormat = this.CreateSubStringClause(yearPeriodColumn, expression.YearStart + 1, expression.YearLength, "=");

            this._whereBuilder = new TimeTranscodingWhereBuilder(this.Periodicity, this.Expression, whereFormat, yearOnlyEnd, yearOnlyStart, yearOnlyWhereFormat);
            this._fieldOrdinals = new TimeTranscodingFieldOrdinal(mapping, this.Expression);
        }
Пример #11
0
 public CodeSourceAndCollection this[CodeSegDefinition aCodeSeg]
 {
     get
     {
         CodeSourceAndCollection ret = null;
         //
         foreach (CodeSource source in this)
         {
             CodeCollection col = source[aCodeSeg];
             if (col != null)
             {
                 ret = new CodeSourceAndCollection(source, col);
                 break;
             }
         }
         //
         return(ret);
     }
 }
Пример #12
0
        /// <summary>
        /// Maps the column of the mapping to the components of this <see cref="ComponentMappingNto1"/> object and transcodes it.
        /// </summary>
        /// <param name="reader">
        /// The DataReader for retrieving the values of the column.
        /// </param>
        /// <returns>
        /// The value of the component or null if no transcoding rule for the column values is found
        /// </returns>
        public string MapComponent(IDataReader reader)
        {
            string ret = null;

            this.BuildOrdinals(reader);
            ColumnOrdinal column      = this.ColumnOrdinals[0];
            var           resultCodes = new CodeCollection {
                DataReaderHelper.GetString(reader, column.Value)
            };

            CodeCollection transcodedCodes = this.Mapping.Transcoding.TranscodingRules.GetDsdCodes(resultCodes);

            if (transcodedCodes != null && this._componentIndex < transcodedCodes.Count)
            {
                ret = transcodedCodes[this._componentIndex];
            }

            return(ret);
        }
Пример #13
0
        /// <summary>
        /// Maps the column of the mapping to the component of this ComponentMapping1to1T object
        /// and transcodes it.
        /// </summary>
        /// <param name="reader">
        /// The DataReader for retrieving the values of the column.
        /// </param>
        /// <returns>
        /// The value of the component or null if no transcoding rule for the column values is found
        /// </returns>
        public string MapComponent(IDataReader reader)
        {
            var resultCodes = new CodeCollection();

            this.BuildOrdinals(reader);
            var    column      = this.ColumnOrdinals[0];
            string columnValue = DataReaderHelper.GetString(reader, column.Value);

            resultCodes.Add(columnValue);
            Collection <string> transcodedCodes = this.Mapping.Transcoding.TranscodingRules.GetDsdCodes(resultCodes);
            string ret = null;

            if (transcodedCodes != null && transcodedCodes.Count > 0)
            {
                ret = transcodedCodes[0];
            }

            return(ret);
        }
Пример #14
0
        /// <summary>
        /// Transcodes the time period returned by the local database to SDMX Time period
        /// </summary>
        /// <param name="reader">
        /// The data reader reading the Dissemination database
        /// </param>
        /// <returns>
        /// The transcoded time period, as in SDMX Time period type
        /// </returns>
        public string MapComponent(IDataReader reader)
        {
            this._fieldOrdinals.BuildOrdinal(reader);
            string year = DataReaderHelper.GetString(reader, this._fieldOrdinals.YearOrdinal);

            if (this.Expression.YearLength > 0)
            {
                year = year.Substring(this.Expression.YearStart, this.Expression.YearLength);
            }

            string period = DataReaderHelper.GetString(reader, this._fieldOrdinals.PeriodOrdinal);

            if (this.Expression.PeriodLength > 0)
            {
                int rowPeriodLen = this.Expression.PeriodLength;
                if (this.Expression.PeriodLength + this.Expression.PeriodStart > period.Length)
                {
                    rowPeriodLen = period.Length - this.Expression.PeriodStart;
                }

                period = period.Substring(this.Expression.PeriodStart, rowPeriodLen);
            }

            this._periodLocalCode.Clear();
            this._periodLocalCode.Add(period);
            CodeCollection periodDsdCode = this.Expression.TranscodingRules.GetDsdCodes(this._periodLocalCode);

            if (periodDsdCode == null)
            {
                return(null); // MAT-495

                // periodDsdCode = periodLocalCode;
            }

            string ret = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", year, periodDsdCode[0]);

            // ret = _timePeriodTranscoding[String.Format(CultureInfo.InvariantCulture,"{0}-{1}", year, period)];
            return(ret);
        }
Пример #15
0
        protected override void OnReadComplete()
        {
            try
            {
                base.OnReadComplete();
            }
            finally
            {
                System.Diagnostics.Debug.Assert(base.Count == 1);
                CodeCollection col           = this[0];
                bool           codeAvailable = col.IsCodeAvailable;
                //
                if (iImageContent != null && codeAvailable == false)
                {
                    // Update the underlying collection with it.
                    col.Code = iImageContent.GetAllData();

                    // Don't need this anymore
                    iImageContent.Dispose();
                    iImageContent = null;
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TimeDimension2Column"/> class.
        /// </summary>
        /// <param name="mapping">
        /// The time dimension mapping
        /// </param>
        /// <param name="expression">
        /// The TRANSCODING.EXPRESSION contents
        /// </param>
        /// <param name="databaseType">
        /// The dissemination database vendor from  DB_CONNECTION.DB_TYPE at Mapping Store database. It is used to determine the substring command to use
        /// </param>
        /// <exception cref="TranscodingException">
        /// Occurs when transcoding cannot performed due to incorrect mapping store data
        /// </exception>
        public TimeDimension2Column(MappingEntity mapping, TimeExpressionEntity expression, string databaseType)
            : base(mapping, expression, databaseType)
        {
            string yearOnlyWhereFormat;
            string yearOnlyStart;
            string yearOnlyEnd;
            string whereFormat;

            this._periodLocalCode = new CodeCollection();
            string yearColumn   = GetColumnName(mapping, expression.YearColumnSysId);
            string periodColumn = GetColumnName(mapping, expression.PeriodColumnSysId);

            string periodClause = expression.PeriodLength == 0
                                      ? string.Format(FormatProvider, "( {0} = '{1}' )", periodColumn, "{0}")
                                      : this.CreateSubStringClause(periodColumn, expression.PeriodStart + 1, expression.PeriodLength, "=");

            if (expression.YearLength == 0)
            {
                yearOnlyStart       = string.Format(FormatProvider, " ( {0} >= '{1}' )", yearColumn, "{0}");
                yearOnlyEnd         = string.Format(FormatProvider, " ( {0} <= '{1}' )", yearColumn, "{0}");
                yearOnlyWhereFormat = string.Format(FormatProvider, "( {0} = '{1}' )", yearColumn, "{0}");

                // whereFormat = String.Format(FormatProvider,"({0} = '{1}' and {2} )",yearColumn, "{0}",periodClause);
                whereFormat = periodClause;
            }
            else
            {
                yearOnlyStart = this.CreateSubStringClause(yearColumn, expression.YearStart + 1, expression.YearLength, ">=");
                yearOnlyEnd   = this.CreateSubStringClause(yearColumn, expression.YearStart + 1, expression.YearLength, "<=");

                whereFormat         = periodClause;
                yearOnlyWhereFormat = this.CreateSubStringClause(yearColumn, expression.YearStart + 1, expression.YearLength, "=");
            }

            this._whereBuilder  = new TimeTranscodingWhereBuilder(this.Periodicity, this.Expression, whereFormat, yearOnlyEnd, yearOnlyStart, yearOnlyWhereFormat);
            this._fieldOrdinals = new TimeTranscodingFieldOrdinal(mapping, this.Expression);
        }
Пример #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TimeDimension2Column"/> class. 
        /// </summary>
        /// <param name="mapping">
        /// The time dimension mapping
        /// </param>
        /// <param name="expression">
        /// The TRANSCODING.EXPRESSION contents
        /// </param>
        /// <param name="databaseType">
        /// The dissemination database vendor from  DB_CONNECTION.DB_TYPE at Mapping Store database. It is used to determine the substring command to use
        /// </param>
        /// <exception cref="TranscodingException">
        /// Occurs when transcoding cannot performed due to incorrect mapping store data
        /// </exception>
        public TimeDimension2Column(MappingEntity mapping, TimeExpressionEntity expression, string databaseType)
            : base(mapping, expression, databaseType)
        {
            string yearOnlyWhereFormat;
            string yearOnlyStart;
            string yearOnlyEnd;
            string whereFormat;
            this._periodLocalCode = new CodeCollection();
            string yearColumn = GetColumnName(mapping, expression.YearColumnSysId);
            string periodColumn = GetColumnName(mapping, expression.PeriodColumnSysId);

            string periodClause = expression.PeriodLength == 0
                                      ? string.Format(FormatProvider, "( {0} = '{1}' )", periodColumn, "{0}")
                                      : this.CreateSubStringClause(periodColumn, expression.PeriodStart + 1, expression.PeriodLength, "=");

            if (expression.YearLength == 0)
            {
                yearOnlyStart = string.Format(FormatProvider, " ( {0} >= '{1}' )", yearColumn, "{0}");
                yearOnlyEnd = string.Format(FormatProvider, " ( {0} <= '{1}' )", yearColumn, "{0}");
                yearOnlyWhereFormat = string.Format(FormatProvider, "( {0} = '{1}' )", yearColumn, "{0}");

                // whereFormat = String.Format(FormatProvider,"({0} = '{1}' and {2} )",yearColumn, "{0}",periodClause);
                whereFormat = periodClause;
            }
            else
            {
                yearOnlyStart = this.CreateSubStringClause(yearColumn, expression.YearStart + 1, expression.YearLength, ">=");
                yearOnlyEnd = this.CreateSubStringClause(yearColumn, expression.YearStart + 1, expression.YearLength, "<=");

                whereFormat = periodClause;
                yearOnlyWhereFormat = this.CreateSubStringClause(yearColumn, expression.YearStart + 1, expression.YearLength, "=");
            }

            this._whereBuilder = new TimeTranscodingWhereBuilder(this.Periodicity, this.Expression, whereFormat, yearOnlyEnd, yearOnlyStart, yearOnlyWhereFormat);
            this._fieldOrdinals = new TimeTranscodingFieldOrdinal(mapping, this.Expression);
        }
Пример #18
0
        /// <summary>
        /// Maps the column of the mapping to the components of this <see cref="ComponentMappingNto1"/> object and transcodes it.
        /// </summary>
        /// <param name="reader">
        /// The DataReader for retrieving the values of the column. 
        /// </param>
        /// <returns>
        /// The value of the component or null if no transcoding rule for the column values is found 
        /// </returns>
        public string MapComponent(IDataReader reader)
        {
            string ret = null;
            this.BuildOrdinals(reader);
            ColumnOrdinal column = this.ColumnOrdinals[0];
            var resultCodes = new CodeCollection { DataReaderHelper.GetString(reader, column.Value) };

            CodeCollection transcodedCodes = this.Mapping.Transcoding.TranscodingRules.GetDsdCodes(resultCodes);

            if (transcodedCodes != null && this._componentIndex < transcodedCodes.Count)
            {
                ret = transcodedCodes[this._componentIndex];
            }

            return ret;
        }
        /// <summary>
        /// Retrieve TimeDimension transcoding, if <paramref name="timeDimensionMapping"/> is null
        /// </summary>
        /// <param name="mappingStoreDb">
        /// The mapping store DB.
        /// </param>
        /// <param name="timeDimensionMapping">
        /// The time dimension mapping.
        /// </param>
        private static void RetrieveTimeDimensionTranscoding(
            Database mappingStoreDb, MappingEntity timeDimensionMapping)
        {
            if (timeDimensionMapping == null)
            {
                return;
            }

            RetrieveTimeTranscoding(mappingStoreDb, timeDimensionMapping);
            TimeTranscodingCollection timeTranscodingCollection = timeDimensionMapping.Transcoding.TimeTranscodingCollection;
            if (timeTranscodingCollection.Count == 1
                && TimeFormat.GetTimeFormatFromCodeId(timeTranscodingCollection[0].FrequencyValue).EnumType == TimeFormatEnumType.Year)
            {
                return;
            }

            var codelists = PeriodCodelist.PeriodCodelistIdMap;
            IDictionary<string, TimeTranscodingEntity> transcodingMap = new Dictionary<string, TimeTranscodingEntity>(StringComparer.Ordinal);
            foreach (var periodObject in codelists)
            {
                if (timeTranscodingCollection.Contains(periodObject.Key))
                {
                    var timeTranscodingEntity = timeTranscodingCollection[periodObject.Key];
                    if (timeTranscodingEntity.PeriodColumnId > 0)
                    {
                        var timeDimensionRules = new TranscodingRulesEntity();
                        timeDimensionRules.AddColumn(timeTranscodingEntity.PeriodColumnId, 0);
                        timeDimensionRules.AddComponent(timeDimensionMapping.Components[0].SysId, 0);
                        timeTranscodingEntity.TranscodingRules = timeDimensionRules;
                        transcodingMap.Add(periodObject.Value.Id, timeTranscodingEntity);
                    }

                }
            }

            DbParameter parameter = mappingStoreDb.CreateInParameter(ParameterNameConstants.TranscodingId, DbType.Int64, timeDimensionMapping.Transcoding.SysId);

            using (DbCommand command = mappingStoreDb.GetSqlStringCommandFormat(MappingStoreSqlStatements.TranscodingRulesTimeDimension, parameter))
            using (IDataReader dataReader = mappingStoreDb.ExecuteReader(command))
            {
                int dsdcodeIdx = dataReader.GetOrdinal("DSDCODE");
                int localcodeIdx = dataReader.GetOrdinal("LOCALCODE");
                int codelistId = dataReader.GetOrdinal("CODELIST_ID");

                while (dataReader.Read())
                {
                    var periodCodelist = DataReaderHelper.GetString(dataReader, codelistId);
                    TimeTranscodingEntity timeTranscodingEntity;
                    if (transcodingMap.TryGetValue(periodCodelist, out timeTranscodingEntity))
                    {
                        var timeDimensionRules = timeTranscodingEntity.TranscodingRules;
                        var dsdperiod = new CodeCollection();
                        var localperiod = new CodeCollection();
                        dsdperiod.Add(DataReaderHelper.GetString(dataReader, dsdcodeIdx));
                        localperiod.Add(DataReaderHelper.GetString(dataReader, localcodeIdx));
                        timeDimensionRules.Add(localperiod, dsdperiod);
                    }
                }
            }
        }
        /// <summary>
        /// The method retrieves the <see cref="TranscodingRulesEntity"/> object
        /// by the transcoding system identifier
        /// </summary>
        /// <param name="mappingStoreDb">
        /// The <see cref="Database"/> instance for Mapping Store database
        /// </param>
        /// <param name="sysId">
        /// The mapping set with the specified system identifier
        /// </param>
        /// <param name="timeDimensionMapping">
        /// The TRANSCODING.TR_ID value of the TimeDimension, if there is TimeDimension and is transcoded; otherwise set to null 
        /// </param>
        /// <param name="mappingsMap">
        /// The map between COMPONENT_MAPPING.MAP_ID value and MappingEntity 
        /// </param>
        private static void GetTranscodingRulesByMapSetId(Database mappingStoreDb, long sysId, MappingEntity timeDimensionMapping, IDictionary<long, MappingEntity> mappingsMap)
        {
            string paramId = mappingStoreDb.BuildParameterName(ParameterNameConstants.IdParameter);
            string timeDimensionTranscodingIdParam = mappingStoreDb.BuildParameterName(ParameterNameConstants.TranscodingId);

            object timedimensionID = timeDimensionMapping == null ? (object)null : timeDimensionMapping.Transcoding.SysId;

            // holds the dsd codes by rule
            var componentsByRule = new Dictionary<long, CodeCollection>();

            string sql = string.Format(
               CultureInfo.InvariantCulture,
               MappingStoreSqlStatements.TranscodingRulesDsdCodes,
               paramId,
               timeDimensionTranscodingIdParam);

            using (DbCommand command = mappingStoreDb.GetSqlStringCommand(sql))
            {
                mappingStoreDb.AddInParameter(command, ParameterNameConstants.IdParameter, DbType.Int64, sysId);
                mappingStoreDb.AddInParameter(command, ParameterNameConstants.TranscodingId, DbType.Int64, timedimensionID);

                using (IDataReader dataReader = mappingStoreDb.ExecuteReader(command))
                {
                    int pos = 0;

                    long prevMapId = -1;

                    TranscodingRulesEntity currentRules = null;
                    long firstTrRuleID = -1;
                    long curTrRuleID = -1;
                    long prevTrRuleID = -1;
                    
                    var componentList = new CodeCollection();

                    int ruleIDIdx = dataReader.GetOrdinal("TR_RULE_ID");
                    int componentIdx = dataReader.GetOrdinal("COMPONENT");
                    int codeIdx = dataReader.GetOrdinal("CODE");
                    int mapIdIdx = dataReader.GetOrdinal("MAP_ID");
                    while (dataReader.Read())
                    {
                        long curMapId = DataReaderHelper.GetInt64(dataReader, mapIdIdx);
                        if (prevMapId != curMapId || currentRules == null)
                        {
                            prevMapId = curMapId;
                            if (curTrRuleID > -1)
                            {
                                componentsByRule.Add(curTrRuleID, componentList);
                            }

                            componentList = new CodeCollection();
                            firstTrRuleID = -1;
                            prevTrRuleID = -1;
                            pos = 0;
                            MappingEntity curretMapping = mappingsMap[curMapId];
                            currentRules = new TranscodingRulesEntity();
                            curretMapping.Transcoding.TranscodingRules = currentRules;
                        }

                        curTrRuleID = DataReaderHelper.GetInt64(dataReader, ruleIDIdx);
                        if (firstTrRuleID == -1 || firstTrRuleID == curTrRuleID)
                        {
                            firstTrRuleID = curTrRuleID;
                            prevTrRuleID = curTrRuleID;
                            currentRules.AddComponent(DataReaderHelper.GetInt64(dataReader, componentIdx), pos);

                            pos++;
                        }
                        else if (prevTrRuleID != curTrRuleID)
                        {
                            componentsByRule.Add(prevTrRuleID, componentList);
                            componentList = new CodeCollection();
                            prevTrRuleID = curTrRuleID;
                        }

                        componentList.Add(DataReaderHelper.GetString(dataReader, codeIdx));
                    }

                    if (curTrRuleID > -1)
                    {
                        componentsByRule.Add(curTrRuleID, componentList);
                    }
                }
            }

            if (componentsByRule.Count > 0)
            {
                sql = string.Format(
              CultureInfo.InvariantCulture,
              MappingStoreSqlStatements.TranscodingRulesLocalCodes,
              paramId,
              timeDimensionTranscodingIdParam);
                using (DbCommand command = mappingStoreDb.GetSqlStringCommand(sql))
                {
                    mappingStoreDb.AddInParameter(command, ParameterNameConstants.IdParameter, DbType.Int64, sysId);
                    mappingStoreDb.AddInParameter(command, ParameterNameConstants.TranscodingId, DbType.Int64, timedimensionID);

                    using (IDataReader dataReader = mappingStoreDb.ExecuteReader(command))
                    {
                        long prevMapId = -1;

                        int pos = 0;
                        TranscodingRulesEntity currentRules = null;
                        long firstTrRuleID = -1;
                        long curTrRuleID = -1;
                        long prevTrRuleID = -1;
                        var columnList = new CodeCollection();

                        int ruleIDIdx = dataReader.GetOrdinal("TR_RULE_ID");
                        int columnIdx = dataReader.GetOrdinal("LOCAL_COLUMN");
                        int codeIdx = dataReader.GetOrdinal("CODE");
                        int mapIdIdx = dataReader.GetOrdinal("MAP_ID");
                        while (dataReader.Read())
                        {
                            long curMapId = DataReaderHelper.GetInt64(dataReader, mapIdIdx);
                            if (prevMapId != curMapId || currentRules == null)
                            {
                                prevMapId = curMapId;
                                if (curTrRuleID > -1 && currentRules != null)
                                {
                                    currentRules.Add(columnList, componentsByRule[curTrRuleID]);
                                }

                                firstTrRuleID = -1;
                                prevTrRuleID = -1;
                                pos = 0;
                                columnList = new CodeCollection();
                                MappingEntity curretMapping = mappingsMap[curMapId];
                                currentRules = curretMapping.Transcoding.TranscodingRules;
                            }

                            curTrRuleID = DataReaderHelper.GetInt64(dataReader, ruleIDIdx);
                            if (firstTrRuleID == -1 || firstTrRuleID == curTrRuleID)
                            {
                                firstTrRuleID = curTrRuleID;
                                prevTrRuleID = curTrRuleID;
                                currentRules.AddColumn(DataReaderHelper.GetInt64(dataReader, columnIdx), pos);
                                pos++;
                            }
                            else if (prevTrRuleID != curTrRuleID)
                            {
                                currentRules.Add(columnList, componentsByRule[prevTrRuleID]);
                                columnList = new CodeCollection();
                                prevTrRuleID = curTrRuleID;
                            }

                            columnList.Add(DataReaderHelper.GetString(dataReader, codeIdx));
                        }

                        if (curTrRuleID > -1 && currentRules != null)
                        {
                            currentRules.Add(columnList, componentsByRule[curTrRuleID]);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Maps the column of the mapping to the component of this ComponentMapping1to1T object
        /// and transcodes it. 
        /// </summary>
        /// <param name="reader">
        /// The DataReader for retrieving the values of the column.
        /// </param>
        /// <returns>
        /// The value of the component or null if no transcoding rule for the column values is found
        /// </returns>
        public string MapComponent(IDataReader reader)
        {
            var resultCodes = new CodeCollection();
            this.BuildOrdinals(reader);
            var column = this.ColumnOrdinals[0];
            string columnValue = DataReaderHelper.GetString(reader, column.Value);
            resultCodes.Add(columnValue);
            Collection<string> transcodedCodes = this.Mapping.Transcoding.TranscodingRules.GetDsdCodes(resultCodes);
            string ret = null;
            if (transcodedCodes != null && transcodedCodes.Count > 0)
            {
                ret = transcodedCodes[0];
            }

            return ret;
        }
Пример #22
0
        public override CodeCollection ActivateAndGetCollection(CodeSegDefinition aCodeSegment)
        {
            CodeCollection ret = iRelocator.Activate(aCodeSegment);

            return(ret);
        }
 internal CodeSourceAndCollection(CodeSourceAndCollection aCopy, CodeCollection aCollection)
 {
     iSource     = aCopy.Source;
     iCollection = aCollection;
 }
        /// <summary>
        /// Build where clauses in the form of : (year and (periodA or periodB or ... ) and write them
        /// to a specified StringBuilder
        /// </summary>
        /// <param name="ret">The StringBuilder to write the output</param>
        /// <param name="yearStr">The year string</param>
        /// <param name="firstPeriod">The first period</param>
        /// <param name="lastPeriod">The last period</param>
        /// <param name="periodicity">The periodicity.</param>
        /// <param name="timeExpressionEntity">The time expression entity.</param>
        /// <returns>
        /// The position of the last clause inside the StringBuilder
        /// </returns>
        private int BuildPeriodWhere(StringBuilder ret, string yearStr, int firstPeriod, int lastPeriod, IPeriodicity periodicity, TimeExpressionEntity timeExpressionEntity)
        {
            var queryCode = new CodeCollection();

            ret.Append("( ");
            ret.AppendFormat(this._yearOnlyWhereFormat, yearStr);
            int lastClause = ret.Length;
            ret.Append(" and ");
            ret.Append("( ");
            for (int x = firstPeriod; x <= lastPeriod; x++)
            {
                string periodStr = x.ToString(periodicity.Format, _formatProvider);
                queryCode.Clear();
                queryCode.Add(periodStr);
                string periodCode = timeExpressionEntity.TranscodingRules.GetLocalCodes(queryCode)[0][0];
                ret.AppendFormat(CultureInfo.InvariantCulture, this._whereFormat, periodCode);
                lastClause = ret.Length;
                ret.Append(" or ");
            }

            ret.Length = lastClause;
            ret.Append(") ");
            ret.Append(") ");
            lastClause = ret.Length;
            ret.Append(" or ");
            return lastClause;
        }