コード例 #1
0
        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
            });
        }
コード例 #2
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(part, format, format);
                        process.Load(cfg);
                    }
                    return(true);
                }
            }
            return(false);
        }
コード例 #3
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
     });
 }
コード例 #4
0
        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));

        }
コード例 #5
0
        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)));
        }