예제 #1
0
        private LoadedItemPart CreateLoadedItemPart(IItem item, IStorePropertyBag propertyBagFromTree, HtmlStreamOptionCallback htmlCallback, PropertyDefinition[] additionalPropertyDefinitions, ItemPartIrmInfo itemPartIrmInfo, bool isIrmEnabled, long bytesLoadedForConversation, bool isSmimeSupported, string domainName)
        {
            ConversationBodyScanner bodyScanner = null;
            long bytesLoaded = 0L;

            PropertyDefinition[] loadedProperties = InternalSchema.Combine <PropertyDefinition>(this.queriedPropertyDefinitions, additionalPropertyDefinitions).ToArray <PropertyDefinition>();
            IStorePropertyBag    propertyBag      = this.CalculatePropertyBag(propertyBagFromTree, item, additionalPropertyDefinitions);
            BodyFragmentInfo     bodyFragmentInfo = null;
            bool didLoadSucceed = false;

            if (this.TryLoadBodyScanner(item, htmlCallback, bytesLoadedForConversation, isIrmEnabled, out bodyScanner, out bytesLoaded))
            {
                bodyFragmentInfo = new BodyFragmentInfo(bodyScanner);
                didLoadSucceed   = true;
            }
            AttachmentCollection attachmentCollection = item.AttachmentCollection;

            if (isIrmEnabled)
            {
                this.InitializeIrmInfo(item, itemPartIrmInfo, out attachmentCollection);
            }
            string itemClass = item.TryGetProperty(StoreObjectSchema.ItemClass) as string;

            if (isSmimeSupported && ObjectClass.IsSmimeClearSigned(itemClass))
            {
                this.InitializeSmimeInfo(item, domainName, out attachmentCollection);
            }
            return(new LoadedItemPart(item, propertyBag, bodyFragmentInfo, loadedProperties, itemPartIrmInfo, didLoadSucceed, bytesLoaded, attachmentCollection));
        }
예제 #2
0
        public PersistablePropertyBag CreateAttachment(ICollection <PropertyDefinition> propertiesToLoad, CoreAttachment attachmentToClone, IItem itemToAttach, out int attachmentNumber)
        {
            this.CheckDisposed(null);
            InMemoryPersistablePropertyBag inMemoryPersistablePropertyBag = new InMemoryPersistablePropertyBag(propertiesToLoad);

            inMemoryPersistablePropertyBag.ExTimeZone = this.ExTimeZone;
            if (attachmentToClone != null)
            {
                throw new NotSupportedException("CreateAttachment for copied attachments is not supported");
            }
            attachmentNumber = this.attachmentCounter++;
            inMemoryPersistablePropertyBag[InternalSchema.AttachNum] = attachmentNumber;
            this.newAttachmentList.Add(attachmentNumber, inMemoryPersistablePropertyBag);
            if (itemToAttach != null)
            {
                string text   = itemToAttach.TryGetProperty(InternalSchema.ItemClass) as string;
                Schema schema = (text != null) ? ObjectClass.GetSchema(text) : ItemSchema.Instance;
                propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema.AutoloadProperties, propertiesToLoad);
                using (DisposeGuard disposeGuard = default(DisposeGuard))
                {
                    PersistablePropertyBag persistablePropertyBag = new InMemoryPersistablePropertyBag(propertiesToLoad);
                    disposeGuard.Add <PersistablePropertyBag>(persistablePropertyBag);
                    persistablePropertyBag.ExTimeZone = this.ExTimeZone;
                    CoreItem coreItem = new CoreItem(null, persistablePropertyBag, null, null, Origin.New, ItemLevel.Attached, propertiesToLoad, ItemBindOption.LoadRequiredPropertiesOnly);
                    disposeGuard.Add <CoreItem>(coreItem);
                    CoreItem.CopyItemContent(itemToAttach.CoreItem, coreItem);
                    this.attachedItems.Add(attachmentNumber, coreItem);
                    disposeGuard.Success();
                }
            }
            return(inMemoryPersistablePropertyBag);
        }
        public override Stream OpenPropertyStream(PropertyDefinition propertyDefinition, PropertyOpenMode openMode)
        {
            Stream stream = null;
            StorePropertyDefinition storePropertyDefinition = InternalSchema.ToStorePropertyDefinition(propertyDefinition);

            if (openMode != PropertyOpenMode.Create)
            {
                object        value         = ((IDirectPropertyBag)this.memoryPropertyBag).GetValue(storePropertyDefinition);
                PropertyError propertyError = value as PropertyError;
                if (propertyError == null)
                {
                    stream = this.WrapValueInStream(value);
                }
                else if (propertyError.PropertyErrorCode == PropertyErrorCode.RequireStreamed)
                {
                    stream = this.streamList[storePropertyDefinition];
                }
                else if (openMode == PropertyOpenMode.ReadOnly)
                {
                    throw new ObjectNotFoundException(ServerStrings.StreamPropertyNotFound(storePropertyDefinition.ToString()));
                }
            }
            if (stream == null)
            {
                stream = new MemoryStream();
                ((IDirectPropertyBag)this.memoryPropertyBag).SetValue(storePropertyDefinition, new PropertyError(storePropertyDefinition, PropertyErrorCode.RequireStreamed));
                this.streamList[storePropertyDefinition] = stream;
            }
            if (openMode != PropertyOpenMode.ReadOnly)
            {
                this.isDirty = true;
            }
            stream.Seek(0L, SeekOrigin.Begin);
            return(new StreamWrapper(stream, false));
        }
