internal static void ThrowOnInvalidPropertyType(TnefPropertyType type)
        {
            MsgStoragePropertyTypeRule msgStoragePropertyTypeRule = null;

            if (!MsgStorageRulesTable.rulesTable.TryGetValue(type, out msgStoragePropertyTypeRule))
            {
                throw new NotSupportedException(MsgStorageStrings.UnsupportedPropertyType(string.Format("0x{0:x2}", type)));
            }
        }
 private static void WriteString8Array(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
 {
     string[] array = value as string[];
     if (array == null)
     {
         throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(string[]), value.GetType()));
     }
     MsgStorageRulesTable.InternalWriteStringArray(writer, propertyTag.ToUnicode(), array);
 }
 private static void WriteBinary(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
 {
     byte[] array = value as byte[];
     if (array == null)
     {
         throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(byte[]), value.GetType()));
     }
     writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), array);
     MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, array.Length);
 }
        private static void WriteDouble(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            double?num = value as double?;

            if (num == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(double), value.GetType()));
            }
            MsgStoragePropertyData.WriteProperty(writer.PropertiesWriter, propertyTag, num.Value);
        }
        private static void WriteString8(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            string text = value as string;

            if (text == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(string), value.GetType()));
            }
            MsgStorageRulesTable.InternalWriteString(writer, propertyTag.ToUnicode(), text);
        }
Esempio n. 6
0
 public LockBytesOnStream(Stream stream)
 {
     Util.ThrowOnNullArgument(stream, "stream");
     if (!stream.CanSeek)
     {
         throw new ArgumentException(MsgStorageStrings.StreamNotSeakable("LockBytesOnStream::ctr"));
     }
     this.stream     = stream;
     this.streamLock = new object();
     this.offset     = 0L;
 }
 private static void WriteGuidArray(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
 {
     Guid[] arrayValue = value as Guid[];
     if (arrayValue == null)
     {
         throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(Guid[]), value.GetType()));
     }
     MsgStorageRulesTable.WriteArray(writer, propertyTag, arrayValue.Length, delegate(BinaryWriter binaryWriter, int index)
     {
         binaryWriter.Write(arrayValue[index].ToByteArray());
     });
 }
        private static void WriteGuid(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            Guid?guid = value as Guid?;

            if (guid == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(Guid), value.GetType()));
            }
            byte[] array = guid.Value.ToByteArray();
            writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), array);
            MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, array.Length);
        }
Esempio n. 9
0
 public void WriteProperty(TnefPropertyTag propertyTag, object propertyValue)
 {
     this.CheckDisposed("MsgStorageWriter::WriteProperty(1)");
     if (propertyTag.IsNamed)
     {
         throw new ArgumentException(MsgStorageStrings.InvalidPropertyTag(propertyTag), "propertyTag");
     }
     MsgStorageRulesTable.ThrowOnInvalidPropertyType(propertyTag);
     Util.ThrowOnNullArgument(propertyValue, "propertyValue");
     this.CheckFailure();
     this.CurrentWriter.WriteProperty(propertyTag, propertyValue);
 }
        private static void WriteBoolean(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            bool?flag = value as bool?;

            if (flag == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(bool), value.GetType()));
            }
            short propertyValue = flag.Value ? 1 : 0;

            MsgStoragePropertyData.WriteProperty(writer.PropertiesWriter, propertyTag, propertyValue);
        }
Esempio n. 11
0
 public unsafe void Write(byte *pBuffer, int count)
 {
     this.CheckDisposed("ComStream::Write");
     Util.InvokeComCall(MsgStorageErrorCode.FailedWrite, delegate
     {
         int num = 0;
         this.iStream.Write(pBuffer, count, out num);
         if (num != count)
         {
             throw new MsgStorageException(MsgStorageErrorCode.FailedWrite, MsgStorageStrings.FailedWrite(string.Empty));
         }
     });
 }
Esempio n. 12
0
 public Stream OpenPropertyStream(TnefPropertyTag propertyTag)
 {
     this.CheckDisposed("MsgStorageWriter::OpenPropertyStream(1)");
     if (propertyTag.IsNamed)
     {
         throw new ArgumentException(MsgStorageStrings.InvalidPropertyTag(propertyTag), "propertyTag");
     }
     MsgStorageRulesTable.ThrowOnInvalidPropertyType(propertyTag);
     this.CheckFailure();
     if (propertyTag == TnefPropertyTag.AttachDataObj)
     {
         return(this.CurrentWriter.OpenOleAttachmentStream());
     }
     return(this.CurrentWriter.OpenPropertyStream(propertyTag));
 }
        internal Stream OpenPropertyStream(TnefPropertyTag propertyTag)
        {
            int num = this.prefix.Size;

            while (num + 16 <= this.propertiesContent.Length)
            {
                TnefPropertyTag propertyTag2 = MsgStoragePropertyData.ReadPropertyTag(this.propertiesContent, num);
                if (propertyTag2.ToUnicode() == propertyTag)
                {
                    return(this.InternalOpenPropertyStream(propertyTag2));
                }
                num += 16;
            }
            throw new InvalidOperationException(MsgStorageStrings.PropertyNotFound(propertyTag));
        }
        private static void WriteSysTime(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            DateTime?dateTime = value as DateTime?;

            if (dateTime == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(DateTime), value.GetType()));
            }
            long propertyValue = 0L;

            try
            {
                propertyValue = dateTime.Value.ToFileTimeUtc();
            }
            catch (ArgumentOutOfRangeException)
            {
                propertyValue = 0L;
            }
            MsgStoragePropertyData.WriteProperty(writer.PropertiesWriter, propertyTag, propertyValue);
        }
        private static void WriteArrayOfBinary(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            byte[][] array = value as byte[][];
            if (array == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(byte[][]), value.GetType()));
            }
            MsgSubStorageWriter.WriterBuffer lengthsBuffer = writer.LengthsBuffer;
            for (int num = 0; num != array.Length; num++)
            {
                lengthsBuffer.Writer.Write(array[num].Length);
                lengthsBuffer.Writer.Write(0);
                writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag, num), array[num]);
            }
            int length = lengthsBuffer.GetLength();

            byte[] buffer = lengthsBuffer.GetBuffer();
            writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), buffer, length);
            MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, length);
        }
 private static void WriteSysTimeArray(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
 {
     DateTime[] arrayValue = value as DateTime[];
     if (arrayValue == null)
     {
         throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(DateTime[]), value.GetType()));
     }
     MsgStorageRulesTable.WriteArray(writer, propertyTag, arrayValue.Length, delegate(BinaryWriter binaryWriter, int index)
     {
         long value2 = 0L;
         try
         {
             value2 = arrayValue[index].ToFileTimeUtc();
         }
         catch (ArgumentOutOfRangeException)
         {
             value2 = 0L;
         }
         binaryWriter.Write(value2);
     });
 }
Esempio n. 17
0
        public static ComStorage CreateStorageOnStream(Stream stream, ComStorage.OpenMode openMode)
        {
            Util.ThrowOnNullArgument(stream, "stream");
            ComStorage.CheckOpenMode(openMode, "openMode", ComStorage.validCreateModes);
            ComStorage comStorage = null;

            Interop.IStorage storage = null;
            try
            {
                LockBytesOnStream lockBytes = new LockBytesOnStream(stream);
                int num = Interop.StgCreateDocfileOnILockBytes(lockBytes, (uint)openMode, 0, out storage);
                if (num != 0)
                {
                    throw new MsgStorageException(MsgStorageErrorCode.CreateStorageOnStreamFailed, MsgStorageStrings.FailedCreateStorage("ILockBytes"), num);
                }
                comStorage = new ComStorage(storage);
            }
            finally
            {
                if (comStorage == null && storage != null)
                {
                    Marshal.ReleaseComObject(storage);
                }
            }
            return(comStorage);
        }
Esempio n. 18
0
        public static ComStorage CreateFileStorage(string filename, ComStorage.OpenMode openMode)
        {
            Util.ThrowOnNullArgument(filename, "filename");
            ComStorage.CheckOpenMode(openMode, "openMode", ComStorage.validCreateModes);
            object     obj = null;
            ComStorage result;

            try
            {
                Guid iidistorage = Interop.IIDIStorage;
                int  num         = Interop.StgCreateStorageEx(filename, (uint)openMode, 0, 0U, IntPtr.Zero, IntPtr.Zero, ref iidistorage, out obj);
                if (num != 0)
                {
                    throw new MsgStorageException(MsgStorageErrorCode.CreateFileFailed, MsgStorageStrings.FailedCreateStorage(filename), num);
                }
                Interop.IStorage storage = obj as Interop.IStorage;
                if (storage == null)
                {
                    throw new MsgStorageException(MsgStorageErrorCode.CreateFileFailed, MsgStorageStrings.FailedCreateStorage(filename));
                }
                obj    = null;
                result = new ComStorage(storage);
            }
            finally
            {
                if (obj != null)
                {
                    Marshal.ReleaseComObject(obj);
                }
            }
            return(result);
        }
Esempio n. 19
0
 public unsafe byte[] ReadFromStreamMaxLength(string streamName, int maxSize)
 {
     byte[] result = null;
     Util.InvokeComCall(MsgStorageErrorCode.FailedRead, delegate
     {
         Interop.IStream stream = null;
         try
         {
             this.iStorage.OpenStream(streamName, IntPtr.Zero, 16U, 0U, out stream);
             System.Runtime.InteropServices.ComTypes.STATSTG statstg;
             stream.Stat(out statstg, 1U);
             if (statstg.cbSize > (long)maxSize)
             {
                 throw new MsgStorageException(MsgStorageErrorCode.StorageStreamTooLong, MsgStorageStrings.StreamTooBig(streamName, statstg.cbSize));
             }
             int num  = (int)statstg.cbSize;
             int num2 = 0;
             result   = new byte[num];
             if (result.Length != 0)
             {
                 try
                 {
                     fixed(byte *ptr = &result[0])
                     {
                         stream.Read(ptr, result.Length, out num2);
                     }
                 }
                 finally
                 {
                     byte *ptr = null;
                 }
             }
             if (num2 != result.Length)
             {
                 throw new MsgStorageException(MsgStorageErrorCode.StorageStreamTruncated, MsgStorageStrings.FailedRead(streamName));
             }
         }
         finally
         {
             if (stream != null)
             {
                 Marshal.ReleaseComObject(stream);
             }
         }
     });
     return(result);
 }
Esempio n. 20
0
 public unsafe void WriteBytesToStream(string streamName, byte[] data, int length)
 {
     this.CheckDisposed("ComStream::WriteToStream");
     Util.ThrowOnNullArgument(streamName, "streamName");
     Util.ThrowOnNullArgument(data, "data");
     Util.InvokeComCall(MsgStorageErrorCode.FailedWrite, delegate
     {
         Interop.IStream stream = null;
         try
         {
             int num = 0;
             this.iStorage.CreateStream(streamName, 17U, 0U, 0U, out stream);
             if (length != 0)
             {
                 try
                 {
                     fixed(byte *ptr = &data[0])
                     {
                         stream.Write(ptr, length, out num);
                     }
                 }
                 finally
                 {
                     byte *ptr = null;
                 }
             }
             if (num != length)
             {
                 throw new MsgStorageException(MsgStorageErrorCode.FailedWrite, MsgStorageStrings.FailedWrite(streamName));
             }
         }
         finally
         {
             if (stream != null)
             {
                 Marshal.ReleaseComObject(stream);
             }
         }
     });
 }
 private static void WriteObject(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
 {
     throw new NotSupportedException(MsgStorageStrings.UnsupportedPropertyType("[Object]"));
 }
 private static object ReadObject(MsgSubStorageReader parser, MsgSubStorageReader.PropertyInfo propertyInfo)
 {
     throw new NotSupportedException(MsgStorageStrings.UnsupportedPropertyType("[Object]"));
 }