Beispiel #1
0
        protected override void DoRun(IJobRunEnv env)
        {
            m_source.Mode        = TabularDataStoreMode.Read;
            m_target.Mode        = TabularDataStoreMode.Write;
            m_target.CopyOptions = m_copyOptions;

            Async.SafeOpen(m_source.Connection);
            Async.SafeOpen(m_target.Connection);

            IAsyncResult asyncs = m_source.BeginGetRowFormat(null);

            m_sourceStruct = m_source.EndGetRowFormat(asyncs);

            IAsyncResult asynct = m_target.BeginGetRowFormat(null);

            m_targetStruct = m_target.EndGetRowFormat(asynct);
            var targetFull = m_targetStruct;

            if (m_transform == null)
            {
                m_transform = RowTransformAddonType.Instance.LoadRowTransform(m_transformXml, m_sourceStruct, m_targetStruct);
                if (!m_target.AvailableRowFormat)
                {
                    m_target.SetRowFormat(m_transform.OutputFormat);
                    m_targetStruct = m_transform.OutputFormat;
                }
            }

            GenericDataQueue queue = new GenericDataQueue(m_sourceStruct, m_transform.OutputFormat, m_transform);

            if (m_target.Connection != null && m_target.Connection.SystemConnection != null)
            {
                var fi            = m_source as IDataFormatHolder;
                var fmt           = fi != null ? fi.FormatSettings : new DataFormatSettings();
                var outputAdapter = new RecordToDbAdapter(m_transform.OutputFormat, targetFull, m_target.Connection.Dialect, fmt);
                outputAdapter.ProgressInfo = ProgressInfo;
                queue.AddOutputAdapter(outputAdapter);
            }

            m_source.ProgressInfo = ProgressInfo;
            m_target.ProgressInfo = ProgressInfo;

            IAsyncResult async_src = m_source.BeginRead(null, queue);
            IAsyncResult async_dst = m_target.BeginWrite(null, queue);

            if (async_src is ICancelable)
            {
                m_cancelSrc = (ICancelable)async_src;
            }
            if (async_dst is ICancelable)
            {
                m_cancelDst = (ICancelable)async_dst;
            }
            try
            {
                m_source.EndRead(async_src);
            }
            finally
            {
                m_target.EndWrite(async_dst);
            }

            Async.SafeClose(m_source.Connection);
            Async.SafeClose(m_target.Connection);
        }
Beispiel #2
0
 public override bool AllowExpand()
 {
     Async.SafeOpen(m_conn.Connection);
     RealNode.RefreshChilds(false);
     return(true);
 }
Beispiel #3
0
 private void RestoreDbForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     Async.SafeClose(m_conn.Connection);
 }
Beispiel #4
0
 public override void OpenConnection()
 {
     Async.SafeOpen(m_db.Connection);
 }
Beispiel #5
0
 public IAsyncResult BeginWrite(AsyncCallback callback, IDataQueue queue)
 {
     return(Async.BeginCancelableInvoke((Action <IDataQueue>)DoWrite, callback, new object[] { queue }));
 }
Beispiel #6
0
 public override void CloseAllResources()
 {
     Async.SafeClose(m_conn);
 }
Beispiel #7
0
        public void SetBindings(ITabularDataStore source, ITabularDataStore target)
        {
            using (WaitContext wc = new WaitContext())
            {
                Async.SafeOpen(source.Connection);
                Async.SafeOpen(target.Connection);
                try
                {
                    IAsyncResult res1 = source.BeginGetRowFormat(null);
                    Async.WaitFor(res1);
                    m_source = source.EndGetRowFormat(res1);
                }
                catch (Exception err)
                {
                    throw new BulkCopyInputError("DAE-00181", err);
                }

                if (m_source.Columns.Count == 0)
                {
                    throw new ExpectedError("DAE-00182 " + Texts.Get("s_no_columns_detected_in_imported_source"));
                }

                IAsyncResult res2 = target.BeginGetRowFormat(null);
                Async.WaitFor(res2);
                m_target = target.EndGetRowFormat(res2);

                int acty     = labValue.Top + labValue.Height + 10;
                int colindex = 0;
                foreach (IColumnStructure col in m_target.Columns)
                {
                    Label lab = new Label();
                    Controls.Add(lab);
                    lab.Left = labTarget.Left;
                    lab.Top  = acty;
                    lab.Text = col.ColumnName + " :";

                    CheckBox skip = new CheckBox();
                    Controls.Add(skip);
                    skip.Top   = acty;
                    skip.Width = 30;
                    skip.Left  = labSkip.Left;
                    m_checks.Add(skip);
                    skip.Tag             = colindex;
                    skip.CheckedChanged += new EventHandler(skip_CheckedChanged);

                    ComboBox type = new ComboBox();
                    Controls.Add(type);
                    type.Left          = labType.Left;
                    type.Top           = acty;
                    type.DropDownStyle = ComboBoxStyle.DropDownList;
                    GenericTransform.GetColExprTypes(type.Items);
                    type.SelectedIndex = 0;
                    type.Tag           = colindex;
                    m_typeCombos.Add(type);

                    ComboBox sel = new ComboBox();
                    Controls.Add(sel);
                    sel.Left            = labValue.Left;
                    sel.Top             = acty;
                    sel.DropDownStyle   = ComboBoxStyle.DropDown;
                    sel.DropDownClosed += new EventHandler(sel_DropDownClosed);
                    sel.Tag             = colindex;
                    foreach (IColumnStructure srccol in m_source.Columns)
                    {
                        sel.Items.Add(srccol.ColumnName);
                    }
                    sel.SelectedIndex = sel.Items.IndexOf(col.ColumnName);
                    if (sel.SelectedIndex < 0)
                    {
                        if (col.ColumnOrder < sel.Items.Count)
                        {
                            sel.SelectedIndex = col.ColumnOrder;
                        }
                        else
                        {
                            sel.SelectedIndex = 0;
                        }
                    }
                    m_combos.Add(sel);

                    acty += Math.Max(sel.Height, lab.Height) * 5 / 4;
                    colindex++;
                }
            }
        }
