예제 #1
0
 public void WriteXml(System.Xml.XmlWriter writer)
 {
     if (!string.IsNullOrEmpty(value))
     {
         byte[] rawData = Encoding.Unicode.GetBytes(value);
         writer.WriteBase64(rawData, 0, rawData.Length);
     }
 }
예제 #2
0
        /// <summary>
        /// Function to call when serializing this object to XML
        /// </summary>
        /// <param name="writer">The xml writer</param>
        public virtual void WriteXml(System.Xml.XmlWriter writer)
        {
            writer.WriteAttributeString("Rows", Rows.ToString());
            writer.WriteAttributeString("Cols", Cols.ToString());
            writer.WriteAttributeString("NumberOfChannels", NumberOfChannels.ToString());
            writer.WriteAttributeString("CompressionRatio", SerializationCompressionRatio.ToString());

            writer.WriteStartElement("Bytes");
            Byte[] bytes = Bytes;
            writer.WriteBase64(bytes, 0, bytes.Length);
            writer.WriteEndElement();
        }
예제 #3
0
 void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
 {
     if (Abc != null)
     {
         writer.WriteElementString("Abc", Abc);
     }
     if (Bcd != null)
     {
         writer.WriteStartElement("Bcd");
         writer.WriteBase64(Bcd, 0, Bcd.Length);
         writer.WriteEndElement();
     }
 }
예제 #4
0
        void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
        {
            writer.WriteAttributeString("Rows", this.Height.ToString());
            writer.WriteAttributeString("Cols", this.Width.ToString());
            writer.WriteAttributeString("NumberOfChannels", this.ColorInfo.NumberOfChannels.ToString()); //not used (EmguCV compatibility)
            writer.WriteAttributeString("CompressionRatio", 0.ToString());                               //not used (EmguCV compatibility)

            using (PinnedArray <byte> buff = ((this as IImage).Clone() as Image).buffer)                 //if an user selected GetSubRect(...)
            {
                writer.WriteStartElement("Bytes");
                writer.WriteBase64(buff.Array, 0, buff.Array.Length);
                writer.WriteEndElement();
            }
        }
예제 #5
0
 public void WriteXml(System.Xml.XmlWriter writer)
 {
     writer.WriteStartElement("Name");
     writer.WriteString(this.Name);
     writer.WriteEndElement();
     using (MemoryStream ms = new MemoryStream())
     {
         this.Image.Save(ms, ImageFormat.Bmp);
         byte[] bitmapData = ms.ToArray();
         writer.WriteStartElement("Image");
         writer.WriteBase64(bitmapData, 0, bitmapData.Length);
         writer.WriteEndElement();
     }
 }
 /// <summary>
 /// Writes a protocol-buffer representation of the given instance to the supplied XmlWriter.
 /// </summary>
 /// <typeparam name="T">The type being serialized.</typeparam>
 /// <param name="instance">The existing instance to be serialized (cannot be null).</param>
 /// <param name="writer">The destination XmlWriter to write to.</param>
 public static void Serialize <[DynamicallyAccessedMembers(DynamicAccess.ContractType)] T>(System.Xml.XmlWriter writer, T instance) where T : System.Xml.Serialization.IXmlSerializable
 {
     if (writer is null)
     {
         throw new ArgumentNullException(nameof(writer));
     }
     if (instance is null)
     {
         throw new ArgumentNullException(nameof(instance));
     }
     using MemoryStream ms = new MemoryStream();
     Serializer.Serialize <T>(ms, instance);
     Helpers.GetBuffer(ms, out var segment);
     writer.WriteBase64(segment.Array, segment.Offset, segment.Count);
 }
예제 #7
0
        /// <summary>
        /// Writes a protocol-buffer representation of the given instance to the supplied XmlWriter.
        /// </summary>
        /// <typeparam name="T">The type being serialized.</typeparam>
        /// <param name="instance">The existing instance to be serialized (cannot be null).</param>
        /// <param name="writer">The destination XmlWriter to write to.</param>
        public static void Serialize <T>(System.Xml.XmlWriter writer, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            using (MemoryStream ms = new MemoryStream())
            {
                Serializer.Serialize(ms, instance);
                writer.WriteBase64(ms.GetBuffer(), 0, (int)ms.Length);
            }
        }