예제 #4
0
        public static void PerformActionOnNativePropertyDefinitions <T>(PropertyDependencyType targetDependencyType, ICollection <T> propertyDefinitions, Action <NativeStorePropertyDefinition> action) where T : PropertyDefinition
        {
            EnumValidator.AssertValid <PropertyDependencyType>(targetDependencyType);
            if (propertyDefinitions == null)
            {
                return;
            }
            int actualDependencyCount = 0;

            foreach (T t in propertyDefinitions)
            {
                PropertyDefinition      propertyDefinition      = t;
                StorePropertyDefinition storePropertyDefinition = InternalSchema.ToStorePropertyDefinition(propertyDefinition);
                storePropertyDefinition.ForEachMatch(targetDependencyType, delegate(NativeStorePropertyDefinition item)
                {
                    action(item);
                    actualDependencyCount++;
                });
            }
            int num = (propertyDefinitions.Count >= StorePropertyDefinition.dependencyEstimates.Length) ? propertyDefinitions.Count : StorePropertyDefinition.dependencyEstimates[propertyDefinitions.Count];

            if (actualDependencyCount != num && propertyDefinitions.Count < StorePropertyDefinition.dependencyEstimates.Length)
            {
                Interlocked.Exchange(ref StorePropertyDefinition.dependencyEstimates[propertyDefinitions.Count], actualDependencyCount);
            }
        }
예제 #5
0
        public static IStorePropertyBag[] FindItemsFromInternetId(MailboxSession session, string internetMessageId, params PropertyDefinition[] propertyDefinitions)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullOrEmptyArgument(internetMessageId, "internetMessageId");
            Util.ThrowOnNullOrEmptyArgument(propertyDefinitions, "propertyDefinitions");
            DumpsterFolderHelper.CheckAndCreateFolder(session);
            ICollection <PropertyDefinition> dataColumns = InternalSchema.Combine <PropertyDefinition>(propertyDefinitions, new PropertyDefinition[]
            {
                ItemSchema.InternetMessageId
            });

            IStorePropertyBag[] result;
            using (Folder folder = Folder.Bind(session, DefaultFolderType.RecoverableItemsDeletions))
            {
                using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, null, DumpsterFolderHelper.searchSortBy, dataColumns))
                {
                    if (queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, DumpsterFolderHelper.searchSortBy[0].ColumnDefinition, internetMessageId)))
                    {
                        result = DumpsterFolderHelper.ProcessQueryResult(queryResult, internetMessageId);
                    }
                    else
                    {
                        result = Array <IStorePropertyBag> .Empty;
                    }
                }
            }
            return(result);
        }
 protected override object ReadValue()
 {
     if (this.IsLargeValue())
     {
         StorageGlobals.ContextTraceError(ExTraceGlobals.CcInboundTnefTracer, "InboundTnefConverter::ReadValue: large property value");
         throw new ConversionFailedException(ConversionFailureReason.CorruptContent);
     }
     if (this.PropertyReader.IsMultiValuedProperty)
     {
         Type          elementType = InternalSchema.ClrTypeFromPropTagType(ConvertUtils.GetPropertyBaseType(this.PropertyReader.PropertyTag));
         List <object> list        = new List <object>();
         while (this.PropertyReader.ReadNextValue())
         {
             if (this.PropertyReader.IsLargeValue)
             {
                 throw new ConversionFailedException(ConversionFailureReason.CorruptContent, ServerStrings.LargeMultivaluedPropertiesNotSupportedInTNEF, null);
             }
             object obj = this.ReadSingleValue();
             if (obj == null)
             {
                 throw new ConversionFailedException(ConversionFailureReason.CorruptContent, ServerStrings.InvalidTnef, null);
             }
             list.Add(obj);
         }
         Array array = Array.CreateInstance(elementType, list.Count);
         for (int i = 0; i < array.Length; i++)
         {
             array.SetValue(list[i], i);
         }
         return(array);
     }
     return(this.ReadSingleValue());
 }
예제 #7
0
        private void InternalSetValidatedStoreProperty(PropertyDefinition propertyDefinition, object value)
        {
            this.EnsureInternalDataStructuresAllocated(8);
            Array array = value as Array;

            if (array != null)
            {
                value = MemoryPropertyBag.ClonePropertyValue <Array>(array);
            }
            else if (value is DateTime)
            {
                ExTimeZoneHelperForMigrationOnly.CheckValidationLevel(false, ExTimeZoneHelperForMigrationOnly.ValidationLevel.Low, "MemoryPropertyBag.InternalSetValidatedStoreProperty: System.DateTime", new object[0]);
                value = new ExDateTime(this.ExTimeZone, (DateTime)value);
            }
            else if (value is ExDateTime)
            {
                ((ExDateTime)value).CheckExpectedTimeZone(this.ExTimeZone, ExTimeZoneHelperForMigrationOnly.ValidationLevel.High);
                value = this.ExTimeZone.ConvertDateTime((ExDateTime)value);
            }
            object originalValue = null;
            StorePropertyDefinition storePropertyDefinition = InternalSchema.ToStorePropertyDefinition(propertyDefinition);
            bool flag = (storePropertyDefinition.PropertyFlags & PropertyFlags.TrackChange) == PropertyFlags.TrackChange;

            if (!(value is PropertyError) && flag && this.propertyValues.ContainsKey(propertyDefinition))
            {
                originalValue = this.propertyValues[propertyDefinition];
            }
            this.propertyValues[propertyDefinition] = value;
            if (this.deletedProperties != null)
            {
                this.deletedProperties.Remove(propertyDefinition);
            }
            this.ChangedProperties.TryAdd(propertyDefinition);
            this.AddTrackingInformation(storePropertyDefinition, PropertyTrackingInformation.Modified, originalValue);
        }
