Exemple #1
0
 protected override void DoRun(IJobRunEnv env)
 {
     foreach (var cmd in m_commands)
     {
         cmd.Run(env);
     }
 }
Exemple #2
0
        protected override void DoRun(IJobRunEnv env)
        {
            m_job.m_process.Info("Executing SQL:" + ToString());

            Async.SafeOpen(Database.Connection);
            Database.Connection.Invoke(RunQueries);
            Async.SafeClose(Database.Connection);
        }
Exemple #3
0
 protected override void DoRun(IJobRunEnv env)
 {
     m_job.m_process.Info("Executing SQL:" + ToString());
     using (var conn = Connection.CreateSystemConnection())
     {
         conn.Open();
         conn.SafeChangeDatabase(Database);
         conn.ExecuteNonQueries(Sql, Connection.GetDialect(), null, 3600);
     }
 }
Exemple #4
0
 protected override void DoRun(IJobRunEnv env)
 {
     try
     {
         Async.SafeOpen(m_dst.Connection);
         m_loader.ProgressInfo = ProgressInfo;
         m_dst.Connection.Invoke1(m_loader.LoadDatabase, m_dst);
     }
     finally
     {
         Async.SafeClose(m_dst.Connection);
     }
 }
Exemple #5
0
        protected override void DoRun(IJobRunEnv env)
        {
            var dbconn = Args[0].FindDatabaseConnection(ConnPack);

            if (dbconn != null)
            {
                Async.SafeOpen(dbconn.Connection);
            }

            Place.ProgressInfo     = ProgressInfo;
            Generator.ProgressInfo = ProgressInfo;

            var holder = new ExtendedFileNameHolderInfo
            {
                DirectionIsSave   = true,
                FileExtension     = "sql",
                Filter            = "*.sql|{s_sql_script} (*.sql)",
                RelatedConnection = Args[0].GetConnection(),
                RelatedDatabase   = Args[0].FindDatabaseName()
            };

            Place.SetFileHolderInfo(holder);

            string fn = Place.GetWorkingFileName();

            using (var tw = new StreamWriter(fn))
            {
                var dmp = (Dialect ?? (dbconn != null ? dbconn.Dialect : null) ?? (Args[0].Dialect != null ? Args[0].Dialect : null) ?? GenericDialect.Instance).CreateDumper(tw, FormatProps);
                foreach (var obj in Args)
                {
                    if (dbconn != null)
                    {
                        Generator.GenerateSql(dbconn, obj.GetFullDatabaseRelatedName(), dmp, dmp.Dialect);
                    }
                    else
                    {
                        Generator.GenerateSql(obj, dmp, dmp.Dialect);
                    }
                }
            }
            Place.FinalizeFileName();
        }
Exemple #6
0
        protected override void DoRun(IJobRunEnv env)
        {
            IPhysicalConnection dbconn = null;

            if (m_dataFrame.TabularData.Connection != null)
            {
                ConnPack.GetConnection(m_dataFrame.TabularData.Connection.PhysicalFactory, false);
                Async.SafeOpen(dbconn);
            }

            Place.ProgressInfo     = ProgressInfo;
            Generator.ProgressInfo = ProgressInfo;

            var holder = new ExtendedFileNameHolderInfo
            {
                DirectionIsSave   = true,
                FileExtension     = "sql",
                Filter            = "*.sql|{s_sql_script} (*.sql)",
                RelatedConnection = m_dataFrame.TabularData.Connection != null ? m_dataFrame.TabularData.Connection.PhysicalFactory : null,
                RelatedDatabase   = m_dataFrame.TabularData.DatabaseSource != null ? m_dataFrame.TabularData.DatabaseSource.DatabaseName : null,
            };

            Place.SetFileHolderInfo(holder);

            string fn = Place.GetWorkingFileName();

            using (var tw = new StreamWriter(fn))
            {
                m_dmp = (Dialect ?? (dbconn != null ? dbconn.Dialect : null) ?? m_dataFrame.TabularData.Dialect ?? GenericDialect.Instance).CreateDumper(tw, FormatProps);
                if (Generator.IsRowEnumerator)
                {
                    m_rows.LoadAllRows(ForEachRow);
                }
                else
                {
                    Generator.GenerateSql(m_dmp);
                }
            }
            Place.FinalizeFileName();
        }
