コード例 #1
0
        static void Main(string[] args)
        {
            RsyncSetting.SetConfigSettings();
            RsyncSetting.RuntimeSettings.ScheduleStartTime = RsyncDateTime.GetNow(RsyncDateTime.TimeFormatType.YearSMonthSDateTimeChange);
            Log.WriteLog("#######################################################################");
            Log.WriteLog("Rsync schedule start.");
            SyncResultRecords.Init();
            if (CheckScheduleReady("DownloadCenterRsync"))
            {
                try
                {
                    //1.取api list
                    var api    = new ApiService();
                    var result = api.GetFileList();
                    if (string.IsNullOrEmpty(result))
                    {
                        throw new Exception("Get file list api failed.");
                    }
                    var fileList     = JsonConvert.DeserializeObject <dynamic>(result);
                    var syncDataList = (IEnumerable <dynamic>)fileList.syncdata;
                    var delDataList  = (IEnumerable <dynamic>)fileList.deletedata;
                    Log.WriteLog("Will to deal records sync(" + syncDataList.Count() + ") + del(" + delDataList.Count() + ")");
                    if (syncDataList.Count() + delDataList.Count() > 0)
                    {
                        //2.確認工廠連線
                        if (RsyncSetting.Config.TargetServerTest ||
                            !CheckConnectionOK(RsyncSetting.Config.TargetServerIp))
                        {
                            Log.WriteLog("Reset factory vnet");
                            api.RestFactoryGatway();
                            if (!CheckConnectionOK(RsyncSetting.Config.TargetServerIp))
                            {
                                throw new Exception("Connect to factory (IP:" + RsyncSetting.Config.TargetServerIp + ") failed.");
                            }
                        }

                        //3.確認StoreSimple連線
                        var cmd = new NetCommand();
                        if (!cmd.ExeLoginCmd())
                        {
                            throw new Exception("Not login source server :" + RsyncSetting.Config.SourceServerIP);
                        }
                        if (!cmd.ExeLoginFactoryCmd())
                        {
                            throw new Exception("Not login target server :" + RsyncSetting.Config.TargetServerIp);
                        }

                        //4.rsync
                        SyncData(syncDataList);
                        DeleteData(delDataList);

                        if (SyncResultRecords.All().Count > 0)
                        {
                            RsyncSetting.RuntimeSettings.RsyncResultMessage = GenerateResultMessage(SyncResultRecords.All());
                        }
                    }
                    else
                    {
                        Log.WriteLog("No file need to be sync");
                        RsyncSetting.RuntimeSettings.RsyncResultMessage =
                            "<font color = \"#4A72A2\" size = \"2\" face = \"Verdana, sans-serif\">"
                            + "No file need to be sync </font>";
                    }
                }
                catch (Exception e)
                {
                    Log.WriteLog(e.Message, Log.Type.Exception);
                    RsyncSetting.RuntimeSettings.RsyncResultMessage =
                        "<font color = \"#c61919\" size = \"2\" face = \"Verdana, sans-serif\">" + e.Message + "</font>";
                }
            }
            else
            {
                Log.WriteLog("Wait for anoher schedule is finish", Log.Type.Failed);
                RsyncSetting.RuntimeSettings.RsyncResultMessage =
                    "<font color = \"#c61919\" size = \"2\" face = \"Verdana, sans-serif\">"
                    + "Waiting for anoher schedule is finish</font>";
            }

            Mail mail = new Mail();

            mail.Send();
            Log.WriteLog("Rsync schedule finish.");
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                Setting.SetConfigureSettings();
                Setting.SetScheduleStartTime();
                Setting.SetScheduleID(Time.GetNow(Time.TimeFormatType.YearMonthDayHourMinute));
                Log.WriteLog("#######################################################################");
                Log.WriteLog("Schedule Start.");
                SyncResultRecords.Init();

                var isScheduleReady = CheckScheduleReady("DownloadCenter");
                if (!isScheduleReady)
                {
                    Log.WriteLog("Waiting for anoher schedule is finish", Log.Type.Failed);
                    Setting.SetSyncResultMessage(
                        "<font color = \"#c61919\" size = \"2\" face = \"Verdana, sans-serif\">"
                        + "Waiting for anoher schedule is finish</font>");
                }
                else
                {
                    //1.取SourceSata資料
                    var    api        = new FileApi();
                    JArray syncDatas  = null;
                    JArray storages   = null;
                    var    sourceData = api.GetSyncData();
                    if (sourceData.Item1 != null)
                    {
                        syncDatas = (JArray)sourceData.Item1["syncdata"];
                        storages  = (JArray)sourceData.Item1["storages"];
                        Setting.SetAzureStorageRegion(storages);
                        //Setting.SetAzureStorageRegionCount(api.GetStorageRegionCount());
                    }

                    if (syncDatas == null || syncDatas.Count == 0)
                    {
                        Log.WriteLog("No file need to be sync");
                        Setting.SetSyncResultMessage(
                            "<font color = \"#4A72A2\" size = \"2\" face = \"Verdana, sans-serif\">"
                            + "No file need to be sync </font>");
                    }
                    else if (string.IsNullOrEmpty(Setting.RuntimeSettings.SyncAzureStorageRegion))
                    {
                        Log.WriteLog("Not get azure storage setting", Log.Type.Failed);
                        Setting.SetSyncResultMessage(
                            "<font color = \"#c61919\" size = \"2\" face = \"Verdana, sans-serif\">"
                            + "Not get azure storage setting</font>");
                    }
                    else
                    {
                        //2.登入StoreSimple
                        var cmd     = new NetCommand();
                        var isLogin = cmd.ExeLoginCmd();
                        if (!isLogin)
                        {
                            Log.WriteLog("Not login server " + Setting.Config.TargetServerIP, Log.Type.Failed);
                            Setting.SetSyncResultMessage(
                                "<font color = \"#c61919\" size = \"2\" face = \"Verdana, sans-serif\">"
                                + "Not login server " + Setting.Config.TargetServerIP + "</font>");
                        }
                        else
                        {
                            //3. Sync data
                            SyncData(syncDatas, storages);
                            if (SyncResultRecords.All().Count > 0)
                            {
                                Setting.SetSyncResultMessage(GenerateResultMessage());
                            }
                        }
                    }
                }

                Setting.SetScheduleFinishTime();
                var mail = new Mail();
                mail.sendMail();
                Log.WriteLog("Schedule Finish");
            }
            catch (Exception e)
            {
                Log.WriteLog(e.Message, Log.Type.Exception);
            }
        }