private static void ExportReport(ExportArguments arguments) { var config = ConfigHelper.GetConfig(arguments.ConfigFilePath); var export = new Export(config); export.AsExcel(); }
public async Task InvokeAsync() { var plotExportDialogs = InteractiveWorkflow.Shell.GetService <IRPlotExportDialog>(); var exportImageArguments = new ExportArguments(VisualComponent.Device.PixelWidth, VisualComponent.Device.PixelHeight, VisualComponent.Device.Resolution); var exportImageParameters = plotExportDialogs.ShowExportImageDialog(exportImageArguments, Resources.Plots_ExportAsImageFilter, null, Resources.Plots_ExportAsImageDialogTitle); if (!string.IsNullOrEmpty(exportImageParameters?.FilePath)) { var device = DeviceFromFileExtension(exportImageParameters.FilePath); if (!string.IsNullOrEmpty(device)) { try { await InteractiveWorkflow.Plots.ExportToBitmapAsync( VisualComponent.ActivePlot, device, exportImageParameters.FilePath, exportImageParameters.PixelWidth, exportImageParameters.PixelHeight, exportImageParameters.Resolution); if (exportImageParameters.ViewPlot) { InteractiveWorkflow.Shell.Process().Start(exportImageParameters.FilePath); } } catch (RPlotManagerException ex) { InteractiveWorkflow.Shell.ShowErrorMessage(ex.Message); } catch (OperationCanceledException) { } } else { InteractiveWorkflow.Shell.ShowErrorMessage(string.Format(Resources.Plots_ExportUnsupportedImageFormat, Path.GetExtension(exportImageParameters.FilePath))); } } }
public async Task InvokeAsync() { var plotExportDialogs = InteractiveWorkflow.Services.GetService <IRPlotExportDialog>(); var exportPdfArguments = new ExportArguments(VisualComponent.Device.PixelWidth, VisualComponent.Device.PixelHeight, VisualComponent.Device.Resolution); var exportPdfParameters = plotExportDialogs.ShowExportPdfDialog(exportPdfArguments, Resources.Plots_ExportAsPdfFilter, null, Resources.Plots_ExportAsPdfDialogTitle); if (!string.IsNullOrEmpty(exportPdfParameters?.FilePath)) { try { await InteractiveWorkflow.Plots.ExportToPdfAsync( VisualComponent.ActivePlot, exportPdfParameters.RInternalPdfDevice, exportPdfParameters.RInternalPaperName, exportPdfParameters.FilePath, exportPdfParameters.WidthInInches, exportPdfParameters.HeightInInches); if (exportPdfParameters.ViewPlot) { InteractiveWorkflow.Services.Process().Start(exportPdfParameters.FilePath); } } catch (RPlotManagerException ex) { InteractiveWorkflow.Services.ShowErrorMessage(ex.Message); } catch (OperationCanceledException) { } } }
public async Task <ActionResult> Export([FromQuery] ExportArguments args, CancellationToken cancellation) { var service = GetCrudService(); Stream fileStream = await service.Export(args, cancellation); return(File(fileStream, MimeTypes.Csv)); }
public ExportImageViewModel(ExportArguments imageArguments) { UserWidth = imageArguments.PixelWidth; UserHeight = imageArguments.PixelHeight; IsSaveEnabled = true; IsValidHeight = true; IsValidWidth = true; }
public ExportImageParameters ShowExportImageDialog(ExportArguments imageArguments, string filter, string initialPath = null, string title = null) => new ExportImageParameters { FilePath = SaveFilePath, PixelWidth = 640, PixelHeight = 480, Resolution = 96, ViewPlot = false };
public ExportPdfParameters ShowExportPdfDialog(ExportArguments pdfArguments, string filter, string initialPath = null, string title = null) => new ExportPdfParameters { FilePath = SaveFilePath, WidthInInches = 2, HeightInInches = 2, Resolution = 96, ViewPlot = false };
public virtual async Task <ActionResult> Export([FromQuery] ExportArguments args) { return(await ControllerUtilities.InvokeActionImpl(async() => { // Get abstract grid var response = await GetImplAsync(args); var abstractFile = EntitiesToAbstractGrid(response, args); return AbstractGridToFileResult(abstractFile, args.Format); }, _logger)); }
private async Task ExportAsync(ExportArguments arguments, Action <DummyEntity> handler) { var ctx = QueryContext.Default.Unpublished(arguments.Unpublished); var session = configuration.StartSession(); var contents = session.Contents(arguments.Schema); var total = 0L; var totalRead = 0; var currentPage = 0L; var handled = new HashSet <Guid>(); using (var logLine = log.WriteSameLine()) { do { var query = new ContentQuery { Filter = arguments.Filter, OrderBy = arguments.OrderBy, Search = arguments.FullText, Skip = currentPage * 100, Top = 100 }; var content = await contents.GetAsync(query, ctx); total = content.Total; if (content.Items.Count == 0) { break; } foreach (var entity in content.Items) { if (handled.Add(entity.Id)) { totalRead++; handler(entity); logLine.WriteLine("> Exported: {0} of {1}.", totalRead, total); } } currentPage++; }while (totalRead < total); } log.WriteLine("> Exported: {0} of {1}. Completed.", totalRead, total); }
private async Task ExportAsync(ExportArguments arguments, Action <DummyEntity> handler) { var ctx = QueryContext.Default.Unpublished(arguments.Unpublished); var(_, service) = Configuration.Setup(); var client = service.CreateContentsClient <DummyEntity, DummyData>(arguments.Schema); var total = 0L; var totalRead = 0; var currentPage = 0L; var consoleTop = Console.CursorTop; var handled = new HashSet <Guid>(); do { var query = new ContentQuery { Filter = arguments.Filter, OrderBy = arguments.OrderBy, Search = arguments.FullText, Skip = currentPage * 100, Top = 100 }; var content = await client.GetAsync(query, ctx); total = content.Total; if (content.Items.Count == 0) { break; } foreach (var entity in content.Items) { if (handled.Add(entity.Id)) { totalRead++; handler(entity); Console.WriteLine("> Exported: {0} of {1}.", totalRead, total); Console.SetCursorPosition(0, consoleTop); } } currentPage++; }while (totalRead < total); Console.WriteLine("> Exported: {0} of {1}. Completed.", totalRead, total); }
private ExportImageParameters ShowSaveExportImageDialog(IntPtr owner, ExportArguments imageArguments, string filter, string initialPath = null, string title = null) { var exportImageDialog = new ExportImageDialog(imageArguments); exportImageDialog.ShowModal(); var exportParameters = exportImageDialog.GetExportParameters(); if (exportImageDialog.DialogResult == true) { exportParameters.FilePath = _shell.FileDialog().ShowSaveFileDialog(filter, initialPath, title); return(exportParameters); } return(null); }
public ExportPdfViewModel(ExportArguments pdfArguments) { IsSaveEnabled = true; IsValidWidth = true; IsValidHeight = true; _pdfPapers = PDFExportOptions.GetPdfPapers(pdfArguments.PixelWidth, pdfArguments.PixelHeight, pdfArguments.Resolution).ToList(); SelectedPDFPaperType = _pdfPapers[0]; SelectedPDFPaperType.PaperHeight = Validate(SelectedPDFPaperType.PaperHeight); SelectedPDFPaperType.PaperWidth = Validate(SelectedPDFPaperType.PaperWidth); _paperOrientations = PDFExportOptions.GetPaperOrientations().ToList(); SelectedOrientation = _paperOrientations[0]; _pdfDeviceOptions = PDFExportOptions.GetPdfDeviceOptions().ToList(); SelectedDevice = _pdfDeviceOptions[0]; }
private static List <(string Name, string[] Path)> GetFields(ExportArguments arguments) { var fields = new List <(string Name, string[] Path)>(); foreach (var item in arguments.Fields.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)) { var parts = item.Split('='); string[] GetPath(string value) { var path = value.Split('.', StringSplitOptions.RemoveEmptyEntries); if (path.Length == 2 && string.Equals(path[0], "Data", StringComparison.OrdinalIgnoreCase)) { return(path.Union(Enumerable.Repeat("iv", 1)).ToArray()); } return(path); } if (parts.Length == 1) { fields.Add((parts[0], GetPath(parts[0]))); } else if (parts.Length == 2) { fields.Add((parts[0], GetPath(parts[1]))); } else { throw new SquidexException("Field definition not valid."); } } return(fields); }
protected override AbstractDataGrid DtosToAbstractGrid(GetResponse <View> response, ExportArguments args) { throw new NotImplementedException(); }
public ExportPdfParameters ShowExportPdfDialog(ExportArguments pdfArguements, string filter, string initialPath = null, string title = null) => ShowSaveExportPdfDialog(_shell.GetDialogOwnerWindow(), pdfArguements, filter, initialPath, title);
protected override AbstractDataGrid DtosToAbstractGrid(GetResponse <Agent> response, ExportArguments args) { // Get all the properties without Id and EntityState var type = typeof(Agent); var custodySaveProps = typeof(CustodyForSave).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); var agentSaveProps = typeof(AgentForSave).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); var readProps = typeof(Agent).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); var saveProps = custodySaveProps.Union(agentSaveProps); var props = saveProps.Union(readProps); if (ViewId() == ORGANIZATION) { // For organizations, some properties are left blank var exemptProperties = new string[] { nameof(Agent.Title), nameof(Agent.Title2), nameof(Agent.Gender) }; props.Where(p => !exemptProperties.Contains(p.Name)); } var propsArray = props.ToArray(); // The result that will be returned var result = new AbstractDataGrid(propsArray.Length, response.Data.Count() + 1); // Add the header List <PropertyInfo> addedProps = new List <PropertyInfo>(propsArray.Length); { var header = result[result.AddRow()]; int i = 0; foreach (var prop in propsArray) { var display = _metadataProvider.GetMetadataForProperty(type, prop.Name)?.DisplayName ?? prop.Name; if (display != Constants.Hidden) { header[i] = AbstractDataCell.Cell(display); // Add the proper styling if (prop.PropertyType.IsDateOrTime()) { var att = prop.GetCustomAttribute <DataTypeAttribute>(); var isDateOnly = att != null && att.DataType == DataType.Date; header[i].NumberFormat = ExportDateTimeFormat(dateOnly: isDateOnly); } addedProps.Add(prop); i++; } } } // Add the rows foreach (var entity in response.Data) { var row = result[result.AddRow()]; int i = 0; foreach (var prop in addedProps) { var content = prop.GetValue(entity); // Special handling for choice lists var choiceListAttr = prop.GetCustomAttribute <ChoiceListAttribute>(); if (choiceListAttr != null) { var choiceIndex = Array.FindIndex(choiceListAttr.Choices, e => e.Equals(content)); if (choiceIndex != -1) { string displayName = choiceListAttr.DisplayNames[choiceIndex]; content = _localizer[displayName]; } } // Special handling for DateTimeOffset if (prop.PropertyType.IsDateTimeOffset() && content != null) { content = ToExportDateTime((DateTimeOffset)content); } row[i] = AbstractDataCell.Cell(content); i++; } } return(result); }
public ExportImageParameters ShowExportImageDialog(ExportArguments imageArguments, string filter, string initialPath = null, string title = null) => ShowSaveExportImageDialog(_shell.GetDialogOwnerWindow(), imageArguments, filter, initialPath, title);
public async Task Export(ExportArguments arguments) { var session = configuration.StartSession(); if (arguments.Format == Format.JSON) { var fileOrFolder = arguments.Output; if (arguments.FilePerContent) { if (string.IsNullOrWhiteSpace(fileOrFolder)) { fileOrFolder = $"{arguments.Schema}_{DateTime.UtcNow:yyyy-MM-dd-hh-mm-ss}"; } Directory.CreateDirectory(fileOrFolder); } else { if (string.IsNullOrWhiteSpace(fileOrFolder)) { fileOrFolder = $"{arguments.Schema}_{DateTime.UtcNow:yyyy-MM-dd-hh-mm-ss}.json"; } if (File.Exists(fileOrFolder)) { File.Delete(fileOrFolder); } } if (arguments.FilePerContent) { await session.ExportAsync(arguments, log, async entity => { var fileName = $"{arguments.Schema}_{entity.Id}.json"; var filePath = Path.Combine(fileOrFolder, fileName); if (arguments.FullEntities) { await Helper.WriteJsonToFileAsync(entity, filePath); } else { await Helper.WriteJsonToFileAsync(entity.Data, filePath); } }); } else if (arguments.JsonArray) { var allRecords = new List <DynamicContent>(); await session.ExportAsync(arguments, log, entity => { allRecords.Add(entity); return(Task.CompletedTask); }); if (arguments.FullEntities) { await Helper.WriteJsonToFileAsync(allRecords, fileOrFolder); } else { await Helper.WriteJsonToFileAsync(allRecords.Select(x => x.Data), fileOrFolder); } } else { await using (var stream = new FileStream(fileOrFolder, FileMode.Create, FileAccess.Write)) { await using (var writer = new StreamWriter(stream)) { await session.ExportAsync(arguments, log, async entity => { if (arguments.FullEntities) { await writer.WriteJsonAsync(entity); } else { await writer.WriteJsonAsync(entity.Data); } await writer.WriteLineAsync(); await writer.WriteLineAsync(JsonSeparator); }); } } } } else { if (arguments.FilePerContent) { throw new CLIException("Multiple files are not supported for CSV export."); } var file = arguments.Output; if (string.IsNullOrWhiteSpace(file)) { file = $"{arguments.Schema}_{DateTime.UtcNow:yyyy-MM-dd-hh-mm-ss}.csv"; } var converter = new Squidex2CsvConverter(arguments.Fields); await using (var stream = new FileStream(file, FileMode.Create, FileAccess.Write)) { await using (var streamWriter = new StreamWriter(stream)) { var csvOptions = new CsvConfiguration(CultureInfo.InvariantCulture) { Delimiter = ";" }; await using (var writer = new CsvWriter(streamWriter, csvOptions)) { foreach (var fieldName in converter.FieldNames) { writer.WriteField(fieldName); } await writer.NextRecordAsync(); await session.ExportAsync(arguments, log, async entity => { foreach (var value in converter.GetValues(entity)) { if (value is string text) { writer.WriteField(text, true); } else { writer.WriteField(value); } } await writer.NextRecordAsync(); }); } } } } }
/// <summary> /// Transforms an Entity response into an abstract grid that can be transformed into an file /// </summary> protected AbstractDataGrid EntitiesToAbstractGrid(GetResponse <TEntity> response, ExportArguments args) { throw new NotImplementedException(); }
public ExportImageDialog(ExportArguments imageArguments) { InitializeComponent(); _exportVM = new ExportImageViewModel(imageArguments); DataContext = _exportVM; }
public async Task Export(ExportArguments arguments) { var ctx = QueryContext.Default.Unpublished(arguments.Unpublished); var(_, service) = Configuration.Setup(); var client = service.CreateContentsClient <DummyEntity, DummyData>(arguments.Schema); if (arguments.Format == Format.JSON) { if (!string.IsNullOrWhiteSpace(arguments.Fields)) { throw new SquidexException("Fields are not used for JSON export."); } var fileOrFolder = arguments.Output; if (arguments.FilePerContent) { if (string.IsNullOrWhiteSpace(fileOrFolder)) { fileOrFolder = $"{arguments.Schema}_{DateTime.UtcNow:yyyy-MM-dd-hh-mm-ss}"; } if (!Directory.Exists(fileOrFolder)) { Directory.CreateDirectory(fileOrFolder); } } else { if (string.IsNullOrWhiteSpace(fileOrFolder)) { fileOrFolder = $"{arguments.Schema}_{DateTime.UtcNow:yyyy-MM-dd-hh-mm-ss}.json"; } if (File.Exists(fileOrFolder)) { File.Delete(fileOrFolder); } } await ExportAsync(arguments, entity => { if (arguments.FilePerContent) { File.WriteAllText(Path.Combine(fileOrFolder, $"{arguments.Schema}_{entity.Id}.json"), entity.JsonPrettyString()); } else { File.AppendAllText(fileOrFolder, entity.JsonPrettyString()); } }); } else { if (arguments.FilePerContent) { throw new SquidexException("Multiple files are not supported for CSV export."); } if (string.IsNullOrWhiteSpace(arguments.Fields)) { throw new SquidexException("Fields must be defined for CSV export."); } var file = arguments.Output; if (string.IsNullOrWhiteSpace(file)) { file = $"{arguments.Schema}_{DateTime.UtcNow:yyyy-MM-dd-hh-mm-ss}.csv"; } var converter = new Squidex2CsvConverter(arguments.Fields); using (var stream = new FileStream(file, FileMode.Create, FileAccess.Write)) { using (var streamWriter = new StreamWriter(stream)) { var csvOptions = new CsvConfiguration(CultureInfo.InvariantCulture) { Delimiter = ";" }; using (var writer = new CsvWriter(streamWriter, csvOptions)) { foreach (var fieldName in converter.FieldNames) { writer.WriteField(fieldName); } writer.NextRecord(); await ExportAsync(arguments, entity => { foreach (var value in converter.GetValues(entity)) { if (value is string text) { writer.WriteField(text, true); } else { writer.WriteField(value); } } writer.NextRecord(); }); } } } } }
public ExportPDFDialog(ExportArguments pdfArguments) { InitializeComponent(); _exportPdfViewModel = new ExportPdfViewModel(pdfArguments); DataContext = _exportPdfViewModel; }
protected override AbstractDataGrid DtosToAbstractGrid(GetResponse <MeasurementUnit> response, ExportArguments args) { // Get all the properties without Id and EntityState var type = typeof(MeasurementUnit); var readProps = typeof(MeasurementUnit).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); var saveProps = typeof(MeasurementUnitForSave).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); var props = saveProps.Union(readProps).ToArray(); // The result that will be returned var result = new AbstractDataGrid(props.Length, response.Data.Count() + 1); // Add the header List <PropertyInfo> addedProps = new List <PropertyInfo>(props.Length); { var header = result[result.AddRow()]; int i = 0; foreach (var prop in props) { var display = _metadataProvider.GetMetadataForProperty(type, prop.Name)?.DisplayName ?? prop.Name; if (display != Constants.Hidden) { header[i] = AbstractDataCell.Cell(display); // Add the proper styling for DateTime and DateTimeOffset if (prop.PropertyType.IsDateOrTime()) { var att = prop.GetCustomAttribute <DataTypeAttribute>(); var isDateOnly = att != null && att.DataType == DataType.Date; header[i].NumberFormat = ExportDateTimeFormat(dateOnly: isDateOnly); } addedProps.Add(prop); i++; } } } // Add the rows foreach (var entity in response.Data) { var metadata = entity.EntityMetadata; var row = result[result.AddRow()]; int i = 0; foreach (var prop in addedProps) { metadata.TryGetValue(prop.Name, out FieldMetadata meta); if (meta == FieldMetadata.Loaded) { var content = prop.GetValue(entity); // Special handling for choice lists var choiceListAttr = prop.GetCustomAttribute <ChoiceListAttribute>(); if (choiceListAttr != null) { var choiceIndex = Array.FindIndex(choiceListAttr.Choices, e => e.Equals(content)); if (choiceIndex != -1) { string displayName = choiceListAttr.DisplayNames[choiceIndex]; content = _localizer[displayName]; } } // Special handling for DateTimeOffset if (prop.PropertyType.IsDateTimeOffset() && content != null) { content = ToExportDateTime((DateTimeOffset)content); } row[i] = AbstractDataCell.Cell(content); } else if (meta == FieldMetadata.Restricted) { row[i] = AbstractDataCell.Cell(Constants.Restricted); } else { row[i] = AbstractDataCell.Cell("-"); } i++; } } return(result); }