예제 #8
0
        public ICoreItem OpenAttachedItem(ICollection <PropertyDefinition> propertiesToLoad, AttachmentPropertyBag attachmentBag, bool isNew)
        {
            this.CheckDisposed(null);
            CoreItem coreItem         = null;
            int      attachmentNumber = attachmentBag.AttachmentNumber;

            if (this.attachedItems.TryGetValue(attachmentNumber, out coreItem))
            {
                string text   = coreItem.PropertyBag.TryGetProperty(InternalSchema.ItemClass) as string;
                Schema schema = (text != null) ? ObjectClass.GetSchema(text) : MessageItemSchema.Instance;
                propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema.AutoloadProperties, propertiesToLoad);
                coreItem.PropertyBag.Load(propertiesToLoad);
            }
            else
            {
                if (!isNew)
                {
                    throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenEmbeddedMessage);
                }
                string text2   = attachmentBag.TryGetProperty(InternalSchema.ItemClass) as string;
                Schema schema2 = (text2 != null) ? ObjectClass.GetSchema(text2) : MessageItemSchema.Instance;
                propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema2.AutoloadProperties, propertiesToLoad);
                coreItem         = new CoreItem(null, new InMemoryPersistablePropertyBag(propertiesToLoad)
                {
                    ExTimeZone = this.ExTimeZone
                }, StoreObjectId.DummyId, null, Origin.New, ItemLevel.Attached, propertiesToLoad, ItemBindOption.LoadRequiredPropertiesOnly);
                if (text2 != null)
                {
                    coreItem.PropertyBag[InternalSchema.ItemClass] = text2;
                }
                this.attachedItems.Add(attachmentNumber, coreItem);
            }
            return(new CoreItemWrapper(coreItem));
        }
예제 #9
0
        private static ICollection <NativeStorePropertyDefinition> GetNativePropertyDefinitions <T>(PropertyDependencyType targetDependencyType, ICollection <T> propertyDefinitions, bool hashSetOrList, Predicate <NativeStorePropertyDefinition> addToCollection) where T : PropertyDefinition
        {
            EnumValidator.AssertValid <PropertyDependencyType>(targetDependencyType);
            if (propertyDefinitions == null)
            {
                return(StorePropertyDefinition.EmptyNativeStoreProperties);
            }
            int num = (propertyDefinitions.Count >= StorePropertyDefinition.dependencyEstimates.Length) ? propertyDefinitions.Count : StorePropertyDefinition.dependencyEstimates[propertyDefinitions.Count];
            ICollection <NativeStorePropertyDefinition> collection = null;
            Action <NativeStorePropertyDefinition>      action;

            if (hashSetOrList)
            {
                HashSet <NativeStorePropertyDefinition> nativePropertyDefinitionsSet = new HashSet <NativeStorePropertyDefinition>(num);
                action = delegate(NativeStorePropertyDefinition item)
                {
                    if (addToCollection == null)
                    {
                        nativePropertyDefinitionsSet.TryAdd(item);
                        return;
                    }
                    if (addToCollection(item))
                    {
                        nativePropertyDefinitionsSet.TryAdd(item);
                    }
                };
                collection = nativePropertyDefinitionsSet;
            }
            else
            {
                IList <NativeStorePropertyDefinition> loadList = new List <NativeStorePropertyDefinition>(num);
                action = delegate(NativeStorePropertyDefinition item)
                {
                    if (addToCollection == null)
                    {
                        loadList.Add(item);
                        return;
                    }
                    if (addToCollection(item))
                    {
                        loadList.Add(item);
                    }
                };
                collection = loadList;
            }
            foreach (T t in propertyDefinitions)
            {
                PropertyDefinition      propertyDefinition      = t;
                StorePropertyDefinition storePropertyDefinition = InternalSchema.ToStorePropertyDefinition(propertyDefinition);
                storePropertyDefinition.ForEachMatch(targetDependencyType, action);
            }
            int count = collection.Count;

            if (count != num && propertyDefinitions.Count < StorePropertyDefinition.dependencyEstimates.Length)
            {
                Interlocked.Exchange(ref StorePropertyDefinition.dependencyEstimates[propertyDefinitions.Count], count);
            }
            return(collection);
        }
예제 #10
0
        public HashSet <PropertyDefinition> CalculatePropertyDefinitionsToBeLoaded(ICollection <PropertyDefinition> requestedProperties)
        {
            ICollection <PropertyDefinition> collection = InternalSchema.Combine <PropertyDefinition>(ConversationTreeFactory.RequiredBuildTreeProperties, requestedProperties);
            HashSet <PropertyDefinition>     hashSet    = new HashSet <PropertyDefinition>(collection);

            hashSet.ExceptWith(ConversationDataExtractor.BodyPropertiesCanBeExtracted);
            return(hashSet);
        }