예제 #8
0
        /// <summary>
        /// Writes a protocol-buffer representation of the given instance to the supplied XmlWriter.
        /// </summary>
        /// <typeparam name="T">The type being serialized.</typeparam>
        /// <param name="instance">The existing instance to be serialized (cannot be null).</param>
        /// <param name="writer">The destination XmlWriter to write to.</param>
        public static void Serialize <T>(System.Xml.XmlWriter writer, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
#pragma warning disable RCS1165 // Unconstrained type parameter checked for null.
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
#pragma warning restore RCS1165 // Unconstrained type parameter checked for null.

            using MemoryStream ms = new MemoryStream();
            Serializer.Serialize <T>(ms, instance);
            Helpers.GetBuffer(ms, out var segment);
            writer.WriteBase64(segment.Array, segment.Offset, segment.Count);
        }
예제 #9
0
        /// <summary>
        /// Writes a protocol-buffer representation of the given instance to the supplied XmlWriter.
        /// </summary>
        /// <typeparam name="T">The type being serialized.</typeparam>
        /// <param name="instance">The existing instance to be serialized (cannot be null).</param>
        /// <param name="writer">The destination XmlWriter to write to.</param>
        public static void Serialize <T>(System.Xml.XmlWriter writer, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
#pragma warning disable RCS1165 // Unconstrained type parameter checked for null.
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
#pragma warning restore RCS1165 // Unconstrained type parameter checked for null.

            using (MemoryStream ms = new MemoryStream())
            {
                Serializer.Serialize(ms, instance);
                writer.WriteBase64(Helpers.GetBuffer(ms), 0, (int)ms.Length);
            }
        }
예제 #10
0
 public override void Write(System.Xml.XmlWriter writer)
 {
     writer.WriteStartElement("data");
     writer.WriteBase64(Value, Value.Length, 1);
     writer.WriteEndElement();
 }
예제 #11
0
 public void WriteBase64(byte[] buffer, int index, int count)
 {
     _writer.WriteBase64(buffer, index, count);
 }
예제 #12
0
        protected override void WriteXmlBase(System.Xml.XmlWriter writer)
        {
            base.WriteXmlBase(writer);

            string xsiPrefix     = RmXmlSerializer.UseXsiPrefix(writer);
            string openEhrPrefix = RmXmlSerializer.UseOpenEhrPrefix(writer);

            if (this.AlternateText != null)
            {
                writer.WriteElementString(openEhrPrefix, "alternate_text", RmXmlSerializer.OpenEhrNamespace, this.AlternateText);
            }
            if (this.Uri != null)
            {
                writer.WriteStartElement(openEhrPrefix, "uri", RmXmlSerializer.OpenEhrNamespace);
                if (this.Uri.GetType() == typeof(OpenEhr.RM.DataTypes.Uri.DvEhrUri))
                {
                    string ehrUriType = "DV_EHR_URI";
                    if (!string.IsNullOrEmpty(openEhrPrefix))
                    {
                        ehrUriType = openEhrPrefix + ":" + ehrUriType;
                    }
                    writer.WriteAttributeString(xsiPrefix, "type", RmXmlSerializer.XsiNamespace, ehrUriType);
                }
                this.Uri.WriteXml(writer);
                writer.WriteEndElement();
            }

            if (this.Data != null)
            {
                writer.WriteStartElement(openEhrPrefix, "data", RmXmlSerializer.OpenEhrNamespace);
                writer.WriteBase64(this.Data, 0, this.Data.Length);
                writer.WriteEndElement();
            }

            if (this.MediaType != null)
            {
                writer.WriteStartElement(openEhrPrefix, "media_type", RmXmlSerializer.OpenEhrNamespace);
                this.MediaType.WriteXml(writer);
                writer.WriteEndElement();
            }

            if (this.CompressionAlgorithm != null)
            {
                writer.WriteStartElement(openEhrPrefix, "compression_algorithm", RmXmlSerializer.OpenEhrNamespace);
                this.CompressionAlgorithm.WriteXml(writer);
                writer.WriteEndElement();
            }

            if (this.IntegrityCheck != null)
            {
                writer.WriteStartElement(openEhrPrefix, "integrity_check", RmXmlSerializer.OpenEhrNamespace);
                writer.WriteBase64(this.IntegrityCheck, 0, this.IntegrityCheck.Length);
                writer.WriteEndElement();
            }

            if (this.IntegrityCheckAlgorithm != null)
            {
                writer.WriteStartElement(openEhrPrefix, "integrity_check_algorithm", RmXmlSerializer.OpenEhrNamespace);
                this.IntegrityCheckAlgorithm.WriteXml(writer);
                writer.WriteEndElement();
            }

            writer.WriteElementString(openEhrPrefix, "size", RmXmlSerializer.OpenEhrNamespace, this.Size.ToString());

            if (this.Thumbnail != null)
            {
                writer.WriteStartElement(openEhrPrefix, "thumbnail", RmXmlSerializer.OpenEhrNamespace);
                this.Thumbnail.WriteXml(writer);
                writer.WriteEndElement();
            }
        }
