public override Stream OpenPropertyStream(PropertyDefinition propertyDefinition, PropertyOpenMode openMode) { base.CheckDisposed("OpenPropertyStream"); EnumValidator.AssertValid <PropertyOpenMode>(openMode); NativeStorePropertyDefinition nativeStorePropertyDefinition = propertyDefinition as NativeStorePropertyDefinition; if (nativeStorePropertyDefinition == null) { throw new InvalidOperationException(ServerStrings.ExPropertyNotStreamable(propertyDefinition.ToString())); } Stream result; using (DisposeGuard disposeGuard = default(DisposeGuard)) { StoreObjectStream storeObjectStream = new StoreObjectStream(this, nativeStorePropertyDefinition, openMode); disposeGuard.Add <StoreObjectStream>(storeObjectStream); this.listOfStreams.Add(storeObjectStream); disposeGuard.Success(); if (openMode == PropertyOpenMode.Create || openMode == PropertyOpenMode.Modify) { this.TrackProperty(nativeStorePropertyDefinition, true); } result = storeObjectStream; } return(result); }
private void FlushCacheIntoPropertyBag() { if (this.storePropertyBag == null) { return; } this.storePropertyBag.Load(null); byte[] array = this.cache.ToArray(); if (this.property.MapiPropertyType == PropType.Binary) { this.storePropertyBag.MemoryPropertyBag[this.property] = array; return; } if (this.property.MapiPropertyType == PropType.String) { this.storePropertyBag.MemoryPropertyBag[this.property] = StoreObjectStream.GetUnicodeEncoding().GetString(array, 0, StoreObjectStream.GetByteCount(array)); } }
private void CreateCache(object value) { if (value == null) { this.cache = StoreObjectStream.CreateExpandableMemoryStream(null); } else if (this.property.MapiPropertyType == PropType.Binary) { this.cache = StoreObjectStream.CreateExpandableMemoryStream((byte[])value); } else if (this.property.MapiPropertyType == PropType.String) { byte[] bytes = StoreObjectStream.GetUnicodeEncoding().GetBytes((string)value); PooledMemoryStream pooledMemoryStream = StoreObjectStream.CreateExpandableMemoryStream(bytes); pooledMemoryStream.Position = 0L; this.cache = pooledMemoryStream; } this.maximumCacheSize = ((32768 > (int)this.cache.Length) ? 32768 : ((int)this.cache.Length)); }
internal void OnStreamClose(StoreObjectStream stream) { this.listOfStreams.Remove(stream); }