예제 #11
0
        private SortOrder GetSortOrder(MapiTable table, SortBy[] sortColumns, GroupByAndOrder[] groupBy, int expandCount, ref List <PropTag> alteredProperties)
        {
            if ((sortColumns == null || sortColumns.Length == 0) && (groupBy == null || groupBy.Length == 0))
            {
                return(null);
            }
            SortOrder sortOrder = new SortOrder();

            if (groupBy != null)
            {
                for (int i = 0; i < groupBy.Length; i++)
                {
                    NativeStorePropertyDefinition nativeGroupBy = InternalSchema.ToStorePropertyDefinition(groupBy[i].GroupByColumn).GetNativeGroupBy();
                    PropTag   sortPropertyTag  = this.GetSortPropertyTag(nativeGroupBy, ref alteredProperties);
                    GroupSort nativeGroupSort  = InternalSchema.ToStorePropertyDefinition(groupBy[i].GroupSortColumn.ColumnDefinition).GetNativeGroupSort(groupBy[i].GroupSortColumn.SortOrder, groupBy[i].GroupSortColumn.Aggregate);
                    PropTag   sortPropertyTag2 = this.GetSortPropertyTag((NativeStorePropertyDefinition)nativeGroupSort.ColumnDefinition, ref alteredProperties);
                    SortFlags sortFlag;
                    switch (nativeGroupSort.Aggregate)
                    {
                    case Aggregate.Min:
                        sortFlag = SortFlags.CategoryMin;
                        break;

                    case Aggregate.Max:
                        sortFlag = SortFlags.CategoryMax;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException("groupBy", nativeGroupSort.Aggregate, ServerStrings.ExInvalidAggregate);
                    }
                    sortOrder.AddCategory(sortPropertyTag, QueryExecutor.SortOrderToSortFlags(nativeGroupSort.SortOrder));
                    if (sortPropertyTag != sortPropertyTag2)
                    {
                        sortOrder.Add(sortPropertyTag2, sortFlag);
                    }
                }
                sortOrder.ExpandCount = expandCount;
            }
            if (sortOrder.GetSortCount() > 4)
            {
                throw new ArgumentException(ServerStrings.ExTooComplexGroupSortParameter, "groupBy");
            }
            if (sortColumns != null && sortColumns.Length > 0)
            {
                SortBy[] nativeSortBy = QueryExecutor.GetNativeSortBy(sortColumns);
                if (nativeSortBy.Length + sortOrder.GetSortCount() > 6)
                {
                    throw new ArgumentOutOfRangeException("sortColumns", ServerStrings.ExTooManySortColumns);
                }
                for (int j = 0; j < nativeSortBy.Length; j++)
                {
                    PropertyDefinition columnDefinition = nativeSortBy[j].ColumnDefinition;
                    PropTag            sortPropertyTag3 = this.GetSortPropertyTag((NativeStorePropertyDefinition)columnDefinition, ref alteredProperties);
                    sortOrder.Add(sortPropertyTag3, QueryExecutor.SortOrderToSortFlags(nativeSortBy[j].SortOrder));
                }
            }
            return(sortOrder);
        }
예제 #12
0
 public virtual Stream OpenPropertyStream(PropertyDefinition propertyDefinition, PropertyOpenMode openMode)
 {
     this.CheckDisposed("OpenProperyStream");
     EnumValidator.ThrowIfInvalid <PropertyOpenMode>(openMode, "openMode");
     InternalSchema.ToStorePropertyDefinition(propertyDefinition);
     if (!(propertyDefinition is NativeStorePropertyDefinition))
     {
         throw new NotSupportedException(ServerStrings.ExCalculatedPropertyStreamAccessNotSupported(propertyDefinition.Name));
     }
     return(this.PropertyBag.OpenPropertyStream(propertyDefinition, openMode));
 }
예제 #13
0
        internal static Dictionary <StorePropertyDefinition, int> CreatePropertyPositionsDictionary(ICollection <PropertyDefinition> columns)
        {
            Dictionary <StorePropertyDefinition, int> dictionary = new Dictionary <StorePropertyDefinition, int>(columns.Count);
            int num = 0;

            foreach (PropertyDefinition propertyDefinition in columns)
            {
                StorePropertyDefinition propertyDefinition2 = (StorePropertyDefinition)propertyDefinition;
                dictionary.Add(InternalSchema.ToStorePropertyDefinition(propertyDefinition2), num++);
            }
            return(dictionary);
        }
예제 #14
0
 public static IEnumerable <PropValue> ConvertEnumerator <PropDefType>(IEnumerable <KeyValuePair <PropDefType, object> > sourceEnumerator) where PropDefType : PropertyDefinition
 {
     if (sourceEnumerator != null)
     {
         foreach (KeyValuePair <PropDefType, object> pair in sourceEnumerator)
         {
             KeyValuePair <PropDefType, object> keyValuePair            = pair;
             StorePropertyDefinition            storePropertyDefinition = InternalSchema.ToStorePropertyDefinition(keyValuePair.Key);
             KeyValuePair <PropDefType, object> keyValuePair2           = pair;
             yield return(new PropValue(storePropertyDefinition, keyValuePair2.Value));
         }
     }
     yield break;
 }
예제 #15
0
        internal static IEnumerable <PropValue> ResolveProperties(MemoryPropertyBag client, MemoryPropertyBag server, MemoryPropertyBag original, AcrProfile profile)
        {
            ConflictResolutionResult resolutionResult = profile.ResolveConflicts(MasterCategoryList.GetPropValuesToResolve(client, server, original, profile));

            if (resolutionResult.SaveStatus == SaveResult.IrresolvableConflict)
            {
                throw new Exception();
            }
            foreach (PropertyConflict conflict in resolutionResult.PropertyConflicts)
            {
                yield return(new PropValue(InternalSchema.ToStorePropertyDefinition(conflict.PropertyDefinition), conflict.ResolvedValue));
            }
            yield break;
        }
        protected List <PropValue> GetPropValuesFromValues(ExTimeZone exTimeZone, IList <PropertyDefinition> propertyDefinitions, IList <object> propertyValues)
        {
            ICollection <PropTag> collection = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions <PropertyDefinition>(this.Session.Mailbox.MapiStore, this.Session, false, propertyDefinitions);
            List <PropValue>      list       = new List <PropValue>(propertyDefinitions.Count);
            int num = 0;

            foreach (PropTag propTag in collection)
            {
                InternalSchema.CheckPropertyValueType(propertyDefinitions[num], propertyValues[num]);
                list.Add(MapiPropertyBag.GetPropValueFromValue(this.Session, exTimeZone, propTag, propertyValues[num]));
                num++;
            }
            return(list);
        }
