Exemplo n.º 1
0
        /// <summary>
        /// Deserializes an event sequence token
        /// </summary>
        /// <param name="expected">The expected type.</param>
        /// <param name="reader">The binary stream to read from.</param>
        /// <returns></returns>
        public static object Deserialize(Type expected, BinaryTokenStreamReader reader)
        {
            var deserialized = new EventHubSequenceTokenV2(reader.ReadString(), reader.ReadLong(), reader.ReadInt());

            DeserializationContext.Current.RecordObject(deserialized);
            return(deserialized);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deserializes an event sequence token
        /// </summary>
        /// <param name="expected">The expected type.</param>
        /// <param name="context">The deserialization context.</param>
        /// <returns></returns>
        public static object Deserialize(Type expected, IDeserializationContext context)
        {
            var reader       = context.StreamReader;
            var deserialized = new EventHubSequenceTokenV2(reader.ReadString(), reader.ReadLong(), reader.ReadInt());

            context.RecordObject(deserialized);
            return(deserialized);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a deep copy of the token.
        /// </summary>
        /// <param name="original">The token to copy</param>
        /// <returns>A copy</returns>
        public static object DeepCopy(object original)
        {
            var source = original as EventHubSequenceTokenV2;
            if (source == null)
            {
                return null;
            }

            var copy = new EventHubSequenceTokenV2(source.EventHubOffset, source.SequenceNumber, source.EventIndex);
            SerializationContext.Current.RecordObject(original, copy);
            return copy;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a deep copy of the token.
        /// </summary>
        /// <param name="original">The token to copy</param>
        /// <param name="context">The serialization context.</param>
        /// <returns>A copy</returns>
        public static object DeepCopy(object original, ICopyContext context)
        {
            var source = original as EventHubSequenceTokenV2;

            if (source == null)
            {
                return(null);
            }

            var copy = new EventHubSequenceTokenV2(source.EventHubOffset, source.SequenceNumber, source.EventIndex);

            context.RecordCopy(original, copy);
            return(copy);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a deep copy of the token.
        /// </summary>
        /// <param name="original">The token to copy</param>
        /// <returns>A copy</returns>
        public static object DeepCopy(object original)
        {
            var source = original as EventHubSequenceTokenV2;

            if (source == null)
            {
                return(null);
            }

            var copy = new EventHubSequenceTokenV2(source.EventHubOffset, source.SequenceNumber, source.EventIndex);

            SerializationContext.Current.RecordObject(original, copy);
            return(copy);
        }
        public void EventHubSequenceTokenV2_DeepCopy_IfNotNull()
        {
            var token = new EventHubSequenceTokenV2("name", long.MaxValue, int.MaxValue);
            var copy = EventHubSequenceTokenV2.DeepCopy(token) as EventSequenceToken;
            Assert.NotNull(copy);
            Assert.NotSame(token, copy);
            Assert.Equal(token.EventIndex, copy.EventIndex);
            Assert.Equal(token.SequenceNumber, copy.SequenceNumber);

            var writer = new BinaryTokenStreamWriter();
            SerializationManager.Serialize(token, writer);
            var bytes = writer.ToByteArray();

            var reader = new BinaryTokenStreamReader(bytes);
            copy = SerializationManager.Deserialize(reader) as EventHubSequenceTokenV2;
            Assert.NotNull(copy);
            Assert.NotSame(token, copy);
            Assert.Equal(token.EventIndex, copy.EventIndex);
            Assert.Equal(token.SequenceNumber, copy.SequenceNumber);
        }
 public void EventHubSequenceTokenV2_Serialize_IfNotNull()
 {
     var writer = new BinaryTokenStreamWriter();
     var token = new EventHubSequenceTokenV2("name", long.MaxValue, int.MaxValue);
     EventHubSequenceTokenV2.Serialize(token, writer, null);
     var reader = new BinaryTokenStreamReader(writer.ToByteArray());
     var deserialized = EventHubSequenceTokenV2.Deserialize(typeof (EventHubSequenceTokenV2), reader) as EventHubSequenceTokenV2;
     Assert.NotNull(deserialized);
     Assert.NotSame(token, deserialized);
     Assert.Equal(token.EventIndex, deserialized.EventIndex);
     Assert.Equal(token.SequenceNumber, deserialized.SequenceNumber);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Deserializes an event sequence token
 /// </summary>
 /// <param name="expected">The expected type.</param>
 /// <param name="reader">The binary stream to read from.</param>
 /// <returns></returns>
 public static object Deserialize(Type expected, BinaryTokenStreamReader reader)
 {
     var deserialized = new EventHubSequenceTokenV2(reader.ReadString(), reader.ReadLong(), reader.ReadInt());
     DeserializationContext.Current.RecordObject(deserialized);
     return deserialized;
 }