Пример #1
0
        /// <summary>
        /// Invokes all the Initialiser methods defined in this class
        /// </summary>
        /// <param name="extension">The extension of the current file</param>
        /// <returns>true if the file type could be determined, false otherwise</returns>
        private bool InvokeInitialisers(string extension)
        {
            try
            {
                using (new BinaryDataLock(m_fileData.BinaryFileData))
                {
                    if (0 < extension.Length)
                    {
                        MethodInfo method;
                        if (m_ExtensionDictionary.TryGetValue(extension, out method))
                            return InvokeMethod(method);

                        return false;
                    }

                    foreach (MethodInfo method in m_InitialiserMethods)
                    {
                        if (InvokeMethod(method))
                            return true;
                    }

                    return false;
                }
            }
			catch(Exception ex)
			{
				Logger.LogError(ex.Message);
				return false;
			}
            finally
            {
                if (m_lockbyteswrapper != null)
                    m_lockbyteswrapper.Dispose();
                m_lockbyteswrapper = null;

            }

        }
Пример #2
0
        public static string GetMessageClassNotOnDisk(BinaryData binaryData)
        {
            using (LockBytesWrapper lockbyteswrapper = new LockBytesWrapper(binaryData))
            {
                if (null == lockbyteswrapper.ILockBytesInterface)
                    return String.Empty;

                StructuredStorageInterface.IStorage iStorage = null;

                uint iRet =
                    StructuredStorageInterface.StgOpenStorageOnILockBytes(lockbyteswrapper.ILockBytesInterface, null,
                                                                          StructuredStorageInterface.ReadOnlyMode,
                                                                          System.IntPtr.Zero, 0, out iStorage);
                if (0 != iRet)
                {
                    ComObjectGovernor.ReleaseObject(iStorage);
                    return String.Empty;
                }

                IStream iStream = null;
                Encoding encoding = Encoding.ASCII;

                try
                {
                    iStream = iStorage.OpenStream("__substg1.0_001A001F", IntPtr.Zero,
                                                  Convert.ToInt32(StructuredStorageInterface.ReadOnlyMode), 0);
                    encoding = Encoding.Unicode;
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    try
                    {
                        iStream = iStorage.OpenStream("__substg1.0_001A001E", IntPtr.Zero,
                                                      Convert.ToInt32(StructuredStorageInterface.ReadOnlyMode), 0);
                    }
                    catch (System.Runtime.InteropServices.COMException)
                    {
                        ComObjectGovernor.ReleaseObject(iStorage);
                        return String.Empty;
                    }
                }

                try
                {
                    System.Runtime.InteropServices.ComTypes.STATSTG stat;
                    iStream.Stat(out stat, 0);

                    IntPtr read = IntPtr.Zero;
                    byte[] contents = new byte[stat.cbSize];
                    iStream.Read(contents, (int)stat.cbSize, read);

                    return encoding.GetString(contents);                    
                }
                finally
                {
                    ComObjectGovernor.ReleaseObject(iStream);
                    ComObjectGovernor.ReleaseObject(iStorage);
                }
            }
        }
Пример #3
0
        private void Dispose(bool disposing)
        {
            CreateLock();

            lock (m_lock)
            {
                if (m_bdisposed)
                    return;

                m_bdisposed = true;
            }

            if (disposing)
            {
                GC.SuppressFinalize(this);

                if (null != m_impl)
                {
                    m_impl.Dispose();
                    m_impl = null;
                }
            }

            if (null != m_lockbyteswrapper)
                m_lockbyteswrapper.Dispose();

            m_lockbyteswrapper = null;
        }
Пример #4
0
		private IStream GetStream(out StructuredStorageInterface.IStorage iStorage, string streamname)
		{
			if (m_bNotAStreamFile)
			{
				iStorage = null;
				return null;
			}

			if (!HasStructuredStorageHeader())
			{
				m_bNotAStreamFile = false;
				iStorage = null;
				return null;
			}

            uint iRet = 0;
            if (Workshare.Interop.Options.OptionApi.GetBool("UseDiskBasedFiles") && !string.IsNullOrEmpty(m_fileData.Filename) && m_fileData.BinaryFileData is DiskBinaryData)
            {
				iRet = StructuredStorageInterface.StgOpenStorage(m_fileData.Filename, null, StructuredStorageInterface.ReadOnlyModeTransacted, System.IntPtr.Zero, 0, out iStorage);
            }
            else
            {
                if (m_lockbyteswrapper == null)
                {
                    m_lockbyteswrapper = new LockBytesWrapper(m_fileData.BinaryFileData);
                }
                else
                {
                    if (!m_lockbyteswrapper.Represents(m_fileData.BinaryFileData))
                    {
                        throw new InvalidOperationException("Invalid use of lockbyteswrapper in FileTypeIdentifiers");
                    }
                }

                if (null == m_lockbyteswrapper.ILockBytesInterface)
                {
                    ErrorMessage errorMessage = new ErrorMessage(
                        "EXPECTED_VALID",
                        "Workshare.Policy.Engine.Properties",
                        Assembly.GetExecutingAssembly());
                    Logger.LogError(errorMessage.LogString);
                    throw new NullReferenceException(errorMessage.DisplayString + " - " + "ILockBytes");
                }

			    iRet = StructuredStorageInterface.StgOpenStorageOnILockBytes(m_lockbyteswrapper.ILockBytesInterface, null, StructuredStorageInterface.ReadOnlyMode, System.IntPtr.Zero, 0, out iStorage);
            }

            if (0 != iRet)
			{
				ComObjectGovernor.ReleaseObject(iStorage);

				if (StructuredStorageInterface.STG_E_SHAREVIOLATION != iRet)
				{
					m_bNotAStreamFile = true;
					return null;
				}

				ErrorMessage errorMessage = new ErrorMessage(
					"FAILED_OPEN_STORAGE",
					"Workshare.Policy.Engine.Properties",
					Assembly.GetExecutingAssembly(), iRet.ToString("x", CultureInfo.InvariantCulture));
				Logger.LogError(errorMessage.LogString);
				throw new FileLoadException(errorMessage.DisplayString, m_fileData.Filename);
			}

			IStream iStream;
			try
			{
				iStream = iStorage.OpenStream(streamname, IntPtr.Zero, Convert.ToInt32(StructuredStorageInterface.ReadOnlyMode), 0);
			}
			catch (System.Runtime.InteropServices.COMException)
			{
				ComObjectGovernor.ReleaseObject(iStorage);

				// iStorage.OpenStream no longer throws STG_E_FILENOTFOUND for some reason, and instead throws an RPC error
				// which is quite generic anyway ... so we no longer check for error code.
				//if (StructuredStorageInterface.STG_E_FILENOTFOUND != (uint) e.ErrorCode)
					//throw e;


				return null;
			}

			return iStream;
		}