public IProcessController Compose(string cfg, LogLevel logLevel = LogLevel.Info, Dictionary <string, string> parameters = null, string placeHolderStyle = "@()") { var logger = new TraceLogger(logLevel); var container = ConfigurationContainer.Create(cfg, logger, parameters, placeHolderStyle); Process = parameters == null?container.Resolve <Process>(new NamedParameter("cfg", cfg)) : container.Resolve <Process>(new NamedParameter("cfg", cfg), new NamedParameter("parameters", parameters)); if (Process.Errors().Any()) { foreach (var error in Process.Errors()) { Trace.WriteLine(error); } throw new Exception("Configuration Error(s)"); } if (Process.Warnings().Any()) { foreach (var warning in Process.Warnings()) { Trace.WriteLine(warning); } } return(DefaultContainer.Create(Process, logger, placeHolderStyle).Resolve <IProcessController>(new NamedParameter("cfg", cfg))); }
public IProcessController Compose(string cfg, LogLevel logLevel = LogLevel.Info, Dictionary <string, string> parameters = null) { var builder = new ContainerBuilder(); builder.RegisterModule(new RootModule(@"Shorthand.xml")); var container = builder.Build(); Process = parameters == null?container.Resolve <Process>(new NamedParameter("cfg", cfg)) : container.Resolve <Process>(new NamedParameter("cfg", cfg), new NamedParameter("parameters", parameters)); if (Process.Errors().Any()) { foreach (var error in Process.Errors()) { Trace.WriteLine(error); } throw new Exception("Configuration Error(s)"); } if (Process.Warnings().Any()) { foreach (var warning in Process.Warnings()) { Trace.WriteLine(warning); } } return(DefaultContainer.Create(Process, new TraceLogger(logLevel)).Resolve <IProcessController>(new NamedParameter("cfg", cfg))); }
public ActionResult Download(int id) { var part = _orchardServices.ContentManager.Get(id).As <PipelineConfigurationPart>(); var process = new Process { Name = "Export" }; if (part == null) { process.Name = "Not Found"; return(new FileStreamResult(Common.GenerateStreamFromString(process.Serialize()), "text/xml") { FileDownloadName = id + ".xml" }); } if (!_orchardServices.Authorizer.Authorize(Permissions.ViewContent, part)) { process.Name = "Not Authorized"; return(new FileStreamResult(Common.GenerateStreamFromString(process.Serialize()), "text/xml") { FileDownloadName = id + ".xml" }); } return(new FileStreamResult(Common.GenerateStreamFromString(part.Configuration), "text/" + part.EditorMode) { FileDownloadName = _slugService.Slugify(part.Title()) + "." + part.EditorMode }); }
private bool MissingFieldHelper(Process process, PipelineConfigurationPart part, string format, IDictionary <string, string> parameters) { if (process.Entities.Any(e => !e.Fields.Any(f => f.Input))) { var schemaHelper = _orchardServices.WorkContext.Resolve <ISchemaHelper>(); if (schemaHelper.Help(process)) { // remove this stuff before serialization // todo: get clean, unmodified, and unvalidated configuration to to add fields to and serialize // because below won't work in all cases (i.e. producer transforms...) foreach (var entity in process.Entities) { entity.Fields.RemoveAll(f => f.System); } foreach (var field in process.GetAllFields().Where(f => !string.IsNullOrEmpty(f.T))) { field.T = string.Empty; } if (part.EditorMode == format) { process.Load(process.Serialize(), parameters); } else { var cfg = process.Serialize(); process = _processService.Resolve(part, format, format); process.Load(cfg); } return(true); } } return(false); }
public ActionResult Content(int id) { var process = new Process { Name = "Form", Id = id }; var part = _orchardServices.ContentManager.Get(id).As <PipelineConfigurationPart>(); if (part == null) { process.Status = 404; process.Message = "Not Found"; } else { if (_orchardServices.Authorizer.Authorize(Permissions.ViewContent, part)) { var runner = _orchardServices.WorkContext.Resolve <IRunTimeExecute>(); process = _processService.Resolve(part); var parameters = Common.GetParameters(Request, _orchardServices, _secureFileService); process.Load(part.Configuration, parameters); runner.Execute(process); } else { process.Message = "Unauthorized"; process.Status = 401; } } return(View(new FormViewModel(part, process))); }
public ActionResult Builder(int id) { var process = new Process { Name = "Builder" }; 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, "xml", "json"); process.Load(part.Configuration, new Dictionary <string, string> { { "DisableValidation", "true" } }); process.Buffer = false; // no buffering for builder process.ReadOnly = true; // force builder to omit system fields } else { _orchardServices.Notifier.Warning(user == "Anonymous" ? T("Sorry. Anonymous users do not have permission to build reports. You have to login.") : T("Sorry {0}. You do not have permission to build this report.", user)); } } return(View(new BuilderViewModel(process))); }
public ActionResult Index(int id) { var timer = new Stopwatch(); timer.Start(); var process = new Process { Name = "PivotTable" }; 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, _secureFileService); GetStickyParameters(part.Id, parameters); process.Load(part.Configuration, parameters); process.Mode = "pivot"; process.ReadOnly = true; // force pivot to omit system fields SetStickyParameters(part.Id, process.Parameters); // no paging foreach (var entity in process.Entities) { entity.Page = 0; } // no actions process.Actions.Clear(); if (IsMissingRequiredParameters(process.Parameters, _orchardServices.Notifier)) { return(View(new ReportViewModel(process, part))); } // note: currently the view executes the process and converts the rows to a JSON format, // as opposed to how it works for the map where it initiates a "download" } 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(string arrangement, ContentItem item, IDictionary <string, string> parameters, bool validateParameters = true) { var combinedParameters = parameters ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var builder = new ContainerBuilder(); builder.RegisterModule(new ShorthandModule(_logger)); builder.Register(ctx => { var dependancies = new List <IDependency>(); if (item.ContentItem.Has("TransformalizeReportPart")) { dependancies.Add(new ReportParameterModifier()); } if (Serializer != null) { dependancies.Add(Serializer); } dependancies.Add(new ParameterModifier(new PlaceHolderReplacer('@', '[', ']'))); // these were registered by the ShorthandModule are are used to expand shorthand transforms and validators into "longhand". dependancies.Add(ctx.ResolveNamed <IDependency>(TransformModule.FieldsName)); dependancies.Add(ctx.ResolveNamed <IDependency>(TransformModule.ParametersName)); dependancies.Add(ctx.ResolveNamed <IDependency>(ValidateModule.FieldsName)); dependancies.Add(ctx.ResolveNamed <IDependency>(ValidateModule.ParametersName)); string modified = arrangement; if (_httpContext.HttpContext.Request.Method == "GET" && item.ContentItem.Has("TransformalizeFormPart")) { modified = _loadFormModifier.Modify(arrangement, item.Id, combinedParameters); } if (validateParameters) { modified = _transformalizeParameters.Modify(arrangement, item.Id, combinedParameters); } var process = new Process(modified, combinedParameters, dependancies.ToArray()); if (process.Errors().Any()) { _logger.Error(() => "The configuration has errors."); foreach (var error in process.Errors()) { _logger.Error(() => error); } } process.Id = item.Id; return(process); }).As <Process>().InstancePerDependency(); return(builder.Build().BeginLifetimeScope()); }
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"; } } }
private static ContentResult Get503(string action, Process process, string format, long time) { process.Request = action; process.Status = 503; process.Message = string.Join("\n", process.Errors()); process.Time = time; return(new ContentResult { Content = process.Serialize(), ContentType = "text/" + format }); }
public ActionResult Index(int id) { var timer = new Stopwatch(); timer.Start(); var process = new Process { Name = "PivotTable" }; 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, _secureFileService); process.Load(part.Configuration, parameters); process.Mode = "pivot"; process.Buffer = false; // no buffering for pivot tables process.ReadOnly = true; // force pivot to omit system fields // no paging foreach (var entity in process.Entities) { entity.Page = 0; } // no actions process.Actions.Clear(); } 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))); }
private static void RemoveCredentials(Process process) { foreach (var connection in process.Connections) { connection.ConnectionString = string.Empty; connection.User = string.Empty; connection.Password = string.Empty; } foreach (var parameter in process.Environments.SelectMany(environement => environement.Parameters)) { if (parameter.Name.Equals("user", StringComparison.OrdinalIgnoreCase)) { parameter.Value = string.Empty; } if (parameter.Name.Equals("password")) { parameter.Value = string.Empty; } } }
public ActionResult Index(int id) { var timer = new Stopwatch(); timer.Start(); var settings = _orchardServices.WorkContext.CurrentSite.As <PipelineSettingsPart>(); var process = new Process { Name = "Calendar" }; var part = _orchardServices.ContentManager.Get(id).As <PipelineConfigurationPart>(); if (part == null) { process.Name = "Not Found"; return(new HttpNotFoundResult()); } if (!_orchardServices.Authorizer.Authorize(Permissions.ViewContent, part)) { return(new HttpUnauthorizedResult()); } process = _processService.Resolve(part); var parameters = Common.GetParameters(Request, _orchardServices, _secureFileService); GetStickyParameters(part.Id, parameters); process.Load(part.Configuration, parameters); if (process.Errors().Any()) { foreach (var error in process.Errors()) { _orchardServices.Notifier.Add(NotifyType.Error, T(error)); } return(new HttpStatusCodeResult(500, "There are errors in the configuration.")); } process.Mode = "calendar"; process.ReadOnly = true; // force calendar to omit system fields process.Pipeline = "parallel.linq"; SetStickyParameters(part.Id, process.Parameters); // 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 sizes = new List <int>(); sizes.AddRange(part.Sizes(part.PageSizes)); if (part.CalendarPaging) { sizes.AddRange(part.Sizes(part.MapSizes)); // MapSizes is now "Extended" sizes } var stickySize = GetStickyParameter(part.Id, "size", () => sizes.Min()); Common.SetPageSize(process, parameters, sizes.Min(), stickySize, sizes.Max()); if (IsMissingRequiredParameters(process.Parameters, _orchardServices.Notifier)) { return(View(new ReportViewModel(process, part))); } try { var runner = _orchardServices.WorkContext.Resolve <IRunTimeExecute>(); runner.Execute(process); process.Request = "Execute"; process.Time = timer.ElapsedMilliseconds; if (process.Log.Any(l => l.LogLevel == LogLevel.Error)) { foreach (var error in process.Log.Where(l => l.LogLevel == LogLevel.Error)) { _orchardServices.Notifier.Add(NotifyType.Error, T(error.Message)); } process.Status = 500; return(new HttpStatusCodeResult(500)); } } catch (Exception ex) { Logger.Error(ex, ex.Message); _orchardServices.Notifier.Error(T(ex.Message)); } return(View(new ReportViewModel(process, part))); }
public ActionResult Index(int id) { var timer = new Stopwatch(); timer.Start(); var referrer = HttpContext.Request.UrlReferrer == null?Url.Action("Index", "Report", new { Id = id }) : HttpContext.Request.UrlReferrer.ToString(); var process = new Process { Name = "Action" }; var part = _orchardServices.ContentManager.Get(id).As <PipelineConfigurationPart>(); if (part == null) { process.Name = "Not Found"; _orchardServices.Notifier.Add(NotifyType.Error, T("Could not find pipeline id {0}", id)); return(_batchRedirectService.Redirect(referrer, null)); } 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, _secureFileService); 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.ReadOnly = true; // force actions to omit system fields if (parameters.ContainsKey("action")) { var action = process.Actions.FirstOrDefault(a => a.Description == parameters["action"]); var system = process.Parameters.FirstOrDefault(p => p.Name.Equals("System", StringComparison.OrdinalIgnoreCase)); if (system == null) { Logger.Error("The {0} requires a System parameter in order to run bulk actions.", part.Title()); _orchardServices.Notifier.Error(T("The {0} requires a System parameter in order to run bulk actions.", part.Title())); } else { if (system.Value == "*") { _orchardServices.Notifier.Warning(T("The {0} must be selected in order to run an action.", system.Label)); system = null; } } if (action != null && system != null) { // check security var actionPart = _orchardServices.ContentManager.Get(action.Id); if (actionPart == null) { _orchardServices.Notifier.Add(NotifyType.Error, T("Could not find orchard content id {0} referenced in the {1}:{2} action.", id, action.Type, action.Description)); return(_batchRedirectService.Redirect(referrer, null)); } if (_orchardServices.Authorizer.Authorize(Permissions.ViewContent, actionPart)) { parameters["entity"] = process.Entities.First().Alias; var batchParameters = _batchCreateService.Create(process, parameters); batchParameters["Orchard.User"] = parameters["Orchard.User"]; batchParameters["count"] = parameters.ContainsKey("count") ? parameters["count"] : "0"; var count = _batchWriteService.Write(Request, process, batchParameters); if (count > 0) { // get default parameters from process foreach (var p in process.Parameters.Where(pr => pr.Value != "*")) { if (!batchParameters.ContainsKey(p.Name)) { batchParameters[p.Name] = p.Value; } } // get parameters from action foreach (var p in action.Parameters.Where(pr => pr.Value != "*")) { if (batchParameters.ContainsKey(p.Name)) { _orchardServices.Notifier.Add(NotifyType.Warning, T("The action parameter {0} is hiding another parameter", p.Name)); } batchParameters[p.Name] = p.Value; } 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))); } return(_batchRedirectService.Redirect(referrer, null)); } 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(_batchRedirectService.Redirect(referrer, null)); } } else { return(new HttpUnauthorizedResult("You do not have access to this bulk action.")); } } } else { _orchardServices.Notifier.Warning(T("An action must be specified.")); } } 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(_batchRedirectService.Redirect(referrer, null)); }
public ILifetimeScope CreateScope(Process process, IPipelineLogger logger) { var builder = new ContainerBuilder(); // the modules below rely on this process being there builder.Properties["Process"] = process; builder.Register(ctx => process).As <Process>(); builder.RegisterInstance(logger).As <IPipelineLogger>().SingleInstance(); // register short-hand for t attribute, allowing for additional transforms var tm = new TransformModule(process, _methods, _shortHand, logger) { Plugins = false }; // adding additional transforms here tm.AddTransform(new TransformHolder((c) => new UsernameTransform(_httpContext, c), new UsernameTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new UserIdTransform(_httpContext, _userService, c), new UserIdTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new UserEmailTransform(_httpContext, _userService, c), new UserEmailTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new OrchardRazorTransform(c, _memoryCache, _signal), new OrchardRazorTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new OrchardFluidTransform(c, _memoryCache, _signal), new OrchardFluidTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new OrchardJintTransform(c, new DefaultReader(new FileReader(), new WebReader()), _memoryCache, _signal), new OrchardJintTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new ToLocalTimeTransform(c, _clock, _localClock), new ToLocalTimeTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new GetEncodedUrlTransform(_httpContext, c), new GetEncodedUrlTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new GetDisplayUrlTransform(_httpContext, c), new GetDisplayUrlTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new OrchardTimeZoneTransform(c), new OrchardTimeZoneTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new GeocodeTransform(c), new GeocodeTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new PlaceTransform(c), new PlaceTransform().GetSignatures())); tm.AddTransform(new TransformHolder((c) => new FilePartTransform(c, _fileService), new FilePartTransform().GetSignatures())); builder.RegisterModule(tm); // register short-hand for v attribute, allowing for additional validators var vm = new ValidateModule(process, _methods, _shortHand, logger) { Plugins = false }; // adding additional validators here builder.RegisterModule(vm); // using custom internal module that does not handle the nested transformalize actions builder.RegisterModule(new OrchardInternalModule(process)); // handling nested transformalize actions here instead foreach (var action in process.Actions.Where(a => a.GetModes().Any(m => m == process.Mode || m == "*"))) { if (action.Type == "tfl") { builder.Register <IAction>(ctx => { return(new PipelineAction(action, _serviceProvider)); }).Named <IAction>(action.Key); } } // register providers var providers = new HashSet <string>(process.Connections.Select(c => c.Provider)); // relational databases builder.RegisterModule(new AdoProviderModule()); if (providers.Contains("sqlserver")) { builder.RegisterModule(new SqlServerModule() { ConnectionFactory = (c) => new ProfiledConnectionFactory(new SqlServerConnectionFactory(c)) }); } if (providers.Contains("postgresql")) { builder.RegisterModule(new PostgreSqlModule() { ConnectionFactory = (c) => new ProfiledConnectionFactory(new PostgreSqlConnectionFactory(c)) }); } if (providers.Contains("sqlite")) { builder.RegisterModule(new SqliteModule() { ConnectionFactory = (c) => new ProfiledConnectionFactory(new SqliteConnectionFactory(c)) }); } if (providers.Contains("mysql")) { builder.RegisterModule(new MySqlModule() { ConnectionFactory = (c) => new ProfiledConnectionFactory(new MySqlConnectionFactory(c)) }); } // search engines if (providers.Contains("elasticsearch")) { builder.RegisterModule(new ElasticsearchModule()); } // solr // lucene // importing, exporting var stream = _httpContext.HttpContext.Response.Body; if (providers.Contains("file")) { builder.RegisterModule(new CsvHelperProviderModule(stream)); } if (providers.Contains("excel")) { builder.RegisterModule(new OrchardExcelModule()); } // exporting if (providers.Contains("json")) { builder.RegisterModule(new JsonProviderModule(stream) { UseAsyncMethods = true }); } if (providers.Contains("geojson")) { builder.RegisterModule(new GeoJsonProviderModule(stream) { UseAsyncMethods = true }); } // misc if (providers.Contains("bogus")) { builder.RegisterModule(new BogusModule()); } if (providers.Contains("log") || process.Actions.Any(a => a.Type == "log")) { builder.RegisterModule(new OrchardLogModule(process)); } if (providers.Contains("mail")) { builder.RegisterModule(new MailModule()); } if (providers.Contains("aws")) { var services = new HashSet <string>(process.Connections.Where(c => c.Provider == "aws").Select(c => c.Service)); if (services.Contains("logs")) { builder.RegisterModule(new AwsCloudWatchProviderModule()); } if (services.Contains("connect")) { builder.RegisterModule(new AmazonConnectProviderModule()); } } // transform and validation modules need these properties builder.Properties["ShortHand"] = _shortHand; builder.Properties["Methods"] = _methods; // register transform modules here builder.RegisterModule(new JsonTransformModule()); builder.RegisterModule(new HumanizeModule()); builder.RegisterModule(new FileModule()); builder.RegisterModule(new AdoTransformModule()); builder.RegisterModule(new LambdaParserModule()); builder.RegisterModule(new AwsTransformModule()); // register validator modules here builder.RegisterModule(new JintValidateModule()); // 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 var formWriter = false; foreach (var connection in process.Connections) { builder.Register(ctx => new ConnectionContext(ctx.Resolve <IContext>(), connection)).Named <IConnectionContext>(connection.Key); // there can only be one form writer if (!formWriter && connection.Table != "[default]" && connection.Provider != "[default]") { builder.Register(ctx => { var context = ctx.ResolveNamed <IConnectionContext>(connection.Key); var connectionFactory = ctx.ResolveNamed <IConnectionFactory>(connection.Key); return(new AdoFormCommandWriter(context, connectionFactory)); }).As <AdoFormCommandWriter>(); formWriter = true; } if (connection.Name != process.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.Input); 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 output = process.GetOutputConnection(); var context = ctx.ResolveNamed <IContext>(entity.Key); var outputController = ctx.IsRegisteredWithName <IOutputController>(entity.Key) ? ctx.ResolveNamed <IOutputController>(entity.Key) : new NullOutputController(); var pipeline = new DefaultPipeline(outputController, context); if (entity.IsMaster) { if (GetReaderAlternate != null) { // Using an alternate reader (e.g. a ParameterRowReader that reads parameters into a row) var input = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity)); pipeline.Register(GetReaderAlternate(input, rowFactory)); } else if (GetReaderDecorator != null && ctx.IsRegisteredWithName(entity.Key, typeof(IRead))) { // Decorating the normally registered reader (e.g. ParameterRowReader updating a row from an AdoReader) // TODO: Support IInputProvider instead of just IRead var input = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity)); pipeline.Register(GetReaderDecorator(ctx.ResolveNamed <IRead>(entity.Key), input, rowFactory)); } else { 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); } } else { // 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 && !output.Provider.In("internal", "log")) { 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); } if (process.Entities.Count > 1 && process.Relationships.Any()) { // 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 output = process.GetOutputConnection(); var isAdo = _adoProviders.Contains(output.Provider); if (process.Flatten && isAdo) { if (ctx.IsRegisteredWithName <IAction>(output.Key)) { controller.PostActions.Add(ctx.ResolveNamed <IAction>(output.Key)); } else { context.Error($"Could not find ADO Flatten Action for provider {output.Provider}."); } } // actions foreach (var action in process.Actions.Where(a => a.GetModes().Any(m => m == process.Mode || m == "*"))) { if (ctx.IsRegisteredWithName <IAction>(action.Key)) { if (action.Before) { controller.PreActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } if (action.After) { controller.PostActions.Add(ctx.ResolveNamed <IAction>(action.Key)); } } else { if (action.Type != "internal") { _logger.Warn(() => $"The action {action.Name} with type {action.Type} isn't registered."); } } } 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>(); var build = builder.Build(); return(build.BeginLifetimeScope()); }
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; } } } }
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()); }
public ActionResult Index(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, _orchardServices, _secureFileService); 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.Mode = "report"; 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"; } } Common.TranslatePageParametersToEntities(process, parameters, "page"); if (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) { return(new HttpNotFoundResult(string.Format("The action id {0} does not refer to a content item id.", action.Id))); } if (_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("Index", 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.")); } } } 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"; } } 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 ProcessControlModule(Process process) { _process = process; }
public ActionResult Index(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, _orchardServices, _secureFileService); 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"; } GetStickyParameters(part.Id, parameters); process.Load(part.Configuration, parameters); process.Mode = "report"; process.ReadOnly = true; // force reporting to omit system fields SetStickyParameters(part.Id, process.Parameters); // 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 sizes = new List <int>(); sizes.AddRange(part.Sizes(part.PageSizes)); var stickySize = GetStickyParameter(part.Id, "size", () => sizes.Min()); Common.SetPageSize(process, parameters, sizes.Min(), stickySize, sizes.Max()); 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 (part.ReportRowClassField != string.Empty || part.ReportRowStyleField != string.Empty) { var fieldAliases = new HashSet <string>(process.GetAllFields().Select(f => f.Alias)); if (part.ReportRowClassField != string.Empty && !fieldAliases.Contains(part.ReportRowClassField)) { _orchardServices.Notifier.Error(T("Can not find report row class field {0}", part.ReportRowClassField)); return(View(new ReportViewModel(process, part))); } if (part.ReportRowStyleField != string.Empty && !fieldAliases.Contains(part.ReportRowStyleField)) { _orchardServices.Notifier.Error(T("Can not find report row style field {0}", part.ReportRowStyleField)); return(View(new ReportViewModel(process, part))); } } if (!process.Errors().Any()) { if (IsMissingRequiredParameters(process.Parameters, _orchardServices.Notifier)) { return(View(new ReportViewModel(process, part))); } 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"; } } 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 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)); }
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 static ILifetimeScope Create(Process process, IPipelineLogger logger, string placeHolderStyle) { var loadContext = new PipelineContext(logger, process); if (process.OutputIsConsole()) { logger.SuppressConsole(); } var builder = new ContainerBuilder(); builder.Properties["Process"] = process; builder.Register(ctx => placeHolderStyle).Named <string>("placeHolderStyle"); builder.RegisterInstance(logger).As <IPipelineLogger>().SingleInstance(); /* this stuff is loaded (again) because tfl actions can create processes, which will need short-hand to expand configuration in advance */ builder.RegisterCallback(new TransformModule(process, logger).Configure); builder.RegisterCallback(new ValidateModule(process, logger).Configure); builder.RegisterCallback(new RootModule().Configure); builder.RegisterCallback(new ContextModule(process).Configure); // provider loading section var providers = new HashSet <string>(process.Connections.Select(c => c.Provider).Distinct(), StringComparer.OrdinalIgnoreCase); builder.RegisterCallback(new InternalModule(process).Configure); builder.RegisterCallback(new FileModule(process).Configure); if (providers.Contains("console")) { builder.RegisterCallback(new ConsoleModule(process).Configure); } if (providers.Contains("kml")) { builder.RegisterCallback(new KmlModule(process).Configure); } if (providers.Contains("filesystem")) { builder.RegisterCallback(new FileSystemModule(process).Configure); } var pluginsFolder = Path.Combine(AssemblyDirectory, "plugins"); if (Directory.Exists(pluginsFolder)) { var assemblies = new List <Assembly>(); var files = Directory.GetFiles(pluginsFolder, "Transformalize.Provider.*.Autofac.dll", SearchOption.TopDirectoryOnly); foreach (var file in files) { var info = new FileInfo(file); var name = info.Name.ToLower().Split('.').FirstOrDefault(f => f != "dll" && f != "transformalize" && f != "provider" && f != "autofac"); // temporary hack if (name.StartsWith("amazonkinesis")) { name = name.Replace("amazonkinesis", string.Empty); } switch (name) { case "filehelpers" when(providers.Contains("file") || providers.Contains("folder")): loadContext.Debug(() => "Loading filehelpers provider"); assemblies.Add(Assembly.LoadFile(new FileInfo(file).FullName)); break; case "ado": loadContext.Debug(() => "Loading ADO provider"); assemblies.Add(Assembly.LoadFile(new FileInfo(file).FullName)); break; default: if (providers.Contains(name)) { loadContext.Debug(() => $"Loading {name} provider."); var assembly = Assembly.LoadFile(new FileInfo(file).FullName); assemblies.Add(assembly); } else { loadContext.Debug(() => $"Loading {name} isn't necessary for this arrangement."); } break; } } if (assemblies.Any()) { builder.RegisterAssemblyModules(assemblies.ToArray()); } } // etc builder.RegisterCallback(new EntityPipelineModule(process).Configure); builder.RegisterCallback(new ProcessPipelineModule(process).Configure); builder.RegisterCallback(new ProcessControlModule(process).Configure); return(builder.Build().BeginLifetimeScope()); }
public static ILifetimeScope Create(Process process, IPipelineLogger logger, string placeHolderStyle) { var loadContext = new PipelineContext(logger, process); if (process.OutputIsConsole()) { logger.SuppressConsole(); } var builder = new ContainerBuilder(); builder.Properties["Process"] = process; builder.Register(ctx => placeHolderStyle).Named <string>("placeHolderStyle"); builder.RegisterInstance(logger).As <IPipelineLogger>().SingleInstance(); /* this stuff is loaded (again) because tfl actions can create processes, which will need short-hand to expand configuration in advance */ builder.RegisterCallback(new TransformModule(process, logger).Configure); builder.RegisterCallback(new ShorthandTransformModule().Configure); builder.RegisterCallback(new ValidateModule().Configure); builder.RegisterCallback(new ShorthandValidateModule().Configure); builder.RegisterCallback(new RootModule().Configure); builder.RegisterCallback(new ContextModule(process).Configure); // provider loading section var providers = new HashSet <string>(process.Connections.Select(c => c.Provider).Distinct(), StringComparer.OrdinalIgnoreCase); builder.RegisterCallback(new InternalModule(process).Configure); builder.RegisterCallback(new AdoModule(process).Configure); if (providers.Contains("console")) { builder.RegisterCallback(new ConsoleModule(process).Configure); } if (providers.Contains("file")) { builder.RegisterCallback(new FileModule(process).Configure); } if (providers.Contains("geojson")) { builder.RegisterCallback(new GeoJsonModule(process).Configure); } if (providers.Contains("kml")) { builder.RegisterCallback(new KmlModule(process).Configure); } if (providers.Contains("folder")) { builder.RegisterCallback(new FolderModule(process).Configure); } if (providers.Contains("filesystem")) { builder.RegisterCallback(new FileSystemModule(process).Configure); } if (providers.Contains("excel")) { builder.RegisterCallback(new ExcelModule(process).Configure); } if (providers.Contains("web")) { builder.RegisterCallback(new WebModule(process).Configure); } if (providers.Contains("rethinkdb")) { builder.RegisterCallback(new RethinkDBModule(process).Configure); } var pluginsFolder = Path.Combine(AssemblyDirectory, "plugins"); if (Directory.Exists(pluginsFolder)) { var assemblies = new List <Assembly>(); foreach (var file in Directory.GetFiles(pluginsFolder, "Transformalize.Provider.*.Autofac.dll", SearchOption.TopDirectoryOnly)) { var info = new FileInfo(file); var name = info.Name.ToLower().Split('.').FirstOrDefault(f => f != "dll" && f != "transformalize" && f != "provider" && f != "autofac"); if (!providers.Contains(name)) { continue; } loadContext.Debug(() => $"Loading {name} provider"); var assembly = Assembly.LoadFile(new FileInfo(file).FullName); assemblies.Add(assembly); } if (assemblies.Any()) { builder.RegisterAssemblyModules(assemblies.ToArray()); } } // template providers builder.RegisterCallback(new RazorModule(process).Configure); // etc builder.RegisterCallback(new MapModule(process).Configure); builder.RegisterCallback(new TemplateModule(process).Configure); builder.RegisterCallback(new ActionModule(process).Configure); builder.RegisterCallback(new EntityPipelineModule(process).Configure); builder.RegisterCallback(new ProcessPipelineModule(process).Configure); builder.RegisterCallback(new ProcessControlModule(process).Configure); return(builder.Build().BeginLifetimeScope()); }