예제 #17
0
        public override PropertyValueTrackingData GetOriginalPropertyInformation(PropertyDefinition propertyDefinition)
        {
            StorePropertyDefinition storePropertyDefinition = InternalSchema.ToStorePropertyDefinition(propertyDefinition);

            if ((storePropertyDefinition.PropertyFlags & PropertyFlags.TrackChange) != PropertyFlags.TrackChange)
            {
                return(PropertyValueTrackingData.PropertyValueTrackDataNotTracked);
            }
            if (this.TrackedPropertyInformation != null && this.TrackedPropertyInformation.ContainsKey(propertyDefinition))
            {
                return(this.TrackedPropertyInformation[propertyDefinition]);
            }
            return(PropertyValueTrackingData.PropertyValueTrackDataUnchanged);
        }
예제 #18
0
        public static IStorePropertyBag[] FindItemsFromInternetId(MailboxSession session, string internetMessageId, ItemQueryType itemQueryType, params PropertyDefinition[] propertyDefinitions)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullOrEmptyArgument(internetMessageId, "internetMessageId");
            Util.ThrowOnNullOrEmptyArgument(propertyDefinitions, "propertyDefinitions");
            ICollection <PropertyDefinition> properties = InternalSchema.Combine <PropertyDefinition>(propertyDefinitions, new PropertyDefinition[]
            {
                ItemSchema.InternetMessageId,
                ItemSchema.InternetMessageIdHash
            });
            int internetMessageIdHash = (int)AllItemsFolderHelper.GetHashValue(internetMessageId);

            IStorePropertyBag[] array = AllItemsFolderHelper.RunQueryOnAllItemsFolder <IStorePropertyBag[]>(session, AllItemsFolderHelper.SupportedSortBy.InternetMessageIdHash, internetMessageIdHash, null, (QueryResult queryResult) => AllItemsFolderHelper.ProcessQueryResult(queryResult, internetMessageId, internetMessageIdHash), properties, itemQueryType);
            return(array ?? Array <IStorePropertyBag> .Empty);
        }
예제 #19
0
 public object this[PropertyDefinition propertyDefinition]
 {
     get
     {
         StorePropertyDefinition other = InternalSchema.ToStorePropertyDefinition(propertyDefinition);
         for (int i = 0; i < this.columns.Length; i++)
         {
             StorePropertyDefinition storePropertyDefinition = InternalSchema.ToStorePropertyDefinition(this.columns[i]);
             if (storePropertyDefinition.CompareTo(other) == 0)
             {
                 return(this.row[i]);
             }
         }
         return(new PropertyError(propertyDefinition, PropertyErrorCode.NotFound));
     }
 }
예제 #20
0
 private void OnOpenConnection(ICollection <PropertyDefinition> propertiesToLoad)
 {
     if (this.persistablePropertyBag == null)
     {
         Schema attachmentSchema = AttachmentPropertyBag.GetAttachmentSchema(this.AttachMethod);
         propertiesToLoad            = InternalSchema.Combine <PropertyDefinition>(attachmentSchema.AutoloadProperties, propertiesToLoad);
         this.persistablePropertyBag = this.attachmentProvider.OpenAttachment(propertiesToLoad, this);
         this.persistablePropertyBag.Context.Session   = this.attachmentTablePropertyBag.Context.Session;
         this.persistablePropertyBag.Context.CoreState = this.attachmentTablePropertyBag.Context.CoreState;
         this.UpdateAttachmentTableCache();
     }
     else if (propertiesToLoad != null)
     {
         this.persistablePropertyBag.Load(propertiesToLoad);
     }
     this.attachmentProvider.OnAttachmentLoad(this);
 }
예제 #21
0
        private static SortBy[] GetNativeSortBy(SortBy[] originalSortBy)
        {
            List <SortBy> list = new List <SortBy>();

            for (int i = 0; i < originalSortBy.Length; i++)
            {
                SortBy sortBy = originalSortBy[i];
                if (sortBy == null)
                {
                    ExTraceGlobals.StorageTracer.TraceError <int>(0L, "Folder.GetNativeSortBy. SortColumns[i] should not be Null. i = {0}.", i);
                    throw new ArgumentException(ServerStrings.ExNullSortOrderParameter(i));
                }
                StorePropertyDefinition storePropertyDefinition = InternalSchema.ToStorePropertyDefinition(sortBy.ColumnDefinition);
                SortBy[] nativeSortBy = storePropertyDefinition.GetNativeSortBy(sortBy.SortOrder);
                list.AddRange(nativeSortBy);
            }
            return(list.ToArray());
        }
        private AttachmentPropertyBag InternalCreateAttachmentPropertyBag(AttachmentType?type, CoreAttachment attachmentToClone, IItem itemToAttach)
        {
            this.InitCollection("InternalCreateAttachmentPropertyBag", true);
            bool flag             = false;
            int  attachmentNumber = -1;
            PersistablePropertyBag persistablePropertyBag = null;
            AttachmentPropertyBag  attachmentPropertyBag  = null;

            try
            {
                Schema attachmentSchema = CoreAttachmentCollection.GetAttachmentSchema(type);
                ICollection <PropertyDefinition> prefetchProperties = InternalSchema.Combine <PropertyDefinition>(attachmentSchema.AutoloadProperties, (ICollection <PropertyDefinition>) this.fetchProperties);
                persistablePropertyBag           = this.attachmentProvider.CreateAttachment(prefetchProperties, attachmentToClone, itemToAttach, out attachmentNumber);
                attachmentPropertyBag            = new AttachmentPropertyBag(this.attachmentProvider, attachmentNumber, persistablePropertyBag, true);
                attachmentPropertyBag.ExTimeZone = this.ExTimeZone;
                if (type != null)
                {
                    int num = CoreAttachment.AttachmentTypeToAttachMethod(type.Value);
                    ((IDirectPropertyBag)attachmentPropertyBag).SetValue(InternalSchema.AttachMethod, num);
                }
                this.isDirty = true;
                this.IsClonedFromAnExistingAttachmentCollection = false;
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    if (attachmentPropertyBag != null)
                    {
                        attachmentPropertyBag.Dispose();
                        attachmentPropertyBag = null;
                    }
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                        persistablePropertyBag = null;
                    }
                }
            }
            return(attachmentPropertyBag);
        }
