Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves this process to a file
        /// </summary>
        /// <param name="file">The file to save this process to</param>
        /// <param name="name">The name of the process</param>
        public override void Save(string file, string name)
        {
            FdoBulkCopyTaskDefinition def = new FdoBulkCopyTaskDefinition();
            def.name = name;

            List<FdoConnectionEntryElement> connList = new List<FdoConnectionEntryElement>();
            List<FdoCopyTaskElement> copyTasks = new List<FdoCopyTaskElement>();

            foreach (string connName in _options.ConnectionNames)
            {
                FdoConnection conn = _options.GetConnection(connName);
                FdoConnectionEntryElement entry = new FdoConnectionEntryElement();
                entry.name = connName;
                entry.provider = conn.Provider;
                entry.ConnectionString = conn.ConnectionString;

                if (conn.HasConfiguration)
                {
                    string path = Path.GetDirectoryName(file);
                    path = Path.Combine(path, entry.name + "_configuration.xml");

                    conn.SaveConfiguration(path);
                    entry.configPath = path;
                }

                connList.Add(entry);
            }

            foreach (FdoClassCopyOptions copt in _options.ClassCopyOptions)
            {
                copyTasks.Add(copt.ToElement());
            }

            def.Connections = connList.ToArray();
            def.CopyTasks = copyTasks.ToArray();

            using (StreamWriter writer = new StreamWriter(file, false))
            {
                XmlSerializer ser = new XmlSerializer(typeof(FdoBulkCopyTaskDefinition));
                ser.Serialize(writer, def);
            }
        }