Пример #1
0
        public async Task <DataExportResult> ExportAsync(DataExportRequest request, CancellationToken cancellationToken)
        {
            var ctx = new DataExporterContext(request, false, cancellationToken);

            if (request?.Profile?.Enabled ?? false)
            {
                var lockKey = $"dataexporter:profile:{request.Profile.Id}";
                if (!AsyncLock.IsLockHeld(lockKey))
                {
                    using (await AsyncLock.KeyedAsync(lockKey, cancellationToken: cancellationToken))
                    {
                        // TODO: (mg) (core) start to export in ExportAsync.
                        //await ExportCoreOuterAsync(ctx);
                    }

                    cancellationToken.ThrowIfCancellationRequested();
                }
                else
                {
                    ctx.Result.LastError = $"The execution of the profile \"{request.Profile.Name.NaIfEmpty()}\" (ID {request.Profile.Id}) is locked.";
                }
            }

            return(ctx.Result);
        }
Пример #2
0
        public async Task Run(TaskExecutionContext ctx, CancellationToken cancelToken = default)
        {
            var profileId = ctx.ExecutionInfo.Task.Alias.ToInt();
            var profile   = await _db.ExportProfiles
                            .Include(x => x.Deployments)
                            .FindByIdAsync(profileId, true, cancelToken);

            if (profile == null)
            {
                return;
            }

            var provider = _providerManager.GetProvider <IExportProvider>(profile.ProviderSystemName);

            if (provider == null)
            {
                throw new SmartException(T("Admin.Common.ProviderNotLoaded", profile.ProviderSystemName.NaIfEmpty()));
            }

            // Create export request.
            var request = new DataExportRequest(profile, provider)
            {
                ProgressCallback = OnProgress
            };

            if (ctx.Parameters.ContainsKey("SelectedIds"))
            {
                request.EntitiesToExport = ctx.Parameters["SelectedIds"]
                                           .SplitSafe(",")
                                           .Select(x => x.ToInt())
                                           .ToList();
            }

            if (ctx.Parameters.ContainsKey("ActionOrigin"))
            {
                request.ActionOrigin = ctx.Parameters["ActionOrigin"];
            }

            // Process!
            await _dataExporter.ExportAsync(request, cancelToken);

            Task OnProgress(int value, int max, string msg)
            {
                return(ctx.SetProgressAsync(value, max, msg, true));
            }
        }
Пример #3
0
 public Task <DataExportPreviewResult> PreviewAsync(DataExportRequest request, int pageIndex)
 {
     throw new NotImplementedException();
 }