Esempio n. 1
0
 /// <summary>
 /// Reads the body of an object
 /// </summary>
 public override object ReadObject(System.Xml.XmlDictionaryReader reader, bool verifyObjectName)
 {
     if (reader.GetAttribute("nil") == "true") return null;
     reader.ReadStartElement(PROTO_ELEMENT);
     try
     {
         using (MemoryStream ms = new MemoryStream(reader.ReadContentAsBase64()))
         {
             using (ProtoReader protoReader = new ProtoReader(ms, model, null))
             {
                 return model.Deserialize(key, null, protoReader);
             }
         }
     }
     finally
     {
         reader.ReadEndElement();
     }
 }
Esempio n. 2
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. 3
0
        /// <summary>
        /// Reads the body of an object
        /// </summary>
        public override object ReadObject(System.Xml.XmlDictionaryReader reader, bool verifyObjectName)
        {
            if (reader == null) throw new ArgumentNullException("reader");
            reader.MoveToContent();
            bool isSelfClosed = reader.IsEmptyElement, isNil = reader.GetAttribute("nil") == "true";
            reader.ReadStartElement(PROTO_ELEMENT);

            // explicitly null
            if (isNil)
            {
                if(!isSelfClosed) reader.ReadEndElement();
                return null;
            }
            if(isSelfClosed) // no real content
            {
                if (isList || isEnum)
                {
                    return model.Deserialize(Stream.Null, null, type, null);
                }
                ProtoReader protoReader = null;
                try
                {
                    protoReader = ProtoReader.Create(Stream.Null, model, null, ProtoReader.TO_EOF);
                    return model.Deserialize(key, null, protoReader);
                }
                finally
                {
                    ProtoReader.Recycle(protoReader);
                }
            }

            object result;
            Helpers.DebugAssert(reader.CanReadBinaryContent, "CanReadBinaryContent");
            using (MemoryStream ms = new MemoryStream(reader.ReadContentAsBase64()))
            {
                if (isList || isEnum)
                {
                    result = model.Deserialize(ms, null, type, null);
                }
                else
                {
                    ProtoReader protoReader = null;
                    try
                    {
                        protoReader = ProtoReader.Create(ms, model, null, ProtoReader.TO_EOF);
                        result = model.Deserialize(key, null, protoReader);
                    }
                    finally
                    {
                        ProtoReader.Recycle(protoReader);
                    }
                }
            }
            reader.ReadEndElement();
            return result;
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Parse the image response.
        /// </summary>
        /// <param name="oReader">The GeosoftXML response</param>
        /// <param name="oBitmap">The image</param>
        public void Legend(System.Xml.XmlReader oReader, out System.Drawing.Bitmap oBitmap)
        {
            System.IO.MemoryStream oMemStream = new System.IO.MemoryStream();
            oBitmap = null;

            try
            {

                // --- find the dataset edition element ---
                if (oReader.ReadToFollowing(Constant.Tag.LEGEND_TAG))
                {
                    string strValue = oReader.GetAttribute(Constant.Attribute.VALUE_ATTR);
                    bool bValue;

                    if (string.IsNullOrEmpty(strValue))
                        return;

                    if (!bool.TryParse(strValue, out bValue))
                        return;

                    if (!bValue)
                        return;

                    byte[] bImage = new byte[4096];
                    int iCount = 0;

                    do
                    {
                        iCount = oReader.ReadContentAsBase64(bImage, 0, 4096);
                        if (iCount > 0)
                            oMemStream.Write(bImage, 0, iCount);
                    } while (iCount > 0);

                    oMemStream.Seek(0, System.IO.SeekOrigin.Begin);
                    oBitmap = new System.Drawing.Bitmap(oMemStream);
                }
            }
            catch (Exception e)
            {
                throw new DapException("Error retrieving legend", e);
            }
            finally
            {
                oMemStream.Close();
            }
        }