コード例 #1
0
        /// <summary>
        /// Create the IComponentMapping object for a specific component in a mapping depending on the type of mapping e.g. 1
        ///     DSD component - N local columns e.t.c.
        /// </summary>
        /// <param name="component">
        /// The component entity
        /// </param>
        /// <param name="mapping">
        /// The mapping entity
        /// </param>
        /// <returns>
        /// An IComponentMapping object based on the mapping or null if the mapping is not supported
        /// </returns>
        /// <exception cref="TranscodingException">
        /// Invalid or unsupported mapping
        /// </exception>
        public static IComponentMapping CreateComponentMapping(ComponentEntity component, MappingEntity mapping)
        {
            IComponentMapping componentMapping;

            if (mapping.Components.Count == 1)
            {
                // one component
                switch (mapping.Columns.Count)
                {
                case 0:     // no columns => constant mapping
                    if (mapping.Constant != null)
                    {
                        componentMapping = new ComponentMapping1C();
                    }
                    else
                    {
                        throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNoMappingFormat1, mapping.Components[0]));
                    }

                    break;

                case 1:     // 1 to 1 mapping
                    if (mapping.Transcoding != null)
                    {
                        // with transcoding
                        if (mapping.Transcoding.TranscodingRules.ColumnAsKeyPosition.Count > 0 && mapping.Transcoding.TranscodingRules.ComponentAsKeyPosition.Count > 0)
                        {
                            componentMapping = new ComponentMapping1To1T();
                        }
                        else
                        {
                            // transcoding enabled but no transcoding rules
                            // TODO log a warning
                            componentMapping = new ComponentMapping1To1();     // disable transcoding
                        }
                    }
                    else
                    {
                        // without transcoding
                        componentMapping = new ComponentMapping1To1();
                    }

                    break;

                default:     // N columns where N > 1
                    if (mapping.Transcoding != null)
                    {
                        // transcoding is mandatory
                        if (mapping.Transcoding.TranscodingRules.ColumnAsKeyPosition.Count > 0 && mapping.Transcoding.TranscodingRules.ComponentAsKeyPosition.Count > 0)
                        {
                            // there are transcoding rules
                            componentMapping = new ComponentMapping1N();
                        }
                        else
                        {
                            throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNoTranscodingRulesFormat1, component.Id));
                        }
                    }
                    else
                    {
                        throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNoTranscodingFormat1, component.Id));
                    }

                    break;
                }
            }
            else if (mapping.Columns.Count == 1 && mapping.Components.Count > 1)
            {
                // N components to 1 column mapping
                if (mapping.Transcoding != null)
                {
                    // transcoding is mandatory
                    if (mapping.Transcoding.TranscodingRules.ColumnAsKeyPosition.Count > 0 && mapping.Transcoding.TranscodingRules.ComponentAsKeyPosition.Count > 0)
                    {
                        // there are transcoding rules
                        componentMapping = new ComponentMappingNto1(mapping.Transcoding.TranscodingRules.ComponentAsKeyPosition[component.SysId]);
                    }
                    else
                    {
                        throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNoTranscodingRulesFormat1, component.Id));
                    }
                }
                else
                {
                    throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNoTranscodingFormat1, component.Id));
                }
            }
            else
            {
                throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNNMapping, component.Id));
            }

            componentMapping.Mapping   = mapping;
            componentMapping.Component = component;
            return(componentMapping);
        }
コード例 #2
0
        /// <summary>
        /// Create the IComponentMapping object for a specific component in a mapping depending on the type of mapping e.g. 1
        ///     DSD component - N local columns e.t.c.
        /// </summary>
        /// <param name="component">
        /// The component entity
        /// </param>
        /// <param name="mapping">
        /// The mapping entity
        /// </param>
        /// <returns>
        /// An IComponentMapping object based on the mapping or null if the mapping is not supported
        /// </returns>
        /// <exception cref="TranscodingException">
        /// Invalid or unsupported mapping
        /// </exception>
        public static IComponentMapping CreateComponentMapping(ComponentEntity component, MappingEntity mapping)
        {
            IComponentMapping componentMapping;
            if (mapping.Components.Count == 1)
            {
                // one component
                switch (mapping.Columns.Count)
                {
                    case 0: // no columns => constant mapping
                        if (mapping.Constant != null)
                        {
                            componentMapping = new ComponentMapping1C();
                        }
                        else
                        {
                            throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNoMappingFormat1, mapping.Components[0]));
                        }

                        break;
                    case 1: // 1 to 1 mapping
                        if (mapping.Transcoding != null)
                        {
                            // with transcoding
                            if (mapping.Transcoding.TranscodingRules.ColumnAsKeyPosition.Count > 0 && mapping.Transcoding.TranscodingRules.ComponentAsKeyPosition.Count > 0)
                            {
                                componentMapping = new ComponentMapping1To1T();
                            }
                            else
                            {
                                // transcoding enabled but no transcoding rules
                                // TODO log a warning
                                componentMapping = new ComponentMapping1To1(); // disable transcoding
                            }
                        }
                        else
                        {
                            // without transcoding
                            componentMapping = new ComponentMapping1To1();
                        }

                        break;
                    default: // N columns where N > 1
                        if (mapping.Transcoding != null)
                        {
                            // transcoding is mandatory
                            if (mapping.Transcoding.TranscodingRules.ColumnAsKeyPosition.Count > 0 && mapping.Transcoding.TranscodingRules.ComponentAsKeyPosition.Count > 0)
                            {
                                // there are transcoding rules
                                componentMapping = new ComponentMapping1N();
                            }
                            else
                            {
                                throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNoTranscodingRulesFormat1, component.Id));
                            }
                        }
                        else
                        {
                            throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNoTranscodingFormat1, component.Id));
                        }

                        break;
                }
            }
            else if (mapping.Columns.Count == 1 && mapping.Components.Count > 1)
            {
                // N components to 1 column mapping 
                if (mapping.Transcoding != null)
                {
                    // transcoding is mandatory
                    if (mapping.Transcoding.TranscodingRules.ColumnAsKeyPosition.Count > 0 && mapping.Transcoding.TranscodingRules.ComponentAsKeyPosition.Count > 0)
                    {
                        // there are transcoding rules
                        componentMapping = new ComponentMappingNto1(mapping.Transcoding.TranscodingRules.ComponentAsKeyPosition[component.SysId]);
                    }
                    else
                    {
                        throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNoTranscodingRulesFormat1, component.Id));
                    }
                }
                else
                {
                    throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNoTranscodingFormat1, component.Id));
                }
            }
            else
            {
                throw new TranscodingException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.ComponentMappingNNMapping, component.Id));
            }

            componentMapping.Mapping = mapping;
            componentMapping.Component = component;
            return componentMapping;
        }