/// <summary> /// Validate the ticket and optionally add schema info (defaults and PVSI) /// </summary> /// <param name="addSchemaInfo">True adds default elements, default attributes and schema info to the ticket. False leaves this alone. Default is true.</param> /// <param name="workAroundMSBug">True works around an issue in the .NET framework that causes validation to work improperly on schema types that inherit /// from an abstract base class if the document is created via node authoring code instead of by Parse or Load methods. Default is true.</param> /// <returns></returns> public bool Validate(bool addSchemaInfo = true, bool workAroundMSBug = true) { //todo: this method should probably return ResultOf. ResultOf needs to be taken from connent and move to common to accomplish this properly. messages.Clear(); ticket.Document.Validate(SchemaSet.Instance.Schemas, (o, e) => messages.Add(new ValidationMessage(o, e.Severity, e.Message)),addSchemaInfo); if (workAroundMSBug) { using (var tempFileSream = new TempFileStream()) { messages.Clear(); ticket.Document.Save(tempFileSream); tempFileSream.Seek(0, SeekOrigin.Begin); var newDocument = XDocument.Load(tempFileSream); newDocument.Validate(SchemaSet.Instance.Schemas, (o, e) => messages.Add(new ValidationMessage(o, e.Severity, e.Message)), false); } } IsValid = messages.Where(m => m.ValidationMessageType == ValidationMessageType.Error).Count() == 0; Messages = new ReadOnlyCollection<ValidationMessage>(messages); HasValidatedAtLeastOnce = true; return IsValid.Value; }
/// <summary> /// Creates a ticket from a template in an XDocument. /// </summary> /// <param name="document"></param> /// <returns></returns> public static GeneratedTicketTemplateSelectionBuilder CreateFromTemplate(XDocument document) { var stream = new TempFileStream(); document.Save(stream); stream.Seek(0, SeekOrigin.Begin); return CreateFromTemplate(stream); }
/// <summary> /// Gets the stream associated with the part. /// </summary> public Stream CopyOfStream() { var tempStream = new TempFileStream(); Message.SaveHttpReady(tempStream); tempStream.Seek(0, SeekOrigin.Begin); return tempStream; }
/// <summary> /// Generate a tree for this template. /// </summary> /// <param name="vars">Name/value pairs.</param> /// <param name="makeIdsUnique">True to make ids in the file globally unique. If false, IDs will be taken from the template.</param> /// <param name="jobId">The new JobID value.</param> /// <returns>The tree containing the generated JDF.</returns> public XDocument Generate(Dictionary<string, object> vars, string jobId = null, bool makeIdsUnique = true) { ParameterCheck.ParameterRequired(vars, "vars"); XDocument tree = null; var buffStream = new TempFileStream(); StreamWriter writer = new StreamWriter(buffStream); try { items.Generate(writer, vars); writer.Flush(); buffStream.Seek(0, SeekOrigin.Begin); if (makeIdsUnique) { tree = GenerateNewIds(buffStream, jobId); } else { tree = XDocument.Load(buffStream); } } finally { writer.Close(); buffStream.Close(); } if (tree.XmlType() == XmlType.Jdf) { //the instance document is not a template so set Template to false in the root tree.Root.SetAttributeValue("Template", "false"); } RemoveNullValueAttributes(tree); return tree; }
/// <summary> /// CopyOfStream /// </summary> /// <returns></returns> public Stream CopyOfStream() { var tempStream = new TempFileStream(); stream.Seek(0, SeekOrigin.Begin); stream.CopyTo(tempStream); tempStream.Seek(0, SeekOrigin.Begin); stream.Seek(0, SeekOrigin.Begin); return tempStream; }