APIからリフレッシュを実行するサンプルスクリプト[C#] [Syniti DR (DBMoto)]


SynitiではC#やVBの各APIを使用してレプリケーションを制御することが可能です。
開発環境の準備については以下をご参照ください。

API(C#, VB, C++)の開発環境構築手順

参考:外部からレプリケーションやグループを開始・停止するサンプルC#プログラム

本記事では、APIからリフレッシュ(全件転送)を実行するためのサンプルスクリプトを紹介しています。
これを使用することでバッチや外部のプログラムと連携してリフレッシュを実行することが可能です。

using System;
using HiTSoftware.DBMoto.Application;
using HiTSoftware.DBMoto.ObjectModel;

namespace APISamples
{
    class SampleRefresh
    {
        static void Main(string[] args)
        {
            DBMotoApplication dbmApp = null;
            IServer dbmServer = null;
            IMetadata currentMetadata = null;

            try
            {
                // 初期設定、サーバ接続
                dbmApp = DBMotoApplication.Instance;
                dbmServer = dbmApp.Servers["local"];
                dbmServer.Connect();

                // カレントメタデータのロード
                currentMetadata = dbmServer.Metadatas.DefaultMetadata;
                currentMetadata.Load(true);

                // レプリケーション名を指定
                IReplication repl = currentMetadata.Replications["レプリケーション名"];

                // レプリケーション無効化
                if (repl.ReplStatus != ReplStatus.Disabled)
                {
                    currentMetadata.Replications.Save(repl, false);
                    repl.AsynchDisable();

                    // 待機
                    System.Threading.Thread.Sleep(3000);
                }

                // リフレッシュ有効化
                currentMetadata.Replications.Save(repl, false);
                repl.AsynchSetInitialRefresh(true);

                // 待機
                System.Threading.Thread.Sleep(3000);

                // レプリケーション有効化
                currentMetadata.Replications.Save(repl, false);
                repl.AsynchEnable();

                // 待機
                System.Threading.Thread.Sleep(3000);

                currentMetadata.Replications.Save(repl, false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (currentMetadata != null)
                {
                    currentMetadata.Unload();
                }

                if (dbmServer != null)
                {
                    dbmServer.Disconnect();
                }

                if (dbmApp != null)
                {
                    dbmApp.Dispose();
                }
            }
        }
    }
}

関連したトピックス

コメントを残す

メールアドレスが公開されることはありません。

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください