Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExtendedProperty"/> class.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="value">The value.</param>
        public ExtendedProperty(ExtendedPropertyTag tag, DateTime value)
        {
            this.tag = tag;

            DateTime year1601 = new DateTime(1601, 1, 1);
            TimeSpan timeSpan = value.ToUniversalTime().Subtract(year1601);

            long ticks = timeSpan.Ticks;

            byte[] ticksBytes = BitConverter.GetBytes(ticks);

            this.value = ticksBytes;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExtendedProperty"/> class.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="value">The value.</param>
        /// <exception cref="System.ArgumentNullException">
        /// tag
        /// or
        /// value
        /// </exception>
        public ExtendedProperty(ExtendedPropertyTag tag, string[] value)
        {
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            this.tag = tag;

            if (value != null && value.Length > 0)
            {
                System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();

                using (memoryStream)
                {
                    uint   count       = (uint)value.Length;
                    byte[] countBuffer = BitConverter.GetBytes(count);

                    memoryStream.Write(countBuffer, 0, countBuffer.Length);

                    for (int i = 0; i < count; i++)
                    {
                        if (tag.Type == PropertyType.String)
                        {
                            byte[] buffer = System.Text.Encoding.Unicode.GetBytes(value[i]);

                            byte[] lengthBuffer = BitConverter.GetBytes(buffer.Length);

                            memoryStream.Write(lengthBuffer, 0, lengthBuffer.Length);
                            memoryStream.Write(buffer, 0, buffer.Length);
                        }
                        else
                        {
                            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(value[i]);

                            byte[] lengthBuffer = BitConverter.GetBytes(buffer.Length);

                            memoryStream.Write(lengthBuffer, 0, lengthBuffer.Length);
                            memoryStream.Write(buffer, 0, buffer.Length);
                        }
                    }

                    this.value = memoryStream.ToArray();
                }
            }
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExtendedProperty"/> class.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="value">The value.</param>
        /// <exception cref="System.ArgumentNullException">
        /// tag
        /// or
        /// value
        /// </exception>
        public ExtendedProperty(ExtendedPropertyTag tag, string value)
        {
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            this.tag = tag;

            if (tag.Type == PropertyType.String)
            {
                this.value = System.Text.Encoding.Unicode.GetBytes(value);
            }
            else
            {
                this.value = System.Text.Encoding.UTF8.GetBytes(value);
            }
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtendedProperty"/> class.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <param name="value">The value.</param>
 public ExtendedProperty(ExtendedPropertyTag tag, long value)
 {
     this.tag   = tag;
     this.value = BitConverter.GetBytes(value);
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtendedProperty"/> class.
 /// </summary>
 /// <param name="tag">The tag.</param>
 public ExtendedProperty(ExtendedPropertyTag tag)
 {
     this.tag = tag;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtendedProperty"/> class.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <param name="value">The value.</param>
 public ExtendedProperty(ExtendedPropertyTag tag, byte[] value)
 {
     this.tag   = tag;
     this.value = value;
 }
Example #7
0
        /// <summary>
        /// Gets the <see cref="ExtendedProperty"/> with the specified tag.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <returns>ExtendedProperty.</returns>
        public ExtendedProperty this[ExtendedPropertyTag tag]
        {
            get
            {
                if (tag != null)
                {
                    if (tag is ExtendedPropertyId)
                    {
                        ExtendedPropertyId extendedPropertyId = (ExtendedPropertyId)tag;

                        for (int i = 0; i < this.Count; i++)
                        {
                            ExtendedProperty current = this[i];

                            if (current.Tag is ExtendedPropertyId)
                            {
                                ExtendedPropertyId currentPropertyId = (ExtendedPropertyId)current.Tag;

                                if (currentPropertyId.Id == extendedPropertyId.Id)
                                {
                                    bool isGuidEqual = true;

                                    if (currentPropertyId.Guid != null && extendedPropertyId.Guid != null && currentPropertyId.Guid.Length == extendedPropertyId.Guid.Length)
                                    {
                                        for (int j = 0; j < currentPropertyId.Guid.Length; j++)
                                        {
                                            if (currentPropertyId.Guid[j] != extendedPropertyId.Guid[j])
                                            {
                                                isGuidEqual = false;
                                                break;
                                            }
                                        }
                                    }

                                    if (isGuidEqual)
                                    {
                                        return(current);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        ExtendedPropertyName extendedPropertyName = (ExtendedPropertyName)tag;

                        for (int i = 0; i < this.Count; i++)
                        {
                            ExtendedProperty current = this[i];

                            if (current.Tag is ExtendedPropertyName)
                            {
                                ExtendedPropertyName currentPropertyName = (ExtendedPropertyName)current.Tag;

                                if (currentPropertyName.Name == extendedPropertyName.Name)
                                {
                                    bool isGuidEqual = true;

                                    if (currentPropertyName.Guid != null && extendedPropertyName.Guid != null && currentPropertyName.Guid.Length == extendedPropertyName.Guid.Length)
                                    {
                                        for (int j = 0; j < currentPropertyName.Guid.Length; j++)
                                        {
                                            if (currentPropertyName.Guid[j] != extendedPropertyName.Guid[j])
                                            {
                                                isGuidEqual = false;
                                                break;
                                            }
                                        }
                                    }

                                    if (isGuidEqual)
                                    {
                                        return(current);
                                    }
                                }
                            }
                        }
                    }
                }

                return(null);
            }
        }