private void RunTasks(string messageSuffix, IList <Action <ValidationArgs> > actions) { try { var args = new ValidationArgs(); JobContext.Job.Status.Result = args; JobContext.Job.Status.Total = 3 + actions.Count; ReportProgress(messageSuffix); _validator.GetContent(args); if (!string.IsNullOrWhiteSpace(args.Content)) { ReportProgress(messageSuffix); _validator.SendContent(args); foreach (var action in actions) { ReportProgress(messageSuffix); action(args); } ReportProgress(messageSuffix); _validator.Cleanup(args); } JobContext.SendMessage($"{messageSuffix}:success"); } catch (Exception ex) { JobContext.SendMessage($"{messageSuffix}:fail(error=" + ex.Message + ")"); } }
public override void GetContent(ValidationArgs args) { Item item; if (ItemUri == null || (item = Database.GetItem(ItemUri)) == null) { throw new ApplicationException("The item does not exist."); } if (!item.Paths.IsContentItem) { throw new ApplicationException("The item is not a content item."); } if (item.Visualization.Layout == null) { throw new ApplicationException("The item does not have layout defined."); } try { args.Content = ItemContentHelper.GetContent(item, Cookies); } catch (WebException ex) { throw new ApplicationException("The page failed to render properly: " + ex.Message, ex); } }
public void GetCheckpoints(ValidationArgs args) { var status = _client.GetAssetStatus(args.AssetId); args.TotalCheckpoints = status.TotalCheckpoints; args.TotalErrors = status.TotalErrors; args.List = status.Checkpoints; }
public void GetHighlights(ValidationArgs args, bool source) { if (source) { args.Source = new [] { _client.GetAssetError(args.AssetId, CheckpointId, true) }; } else { args.Preview = _client.GetPageHighlight(args.AssetId); } }
protected override ValidatorResult Evaluate() { try { var args = new ValidationArgs(); GetContent(args); if (string.IsNullOrWhiteSpace(args.Content)) { return(ValidatorResult.Valid); } SendContent(args); GetCheckpoints(args); Cleanup(args); if (args.TotalErrors == 0) { return(ValidatorResult.Valid); } var failed = 0; foreach (var checkpoint in args.List.Where(c => c.Failed)) { failed++; var name = HttpUtility.HtmlEncode(checkpoint.Name.Replace("<br/>", string.Empty)); Errors.Add(string.Format("{0}. {1}", checkpoint.Reference, name)); } Text = GetErrorText(failed, args.List.Length); return(GetFailedResult(ValidatorResult.Error)); } catch (Exception ex) { Text = ex.Message; return(ValidatorResult.Warning); } }
public void Cleanup(ValidationArgs args) { _client.DeleteAsset(args.AssetId); args.AssetId = null; }
public void SendContent(ValidationArgs args) { var asset = _client.CreateAsset(Settings.WebsiteId, args.Content, "text/html"); args.AssetId = asset.Id; }
public abstract void GetContent(ValidationArgs args);