本文整理汇总了C#中NativeMethods.OpenStorage方法的典型用法代码示例。如果您正苦于以下问题:C# NativeMethods.OpenStorage方法的具体用法?C# NativeMethods.OpenStorage怎么用?C# NativeMethods.OpenStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NativeMethods
的用法示例。
在下文中一共展示了NativeMethods.OpenStorage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadStorage
/// <summary>
/// Processes sub storages on the specified storage to capture attachment and recipient data.
/// </summary>
/// <param name="storage"> The storage to check for attachment and recipient data. </param>
protected override void LoadStorage(NativeMethods.IStorage storage)
{
base.LoadStorage(storage);
foreach (var storageStatistic in _subStorageStatistics.Values)
{
// Element is a storage. get it and add its statistics object to the sub storage dictionary
var subStorage = storage.OpenStorage(storageStatistic.pwcsName, IntPtr.Zero, NativeMethods.STGM.READ | NativeMethods.STGM.SHARE_EXCLUSIVE,
IntPtr.Zero, 0);
// Run specific load method depending on sub storage name prefix
if (storageStatistic.pwcsName.StartsWith(MapiTags.RecipStoragePrefix))
{
var recipient = new Recipient(new Storage(subStorage));
_recipients.Add(recipient);
}
else if (storageStatistic.pwcsName.StartsWith(MapiTags.AttachStoragePrefix))
{
if (Type == MessageType.EmailEncryptedAndMeabySigned)
LoadEncryptedAndMeabySignedMessage(subStorage);
else
LoadAttachmentStorage(subStorage, storageStatistic.pwcsName);
}
else
Marshal.ReleaseComObject(subStorage);
}
// Check if there is a named substorage and if so open it and map all the named MAPI properties
if (_subStorageStatistics.ContainsKey(MapiTags.NameIdStorage))
{
var mappingValues = new List<string>();
// Get all the named properties from the _streamStatistics
foreach (var streamStatistic in _streamStatistics)
{
var name = streamStatistic.Value.pwcsName;
if (name.StartsWith(MapiTags.SubStgVersion1))
{
// Get the property value
var propIdentString = name.Substring(12, 4);
// Convert it to a short
var value = ushort.Parse(propIdentString, NumberStyles.HexNumber);
// Check if the value is in the named property range (8000 to FFFE (Hex))
if (value >= 32768 && value <= 65534)
{
// If so then add it to perform mapping later on
if (!mappingValues.Contains(propIdentString))
mappingValues.Add(propIdentString);
}
}
}
// Check if there is also a properties stream and if so get all the named MAPI properties from it
if (_streamStatistics.ContainsKey(MapiTags.PropertiesStream))
{
// Get the raw bytes for the property stream
var propBytes = GetStreamBytes(MapiTags.PropertiesStream);
for (var i = _propHeaderSize; i < propBytes.Length; i = i + 16)
{
// Get property identifer located in 3rd and 4th bytes as a hexdecimal string
var propIdent = new[] { propBytes[i + 3], propBytes[i + 2] };
var propIdentString = BitConverter.ToString(propIdent).Replace("-", string.Empty);
// Convert it to a short
var value = ushort.Parse(propIdentString, NumberStyles.HexNumber);
// Check if the value is in the named property range (8000 to FFFE (Hex))
if (value >= 32768 && value <= 65534)
{
// If so then add it to perform mapping later on
if (!mappingValues.Contains(propIdentString))
mappingValues.Add(propIdentString);
}
}
}
// Check if there is something to map
if (mappingValues.Count <= 0) return;
// Get the Named Id Storage, we need this one to perform the mapping
var storageStat = _subStorageStatistics[MapiTags.NameIdStorage];
var subStorage = storage.OpenStorage(storageStat.pwcsName, IntPtr.Zero,
NativeMethods.STGM.READ | NativeMethods.STGM.SHARE_EXCLUSIVE, IntPtr.Zero, 0);
// Load the subStorage into our mapping class that does all the mapping magic
var mapiToOom = new MapiTagMapper(new Storage(subStorage));
// Get the mapped properties
_namedProperties = mapiToOom.GetMapping(mappingValues);
// Clean up the com object
Marshal.ReleaseComObject(subStorage);
}
//.........这里部分代码省略.........