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); }
private void WriteXml(XmlWriteAdaptor adaptor) { // Source. adaptor.WriteStartElement(Constants.Xml.SourceElement); adaptor.WriteName(_source); adaptor.WriteEndElement(); // Event. adaptor.WriteStartElement(Constants.Xml.EventElement); adaptor.WriteName(_event); adaptor.WriteEndElement(); // Type, Method, Message, Time, Sequence. adaptor.WriteElement(Constants.Xml.TypeElement, _type); adaptor.WriteElement(Constants.Xml.MethodElement, _method); adaptor.WriteElement(Constants.Xml.MessageElement, _message); // The message time is in UTC, but System.Xml.XmlConvert assumes it's local time and writes // the local timezone. Use LinkMe.Framework.Type.DateTime to avoid this. DateTime time = DateTime.FromSystemDateTime(_time, TimeZone.UTC); adaptor.WriteElement(Constants.Xml.TimeElement, TypeXmlConvert.ToString(time)); if (_sequence != 0) { adaptor.WriteElement(Constants.Xml.SequenceElement, TypeXmlConvert.ToString(_sequence)); } // Exception. if (_exception != null) { adaptor.WriteStartElement(Constants.Xml.ExceptionElement); _exception.WriteXml(adaptor.XmlWriter); adaptor.WriteEndElement(); } // Details and Parameters. WriteDetails(adaptor); WriteParameters(adaptor); }
private void ReadStandard(XmlReadAdaptor adaptor) { // Source. if (adaptor.ReadElement(Constants.Xml.SourceElement)) { _source = adaptor.ReadName(); adaptor.ReadEndElement(); } // Event. if (adaptor.ReadElement(Constants.Xml.EventElement)) { _event = adaptor.ReadName(); adaptor.ReadEndElement(); } // Type, Method, Message, Time, Sequence. _type = adaptor.ReadElementString(Constants.Xml.TypeElement, string.Empty); _method = adaptor.ReadElementString(Constants.Xml.MethodElement, string.Empty); _message = adaptor.ReadElementString(Constants.Xml.MessageElement, string.Empty); string timeXml = adaptor.ReadElementString(Constants.Xml.TimeElement, string.Empty); // The time is in the LinkMe.Framework.Type.DateTime format and should always be in UTC. DateTime time = TypeXmlConvert.ToDateTime(timeXml); Debug.Assert(time.TimeZone == TimeZone.UTC, "time.TimeZone == TimeZone.UTC"); _time = time.ToSystemDateTime(); string sequence = adaptor.ReadElementString(Constants.Xml.SequenceElement, string.Empty); _sequence = (sequence.Length == 0 ? 0 : TypeXmlConvert.ToInt32(sequence)); // Exception. _exception = ExceptionInfo.FromXml(adaptor, Constants.Xml.ExceptionElement); }