예제 #13
0
        /// <summary>
        /// Graph object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            // Get an instance ref
            ED instance_ed = (ED)o;

            // Do a base format
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);

            // Null flavor
            if (((ANY)o).NullFlavor != null)
            {
                return;
            }

            // Attributes
            if (instance_ed.MediaType != null && instance_ed.Representation != EncapsulatedDataRepresentation.TXT)
            {
                s.WriteAttributeString("mediaType", instance_ed.MediaType);
            }
            if (instance_ed.Language != null)
            {
                s.WriteAttributeString("language", instance_ed.Language);
            }
            if (instance_ed.Compression != null)
            {
                s.WriteAttributeString("compression", Util.ToWireFormat(instance_ed.Compression));
            }
            if (instance_ed.IntegrityCheckAlgorithm != null)
            {
                s.WriteAttributeString("integrityCheckAlgorithm", Util.ToWireFormat(instance_ed.IntegrityCheckAlgorithm));
            }

            Encoding textEncoding = System.Text.Encoding.UTF8;

            // Representation of data
            if (instance_ed.Data != null && instance_ed.Data.Length > 0)
            {
                switch (instance_ed.Representation)
                {
                case EncapsulatedDataRepresentation.TXT:
                    s.WriteAttributeString("value", textEncoding.GetString(instance_ed.Data));
                    break;

                case EncapsulatedDataRepresentation.B64:
                    s.WriteStartElement("data", "urn:hl7-org:v3");
                    s.WriteBase64(instance_ed.Data, 0, instance_ed.Data.Length);
                    s.WriteEndElement();    // data
                    break;

                case EncapsulatedDataRepresentation.XML:
                    s.WriteStartElement("xml", "urn:hl7-org:v3");
                    s.WriteRaw(instance_ed.XmlData.OuterXml);
                    s.WriteEndElement();     // xml
                    break;
                }
            }

            // Elements
            if (instance_ed.Reference != null)
            {
                s.WriteStartElement("reference", "urn:hl7-org:v3");
                var hostResult = Host.Graph(s, instance_ed.Reference);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }
            if (instance_ed.IntegrityCheck != null && instance_ed.IntegrityCheck.Length > 0)
            {
                s.WriteStartElement("integrityCheck", "urn:hl7-org:v3");
                s.WriteBase64(instance_ed.IntegrityCheck, 0, instance_ed.IntegrityCheck.Length);
                s.WriteEndElement(); // intcheck
            }
            if (instance_ed.Thumbnail != null)
            {
                s.WriteStartElement("thumbnail", "urn:hl7-org:v3");
                var hostResult = Host.Graph(s, instance_ed.Thumbnail);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);

                s.WriteEndElement();
            }
            if (instance_ed.Description != null)
            {
                s.WriteStartElement("description", "urn:hl7-org:v3");
                var hostResult = Host.Graph(s, instance_ed.Description);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }
            if (instance_ed.Translation != null && !instance_ed.Translation.IsNull)
            {
                foreach (var trans in instance_ed.Translation)
                {
                    s.WriteStartElement("translation", "urn:hl7-org:v3");
                    var hostResult = Host.Graph(s, trans);
                    result.Code = hostResult.Code;
                    result.AddResultDetail(hostResult.Details);
                    s.WriteEndElement(); // translation
                }
            }
        }
