Example #1
0
        public static PropertyItem2 FromBlob(string blob)
        {
            PropertyItem2 pi2;

            if (blob.Length > 0 && blob[0] == '<')
            {
                string idStr    = GetProperty(blob, idPropertyName);
                string lenStr   = GetProperty(blob, lenPropertyName);
                string typeStr  = GetProperty(blob, typePropertyName);
                string valueStr = GetProperty(blob, valuePropertyName);

                int    id    = int.Parse(idStr, CultureInfo.InvariantCulture);
                int    len   = int.Parse(lenStr, CultureInfo.InvariantCulture);
                short  type  = short.Parse(typeStr, CultureInfo.InvariantCulture);
                byte[] value = Convert.FromBase64String(valueStr);

                pi2 = new PropertyItem2(id, len, type, value);
            }
            else
            {
                // Old way of serializing: .NET serialized!
                byte[]                      bytes = Convert.FromBase64String(blob);
                MemoryStream                ms    = new MemoryStream(bytes);
                BinaryFormatter             bf    = new BinaryFormatter();
                SerializationFallbackBinder sfb   = new SerializationFallbackBinder();
                sfb.AddAssembly(Assembly.GetExecutingAssembly());
                bf.Binder = sfb;
                pi2       = (PropertyItem2)bf.Deserialize(ms);
            }

            return(pi2);
        }
Example #2
0
        /// <summary>
        /// Copies the given PropertyItem.
        /// </summary>
        /// <param name="pi">The PropertyItem to clone.</param>
        /// <returns>A copy of the given PropertyItem.</returns>
        public static PropertyItem ClonePropertyItem(PropertyItem pi)
        {
            byte[] valueClone;

            if (pi.Value == null)
            {
                valueClone = new byte[0];
            }
            else
            {
                valueClone = (byte[])pi.Value.Clone();
            }

            PropertyItem2 pi2 = new PropertyItem2(pi.Id, pi.Len, pi.Type, valueClone);

            return(pi2.ToPropertyItem());
        }
Example #3
0
        /// <summary>
        /// Creates a new, zero-filled PropertyItem.
        /// </summary>
        /// <returns>A PropertyItem that is zero-filled.</returns>
        public static PropertyItem CreatePropertyItem()
        {
            PropertyItem2 pi2 = new PropertyItem2(0, 0, 0, new byte[0]);

            return(pi2.ToPropertyItem());
        }
Example #4
0
        /// <summary>
        /// Deserializes a PropertyItem from a string previously returned from SerializePropertyItem.
        /// </summary>
        /// <param name="piBlob">The string data to deserialize.</param>
        /// <returns>A PropertyItem instance.</returns>
        /// <remarks>
        /// Note to implementors: The format for the serialized data is intentionally opaque for programmatic users
        /// of this class. However, since this data goes into .PDN files, it must be carefully maintained. See
        /// the PropertyItem2 class for details.
        /// </remarks>
        public static PropertyItem DeserializePropertyItem(string piBlob)
        {
            PropertyItem2 pi2 = PropertyItem2.FromBlob(piBlob);

            return(pi2.ToPropertyItem());
        }
Example #5
0
        /// <summary>
        /// Serializes a PropertyItem into a string blob.
        /// </summary>
        /// <param name="pi">The PropertyItem to serialize.</param>
        /// <returns>A string that may be later deserialized using DeserializePropertyItem.</returns>
        /// <remarks>
        /// Note to implementors: The format for the serialized data is intentionally opaque for programmatic users
        /// of this class. However, since this data goes into .PDN files, it must be carefully maintained. See
        /// the PropertyItem2 class for details.
        /// </remarks>
        public static string SerializePropertyItem(PropertyItem pi)
        {
            PropertyItem2 pi2 = PropertyItem2.FromPropertyItem(pi);

            return(pi2.ToBlob());
        }