예제 #1
0
        private bool WriteInstrumentableParameter(BinaryWriter writer)
        {
            // Ask it.

            IInstrumentable instrumentable = m_value as IInstrumentable;

            if (instrumentable == null)
            {
                return(false);
            }

            // Ask it to save its details.

            InstrumentationDetails details = new InstrumentationDetails();

            instrumentable.Write(details);

            // Write to a stream.

            IBinarySerializable serializable = details;
            MemoryStream        stream       = new MemoryStream();

            using (BinaryWriter valueWriter = new BinaryWriter(stream))
            {
                serializable.Write(valueWriter);
                WriteValueInfo(writer, new ClassInfo(typeof(InstrumentationDetails)), ValueFormat.LinkMeBinary);
                BinaryWriteAdaptor adaptor = new BinaryWriteAdaptor(writer);
                adaptor.Write(stream.ToArray());
            }

            return(true);
        }
예제 #2
0
        private bool WriteSystemBinaryParameter(BinaryWriter writer)
        {
            System.Type type = m_value.GetType();
            if (!type.IsSerializable)
            {
                return(false);
            }

            try
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(stream, m_value);
                    WriteValueInfo(writer, new ClassInfo(type), ValueFormat.SystemBinary);
                    BinaryWriteAdaptor adaptor = new BinaryWriteAdaptor(writer);
                    adaptor.Write(stream.ToArray());
                }

                return(true);
            }
            catch (System.Exception)
            {
                return(false);
            }
        }
예제 #3
0
        private bool WriteLinkMeBinaryParameter(BinaryWriter writer)
        {
            // Ask the object to serialize itself using the IBinarySerializable interface.

            IBinarySerializable serializable = m_value as IBinarySerializable;

            if (serializable == null)
            {
                return(false);
            }

            // Write to a stream.

            MemoryStream stream = new MemoryStream();

            using (BinaryWriter valueWriter = new BinaryWriter(stream))
            {
                serializable.Write(valueWriter);
                WriteValueInfo(writer, new ClassInfo(m_value.GetType()), ValueFormat.LinkMeBinary);
                BinaryWriteAdaptor adaptor = new BinaryWriteAdaptor(writer);
                adaptor.Write(stream.ToArray());
            }

            return(true);
        }
예제 #4
0
        public void Write(BinaryWriter writer)
        {
            var adaptor = new BinaryWriteAdaptor(writer);

            adaptor.Write(_encodingName);
            adaptor.Write(_length);
            adaptor.Write(_type);
        }
예제 #5
0
        public void Write(BinaryWriter writer)
        {
            var adaptor = new BinaryWriteAdaptor(writer);

            adaptor.Write(_cookies.Count);
            for (var index = 0; index < _cookies.Count; ++index)
            {
                _cookies[index].Write(writer);
            }
        }
예제 #6
0
        public void Write(BinaryWriter writer)
        {
            var adaptor = new BinaryWriteAdaptor(writer);

            adaptor.WriteNullable(_key);
            adaptor.Write(_values.Length);
            for (var index = 0; index < _values.Length; ++index)
            {
                adaptor.WriteNullable(_values[index]);
            }
        }
예제 #7
0
        public void Write(BinaryWriter writer)
        {
            var adaptor = new BinaryWriteAdaptor(writer);

            adaptor.WriteNullable(_domain);
            adaptor.Write(DateTime.FromSystemDateTime(_expires, TimeZone.UTC));
            adaptor.Write(_httpOnly);
            adaptor.WriteNullable(_name);
            adaptor.WriteNullable(_path);
            adaptor.Write(_secure);
            adaptor.WriteNullable(_value);
        }
예제 #8
0
        private bool WriteEnumParameter(BinaryWriter writer)
        {
            if (m_value == null || !(m_value is System.Enum))
            {
                return(false);
            }

            // Write out the enum as a string.

            WriteValueInfo(writer, new ClassInfo(m_value.GetType()), ValueFormat.String);
            BinaryWriteAdaptor adaptor = new BinaryWriteAdaptor(writer);

            adaptor.Write(m_value.ToString());
            return(true);
        }
예제 #9
0
        private void WriteStandard(BinaryWriter writer)
        {
            var adaptor = new BinaryWriteAdaptor(writer);

            adaptor.Write(_event);
            adaptor.Write(_source);
            adaptor.Write(_type);
            adaptor.Write(_method);
            adaptor.Write(_message);
            adaptor.Write(_time.Ticks);
            adaptor.Write(_sequence);

            adaptor.Write(_exception != null);
            if (_exception != null)
            {
                ((IBinarySerializable)_exception).Write(writer);
            }
        }
예제 #10
0
        private bool WritePrimitiveTypeParameter(BinaryWriter writer)
        {
            // Get the info.

            PrimitiveTypeInfo primitiveTypeInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(m_value.GetType());

            if (primitiveTypeInfo == null)
            {
                return(false);
            }

            // Indicate that the value is not null.

            WriteRawValueInfo(writer, m_valueFormat, false);

            BinaryWriteAdaptor adaptor = new BinaryWriteAdaptor(writer);

            adaptor.Write(m_value);
            return(true);
        }
예제 #11
0
        private void Write(BinaryWriteAdaptor adaptor, List <InstrumentationEntry> entries)
        {
            adaptor.Write(entries.Count);
            foreach (InstrumentationEntry entry in entries)
            {
                // Key.

                if (entry.Key == null)
                {
                    adaptor.Write(true);
                }
                else
                {
                    adaptor.Write(false);
                    adaptor.Write(entry.Key);
                }

                // Value.

                if (entry.Value == null)
                {
                    adaptor.Write(true);
                }
                else
                {
                    adaptor.Write(false);
                    InstrumentationDetails details = entry.Value as InstrumentationDetails;
                    if (details != null)
                    {
                        adaptor.Write(true);
                        Write(adaptor, details.m_entries);
                    }
                    else
                    {
                        adaptor.Write(false);
                        adaptor.Write(entry.Value);
                    }
                }
            }
        }
예제 #12
0
        public void Write(BinaryWriter writer)
        {
            BinaryWriteAdaptor adaptor = new BinaryWriteAdaptor(writer);

            adaptor.Write(m_headers.Count);
            for (int index = 0; index < m_headers.Count; ++index)
            {
                adaptor.Write(m_headers.GetKey(index));
                string[] values = m_headers.GetValues(index);
                if (values == null)
                {
                    adaptor.Write(0);
                }
                else
                {
                    adaptor.Write(values.Length);
                    for (int valueIndex = 0; valueIndex < values.Length; ++valueIndex)
                    {
                        adaptor.Write(values[valueIndex]);
                    }
                }
            }
        }
예제 #13
0
        protected override void WriteContents(BinaryWriter writer)
        {
            // Pass to base first.

            base.WriteContents(writer);

            // Write out all properties.

            BinaryWriteAdaptor adaptor = new BinaryWriteAdaptor(writer);

            foreach (PropertyInfo propertyInfo in PropertyInfos)
            {
                object value = m_properties[propertyInfo.Name];
                if (value == null)
                {
                    adaptor.Write(true);
                }
                else
                {
                    adaptor.Write(false);
                    adaptor.Write(value, propertyInfo.Type);
                }
            }
        }
예제 #14
0
        void IBinarySerializable.Write(BinaryWriter writer)
        {
            BinaryWriteAdaptor adaptor = new BinaryWriteAdaptor(writer);

            Write(adaptor, m_entries);
        }