예제 #14
0
        /// <summary>
        /// Graph the object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The XmlWriter to write the object to</param>
        /// <param name="o">The object to graph</param>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Get an instance ref
            ED instance_ed = (ED)o;

            // Do a base format
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);

            // Null flavor
            if (((ANY)o).NullFlavor != null)
            {
                return;
            }

            // Attributes
            s.WriteAttributeString("representation", Util.ToWireFormat(instance_ed.Representation));
            if (instance_ed.MediaType != null)
            {
                s.WriteAttributeString("mediaType", Util.ToWireFormat(instance_ed.MediaType));
            }
            if (instance_ed.Language != null)
            {
                s.WriteAttributeString("language", instance_ed.Language);
            }
            if (instance_ed.Compression != null)
            {
                s.WriteAttributeString("compression", Util.ToWireFormat(instance_ed.Compression));
            }
            if (instance_ed.IntegrityCheck != null)
            {
                s.WriteAttributeString("integrityCheck", Convert.ToBase64String(instance_ed.IntegrityCheck));
            }
            if (instance_ed.Description != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Description", "ED", s.ToString()));
            }
            if (instance_ed.IntegrityCheckAlgorithm != null)
            {
                // Incorrect representation of the SHA1 and SHA256 names in r1
                switch ((EncapsulatedDataIntegrityAlgorithm)instance_ed.IntegrityCheckAlgorithm)
                {
                case EncapsulatedDataIntegrityAlgorithm.SHA1:
                    s.WriteAttributeString("integrityCheckAlgorithm", "SHA-1");
                    break;

                case EncapsulatedDataIntegrityAlgorithm.SHA256:
                    s.WriteAttributeString("integrityCheckAlgorithm", "SHA-256");
                    break;
                }
            }

            // Elements
            if (instance_ed.Reference != null)
            {
                TELFormatter refFormatter = new TELFormatter();
                s.WriteStartElement("reference", "urn:hl7-org:v3");
                refFormatter.Graph(s, instance_ed.Reference, result);
                s.WriteEndElement();
            }
            if (instance_ed.Thumbnail != null)
            {
                EDFormatter thumbFormatter = new EDFormatter();
                s.WriteStartElement("thumbnail", "urn:hl7-org:v3");
                thumbFormatter.Graph(s, instance_ed.Thumbnail, result);
                s.WriteEndElement();
            }
            if (instance_ed.Translation != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Translation", "ED", s.ToString()));
            }
            Encoding textEncoding = System.Text.Encoding.UTF8;

            // Value
            if (instance_ed.Data != null && instance_ed.Data.Length > 0)
            {
                if (instance_ed.Representation == EncapsulatedDataRepresentation.B64)
                {
                    s.WriteBase64(instance_ed.Data, 0, instance_ed.Data.Length);
                }
                else if (instance_ed.Representation == EncapsulatedDataRepresentation.TXT)
                {
                    s.WriteString(textEncoding.GetString(instance_ed.Data));
                }
                else
                {
                    char[] charBuffer = textEncoding.GetChars(instance_ed.Data);
                    s.WriteRaw(charBuffer, 0, charBuffer.Length);
                }
            }
        }
예제 #15
0
 public void WriteXml(System.Xml.XmlWriter writer)
 {
     writer.WriteBase64(segment.Array, segment.Offset, segment.Count);
     writer.Flush();
 }