예제 #1
0
        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(format, format);
                        process.Load(cfg);
                    }
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
 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
     });
 }
예제 #3
0
        public ActionResult Report(int id)
        {
            var timer = new Stopwatch();

            timer.Start();

            var process = new Process {
                Name = "Report"
            }.WithDefaults();

            var part = _orchardServices.ContentManager.Get(id).As <PipelineConfigurationPart>();

            if (part == null)
            {
                process.Name = "Not Found";
            }
            else
            {
                if (_orchardServices.Authorizer.Authorize(Permissions.ViewContent, part))
                {
                    process = _processService.Resolve(part.EditorMode, part.EditorMode);

                    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);

                    var provider = process.Output().Provider;
                    if (provider.In("internal", "file"))
                    {
                        // change process for export purposes
                        var output = Request["output"] ?? "page";
                        if (part.Reportable && output != "page")
                        {
                            ConvertToExport(process, part, parameters);
                            process.Load(process.Serialize(), parameters);
                            Response.AddHeader("content-disposition", "attachment; filename=" + process.Output().File);
                            Response.ContentType = "application/csv";
                        }

                        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())
                            {
                                Common.PageHelper(process, parameters);
                                var runner = _orchardServices.WorkContext.Resolve <IRunTimeExecute>();
                                try {
                                    runner.Execute(process);
                                    process.Status  = 200;
                                    process.Message = "Ok";
                                    process.Request = "Run";
                                    process.Time    = timer.ElapsedMilliseconds;
                                    if (process.Output().Provider == "file")
                                    {
                                        Response.Flush();
                                        Response.End();
                                    }
                                } catch (Exception ex) {
                                    Logger.Error(ex, ex.Message);
                                    _orchardServices.Notifier.Error(T(ex.Message));
                                }
                            }
                        }
                    }
                }
                else
                {
                    _orchardServices.Notifier.Warning(T("Output must be set to internal for reporting."));
                }
            }

            return(View(new ReportViewModel(process, part)));
        }