Exemplo n.º 1
0
        public Schedule GetSchedule()
        {
            DemandPermissionsBackup();

            ScheduleResponse response;

            response = BackupService.GetSchedule(GetCurrentTenantId());
            if (response == null)
            {
                return(null);
            }

            var schedule = new Schedule
            {
                StorageType    = response.StorageType,
                StorageParams  = response.StorageParams.ToDictionary(r => r.Key, r => r.Value) ?? new Dictionary <string, string>(),
                CronParams     = new CronParams(response.Cron),
                BackupMail     = response.BackupMail.NullIfDefault(),
                BackupsStored  = response.NumberOfBackupsStored.NullIfDefault(),
                LastBackupTime = response.LastBackupTime
            };

            if ((BackupStorageType)response.StorageType == BackupStorageType.CustomCloud)
            {
                var amazonSettings = CoreConfiguration.GetSection <AmazonS3Settings>();

                var consumer = ConsumerFactory.GetByKey <DataStoreConsumer>("S3");
                if (!consumer.IsSet)
                {
                    consumer["acesskey"]        = amazonSettings.AccessKeyId;
                    consumer["secretaccesskey"] = amazonSettings.SecretAccessKey;

                    consumer["bucket"] = amazonSettings.Bucket;
                    consumer["region"] = amazonSettings.Region;
                }

                schedule.StorageType   = BackupStorageType.ThirdPartyConsumer;
                schedule.StorageParams = consumer.AdditionalKeys.ToDictionary(r => r, r => consumer[r]);
                schedule.StorageParams.Add("module", "S3");

                var Schedule = new CreateScheduleRequest
                {
                    TenantId              = TenantManager.GetCurrentTenant().TenantId,
                    BackupMail            = schedule.BackupMail != null && (bool)schedule.BackupMail,
                    Cron                  = schedule.CronParams.ToString(),
                    NumberOfBackupsStored = schedule.BackupsStored == null ? 0 : (int)schedule.BackupsStored,
                    StorageType           = schedule.StorageType,
                    StorageParams         = schedule.StorageParams
                };

                BackupService.CreateSchedule(Schedule);
            }
            else if ((BackupStorageType)response.StorageType != BackupStorageType.ThirdPartyConsumer)
            {
                schedule.StorageParams["folderId"] = response.StorageBasePath;
            }

            return(schedule);
        }