protected virtual void LoadStorage(NativeMethods.IStorage storage)
{
this.storage = storage;
//ensures memory is released
ReferenceManager.AddItem(this.storage);
NativeMethods.IEnumSTATSTG storageElementEnum = null;
try
{
//enum all elements of the storage
storage.EnumElements(0, IntPtr.Zero, 0, out storageElementEnum);
//iterate elements
while (true)
{
//get 1 element out of the com enumerator
uint elementStatCount;
ComTypes.STATSTG[] elementStats = new ComTypes.STATSTG[1];
storageElementEnum.Next(1, elementStats, out elementStatCount);
//break loop if element not retrieved
if (elementStatCount != 1)
{
break;
}
ComTypes.STATSTG elementStat = elementStats[0];
switch (elementStat.type)
{
case 1:
//element is a storage. add its statistics object to the storage dictionary
subStorageStatistics.Add(elementStat.pwcsName, elementStat);
break;
case 2:
//element is a stream. add its statistics object to the stream dictionary
streamStatistics.Add(elementStat.pwcsName, elementStat);
break;
}
}
}
finally
{
//free memory
if (storageElementEnum != null)
{
Marshal.ReleaseComObject(storageElementEnum);
}
}
}