Exemplo n.º 1
0
        private static async Task <string> GenerateExportFile(DataGridResultViewer resultViewer, IDataExporter dataExporter)
        {
            var tempFileName            = Path.GetTempFileName();
            var connectionConfiguration = ConfigurationProvider.GetConnectionConfiguration(ConfigurationProvider.ConnectionStrings[0].Name);

            Thread.CurrentThread.CurrentCulture = CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

            using (var exportContext = await dataExporter.StartExportAsync(ExportOptions.ToFile(tempFileName, resultViewer.Title), DataExportHelper.GetOrderedExportableColumns(resultViewer.ResultGrid), connectionConfiguration.InfrastructureFactory.DataExportConverter, CancellationToken.None))
            {
                await exportContext.AppendRowsAsync(resultViewer.ResultGrid.Items.Cast <object[]>());

                await exportContext.FinalizeAsync();
            }

            return(tempFileName);
        }
Exemplo n.º 2
0
        private async Task ExportData(IDataExporter dataExporter, ExportOptions exportOptions)
        {
            using (var cancellationTokenSource = new CancellationTokenSource())
            {
                var operationMonitor = new WindowOperationMonitor(cancellationTokenSource)
                {
                    IsIndeterminate = false
                };
                operationMonitor.Show();

                var exception = await App.SafeActionAsync(
                    async delegate
                {
                    using (var exportContext = await dataExporter.StartExportAsync(exportOptions, DataExportHelper.GetOrderedExportableColumns(ResultGrid), _outputViewer.DocumentPage.InfrastructureFactory.DataExportConverter, cancellationTokenSource.Token))
                    {
                        exportContext.SetProgress(_resultRows.Count, operationMonitor);
                        await exportContext.AppendRowsAsync(_resultRows);
                        await exportContext.FinalizeAsync();
                    }
                });

                operationMonitor.Close();

                var isOperationCanceledException = exception is OperationCanceledException;
                if (exception != null && !isOperationCanceledException)
                {
                    Messages.ShowError(exception.Message);
                }
            }
        }