Exemple #7
0
        protected override void DoRun(IJobRunEnv env)
        {
            string dir = GetBackupDir();

            try { Directory.CreateDirectory(dir); }
            catch { }
            string          bckfile  = Path.Combine(dir, CreateFileName());
            IDatabaseWriter writer   = m_format.GetWriter(bckfile + m_format.Extension, m_src);
            var             copyOpts = new DatabaseCopyOptions
            {
                CopyMembers    = m_members,
                DataMode       = DbCopyDataMode.All,
                CopyStructure  = true,
                SchemaMode     = m_src.Dialect.DialectCaps.MultipleSchema ? DbCopySchemaMode.Original : DbCopySchemaMode.Explicit,
                ExplicitSchema = null
            };

            CopyDbJob.CopyDatabase(m_src, writer, ProgressInfo, copyOpts);
            SetCurWork(Texts.Get("s_finishing"));
            BackupContainer bc = new BackupContainer(bckfile, m_format);

            bc.Save();
        }
Exemple #8
0
 protected override void DoRun(IJobRunEnv env)
 {
     DataSynJob.Synchronize(m_src, m_dst, ProgressInfo, m_datasyn, env.GetReportEnv(GroupId) as DataSynReportEnv, m_outFile, m_guienv);
 }
        protected override void DoRun(IJobRunEnv env)
        {
            using (StreamWriter sw = new StreamWriter(File))
            {
                CSharpWriter csw = new CSharpWriter(sw);
                csw.WriteLine("// ***********************************************************************");
                csw.WriteLine("// This code was generated by DatAdmin DB MODEL Plugin, please do not edit");
                csw.WriteLine("// ***********************************************************************");
                csw.WriteLine("using System.Data.Common;");
                csw.Begin("namespace {0}", NamespaceName);
                csw.Begin("public static class {0}", ClassName);

                csw.WriteLine("public static string DBVERSION = {0};", CSharpWriter.StringLiteral(m_versionDb.Versions.Last().Name));

                csw.Begin("private static void ExecuteNonQuery(DbConnection conn, DbTransaction tran, string sql)");
                csw.Begin("using (DbCommand cmd = conn.CreateCommand())");
                csw.WriteLine("cmd.CommandText = sql;");
                csw.WriteLine("cmd.Transaction = tran;");
                csw.WriteLine("cmd.ExecuteNonQuery();");
                csw.End(); // using
                csw.End(); // function

                csw.Begin("public static string GetVersion(DbConnection conn, DbTransaction tran)");
                csw.Begin("try");
                csw.Begin("using (DbCommand cmd = conn.CreateCommand())");
                csw.WriteLine("cmd.Transaction = tran;");
                csw.WriteLine("cmd.CommandText = {0};", CSharpWriter.StringLiteral(m_versionDb.m_props.GetVersionSql));
                csw.WriteLine("return cmd.ExecuteScalar().ToString();");
                csw.End(); // using
                csw.End(); // try
                csw.Begin("catch");
                csw.WriteLine("return null;");
                csw.End(); // catch
                csw.End(); // function

                int vindex = 0;
                foreach (var vd in m_versionDb.Versions)
                {
                    csw.WriteLine("// update to version {0}", vd.Name);
                    csw.Begin("private static void UpdateToVersion_{0}(DbConnection conn, DbTransaction tran)", vindex);
                    foreach (string sql in vd.GetAlterSqls())
                    {
                        csw.WriteLine("ExecuteNonQuery(conn, tran, {0});", CSharpWriter.StringLiteral(sql));
                    }
                    csw.End();
                    vindex++;
                }

                csw.Begin("public static void UpdateDb(DbConnection conn)");
                if (UseTransaction)
                {
                    csw.Begin("using (DbTransaction tran = conn.BeginTransaction())");
                    csw.Begin("try");
                }
                else
                {
                    csw.WriteLine("DbTransaction tran = null;");
                }
                for (int i = 0; i < m_versionDb.Versions.Count; i++)
                {
                    if (i == 0)
                    {
                        csw.WriteLine("if (GetVersion(conn, tran) == null) UpdateToVersion_0(conn, tran);");
                    }
                    else
                    {
                        csw.WriteLine("if (GetVersion(conn, tran) == {0}) UpdateToVersion_{1}(conn, tran);", CSharpWriter.StringLiteral(m_versionDb.Versions[i - 1].Name), i);
                    }
                }
                if (UseTransaction)
                {
                    csw.End(); // try
                    csw.Begin("catch");
                    csw.WriteLine("tran.Rollback();");
                    csw.WriteLine("throw;");
                    csw.End(); // catch
                    csw.WriteLine("tran.Commit();");
                    csw.End(); // using
                }
                csw.End();     // function Run

                csw.Begin("public static void CheckVersion(DbConnection conn)");
                csw.WriteLine("string realversion = GetVersion(conn, null);");
                csw.Begin("if (realversion != DBVERSION)");
                csw.WriteLine("throw new Exception(String.Format(\"Bad version of database, code_version={0}, db_version={1}\", DBVERSION, realversion));");
                csw.End(); // if
                csw.End(); //  CheckVersion

                csw.End(); // class
                csw.End(); // namespace
            }
        }
