Exemple #1
0
        public void EnhancedMemoryStream_Int16()
        {
            var es = new EnhancedMemoryStream();

            es.WriteInt16(0);
            es.WriteInt16(55);
            es.WriteInt16(0x1234);

            es.Seek(0, SeekOrigin.Begin);

            Assert.AreEqual(0, es.ReadInt16());
            Assert.AreEqual(55, es.ReadInt16());
            Assert.AreEqual(0x1234, es.ReadInt16());
        }
Exemple #2
0
        /// <summary>
        /// Constructs an instance by parsing a serialized string.
        /// </summary>
        /// <param name="serialized">The serialized visitor information.</param>
        /// <exception cref="ArgumentNullException">Thrown if <c>null</c> is passed.</exception>
        /// <exception cref="ArgumentException">Thrown if the parameter passed does not represent a valid <see cref="UniqueVisitor" /> instance.</exception>
        /// <remarks>
        /// <para>
        /// The <paramref name="serialized" /> value must have been generated by
        /// a previous call to <see cref="ToString" />.
        /// </para>
        /// </remarks>
        public UniqueVisitor(string serialized)
        {
            if (serialized == null)
            {
                throw new ArgumentNullException("serialized");
            }

            try
            {
                using (var ms = new EnhancedMemoryStream(Convert.FromBase64String(serialized)))
                {
                    if (ms.ReadInt16() != Magic)
                    {
                        throw new FormatException("Bad magic number.");
                    }

                    this.IssueDateUtc = new DateTime(ms.ReadInt64(), DateTimeKind.Utc);
                    this.ID           = new Guid(ms.ReadBytes(32));
                }
            }
            catch (Exception e)
            {
                throw new ArgumentException("Invalid unique serialized visitor.", "seralized", e);
            }
        }