private void ConvertToExport(string user, Process process, PipelineConfigurationPart part, string exportType, IDictionary <string, string> parameters) { var o = process.Output(); switch (exportType) { case "xlsx": var folder = Common.GetAppFolder(); if (!_appDataFolder.DirectoryExists(folder)) { _appDataFolder.CreateDirectory(folder); } var fileName = Common.GetSafeFileName(user, _slugService.Slugify(part.Title()), "xlsx"); o.Provider = "excel"; o.File = _appDataFolder.MapPath(_appDataFolder.Combine(folder, fileName)); break; case "geojson": o.Stream = true; o.Provider = "geojson"; o.File = _slugService.Slugify(part.Title()) + ".geojson"; break; case "kml": o.Stream = true; o.Provider = "kml"; o.File = _slugService.Slugify(part.Title()) + ".kml"; break; default: //csv o.Stream = true; o.Provider = "file"; o.Delimiter = ","; o.File = _slugService.Slugify(part.Title()) + ".csv"; break; } parameters["page"] = "0"; foreach (var entity in process.Entities) { entity.Page = 0; entity.Fields.RemoveAll(f => f.System); foreach (var field in entity.GetAllFields()) { if (field.Alias == Common.BatchValueFieldName) { field.Output = false; } field.T = string.Empty; // because short-hand has already been expanded field.Output = field.Output && field.Export == "defer" || field.Export == "true"; } } }
public ActionResult Index(int id) { var timer = new Stopwatch(); timer.Start(); var process = new Process { Name = "Export" }; var part = _orchardServices.ContentManager.Get(id).As<PipelineConfigurationPart>(); if (part == null) { process.Name = "Not Found"; } else { var user = _orchardServices.WorkContext.CurrentUser == null ? "Anonymous" : _orchardServices.WorkContext.CurrentUser.UserName ?? "Anonymous"; if (_orchardServices.Authorizer.Authorize(Permissions.ViewContent, part)) { process = _processService.Resolve(part); var parameters = Common.GetParameters(Request, _orchardServices, null); process.Load(part.Configuration, parameters); process.Buffer = false; // no buffering for export process.ReadOnly = true; // force exporting to omit system fields // change process for export and batch purposes var reportType = Request["output"] ?? "page"; ConvertToExport(user, process, part, reportType, parameters); process.Load(process.Serialize(), parameters); if (Request["sort"] != null) { _sortService.AddSortToEntity(process.Entities.First(), Request["sort"]); } if (process.Errors().Any()) { foreach (var error in process.Errors()) { _orchardServices.Notifier.Add(NotifyType.Error, T(error)); } } else { if (process.Entities.Any(e => !e.Fields.Any(f => f.Input))) { _orchardServices.WorkContext.Resolve<ISchemaHelper>().Help(process); } if (!process.Errors().Any()) { var runner = _orchardServices.WorkContext.Resolve<IRunTimeExecute>(); try { runner.Execute(process); process.Request = "Export"; process.Time = timer.ElapsedMilliseconds; if (process.Errors().Any()) { foreach (var error in process.Errors()) { _orchardServices.Notifier.Add(NotifyType.Error, T(error)); } process.Status = 500; process.Message = "There are errors in the pipeline. See log."; } else { process.Status = 200; process.Message = "Ok"; } var o = process.Output(); switch (o.Provider) { case "kml": case "geojson": case "file": Response.AddHeader("content-disposition", "attachment; filename=" + o.File); switch (o.Provider) { case "kml": Response.ContentType = "application/vnd.google-earth.kml+xml"; break; case "geojson": Response.ContentType = "application/vnd.geo+json"; break; default: Response.ContentType = "application/csv"; break; } Response.Flush(); Response.End(); return new EmptyResult(); case "excel": return new FilePathResult(o.File, Common.ExcelContentType) { FileDownloadName = _slugService.Slugify(part.Title()) + ".xlsx" }; default: // page and map are rendered to page break; } } catch (Exception ex) { Logger.Error(ex, ex.Message); _orchardServices.Notifier.Error(T(ex.Message)); } } } } else { _orchardServices.Notifier.Warning(user == "Anonymous" ? T("Sorry. Anonymous users do not have permission to view this report. You may need to login.") : T("Sorry {0}. You do not have permission to view this report.", user)); } } return View(new ReportViewModel(process, part)); }
protected override void Load(ContainerBuilder builder) { if (_process == null) { return; } if (!_process.Enabled) { return; } builder.Register <IProcessController>(ctx => { var pipelines = new List <IPipeline>(); // entity-level pipelines foreach (var entity in _process.Entities) { var pipeline = ctx.ResolveNamed <IPipeline>(entity.Key); pipelines.Add(pipeline); if (entity.Delete && _process.Mode != "init") { pipeline.Register(ctx.ResolveNamed <IEntityDeleteHandler>(entity.Key)); } } // process-level pipeline for process level calculated fields if (ctx.IsRegistered <IPipeline>()) { pipelines.Add(ctx.Resolve <IPipeline>()); } var outputConnection = _process.Output(); var context = ctx.Resolve <IContext>(); var controller = new ProcessController(pipelines, context); // output initialization if (_process.Mode == "init") { var output = ctx.ResolveNamed <OutputContext>(outputConnection.Key); switch (outputConnection.Provider) { case "mysql": case "postgresql": case "sqlite": case "access": case "sqlce": case "sqlserver": case "elasticsearch": case "lucene": controller.PreActions.Add(ctx.Resolve <IInitializer>()); break; default: output.Debug(() => $"The {outputConnection.Provider} provider does not support initialization."); break; } } // flatten, should be the first post-action var o = ctx.ResolveNamed <OutputContext>(outputConnection.Key); if (_process.Flatten && _process.Entities.Count > 1 && Constants.AdoProviderSet().Contains(outputConnection.Provider)) { controller.PostActions.Add(new AdoFlattenAction(o, ctx.ResolveNamed <IConnectionFactory>(outputConnection.Key))); } // scripts if (_process.Scripts.Any()) { controller.PreActions.Add(new ScriptLoaderAction(context, ctx.Resolve <IReader>())); } // templates foreach (var template in _process.Templates.Where(t => t.Enabled)) { if (template.Actions.Any()) { if (template.Actions.Any(a => a.GetModes().Any(m => m == _process.Mode))) { controller.PostActions.Add(new RenderTemplateAction(template, ctx.ResolveNamed <ITemplateEngine>(template.Key))); foreach (var action in template.Actions.Where(a => a.GetModes().Any(m => m == _process.Mode || m == "*"))) { if (action.Before) { controller.PreActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } if (action.After) { controller.PostActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } } } } else { controller.PreActions.Add(new TemplateLoaderAction(context, ctx.Resolve <IReader>())); } } // actions foreach (var action in _process.Actions.Where(a => a.GetModes().Any(m => m == _process.Mode || m == "*"))) { if (action.Before) { controller.PreActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } if (action.After) { controller.PostActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } } foreach (var map in _process.Maps.Where(m => !string.IsNullOrEmpty(m.Query))) { controller.PreActions.Add(new MapReaderAction(context, map, ctx.ResolveNamed <IMapReader>(map.Name))); } // for handling multiple entities with non-relational output if (_process.Connections.Any(c => c.Name == Constants.OriginalOutput)) { controller.PostActions.Add(new RecoverOutputAction(ctx.Resolve <IContext>())); } return(controller); }).As <IProcessController>(); }
public ActionResult Report(int id) { var timer = new Stopwatch(); timer.Start(); var process = new Process { Name = "Report" }; var part = _orchardServices.ContentManager.Get(id).As <PipelineConfigurationPart>(); if (part == null) { process.Name = "Not Found"; } else { var user = _orchardServices.WorkContext.CurrentUser == null ? "Anonymous" : _orchardServices.WorkContext.CurrentUser.UserName ?? "Anonymous"; if (_orchardServices.Authorizer.Authorize(Permissions.ViewContent, part)) { process = _processService.Resolve(part); var parameters = Common.GetParameters(Request, _secureFileService, _orchardServices); if (part.NeedsInputFile && Convert.ToInt32(parameters[Common.InputFileIdName]) == 0) { _orchardServices.Notifier.Add(NotifyType.Error, T("This transformalize expects a file.")); process.Name = "File Not Found"; } process.Load(part.Configuration, parameters); process.Buffer = false; // no buffering for reports process.ReadOnly = true; // force reporting to omit system fields // secure actions var actions = process.Actions.Where(a => !a.Before && !a.After && !a.Description.StartsWith("Batch", StringComparison.OrdinalIgnoreCase)); foreach (var action in actions) { var p = _orchardServices.ContentManager.Get(action.Id); if (!_orchardServices.Authorizer.Authorize(Permissions.ViewContent, p)) { action.Description = "BatchUnauthorized"; } } var output = process.Output(); if (_reportOutputs.Contains(output.Provider)) { Common.TranslatePageParametersToEntities(process, parameters, "page"); // change process for export and batch purposes var reportType = Request["output"] ?? "page"; if (!_renderedOutputs.Contains(reportType)) { if (reportType == "batch" && Request.HttpMethod.Equals("POST") && parameters.ContainsKey("action")) { var action = process.Actions.FirstOrDefault(a => a.Description == parameters["action"]); if (action != null) { // check security var actionPart = _orchardServices.ContentManager.Get(action.Id); if (actionPart != null && _orchardServices.Authorizer.Authorize(Permissions.ViewContent, actionPart)) { // security okay parameters["entity"] = process.Entities.First().Alias; var batchParameters = _batchCreateService.Create(process, parameters); Common.AddOrchardVariables(batchParameters, _orchardServices, Request); batchParameters["count"] = parameters.ContainsKey("count") ? parameters["count"] : "0"; var count = _batchWriteService.Write(Request, process, batchParameters); if (count > 0) { if (_batchRunService.Run(action, batchParameters)) { if (action.Url == string.Empty) { if (batchParameters.ContainsKey("BatchId")) { _orchardServices.Notifier.Information(T(string.Format("Processed {0} records in batch {1}.", count, batchParameters["BatchId"]))); } else { _orchardServices.Notifier.Information(T(string.Format("Processed {0} records.", count))); } var referrer = HttpContext.Request.UrlReferrer == null?Url.Action("Report", new { Id = id }) : HttpContext.Request.UrlReferrer.ToString(); return(_batchRedirectService.Redirect(referrer, batchParameters)); } return(_batchRedirectService.Redirect(action.Url, batchParameters)); } var message = batchParameters.ContainsKey("BatchId") ? string.Format("Batch {0} failed.", batchParameters["BatchId"]) : "Batch failed."; Logger.Error(message); _orchardServices.Notifier.Error(T(message)); foreach (var key in batchParameters.Keys) { Logger.Error("Batch Parameter {0} = {1}.", key, batchParameters[key]); } return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, message)); } } else { return(new HttpUnauthorizedResult("You do not have access to this bulk action.")); } } } else // export { ConvertToExport(user, process, part, reportType, parameters); process.Load(process.Serialize(), parameters); } } if (Request["sort"] != null) { _sortService.AddSortToEntity(process.Entities.First(), Request["sort"]); } if (process.Errors().Any()) { foreach (var error in process.Errors()) { _orchardServices.Notifier.Add(NotifyType.Error, T(error)); } } else { if (process.Entities.Any(e => !e.Fields.Any(f => f.Input))) { _orchardServices.WorkContext.Resolve <ISchemaHelper>().Help(process); } if (!process.Errors().Any()) { var runner = _orchardServices.WorkContext.Resolve <IRunTimeExecute>(); try { runner.Execute(process); process.Request = "Run"; process.Time = timer.ElapsedMilliseconds; if (process.Errors().Any()) { foreach (var error in process.Errors()) { _orchardServices.Notifier.Add(NotifyType.Error, T(error)); } process.Status = 500; process.Message = "There are errors in the pipeline. See log."; } else { process.Status = 200; process.Message = "Ok"; } var o = process.Output(); switch (o.Provider) { case "kml": case "geojson": case "file": Response.AddHeader("content-disposition", "attachment; filename=" + o.File); switch (o.Provider) { case "kml": Response.ContentType = "application/vnd.google-earth.kml+xml"; break; case "geojson": Response.ContentType = "application/vnd.geo+json"; break; default: Response.ContentType = "application/csv"; break; } Response.Flush(); Response.End(); return(new EmptyResult()); case "excel": return(new FilePathResult(o.File, Common.ExcelContentType) { FileDownloadName = _slugService.Slugify(part.Title()) + ".xlsx" }); default: // page and map are rendered to page break; } } catch (Exception ex) { Logger.Error(ex, ex.Message); _orchardServices.Notifier.Error(T(ex.Message)); } } } } } else { _orchardServices.Notifier.Warning(user == "Anonymous" ? T("Sorry. Anonymous users do not have permission to view this report. You may need to login.") : T("Sorry {0}. You do not have permission to view this report.", user)); } } return(View(new ReportViewModel(process, part))); }
public ILifetimeScope CreateScope(Process process, IPipelineLogger logger) { var builder = new ContainerBuilder(); #if PLUGINS builder.Properties["Process"] = process; #endif builder.Register(ctx => process).As <Process>(); builder.RegisterInstance(logger).As <IPipelineLogger>().SingleInstance(); // register short-hand for t attribute, allowing for additional transforms var transformModule = new TransformModule(process, _methods, _shortHand, logger); foreach (var t in _transforms) { transformModule.AddTransform(t); } builder.RegisterModule(transformModule); // register short-hand for v attribute, allowing for additional validators var validateModule = new ValidateModule(process, _methods, _shortHand, logger); foreach (var v in _validators) { validateModule.AddValidator(v); } builder.RegisterModule(validateModule); builder.RegisterModule(new InternalModule(process)); #if PLUGINS // just in case other modules need to see these builder.Properties["ShortHand"] = _shortHand; builder.Properties["Methods"] = _methods; #endif // allowing for additional modules foreach (var module in _modules) { builder.RegisterModule(module); } // Process Context builder.Register <IContext>((ctx, p) => new PipelineContext(logger, process)).As <IContext>(); // Process Output Context builder.Register(ctx => { var context = ctx.Resolve <IContext>(); return(new OutputContext(context)); }).As <OutputContext>(); // Connection and Process Level Output Context foreach (var connection in process.Connections) { builder.Register(ctx => new ConnectionContext(ctx.Resolve <IContext>(), connection)).Named <IConnectionContext>(connection.Key); if (connection.Name != "output") { continue; } // register output for connection builder.Register(ctx => { var context = ctx.ResolveNamed <IConnectionContext>(connection.Key); return(new OutputContext(context)); }).Named <OutputContext>(connection.Key); } // Entity Context and RowFactory foreach (var entity in process.Entities) { builder.Register <IContext>((ctx, p) => new PipelineContext(ctx.Resolve <IPipelineLogger>(), process, entity)).Named <IContext>(entity.Key); builder.Register(ctx => { var context = ctx.ResolveNamed <IContext>(entity.Key); return(new InputContext(context)); }).Named <InputContext>(entity.Key); builder.Register <IRowFactory>((ctx, p) => new RowFactory(p.Named <int>("capacity"), entity.IsMaster, false)).Named <IRowFactory>(entity.Key); builder.Register(ctx => { var context = ctx.ResolveNamed <IContext>(entity.Key); return(new OutputContext(context)); }).Named <OutputContext>(entity.Key); var connection = process.Connections.First(c => c.Name == entity.Connection); builder.Register(ctx => new ConnectionContext(ctx.Resolve <IContext>(), connection)).Named <IConnectionContext>(entity.Key); } // entity pipelines foreach (var entity in process.Entities) { builder.Register(ctx => { var type = process.Pipeline == "defer" ? entity.Pipeline : process.Pipeline; var context = ctx.ResolveNamed <IContext>(entity.Key); context.Debug(() => $"Registering {type} for entity {entity.Alias}."); var outputController = ctx.IsRegisteredWithName <IOutputController>(entity.Key) ? ctx.ResolveNamed <IOutputController>(entity.Key) : new NullOutputController(); var pipeline = new DefaultPipeline(outputController, context); // TODO: rely on IInputProvider's Read method instead (after every provider has one) pipeline.Register(ctx.IsRegisteredWithName(entity.Key, typeof(IRead)) ? ctx.ResolveNamed <IRead>(entity.Key) : null); pipeline.Register(ctx.IsRegisteredWithName(entity.Key, typeof(IInputProvider)) ? ctx.ResolveNamed <IInputProvider>(entity.Key) : null); // transforms if (!process.ReadOnly) { pipeline.Register(new SetSystemFields(new PipelineContext(ctx.Resolve <IPipelineLogger>(), process, entity))); } pipeline.Register(new IncrementTransform(context)); pipeline.Register(new DefaultTransform(context, context.GetAllEntityFields().Where(f => !f.System))); pipeline.Register(TransformFactory.GetTransforms(ctx, context, entity.GetAllFields().Where(f => f.Transforms.Any()))); pipeline.Register(ValidateFactory.GetValidators(ctx, context, entity.GetAllFields().Where(f => f.Validators.Any()))); if (!process.ReadOnly) { pipeline.Register(new StringTruncateTransfom(new PipelineContext(ctx.Resolve <IPipelineLogger>(), process, entity))); } pipeline.Register(new LogTransform(context)); // writer, TODO: rely on IOutputProvider instead pipeline.Register(ctx.IsRegisteredWithName(entity.Key, typeof(IWrite)) ? ctx.ResolveNamed <IWrite>(entity.Key) : null); pipeline.Register(ctx.IsRegisteredWithName(entity.Key, typeof(IOutputProvider)) ? ctx.ResolveNamed <IOutputProvider>(entity.Key) : null); // updater pipeline.Register(process.ReadOnly || !ctx.IsRegisteredWithName(entity.Key, typeof(IUpdate)) ? new NullUpdater() : ctx.ResolveNamed <IUpdate>(entity.Key)); return(pipeline); }).Named <IPipeline>(entity.Key); } // process pipeline builder.Register(ctx => { var calc = process.ToCalculatedFieldsProcess(); var entity = calc.Entities.First(); var context = new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, entity); var outputContext = new OutputContext(context); context.Debug(() => $"Registering {process.Pipeline} pipeline."); var outputController = ctx.IsRegistered <IOutputController>() ? ctx.Resolve <IOutputController>() : new NullOutputController(); var pipeline = new DefaultPipeline(outputController, context); // no updater necessary pipeline.Register(new NullUpdater(context, false)); if (!process.CalculatedFields.Any()) { pipeline.Register(new NullReader(context, false)); pipeline.Register(new NullWriter(context, false)); return(pipeline); } // register transforms pipeline.Register(new IncrementTransform(context)); pipeline.Register(new LogTransform(context)); pipeline.Register(new DefaultTransform(new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, entity), entity.CalculatedFields)); pipeline.Register(TransformFactory.GetTransforms(ctx, context, entity.CalculatedFields)); pipeline.Register(ValidateFactory.GetValidators(ctx, context, entity.GetAllFields().Where(f => f.Validators.Any()))); pipeline.Register(new StringTruncateTransfom(new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, entity))); // register input and output pipeline.Register(ctx.IsRegistered <IRead>() ? ctx.Resolve <IRead>() : new NullReader(context)); pipeline.Register(ctx.IsRegistered <IWrite>() ? ctx.Resolve <IWrite>() : new NullWriter(context)); if (outputContext.Connection.Provider == "sqlserver") { pipeline.Register(new MinDateTransform(new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, entity), new DateTime(1753, 1, 1))); } return(pipeline); }).As <IPipeline>(); // process controller builder.Register <IProcessController>(ctx => { var pipelines = new List <IPipeline>(); // entity-level pipelines foreach (var entity in process.Entities) { var pipeline = ctx.ResolveNamed <IPipeline>(entity.Key); pipelines.Add(pipeline); if (entity.Delete && process.Mode != "init") { pipeline.Register(ctx.ResolveNamed <IEntityDeleteHandler>(entity.Key)); } } // process-level pipeline for process level calculated fields if (ctx.IsRegistered <IPipeline>()) { pipelines.Add(ctx.Resolve <IPipeline>()); } var context = ctx.Resolve <IContext>(); var controller = new ProcessController(pipelines, context); // output initialization if (process.Mode == "init" && ctx.IsRegistered <IInitializer>()) { controller.PreActions.Add(ctx.Resolve <IInitializer>()); } // flatten(ing) is first post-action var isAdo = Constants.AdoProviderSet().Contains(process.Output().Provider); if (process.Flatten && isAdo) { if (ctx.IsRegisteredWithName <IAction>(process.Output().Key)) { controller.PostActions.Add(ctx.ResolveNamed <IAction>(process.Output().Key)); } else { context.Error($"Could not find ADO Flatten Action for provider {process.Output().Provider}."); } } // actions foreach (var action in process.Actions.Where(a => a.GetModes().Any(m => m == process.Mode || m == "*"))) { if (action.Before) { controller.PreActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } if (action.After) { controller.PostActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } } return(controller); }).As <IProcessController>(); var build = builder.Build(); return(build.BeginLifetimeScope()); }
protected override void Load(ContainerBuilder builder) { if (_process == null) { return; } if (!_process.Enabled) { return; } builder.Register <IProcessController>(ctx => { var pipelines = new List <IPipeline>(); // entity-level pipelines foreach (var entity in _process.Entities) { var pipeline = ctx.ResolveNamed <IPipeline>(entity.Key); pipelines.Add(pipeline); if (entity.Delete && _process.Mode != "init") { pipeline.Register(ctx.ResolveNamed <IEntityDeleteHandler>(entity.Key)); } } // process-level pipeline for process level calculated fields if (ctx.IsRegistered <IPipeline>()) { pipelines.Add(ctx.Resolve <IPipeline>()); } var outputConnection = _process.Output(); var context = ctx.Resolve <IContext>(); var controller = new ProcessController(pipelines, context); // output initialization if (_process.Mode == "init" && ctx.IsRegistered <IInitializer>()) { controller.PreActions.Add(ctx.Resolve <IInitializer>()); } // flatten, should be the first post-action var o = ctx.ResolveNamed <OutputContext>(outputConnection.Key); var isAdo = Constants.AdoProviderSet().Contains(outputConnection.Provider); if (_process.Flatten && isAdo) { if (ctx.IsRegisteredWithName <IAction>(outputConnection.Key)) { controller.PostActions.Add(ctx.ResolveNamed <IAction>(outputConnection.Key)); } else { o.Error($"Could not find ADO Flatten Action for provider {outputConnection.Provider}."); } } // scripts if (_process.Scripts.Any()) { controller.PreActions.Add(new ScriptLoaderAction(context, ctx.Resolve <IReader>())); } // templates foreach (var template in _process.Templates.Where(t => t.Enabled)) { if (template.Actions.Any()) { if (template.Actions.Any(a => a.GetModes().Any(m => m == _process.Mode))) { controller.PostActions.Add(new RenderTemplateAction(template, ctx.ResolveNamed <ITemplateEngine>(template.Key))); foreach (var action in template.Actions.Where(a => a.GetModes().Any(m => m == _process.Mode || m == "*"))) { if (action.Before) { controller.PreActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } if (action.After) { controller.PostActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } } } } else { controller.PreActions.Add(new TemplateLoaderAction(context, ctx.Resolve <IReader>())); } } // actions foreach (var action in _process.Actions.Where(a => a.GetModes().Any(m => m == _process.Mode || m == "*"))) { if (action.Before) { controller.PreActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } if (action.After) { controller.PostActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } } foreach (var map in _process.Maps.Where(m => !string.IsNullOrEmpty(m.Query))) { controller.PreActions.Add(new MapReaderAction(context, map, ctx.ResolveNamed <IMapReader>(map.Name))); } return(controller); }).As <IProcessController>(); }
private void ConvertToExport(string user, Process process, PipelineConfigurationPart part, string exportType) { var o = process.Output(); switch (exportType) { case "xlsx": var folder = Common.GetAppFolder(); if (!_appDataFolder.DirectoryExists(folder)) { _appDataFolder.CreateDirectory(folder); } var fileName = Common.GetSafeFileName(user, _slugService.Slugify(part.Title()), "xlsx"); o.Provider = "excel"; o.File = _appDataFolder.MapPath(_appDataFolder.Combine(folder, fileName)); break; case "geojson": case "map": o.Stream = true; o.Provider = "geojson"; o.File = _slugService.Slugify(part.Title()) + ".geo.json"; var mapFields = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { part.MapColorField, "geojson-color" }, { part.MapPopUpField, "geojson-description" }, { part.MapLatitudeField, "latitude" }, { part.MapLongitudeField, "longitude" } }; foreach (var entity in process.Entities) { foreach (var field in entity.GetAllFields()) { if (mapFields.ContainsKey(field.Alias)) { field.Output = true; if (!mapFields[field.Alias].Equals(field.Alias, StringComparison.OrdinalIgnoreCase)) { field.Alias = mapFields[field.Alias]; } } else { field.Output = !field.PrimaryKey; } } } break; case "json": o.Stream = true; o.Provider = "json"; o.File = _slugService.Slugify(part.Title()) + ".json"; break; case "calendar": o.Stream = true; o.Provider = "json"; o.File = _slugService.Slugify(part.Title()) + ".json"; var calendarFields = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { part.CalendarIdField, "id" }, { part.CalendarTitleField, "title" }, { part.CalendarUrlField, "url" }, { part.CalendarClassField, "class" }, { part.CalendarStartField, "start" }, { part.CalendarEndField, "end" }, }; foreach (var entity in process.Entities) { foreach (var field in entity.GetAllFields()) { if (calendarFields.ContainsKey(field.Alias)) { field.Output = true; if (!calendarFields[field.Alias].Equals(field.Alias, StringComparison.OrdinalIgnoreCase)) { field.Alias = calendarFields[field.Alias]; } } else { field.Output = !field.PrimaryKey; } } } break; case "kml": o.Stream = true; o.Provider = "kml"; o.File = _slugService.Slugify(part.Title()) + ".kml"; break; default: // csv o.Stream = true; o.Provider = "file"; o.Delimiter = ","; o.TextQualifier = "\""; o.File = _slugService.Slugify(part.Title()) + ".csv"; break; } foreach (var entity in process.Entities) { entity.Fields.RemoveAll(f => f.System); foreach (var field in entity.GetAllFields()) { if (field.Alias == Common.BatchValueFieldName) { field.Output = false; } field.T = string.Empty; // because short-hand has already been expanded switch (exportType) { case "map": case "calendar": // map and calendar have already been modified break; default: field.Output = field.Output && field.Export == "defer" || field.Export == "true"; break; } } } }