Beispiel #8
0
        public static void CopyDatabase(IDatabaseSource src, IDatabaseWriter dst, IProgressInfo progress, DatabaseCopyOptions copyOpts)
        {
            IDatabaseWriter dst2 = null;

            for (; ;)
            {
                dst2 = dst.GetRedirectedWriter();
                if (dst2 == null)
                {
                    break;
                }
                dst = dst2;
            }
            dst.SetSourceInfo(new DatabaseWriterSourceInfo
            {
                Dialect = src.Dialect,
                //CopyMode = copyOpts.Mode,
                SchemaMode = copyOpts.SchemaMode,
            });
            try
            {
                dst.ProgressInfo = progress;

                Async.SafeOpen(src.Connection);
                dst.OpenConnection();

                if (dst.DirectCopy(src))
                {
                    dst.RunDirectCopy(src, copyOpts);
                }
                else
                {
                    copyOpts.CopyMembers.IgnoreSystemObjects = true;
                    IDatabaseStructure tmpDb    = src.InvokeLoadStructure(copyOpts.CopyMembers, progress);
                    DatabaseStructure  sourceDb = new DatabaseStructure(tmpDb);
                    //sourceDb.AutoFillRefs();
                    DatabaseStructure targetDb = sourceDb.GetMappedDatabase(copyOpts, dst.Dialect);
                    if (dst.Dialect != null)
                    {
                        dst.Dialect.MigrateDatabase(targetDb, copyOpts.MigrationProfile, progress);
                    }

                    if (copyOpts.CopyStructure)
                    {
                        dst.WriteStructureBeforeData(targetDb);
                    }

                    bool copydata = copyOpts.DataMode != DbCopyDataMode.None && src.TableCaps.DataStoreForReading && dst.WriterCaps.AcceptData;
                    if (copydata)
                    {
                        dst.BeforeFillData();

                        foreach (var tbl in sourceDb.Tables.SortedByKey <ITableStructure, int>(tbl => copyOpts.DataCopyTables.IndexOf(tbl.FullName)))
                        {
                            if (!copyOpts.CopyTableData(tbl.FullName))
                            {
                                continue;
                            }
                            Logging.Debug("Copying table {0}", tbl);
                            if (progress != null)
                            {
                                progress.SetCurWork(String.Format("{0} {1}", Texts.Get("s_copying_table"), tbl));
                            }
                            GenericDataQueue queue = new GenericDataQueue(tbl, tbl, new IdentityTransform(tbl));
                            queue.ProgressInfo = progress;
                            if (dst.WriterCaps.ExecuteSql)
                            {
                                var ada = new RecordToDbAdapter(tbl, tbl, dst.Dialect, new DataFormatSettings());
                                ada.ProgressInfo = progress;
                                queue.AddOutputAdapter(ada);
                            }
                            ITableSource      tsrc           = src.GetTable(tbl.FullName);
                            ITabularDataStore srcds          = tsrc.GetDataStoreAndReuse();
                            IAsyncResult      async_src      = srcds.BeginRead(null, queue);
                            ITableStructure   newTableStruct = (ITableStructure)targetDb.FindByGroupId(tbl.GroupId);
                            dst.FillTable(newTableStruct, queue, copyOpts.TableOptions);
                            srcds.EndRead(async_src);
                        }
                        dst.AfterFillData();
                    }
                    if (copyOpts.CopyStructure)
                    {
                        dst.WriteStructureAfterData(targetDb);
                    }
                }
            }
            catch (Exception)
            {
                dst.ProcessFailed();
                throw;
            }
            finally
            {
                Async.SafeClose(src.Connection);
                dst.CloseConnection();
            }
        }