Ejemplo n.º 1
0
 public static Uploader_S3 GetInstance(Config_S3 settings)
 {
     lock (padlock)
     {
         return(_instance ?? (_instance = new Uploader_S3(settings)));
     }
 }
Ejemplo n.º 2
0
        protected async Task RawExecute(IJobExecutionContext context)
        {
            var dataMap   = context.JobDetail.JobDataMap;
            var container = context.Scheduler.Context["container"] as IUnityContainer;
            var cfgCloud  = (context.Scheduler.Context["config"] as Config)?.Cloud;
            var jobIndex  = (int)dataMap["index"];
            var cfgJob    = dataMap["data"] as Config_Job;

            logger.Info($"Задача №{jobIndex} запущена: {cfgJob.Name}");

            var jsEngine = container.Resolve <JSEngine>();

            var validFilename = cfgJob.Name.ConvertToValidFilename();
            var filename      = jsEngine.getCloudFilename(validFilename) + ".zip";

            //filename = DateTime.Now.ToString("yyyy.MM.dd/HH.mm.ss") + $"_{filename}.zip";

            logger.Debug("Архивация директории: " + cfgJob.Path);
            logger.Debug("Маски файлов: " + string.Join(", ", cfgJob.Masks.Masks));
            logger.Debug("Тип масок: " + (cfgJob.Masks.MasksExclude ? "Whitelist" : "Blacklist"));

            var jobState = getState(context);

            jobState.inProgress = true;

            jobState.status = "Построение списка файлов";
            var files = FileUtils.GetFilesInDirectory(cfgJob.Path, cfgJob.Masks);

            jobState.status = "Подключение к S3 хранилищу";
            var s3 = Uploader_S3.GetInstance(cfgCloud);

            using (var zip = new ZipTools(cfgJob.Path, files, cfgJob.Password))
            {
                var zipFilename = zip.CreateZip((total, index, name) =>
                {
                    jobState.status  = $"Архивация файла: {name}";
                    jobState.current = index;
                    jobState.total   = total;
                });

                jobState.isBytes = true;
                s3.UploadFile(zipFilename, filename, (sender, args) =>
                {
                    jobState.status  = $"Отправка архива {filename}";
                    jobState.current = args.TransferredBytes;
                    jobState.total   = args.TotalBytes;
                });
            }

            jobState.done();
            logger.Info($"Задача №{jobIndex} завершена: {cfgJob.Name}");
        }