예제 #1
0
        public static ModelTaskServiceSettings LoadSetting(string ServiceName, IConfiguration configuration)
        {
            ModelTaskServiceSettings settings = new ModelTaskServiceSettings();

            settings.IsActive           = Convert.ToBoolean(configuration.GetSection("Services").GetSection(ServiceName).GetSection("IsActive").Value);
            settings.Name               = configuration.GetSection("Services").GetSection(ServiceName).GetSection("Name").Value;
            settings.Url                = configuration.GetSection("Services").GetSection(ServiceName).GetSection("Url").Value;
            settings.UpdateInterval     = Convert.ToInt32(configuration.GetSection("Services").GetSection(ServiceName).GetSection("UpdateInterval").Value);
            settings.IsDebug            = Convert.ToBoolean(configuration.GetSection("Services").GetSection("IsDebug").Value);
            settings.UidTelegramToken   = configuration.GetSection("Services").GetSection("UidTelegramToken").Value;
            settings.UidTelegramDestino = configuration.GetSection("Services").GetSection("UidTelegramDestino").Value;

            return(settings);
        }
        private static async Task <string> ExecuteSqlDatabase(ModelTaskServiceSettings setting)
        {
            try
            {
                Adapters.AdapterSqlDatabase sqlDatabase = new Adapters.AdapterSqlDatabase(setting);
                var schedules = await sqlDatabase.GetDatabaseBackupSchedule(setting.Url, DateTime.Now.Hour, false);

                //foreach (var bkpSchedule in schedules)
                //{

                //}

                if (setting.IsDebug)
                {
                    foreach (var sch in schedules)
                    {
                        await WriteLog("Iniciando processo backup de: " + sch.Databases.DatabaseName + " " + sch.DateHourExecution.Hour);
                    }
                }

                for (int i = 0; i < schedules.Count;)
                {
                    int isExecute     = schedules[i].DateHourExecution.Minute.CompareTo(DateTime.Now.Minute);
                    int lastExecution = schedules[i].DateHourLastExecution.Date.CompareTo(DateTime.Now.Date);
                    if ((isExecute == 0 && lastExecution == -1) || (isExecute == -1 && lastExecution == -1) && !schedules[i].BackupStatus.Equals(Model.Enum.BackupStatus.Runing))
                    {
                        var isUpdated = await _helperSqlDatabase.UpdateStatusDateTimeBackup(schedules[i], Model.Enum.BackupStatus.Runing, setting);

                        var resp = _helperSqlDatabase.BackupRun(schedules[i], setting);
                        i++;
                    }
                }

                await Task.Delay((setting.UpdateInterval * 60) * 1000);

                return("OK");
            }
            catch (Exception err)
            {
                await WriteLog(err.Message);

                return("OK");
            }
        }
        private static async Task <string> ExecuteUploadGoogleDrive(ModelTaskServiceSettings setting)
        {
            try
            {
                Adapters.AdapterSqlDatabase sqlDatabase = new Adapters.AdapterSqlDatabase(setting);

                var schedules = await sqlDatabase.GetDatabaseBackupSchedule(setting.Url, DateTime.Now.Hour, true);

                for (int i = 0; i < schedules.Count; i++)
                {
                    var resp = _helperSqlDatabase.ExecuteUpload(schedules[i], setting);
                }
                await Task.Delay((setting.UpdateInterval * 60) * 1000);

                return("OK");
            }
            catch (Exception err)
            {
                await WriteLog(err.Message);

                return("OK");
            }
        }