internal FdoCopyTaskElement ToElement()
        {
            FdoCopyTaskElement el = new FdoCopyTaskElement();
            el.name = this.Name;
            el.createIfNotExists = this.CreateIfNotExists;
            el.Options = new FdoCopyOptionsElement();
            el.Options.DeleteTarget = this.DeleteTarget;
            el.Options.Filter = this.SourceFilter;
            el.Options.FlattenGeometries = this.FlattenGeometries;
            el.Options.FlattenGeometriesSpecified = true;
            el.Options.ForceWKB = this.ForceWkb;
            el.Options.ForceWKBSpecified = true;

            if (this.BatchSize > 0)
                el.Options.BatchSize = this.BatchSize.ToString();

            el.Source = new FdoCopySourceElement();

            el.Source.connection = this.SourceConnectionName;
            el.Source.schema = this.SourceSchema;
            el.Source.@class = this.SourceClassName;

            el.Target = new FdoCopyTargetElement();

            el.Target.connection = this.TargetConnectionName;
            el.Target.schema = this.TargetSchema;
            el.Target.@class = this.TargetClassName;

            List<FdoPropertyMappingElement> propMappings = new List<FdoPropertyMappingElement>();
            List<FdoExpressionMappingElement> exprMappings = new List<FdoExpressionMappingElement>();

            List<string> check = new List<string>(this.CheckSourceProperties);
            Dictionary<string, FdoPropertyMappingElement> convRules = new Dictionary<string, FdoPropertyMappingElement>();
            foreach (FdoDataPropertyConversionRule rule in this.ConversionRules)
            {
                FdoPropertyMappingElement map = new FdoPropertyMappingElement();
                //map.sourceDataType = rule.SourceDataType.ToString();
                //map.targetDataType = rule.TargetDataType.ToString();
                map.nullOnFailedConversion = rule.NullOnFailure;
                map.truncate = rule.Truncate;
                map.source = rule.SourceProperty;
                map.target = rule.TargetProperty;
                if (check.Contains(map.source))
                    map.createIfNotExists = true;

                convRules.Add(map.source, map);
            }

            foreach (string prop in this.SourcePropertyNames)
            {
                if (convRules.ContainsKey(prop))
                {
                    propMappings.Add(convRules[prop]);
                }
                else
                {
                    FdoPropertyMappingElement map = new FdoPropertyMappingElement();
                    map.source = prop;
                    map.target = this.GetTargetProperty(prop);
                    if (check.Contains(map.source))
                        map.createIfNotExists = true;

                    propMappings.Add(map);
                }
            }

            foreach (string alias in this.SourceAliases)
            {
                FdoExpressionMappingElement map = new FdoExpressionMappingElement();
                map.alias = alias;
                map.Expression = this.GetExpression(alias);
                map.target = this.GetTargetPropertyForAlias(alias);
                if (check.Contains(map.alias))
                    map.createIfNotExists = true;

                exprMappings.Add(map);
            }

            el.PropertyMappings = propMappings.ToArray();
            el.ExpressionMappings = exprMappings.ToArray();

            return el;
        }
Пример #2
0
        private FdoBulkCopyTaskDefinition Save()
        {
            FdoBulkCopyTaskDefinition def = new FdoBulkCopyTaskDefinition();
            def.name = txtName.Text;
            List<FdoConnectionEntryElement> conns = new List<FdoConnectionEntryElement>();
            foreach (DataGridViewRow row in grdConnections.Rows)
            {
                FdoConnectionEntryElement entry = new FdoConnectionEntryElement();
                entry.name = row.Cells[0].Value.ToString();
                entry.provider = row.Cells[1].Value.ToString();
                entry.ConnectionString = row.Cells[3].Value.ToString();
                conns.Add(entry);
            }
            List<FdoCopyTaskElement> tasks = new List<FdoCopyTaskElement>();
            foreach (CopyTaskNodeDecorator dec in _tasks.Values)
            {
                FdoCopyTaskElement task = new FdoCopyTaskElement();
                task.name = dec.Name;
                task.createIfNotExists = dec.CreateIfNotExists;

                task.Source = new FdoCopySourceElement();
                task.Target = new FdoCopyTargetElement();
                task.Options = new FdoCopyOptionsElement();
                List<FdoPropertyMappingElement> pmaps = new List<FdoPropertyMappingElement>();
                List<FdoExpressionMappingElement> emaps = new List<FdoExpressionMappingElement>();

                //Source
                task.Source.@class = dec.SourceClassName;
                task.Source.connection = dec.SourceConnectionName;
                task.Source.schema = dec.SourceSchemaName;

                //Target
                task.Target.@class = dec.TargetClassName;
                task.Target.connection = dec.TargetConnectionName;
                task.Target.schema = dec.TargetSchemaName;

                //Options
                task.Options.BatchSize = dec.Options.BatchSize.ToString();
                task.Options.FlattenGeometries = dec.Options.Flatten;
                task.Options.FlattenGeometriesSpecified = true;
                task.Options.DeleteTarget = dec.Options.Delete;
                task.Options.Filter = dec.Options.SourceFilter;
                task.Options.ForceWKB = dec.Options.ForceWkb;
                task.Options.ForceWKBSpecified = true;

                //Property Mappings
                NameValueCollection mappings = dec.PropertyMappings.GetPropertyMappings();
                foreach (string srcProp in mappings.Keys)
                {
                    string dstProp = mappings[srcProp];
                    FdoPropertyMappingElement p = new FdoPropertyMappingElement();
                    p.source = srcProp;
                    p.target = dstProp;

                    PropertyConversionNodeDecorator conv = dec.PropertyMappings.GetConversionRule(p.source);
                    p.nullOnFailedConversion = conv.NullOnFailedConversion;
                    p.truncate = conv.Truncate;
                    p.createIfNotExists = conv.CreateIfNotExists;

                    pmaps.Add(p);
                }

                foreach (string alias in dec.ExpressionMappings.GetAliases())
                {
                    FdoExpressionMappingElement e = new FdoExpressionMappingElement();
                    e.alias = alias;
                    ExpressionMappingInfo exMap = dec.ExpressionMappings.GetMapping(alias);
                    e.Expression = exMap.Expression;
                    e.target = exMap.TargetProperty;

                    PropertyConversionNodeDecorator conv = dec.ExpressionMappings.GetConversionRule(e.alias);
                    e.nullOnFailedConversion = conv.NullOnFailedConversion;
                    e.truncate = conv.Truncate;
                    e.createIfNotExists = conv.CreateIfNotExists;

                    emaps.Add(e);
                }

                task.PropertyMappings = pmaps.ToArray();
                task.ExpressionMappings = emaps.ToArray();

                tasks.Add(task);
            }
            def.Connections = conns.ToArray();
            def.CopyTasks = tasks.ToArray();
            return def;
        }