Esempio n. 1
0
        /// <summary>
        /// Applies a protocol-buffer from an XmlReader to an existing instance.
        /// </summary>
        /// <typeparam name="T">The type being merged.</typeparam>
        /// <param name="instance">The existing instance to be modified (cannot be null).</param>
        /// <param name="reader">The XmlReader containing the data to apply to the instance (cannot be null).</param>
        public static void Merge <[DynamicallyAccessedMembers(DynamicAccess.ContractType)] T>(System.Xml.XmlReader reader, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (reader is null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (instance is null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
            const int LEN = 4096;

            byte[] buffer = new byte[LEN];
            int    read;

            using MemoryStream ms = new MemoryStream();
            int depth = reader.Depth;

            while (reader.Read() && reader.Depth > depth)
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                {
                    while ((read = reader.ReadContentAsBase64(buffer, 0, LEN)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    if (reader.Depth <= depth)
                    {
                        break;
                    }
                }
            }
            ms.Position = 0;
            Serializer.Merge(ms, instance);
        }
Esempio n. 2
0
        /// <summary>
        /// Applies a protocol-buffer from an XmlReader to an existing instance.
        /// </summary>
        /// <typeparam name="T">The type being merged.</typeparam>
        /// <param name="instance">The existing instance to be modified (cannot be null).</param>
        /// <param name="reader">The XmlReader containing the data to apply to the instance (cannot be null).</param>
        public static void Merge <T>(System.Xml.XmlReader reader, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
#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.

            const int LEN    = 4096;
            byte[]    buffer = new byte[LEN];
            int       read;
            using MemoryStream ms = new MemoryStream();
            int depth = reader.Depth;
            while (reader.Read() && reader.Depth > depth)
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                {
                    while ((read = reader.ReadContentAsBase64(buffer, 0, LEN)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    if (reader.Depth <= depth)
                    {
                        break;
                    }
                }
            }
            ms.Position = 0;
            Serializer.Merge(ms, instance);
        }
Esempio n. 3
0
    void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
    {
        reader.ReadStartElement();
        reader.ReadStartElement("Abc");
        Abc = reader.ReadString();
        reader.ReadEndElement();
        reader.ReadStartElement("Bcd");
        reader.Read();
        MemoryStream ms = null;

        byte[] buffer = new byte[256];
        int    bytesRead;

        while ((bytesRead = reader.ReadContentAsBase64(buffer, 0, buffer.Length)) > 0)
        {
            if (ms == null)
            {
                ms = new MemoryStream(bytesRead);
            }
            ms.Write(buffer, 0, bytesRead);
        }
        if (ms != null)
        {
            Bcd = ms.ToArray();
        }
        reader.ReadEndElement();
    }
Esempio n. 4
0
        /// <summary>

        /// Applies a protocol-buffer from an XmlReader to an existing instance.

        /// </summary>

        /// <typeparam name="T">The type being merged.</typeparam>

        /// <param name="instance">The existing instance to be modified (cannot be null).</param>

        /// <param name="reader">The XmlReader containing the data to apply to the instance (cannot be null).</param>

        public static void Merge <T>(System.Xml.XmlReader reader, T instance) where T : System.Xml.Serialization.IXmlSerializable

        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }



            const int LEN = 4096;

            byte[] buffer = new byte[LEN];

            int read;

            using (MemoryStream ms = new MemoryStream())

            {
                int depth = reader.Depth;

                while (reader.Read() && reader.Depth > depth)

                {
                    if (reader.NodeType == System.Xml.XmlNodeType.Text)

                    {
                        while ((read = reader.ReadContentAsBase64(buffer, 0, LEN)) > 0)

                        {
                            ms.Write(buffer, 0, read);
                        }

                        if (reader.Depth <= depth)
                        {
                            break;
                        }
                    }
                }

                ms.Position = 0;

                Serializer.Merge(ms, instance);
            }
        }
Esempio n. 5
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            reader.Read();

            List <ArraySegment <byte> > data = new List <ArraySegment <byte> >();

            for (; ;)
            {
                byte[] buffer    = new byte[65536];
                int    bytesRead = reader.ReadContentAsBase64(buffer, 0, buffer.Length);
                if (bytesRead > 0)
                {
                    data.Add(new ArraySegment <byte>(buffer, 0, bytesRead));
                }
                else
                {
                    if (data.Count == 0)
                    {
                        segment = new ArraySegment <byte>();
                    }
                    else if (data.Count == 1)
                    {
                        segment = data[0];
                    }
                    else if (data.Count > 1)
                    {
                        int    totalBytes   = data.Sum((seg) => seg.Count);
                        byte[] joinedBuffer = new byte[totalBytes];
                        int    offset       = 0;
                        foreach (var seg in data)
                        {
                            Buffer.BlockCopy(seg.Array, seg.Offset, joinedBuffer, offset, seg.Count);
                            offset += seg.Count;
                        }
                        segment = new ArraySegment <byte>(joinedBuffer, 0, totalBytes);
                    }
                    return;
                }
            }
        }
Esempio n. 6
0
        protected override void ReadXmlBase(System.Xml.XmlReader reader)
        {
            base.ReadXmlBase(reader);

            if (reader.LocalName == "alternate_text")
            {
                this.alternateText = reader.ReadElementString("alternate_text", RmXmlSerializer.OpenEhrNamespace);
            }
            reader.MoveToContent();

            if (reader.LocalName == "uri")
            {
                string uriType = reader.GetAttribute("type", RmXmlSerializer.XsiNamespace);
                if (uriType != null)
                {
                    Check.Assert(uriType.IndexOf("DV_EHR_URI") > 0, "uriType must be DV_EHR_URI, but it is " + uriType);
                    this.uri = new OpenEhr.RM.DataTypes.Uri.DvEhrUri();
                }
                this.uri = new OpenEhr.RM.DataTypes.Uri.DvUri();
                this.uri.ReadXml(reader);
            }

            if (reader.LocalName == "data")
            {
                reader.MoveToContent();
                reader.ReadStartElement();
                byte[] buffer = new byte[1024];
                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
                int bytesRead = reader.ReadContentAsBase64(buffer, 0, 1024);
                while (bytesRead > 0)
                {
                    writer.Write(buffer, 0, bytesRead);
                    bytesRead = reader.ReadContentAsBase64(buffer, 0, 1024);
                }
                writer.Close();
                reader.MoveToContent();
                reader.ReadEndElement();
                this.data = stream.ToArray();
            }
            reader.MoveToContent();

            if (reader.LocalName == "media_type")
            {
                this.mediaType = new OpenEhr.RM.DataTypes.Text.CodePhrase();
                this.mediaType.ReadXml(reader);
            }

            if (reader.LocalName == "compression_algorithm")
            {
                this.compressionAlgorithm = new OpenEhr.RM.DataTypes.Text.CodePhrase();
                this.compressionAlgorithm.ReadXml(reader);
            }

            if (reader.LocalName == "integrity_check")
            {
                reader.ReadElementContentAsBase64(this.integrityCheck, 0, this.integrityCheck.Length);
            }
            reader.MoveToContent();

            if (reader.LocalName == "integrity_check_algorithm")
            {
                this.integrityCheckAlgorithm = new OpenEhr.RM.DataTypes.Text.CodePhrase();
                this.integrityCheckAlgorithm.ReadXml(reader);
            }

            Check.Assert(reader.LocalName == "size", "Expected LocalName is 'size', not " + reader.LocalName);
            this.size = reader.ReadElementContentAsInt("size", RmXmlSerializer.OpenEhrNamespace);
            reader.MoveToContent();

            if (reader.LocalName == "thumbnail")
            {
                this.thumbnail = new DvMultimedia();
                this.thumbnail.ReadXml(reader);
            }
        }