public static bool ValidateArchetype(ARCHETYPE archetype) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; settings.OmitXmlDeclaration = true; settings.Indent = false; MemoryStream stream = Serialize(settings, archetype); AmSerializer.ValidateArchetype(stream); return(true); }
public static string ArchetypeDigest(ARCHETYPE archetype) { var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, OmitXmlDeclaration = true, Indent = false }; //#if DEBUG // using (var writer = XmlWriter.Create(@".\CanonicalArchetype2.xml", new XmlWriterSettings { Indent = true })) // AmSerializer.Serialize(writer, archetype); //#endif byte[] data; using (MemoryStream stream = AmSerializer.Serialize(settings, archetype)) { #if XMLParser AmSerializer.ValidateArchetype(stream); #endif data = stream.ToArray(); } // Remove UTF-8 BOM int offset = 0; if (data.Length < 1) { throw new ApplicationException("Canonical archetype model must have length greater than 0"); } if (data[0] == 239) // UTF-8 BOM: EF BB BF (239 187 191) { offset = 3; if (data.Length <= offset) { throw new ApplicationException("Canonical archetype model must have length greater than the BOM offset"); } } if (data[offset] != 60) // XML root element (<) { throw new ApplicationException("Unexpected start character of canonical archetype model"); } MD5 md5 = new MD5CryptoServiceProvider(); SoapHexBinary hexEncoder = new SoapHexBinary(md5.ComputeHash(data, offset, data.Length - offset)); return(hexEncoder.ToString()); }
public static ARCHETYPE Build(openehr.openehr.am.archetype.ARCHETYPE archetype, CloneConstraintVisitor visitor) { if (archetype == null) { throw new ArgumentNullException("archetype must not be null"); } if (visitor == null) { throw new ArgumentNullException("visitor must not be null"); } ARCHETYPE result = visitor.CloneArchetype(archetype); #if XMLParser AmSerializer.ValidateArchetype(result); #endif return(result); }