예제 #23
0
        private static NativeStorePropertyDefinition GetPropDefByMapiNamedProp(NamedProp prop, PropType type, NativeStorePropertyDefinition.TypeCheckingFlag propertyTypeCheckingFlag)
        {
            if (prop == null)
            {
                return(null);
            }
            switch (prop.Kind)
            {
            case NamedPropKind.Id:
                return(GuidIdPropertyDefinition.InternalCreateCustom(string.Empty, type, prop.Guid, prop.Id, PropertyFlags.None, propertyTypeCheckingFlag, new PropertyDefinitionConstraint[0]));

            case NamedPropKind.String:
                if (GuidNamePropertyDefinition.IsValidName(prop.Guid, prop.Name))
                {
                    return(GuidNamePropertyDefinition.InternalCreate(string.Empty, InternalSchema.ClrTypeFromPropTagType(type), type, prop.Guid, prop.Name, PropertyFlags.None, propertyTypeCheckingFlag, true, PropertyDefinitionConstraint.None));
                }
                return(null);

            default:
                throw new ArgumentOutOfRangeException("prop.Kind");
            }
        }
예제 #24
0
 internal void LoadDataFromXsoRows(ADObjectId mailboxOwnerId, object[] objectRow, PropertyDefinition[] xsoPropertyDefinitions)
 {
     if (mailboxOwnerId == null)
     {
         throw new ArgumentNullException("mailboxOwnerId");
     }
     if (objectRow == null)
     {
         throw new ArgumentNullException("objectRow");
     }
     if (xsoPropertyDefinitions == null)
     {
         throw new ArgumentNullException("xsoPropertyDefinitions");
     }
     if (objectRow.Length != xsoPropertyDefinitions.Length)
     {
         throw new ArgumentException("xsoPropertyDefinitions and objectRow length mismatch");
     }
     base.InstantiationErrors.Clear();
     this.MailboxOwnerId = mailboxOwnerId;
     for (int i = 0; i < xsoPropertyDefinitions.Length; i++)
     {
         XsoDriverPropertyDefinition relatedWrapperProperty = this.Schema.GetRelatedWrapperProperty(xsoPropertyDefinitions[i]);
         try
         {
             object obj = objectRow[i];
             StorePropertyDefinition propertyDefinition = InternalSchema.ToStorePropertyDefinition(xsoPropertyDefinitions[i]);
             if (obj != null)
             {
                 this.propertyBag.SetField(relatedWrapperProperty, PropertyBag.CheckPropertyValue <object>(propertyDefinition, obj, null));
             }
         }
         catch (StoragePermanentException ex)
         {
             base.InstantiationErrors.Add(new PropertyValidationError(ex.LocalizedString, relatedWrapperProperty, null));
         }
     }
 }
