Exemplo n.º 1
0
        public override void PublishChanges(DistributedTask task)
        {
            var thirdpartyTask = ThirdPartyOperation.GetDistributedTask();
            var daoTask        = DaoOperation.GetDistributedTask();

            var error1 = thirdpartyTask.GetProperty <string>(ERROR);
            var error2 = daoTask.GetProperty <string>(ERROR);

            if (!string.IsNullOrEmpty(error1))
            {
                Error = error1;
            }
            else if (!string.IsNullOrEmpty(error2))
            {
                Error = error2;
            }

            successProcessed = thirdpartyTask.GetProperty <int>(PROCESSED) + daoTask.GetProperty <int>(PROCESSED);

            var progressSteps = ThirdPartyOperation.Total + DaoOperation.Total + 1;

            var progress = (int)(successProcessed / (double)progressSteps * 100);

            base.FillDistributedTask();

            TaskInfo.SetProperty(PROGRESS, progress < 100 ? progress : progress);
            TaskInfo.PublishChanges();
        }
        public override void RunJob(DistributedTask _, CancellationToken cancellationToken)
        {
            base.RunJob(_, cancellationToken);

            using var scope = ThirdPartyOperation.CreateScope();
            var globalStore      = scope.ServiceProvider.GetService <GlobalStore>();
            var filesLinkUtility = scope.ServiceProvider.GetService <FilesLinkUtility>();

            using var stream = TempStream.Create();
            using (var zip = new ZipOutputStream(stream, true)
            {
                CompressionLevel = Ionic.Zlib.CompressionLevel.Level3,
                AlternateEncodingUsage = ZipOption.AsNecessary,
                AlternateEncoding = Encoding.UTF8,
            })
            {
                (ThirdPartyOperation as FileDownloadOperation <string>).CompressToZip(zip, stream, scope);
                (DaoOperation as FileDownloadOperation <int>).CompressToZip(zip, stream, scope);
            }

            if (stream != null)
            {
                stream.Position = 0;
                const string fileName = FileConstant.DownloadTitle + ".zip";
                var          store    = globalStore.GetStore();
                store.Save(
                    FileConstant.StorageDomainTmp,
                    string.Format(@"{0}\{1}", ((IAccount)Thread.CurrentPrincipal.Identity).ID, fileName),
                    stream,
                    "application/zip",
                    "attachment; filename=\"" + fileName + "\"");
                Status = string.Format("{0}?{1}=bulk", filesLinkUtility.FileHandlerPath, FilesLinkUtility.Action);
            }
        }
Exemplo n.º 3
0
        public override void RunJob(DistributedTask _, CancellationToken cancellationToken)
        {
            ThirdPartyOperation.GetDistributedTask().Publication = PublishChanges;
            ThirdPartyOperation.RunJob(_, cancellationToken);

            DaoOperation.GetDistributedTask().Publication = PublishChanges;
            DaoOperation.RunJob(_, cancellationToken);
        }
Exemplo n.º 4
0
        protected internal override void FillDistributedTask()
        {
            ThirdPartyOperation.FillDistributedTask();
            DaoOperation.FillDistributedTask();

            HoldResult = ThirdPartyOperation.HoldResult || DaoOperation.HoldResult;
            Total      = ThirdPartyOperation.Total + DaoOperation.Total;
            Source     = string.Join(SPLIT_CHAR, ThirdPartyOperation.Source, DaoOperation.Source);
            base.FillDistributedTask();
        }
Exemplo n.º 5
0
        public override void RunJob(DistributedTask distributedTask, CancellationToken cancellationToken)
        {
            base.RunJob(distributedTask, cancellationToken);

            using var scope = ThirdPartyOperation.CreateScope();
            var scopeClass = scope.ServiceProvider.GetService <FileDownloadOperationScope>();

            var(globalStore, filesLinkUtility, _, _, _) = scopeClass;
            var stream = TempStream.Create();

            (ThirdPartyOperation as FileDownloadOperation <string>).CompressToZip(stream, scope);
            (DaoOperation as FileDownloadOperation <int>).CompressToZip(stream, scope);

            if (stream != null)
            {
                var archiveExtension = "";

                using (var zip = scope.ServiceProvider.GetService <CompressToArchive>())
                {
                    archiveExtension = zip.ArchiveExtension;
                }

                stream.Position = 0;
                string fileName = FileConstant.DownloadTitle + archiveExtension;
                var    store    = globalStore.GetStore();
                var    path     = string.Format(@"{0}\{1}", ((IAccount)Thread.CurrentPrincipal.Identity).ID, fileName);

                if (store.IsFile(FileConstant.StorageDomainTmp, path))
                {
                    store.Delete(FileConstant.StorageDomainTmp, path);
                }

                store.Save(
                    FileConstant.StorageDomainTmp,
                    path,
                    stream,
                    MimeMapping.GetMimeMapping(path),
                    "attachment; filename=\"" + fileName + "\"");
                Result = string.Format("{0}?{1}=bulk&ext={2}", filesLinkUtility.FileHandlerPath, FilesLinkUtility.Action, archiveExtension);

                TaskInfo.SetProperty(PROGRESS, 100);
                TaskInfo.SetProperty(RESULT, Result);
                TaskInfo.SetProperty(FINISHED, true);
            }

            TaskInfo.PublishChanges();
        }