Exemple #10
0
        protected override void DoRun(IJobRunEnv env)
        {
            IDatabaseLoader loader = m_backup.GetLoader(m_dst);

            loader.LoadDatabase(m_dst);
        }
Exemple #11
0
        public virtual void Run(IJobRunEnv env)
        {
            JobReportEnvBase repenv = null;

            if (m_job.Root != this)
            {
                repenv = CreateReportEnv();
            }
            if (repenv != null)
            {
                try
                {
                    env.SetReportEnv(GroupId, repenv);
                    repenv.OnStart();
                }
                catch (Exception err)
                {
                    ProgressInfo.Warning("Error initializing reports:" + err.Message);
                }
            }
            try
            {
                using (var ub = new UsageBuilder(UsageEventName))
                {
                    GetUsageParams(ub);

                    try
                    {
                        if (m_job.m_process != null)
                        {
                            JobCommand oldcmd = m_job.m_process.CurrentCommand;
                            try
                            {
                                m_job.m_process.CurrentCommand = this;
                                DoRun(env);
                            }
                            finally
                            {
                                m_job.m_process.CurrentCommand = oldcmd;
                                // close connections
                                ConnPack = null;
                            }
                        }
                        else
                        {
                            try
                            {
                                DoRun(env);
                            }
                            finally
                            {
                                // close connections
                                ConnPack = null;
                            }
                        }
                        ub["result"] = "ok";
                    }
                    catch (Exception err)
                    {
                        ub["result"] = "error";
                        ub["error"]  = err.Message;
                        throw;
                    }
                }
            }
            finally
            {
                if (repenv != null)
                {
                    try
                    {
                        repenv.OnFinish();
                    }
                    catch (Exception err)
                    {
                        ProgressInfo.Warning("Error finishing reports:" + err.Message);
                    }
                    try
                    {
                        repenv.Dispose();
                    }
                    catch (Exception err)
                    {
                        ProgressInfo.Warning("Error disposing reports:" + err.Message);
                    }
                }
            }
        }
Exemple #12
0
        protected override void DoRun(IJobRunEnv env)
        {
            var job = Job.LoadFromFile(Path.Combine(Core.JobsDirectory, JobFile));

            job.Run(new Dictionary <string, string>());
        }
Exemple #13
0
 protected override void DoRun(IJobRunEnv env)
 {
     ProgressInfo.Warning("Error when loading job command");
     ProgressInfo.Error(Message);
 }
Exemple #14
0
 protected abstract void DoRun(IJobRunEnv env);
Exemple #15
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);
        }
Exemple #16
0
 protected override void DoRun(IJobRunEnv env)
 {
     CopyDbJob.CopyDatabase(m_src, m_dst, ProgressInfo, m_copyOpts);
 }