예제 #25
0
        private void RetryBigProperties(IList <NativeStorePropertyDefinition> allPropDefs, ICollection <PropTag> allPropTags, object[] allValues)
        {
            List <int> list  = null;
            int        count = allPropDefs.Count;

            for (int i = 0; i < count; i++)
            {
                if (PropertyError.IsPropertyValueTooBig(allValues[i]) && MapiPropertyBag.IsPropertyRetriable(allPropDefs[i]))
                {
                    if (list == null)
                    {
                        list = new List <int>(10);
                    }
                    list.Add(i);
                }
            }
            if (list == null)
            {
                return;
            }
            PropTag[] array = new PropTag[count];
            allPropTags.CopyTo(array, 0);
            bool flag = true;

            while (flag && list.Count > 0)
            {
                flag = false;
                PropTag[] array2 = new PropTag[list.Count];
                for (int j = 0; j < array2.Length; j++)
                {
                    array2[j] = array[list[j]];
                }
                PropValue[]  array3       = null;
                StoreSession storeSession = this.StoreSession;
                bool         flag2        = false;
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.BeginMapiCall();
                        storeSession.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    array3 = this.mapiProp.GetProps(array2);
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.ExGetPropsFailed, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiPropertyBag::RetryBigProperties. MapiProp = {0}.", this.MapiProp),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.ExGetPropsFailed, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiPropertyBag::RetryBigProperties. MapiProp = {0}.", this.MapiProp),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (storeSession != null)
                        {
                            storeSession.EndMapiCall();
                            if (flag2)
                            {
                                storeSession.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                for (int k = array3.Length - 1; k >= 0; k--)
                {
                    int    num = list[k];
                    object valueFromPropValue = MapiPropertyBag.GetValueFromPropValue(this.storeSession, this.ExTimeZone, InternalSchema.ToStorePropertyDefinition(allPropDefs[num]), array3[k]);
                    if (!PropertyError.IsPropertyValueTooBig(valueFromPropValue))
                    {
                        allValues[num] = valueFromPropValue;
                        list.RemoveAt(k);
                        flag = true;
                    }
                }
            }
        }
예제 #26
0
        private PropertyError[] InternalSetProperties(PropertyDefinition[] propertyDefinitions, object[] propertyValues, MapiPropertyBag.MapiSetProps mapiSetProps)
        {
            this.CheckDisposed("SetProperties");
            if (propertyDefinitions == null)
            {
                throw new ArgumentNullException(ServerStrings.ExNullParameter("propertyDefinitions", 1));
            }
            if (propertyValues == null)
            {
                throw new ArgumentNullException(ServerStrings.ExNullParameter("propertyValues", 2));
            }
            if (propertyDefinitions.Length == 0)
            {
                return(MapiPropertyBag.EmptyPropertyErrorArray);
            }
            ICollection <PropTag> collection = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions <PropertyDefinition>(this.MapiProp, this.storeSession, (this.saveFlags & PropertyBagSaveFlags.IgnoreUnresolvedHeaders) == PropertyBagSaveFlags.IgnoreUnresolvedHeaders, true, (this.saveFlags & PropertyBagSaveFlags.DisableNewXHeaderMapping) != PropertyBagSaveFlags.DisableNewXHeaderMapping, propertyDefinitions);
            List <PropValue>      list       = new List <PropValue>(propertyDefinitions.Length);
            int num = 0;

            foreach (PropTag propTag in collection)
            {
                if (propTag != PropTag.Unresolved)
                {
                    InternalSchema.CheckPropertyValueType(propertyDefinitions[num], propertyValues[num]);
                    list.Add(MapiPropertyBag.GetPropValueFromValue(this.storeSession, this.ExTimeZone, propTag, propertyValues[num]));
                }
                num++;
            }
            PropProblem[] array        = null;
            StoreSession  storeSession = this.StoreSession;
            bool          flag         = false;

            try
            {
                if (storeSession != null)
                {
                    storeSession.BeginMapiCall();
                    storeSession.BeginServerHealthCall();
                    flag = true;
                }
                if (StorageGlobals.MapiTestHookBeforeCall != null)
                {
                    StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                }
                try
                {
                    array = mapiSetProps(list.ToArray());
                }
                catch (MapiExceptionNotEnoughMemory mapiExceptionNotEnoughMemory)
                {
                    ExTraceGlobals.StorageTracer.TraceError <MapiExceptionNotEnoughMemory>((long)this.GetHashCode(), "MapiPropertyBag::InternalSetProperties. Failed to SetProps due to MapiException {0}.", mapiExceptionNotEnoughMemory);
                    string errorDescription    = mapiExceptionNotEnoughMemory.ToString();
                    List <PropertyError> list2 = new List <PropertyError>();
                    foreach (PropertyDefinition propertyDefinition in propertyDefinitions)
                    {
                        list2.Add(new PropertyError(propertyDefinition, PropertyErrorCode.NotEnoughMemory, errorDescription));
                    }
                    throw PropertyError.ToException(list2.ToArray());
                }
            }
            catch (MapiPermanentException ex)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSetProps, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiPropertyBag::InternalSetProperties.", new object[0]),
                    ex
                });
            }
            catch (MapiRetryableException ex2)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSetProps, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiPropertyBag::InternalSetProperties.", new object[0]),
                    ex2
                });
            }
            finally
            {
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.EndMapiCall();
                        if (flag)
                        {
                            storeSession.EndServerHealthCall();
                        }
                    }
                }
                finally
                {
                    if (StorageGlobals.MapiTestHookAfterCall != null)
                    {
                        StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                    }
                }
            }
            PropertyError[] array2 = MapiPropertyBag.EmptyPropertyErrorArray;
            if (array != null)
            {
                array2 = new PropertyError[array.Length];
                for (int j = 0; j < array.Length; j++)
                {
                    int scode = array[j].Scode;
                    PropertyDefinition propertyDefinition2 = null;
                    int num2 = 0;
                    foreach (PropTag propTag2 in collection)
                    {
                        if (array[j].PropTag == propTag2)
                        {
                            propertyDefinition2 = propertyDefinitions[num2];
                            break;
                        }
                        num2++;
                    }
                    string            errorDescription2;
                    PropertyErrorCode error = MapiPropertyHelper.MapiErrorToXsoError(scode, out errorDescription2);
                    array2[j] = new PropertyError(propertyDefinition2, error, errorDescription2);
                    ExTraceGlobals.StorageTracer.TraceError <string, MapiProp, PropertyError>((long)this.GetHashCode(), "MapiPropertyBag::InternalSetProperties. Failed. PropDef display name= {0}, MapiProp = {1}, Error = {2}.", propertyDefinition2.Name, this.MapiProp, array2[j]);
                }
            }
            return(array2);
        }