Exemplo n.º 6
0
        public override void RunJob(DistributedTask distributedTask, CancellationToken cancellationToken)
        {
            base.RunJob(distributedTask, cancellationToken);

            using var scope = ThirdPartyOperation.CreateScope();
            var scopeClass = scope.ServiceProvider.GetService <FileDownloadOperationScope>();

            var(globalStore, filesLinkUtility, _, _, _) = scopeClass;
            using var stream = TempStream.Create();

            var writerOptions = new ZipWriterOptions(CompressionType.Deflate);

            writerOptions.ArchiveEncoding.Default = Encoding.UTF8;
            writerOptions.DeflateCompressionLevel = SharpCompress.Compressors.Deflate.CompressionLevel.Level3;

            using (var zip = WriterFactory.Open(stream, ArchiveType.Zip, writerOptions))
            {
                (ThirdPartyOperation as FileDownloadOperation <string>).CompressToZip(zip, stream, scope);
                (DaoOperation as FileDownloadOperation <int>).CompressToZip(zip, stream, scope);
            }

            if (stream != null)
            {
                stream.Position = 0;
                const string fileName = FileConstant.DownloadTitle + ".zip";
                var          store    = globalStore.GetStore();
                store.Save(
                    FileConstant.StorageDomainTmp,
                    string.Format(@"{0}\{1}", ((IAccount)Thread.CurrentPrincipal.Identity).ID, fileName),
                    stream,
                    "application/zip",
                    "attachment; filename=\"" + fileName + "\"");
                Status = string.Format("{0}?{1}=bulk", filesLinkUtility.FileHandlerPath, FilesLinkUtility.Action);
            }

            FillDistributedTask();
            TaskInfo.PublishChanges();
        }
Exemplo n.º 7
0
        public void PublishChanges(DistributedTask task)
        {
            var thirdpartyTask = ThirdPartyOperation.GetDistributedTask();
            var daoTask        = DaoOperation.GetDistributedTask();

            var error1 = thirdpartyTask.GetProperty <string>(ERROR);
            var error2 = daoTask.GetProperty <string>(ERROR);

            if (!string.IsNullOrEmpty(error1))
            {
                Error = error1;
            }
            else if (!string.IsNullOrEmpty(error2))
            {
                Error = error2;
            }

            var status1 = thirdpartyTask.GetProperty <string>(RESULT);
            var status2 = daoTask.GetProperty <string>(RESULT);

            if (!string.IsNullOrEmpty(status1))
            {
                Status = status1;
            }
            else if (!string.IsNullOrEmpty(status2))
            {
                Status = status2;
            }

            var finished1 = thirdpartyTask.GetProperty <bool?>(FINISHED);
            var finished2 = daoTask.GetProperty <bool?>(FINISHED);

            if (finished1 != null && finished2 != null)
            {
                TaskInfo.SetProperty(FINISHED, finished1);
            }

            successProcessed = thirdpartyTask.GetProperty <int>(PROCESSED) + daoTask.GetProperty <int>(PROCESSED);


            base.FillDistributedTask();

            var progress = 0;

            if (ThirdPartyOperation.Total != 0)
            {
                progress += thirdpartyTask.GetProperty <int>(PROGRESS);
            }

            if (DaoOperation.Total != 0)
            {
                progress += daoTask.GetProperty <int>(PROGRESS);
            }

            if (ThirdPartyOperation.Total != 0 && DaoOperation.Total != 0)
            {
                progress /= 2;
            }

            TaskInfo.SetProperty(PROGRESS, progress < 100 ? progress : 100);
            TaskInfo.PublishChanges();
        }