public ActionResult Save(int id) { Response.AddHeader("Access-Control-Allow-Origin", "*"); if (!User.Identity.IsAuthenticated) { return(new HttpUnauthorizedResult()); } var part = _orchardServices.ContentManager.Get(id).As <PipelineConfigurationPart>(); if (part == null) { return(new HttpNotFoundResult()); } if (!_orchardServices.Authorizer.Authorize(global::Orchard.Core.Contents.Permissions.ViewContent, part)) { return(new HttpUnauthorizedResult()); } var process = _processService.Resolve(part, part.EditorMode, "json"); process.Load(part.Configuration, _query); if (!string.IsNullOrEmpty(Request.Form["data"])) { var data = _jsonConverter.Deserialize(Request.Form["data"]); Response.ContentType = "application/json"; var inputFields = process.Entities[0].Fields.Where(f => f.Input).ToArray(); var inputFieldNames = inputFields.Select(f => f.Name).ToArray(); foreach (var item in data.rows) { var row = new CfgRow(inputFieldNames); for (var i = 0; i < inputFields.Length; i++) { var field = inputFields[i]; try { var value = field.Convert(item[i].Value); row[field.Name] = value; } catch (Exception) { process.Log.Add(new LogEntry(LogLevel.Error, null, "Trouble converting field {0}'s value {1} to data type {2}.", field.Alias, item[i].Value, field.Type)); return(new ContentResult { Content = process.Serialize() }); } } process.Entities[0].Rows.Add(row); } var runner = _orchardServices.WorkContext.Resolve <IRunTimeExecute>(); runner.Execute(process); process.Status = process.Log.Any(l => l.Level == "error") ? (short)500 : (short)200; return(new ContentResult { Content = process.Serialize() }); } return(new HttpStatusCodeResult(500)); }
public int Write(HttpRequestBase request, Process process, IDictionary <string, string> parameters) { var rows = new List <CfgRow>(); var batchWrite = process.Actions.FirstOrDefault(a => a.Description.Equals(BatchWriteIndicator, StringComparison.OrdinalIgnoreCase)); if (!(batchWrite != null && batchWrite.Id > 0)) { const string message = "Could not find BatchWrite action. You need to have an action with description 'BatchWrite' that is responsible for writing your batch somewhere."; Logger.Error(message); _orchardServices.Notifier.Error(T(message)); return(0); } var part = _orchardServices.ContentManager.Get(batchWrite.Id).As <PipelineConfigurationPart>(); var writer = _processService.Resolve(part); writer.Load(part.Configuration, parameters); if (writer.Errors().Any()) { foreach (var error in writer.Errors()) { _orchardServices.Notifier.Add(NotifyType.Error, T(error)); Logger.Error(error); } return(0); } try { // populate rows with a search or from the request var batchId = parameters["BatchId"]; if (parameters.ContainsKey("count") && parameters["count"] == "All") // with a search { process.Entities.First().Page = 0; process.Output().Provider = "internal"; foreach (var field in process.Entities.First().GetAllFields()) { field.Output = field.Alias == "BatchValue"; } _orchardServices.WorkContext.Resolve <IRunTimeExecute>().Execute(process); rows = process.Entities.First().Rows; } else { var values = request.Form.GetValues("row") ?? request.QueryString.GetValues("row"); // from the request if (values == null) { _orchardServices.Notifier.Warning(T("No rows submitted to bulk action.")); } else { foreach (var value in values) { var row = new CfgRow(new[] { "BatchId", "BatchValue" }); row["BatchId"] = batchId; row["BatchValue"] = value; rows.Add(row); } } } if (rows.Count > 0) { writer.Entities.First().Rows.AddRange(rows); _orchardServices.WorkContext.Resolve <IRunTimeExecute>().Execute(writer); } return(rows.Count); } catch (Exception ex) { _orchardServices.Notifier.Error(T(ex.Message)); Logger.Error(ex, ex.Message); return(0); } }
public bool IsValid(CfgRow row, Field field) { return(Request.HttpMethod == "GET" || field.ValidField == string.Empty || (bool)row[field.ValidField]); }
public string Status(CfgRow row, Field field) { return(IsValid(row, field) ? string.Empty : "has-error"); }
public JvRequest(CfgRow row, string script) { Row = row; Script = script ?? string.Empty; }