예제 #27
0
        internal PropertyError[] DeleteProperties(ICollection <PropertyDefinition> propertyDefinitions)
        {
            this.CheckDisposed("DeleteProperties");
            if (propertyDefinitions == null)
            {
                throw new ArgumentNullException(ServerStrings.ExNullParameter("propertyDefinitions", 1));
            }
            if (propertyDefinitions.Count == 0)
            {
                ExTraceGlobals.StorageTracer.TraceError <string>((long)this.GetHashCode(), "MapiPropertyBag::DeleteProperties. {0} contain zero elements.", "propertyDefinitions");
                throw new ArgumentException(ServerStrings.ExEmptyCollection("propertyDefinitions"), "propertyDefinitions");
            }
            IList <PropertyDefinition> list  = new List <PropertyDefinition>();
            IList <PropertyDefinition> list2 = new List <PropertyDefinition>();

            foreach (PropertyDefinition propertyDefinition in propertyDefinitions)
            {
                StorePropertyDefinition       storePropertyDefinition       = InternalSchema.ToStorePropertyDefinition(propertyDefinition);
                NativeStorePropertyDefinition nativeStorePropertyDefinition = storePropertyDefinition as NativeStorePropertyDefinition;
                if (nativeStorePropertyDefinition != null)
                {
                    list.Add(storePropertyDefinition);
                }
                else
                {
                    list2.Add(storePropertyDefinition);
                }
            }
            ICollection <PropTag> tags = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions <PropertyDefinition>(this.MapiProp, this.storeSession, false, list);

            PropProblem[] array        = null;
            StoreSession  storeSession = this.StoreSession;
            bool          flag         = false;

            try
            {
                if (storeSession != null)
                {
                    storeSession.BeginMapiCall();
                    storeSession.BeginServerHealthCall();
                    flag = true;
                }
                if (StorageGlobals.MapiTestHookBeforeCall != null)
                {
                    StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                }
                array = this.MapiProp.DeleteProps(tags, (this.SaveFlags & PropertyBagSaveFlags.NoChangeTracking) != PropertyBagSaveFlags.NoChangeTracking);
            }
            catch (MapiPermanentException ex)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotDeleteProperties, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiPropertyBag::SetProperty. MapiProp = {0}.", this.MapiProp),
                    ex
                });
            }
            catch (MapiRetryableException ex2)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotDeleteProperties, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiPropertyBag::SetProperty. MapiProp = {0}.", this.MapiProp),
                    ex2
                });
            }
            finally
            {
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.EndMapiCall();
                        if (flag)
                        {
                            storeSession.EndServerHealthCall();
                        }
                    }
                }
                finally
                {
                    if (StorageGlobals.MapiTestHookAfterCall != null)
                    {
                        StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                    }
                }
            }
            PropertyError[] array2;
            if (array != null || list2.Count > 0)
            {
                int num = list2.Count;
                if (array != null)
                {
                    num += array.Length;
                }
                array2 = new PropertyError[num];
                int num2 = 0;
                if (array != null)
                {
                    int i = 0;
                    while (i < array.Length)
                    {
                        int               scode = array[i].Scode;
                        string            errorDescription;
                        PropertyErrorCode error         = MapiPropertyHelper.MapiErrorToXsoError(scode, out errorDescription);
                        PropertyError     propertyError = new PropertyError(list[array[i].Index], error, errorDescription);
                        array2[num2] = propertyError;
                        ExTraceGlobals.StorageTracer.TraceError <string, PropertyError>((long)this.GetHashCode(), "MapiPropertyBag::DeleteProperties. Failed. DisplayName = {0}, Error = {1}.", list[array[i].Index].Name, propertyError);
                        i++;
                        num2++;
                    }
                }
                int count = list2.Count;
                int j     = 0;
                while (j < count)
                {
                    PropertyError propertyError2 = new PropertyError(list2[j], PropertyErrorCode.SetCalculatedPropertyError, ServerStrings.ExSetNotSupportedForCalculatedProperty(list2[j].Name));
                    array2[num2] = propertyError2;
                    ExTraceGlobals.StorageTracer.TraceError <string, PropertyError>((long)this.GetHashCode(), "MapiPropertyBag::DeleteProperties. Failed. DisplayName = {0}, Error = {1}.", list2[j].Name, propertyError2);
                    j++;
                    num2++;
                }
            }
            else
            {
                array2 = MapiPropertyBag.EmptyPropertyErrorArray;
            }
            return(array2);
        }
예제 #28
0
        internal object[] GetProperties(IList <NativeStorePropertyDefinition> propertyDefinitions)
        {
            this.CheckDisposed("GetProperties");
            if (propertyDefinitions == null)
            {
                ExTraceGlobals.StorageTracer.TraceError <string>((long)this.GetHashCode(), "MapiPropertyBag::GetProperties. {0} == null.", "propertyDefinitions");
                throw new ArgumentNullException("propertyDefinitions");
            }
            int count = propertyDefinitions.Count;

            if (count == 0)
            {
                ExTraceGlobals.StorageTracer.TraceError <string>((long)this.GetHashCode(), "MapiPropertyBag::GetProperties. {0} contain zero elements.", "propertyDefinitions");
                throw new ArgumentException(ServerStrings.ExEmptyCollection("propertyDefinitions"), "propertyDefinitions");
            }
            object[] array = new object[count];
            ICollection <PropTag> collection = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions(this.MapiProp, this.storeSession, true, !this.storeSession.Capabilities.IsReadOnly, !this.storeSession.Capabilities.IsReadOnly, propertyDefinitions);

            PropValue[]  array2       = null;
            StoreSession storeSession = this.StoreSession;
            bool         flag         = false;

            try
            {
                if (storeSession != null)
                {
                    storeSession.BeginMapiCall();
                    storeSession.BeginServerHealthCall();
                    flag = true;
                }
                if (StorageGlobals.MapiTestHookBeforeCall != null)
                {
                    StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                }
                array2 = this.MapiProp.GetProps(collection);
            }
            catch (MapiPermanentException ex)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.ExGetPropsFailed, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiPropertyBag::GetProperties. MapiProp = {0}.", this.MapiProp),
                    ex
                });
            }
            catch (MapiRetryableException ex2)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.ExGetPropsFailed, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiPropertyBag::GetProperties. MapiProp = {0}.", this.MapiProp),
                    ex2
                });
            }
            finally
            {
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.EndMapiCall();
                        if (flag)
                        {
                            storeSession.EndServerHealthCall();
                        }
                    }
                }
                finally
                {
                    if (StorageGlobals.MapiTestHookAfterCall != null)
                    {
                        StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                    }
                }
            }
            for (int i = 0; i < count; i++)
            {
                array[i] = MapiPropertyBag.GetValueFromPropValue(this.storeSession, this.ExTimeZone, InternalSchema.ToStorePropertyDefinition(propertyDefinitions[i]), array2[i]);
            }
            this.RetryBigProperties(propertyDefinitions, collection, array);
            return(array);
        }
예제 #29
0
 public new static SearchFolder Bind(StoreSession session, StoreId folderId, ICollection <PropertyDefinition> propsToReturn)
 {
     propsToReturn = InternalSchema.Combine <PropertyDefinition>(FolderSchema.Instance.AutoloadProperties, propsToReturn);
     return(Folder.InternalBind <SearchFolder>(session, folderId, propsToReturn));
 }
 private UnresolvedPropertyDefinition(PropTag propTag) : base(string.Empty, InternalSchema.ClrTypeFromPropTag(propTag))
 {
     this.propertyTag = (uint)propTag;
 }