Example #1
0
        protected virtual ILoadBalanceService CreateLoadBalancerClient(DirectoryServer server, IDirectoryProvider directory)
        {
            ILoadBalanceService result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                LoadBalancerClient loadBalancerClient = LoadBalancerClient.Create(server.Fqdn, directory, this.logger);
                disposeGuard.Add <LoadBalancerClient>(loadBalancerClient);
                bool flag = true;
                ILoadBalanceService loadBalanceService = loadBalancerClient;
                if (!loadBalancerClient.ServerVersion[1])
                {
                    flag = false;
                    loadBalanceService = this.CreateCompatibilityLoadBalanceClient(server);
                }
                else if (!loadBalancerClient.ServerVersion[2])
                {
                    loadBalanceService = new SoftDeletedRemovalCapabilityDecorator(loadBalanceService, server);
                }
                if (!loadBalancerClient.ServerVersion[3])
                {
                    loadBalanceService = new ConsumerMetricsLoadBalanceCapabilityDecorator(loadBalanceService, server);
                }
                if (!loadBalancerClient.ServerVersion[5])
                {
                    loadBalanceService = new CapacitySummaryCapabilityDecorator(loadBalanceService, server, this.serviceContext);
                }
                if (flag)
                {
                    disposeGuard.Success();
                }
                result = loadBalanceService;
            }
            return(result);
        }
Example #2
0
        protected virtual IInjectorService CreateInjectorClient(DirectoryServer server, IDirectoryProvider directory)
        {
            IInjectorService result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                InjectorClient injectorClient = InjectorClient.Create(server.Fqdn, directory, this.logger);
                disposeGuard.Add <InjectorClient>(injectorClient);
                bool             flag            = true;
                IInjectorService injectorService = injectorClient;
                if (!injectorClient.ServerVersion[1])
                {
                    flag            = false;
                    injectorService = this.CreateCompatibilityInjectorClient(server);
                }
                if (!injectorClient.ServerVersion[2])
                {
                    injectorService = new ConsumerMetricsInjectorCapabilityDecorator(injectorService);
                }
                if (flag)
                {
                    disposeGuard.Success();
                }
                result = injectorService;
            }
            return(result);
        }
 public Stream GetReadOnlyApplefileStream()
 {
     base.CheckDisposed("GetReadOnlyApplefileStream");
     if (this.IsFlaggedAsMacAttachment)
     {
         object obj = base.TryGetProperty(InternalSchema.AttachmentMacInfo);
         if (obj is byte[])
         {
             return(new MemoryStream(obj as byte[], false));
         }
         if (PropertyError.IsPropertyValueTooBig(obj))
         {
             return(this.OpenPropertyStream(InternalSchema.AttachmentMacInfo, PropertyOpenMode.ReadOnly));
         }
         using (Stream rawContentStream = this.GetRawContentStream(PropertyOpenMode.ReadOnly))
         {
             if (this.IsMacAttachmentInternal(rawContentStream))
             {
                 using (DisposeGuard disposeGuard = default(DisposeGuard))
                 {
                     Stream stream = disposeGuard.Add <MemoryStream>(new MemoryStream());
                     string text   = null;
                     byte[] array  = null;
                     MimeAppleTranscoder.MacBinToApplefile(rawContentStream, stream, out text, out array);
                     disposeGuard.Success();
                     return(stream);
                 }
             }
             throw new CorruptDataException(ServerStrings.ConversionFailedInvalidMacBin);
         }
     }
     throw new InvalidOperationException();
 }
Example #4
0
 internal BodyTextReader(ICoreItem coreItem, BodyReadConfiguration configuration, Stream inputStream)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         Stream     stream     = null;
         TextReader textReader = null;
         bool       flag       = false;
         this.disposeTracker = this.GetDisposeTracker();
         try
         {
             if (inputStream == null)
             {
                 stream      = BodyReadStream.OpenBodyStream(coreItem);
                 inputStream = stream;
             }
             if (inputStream == null)
             {
                 inputStream = Body.GetEmptyStream();
             }
             textReader = BodyReadDelegates.CreateReader(coreItem, configuration, inputStream, out this.conversionCallbacks);
             flag       = true;
         }
         finally
         {
             if (!flag && stream != null)
             {
                 stream.Dispose();
             }
         }
         this.reader     = textReader;
         this.bodyStream = stream;
         this.isDisposed = false;
         disposeGuard.Success();
     }
 }
Example #5
0
        public static MessageItem CreateDelegateForward(MessageItem originalItem, CultureInfo culture, string imceaDomain, string xLoop, IRuleEvaluationContext context)
        {
            Util.ThrowOnNullArgument(originalItem, "originalItem");
            ExTraceGlobals.StorageTracer.Information(0L, "RuleMessageUtils::CreateDelegateForward.");
            MessageItem result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                MessageItem messageItem = RuleMessageUtils.CreateRedirect(originalItem, culture, imceaDomain, xLoop, context);
                disposeGuard.Add <MessageItem>(messageItem);
                for (int i = 0; i < RuleMessageUtils.rcvdRepresentingProps.Length; i++)
                {
                    if (originalItem.GetValueOrDefault <object>(RuleMessageUtils.rcvdRepresentingProps[i]) == null)
                    {
                        object valueOrDefault = originalItem.GetValueOrDefault <object>(RuleMessageUtils.rcvdByProps[i]);
                        if (valueOrDefault != null)
                        {
                            messageItem[RuleMessageUtils.rcvdRepresentingProps[i]] = valueOrDefault;
                        }
                    }
                    messageItem.Delete(RuleMessageUtils.rcvdByProps[i]);
                }
                object valueOrDefault2 = originalItem.GetValueOrDefault <object>(InternalSchema.SentRepresentingEntryId);
                if (valueOrDefault2 != null)
                {
                    messageItem[InternalSchema.ReadReceiptEntryId] = valueOrDefault2;
                    messageItem[InternalSchema.ReportEntryId]      = valueOrDefault2;
                }
                disposeGuard.Success();
                result = messageItem;
            }
            return(result);
        }
Example #6
0
        private static Folder GetFolder(AnchorContext context, MailboxSession mailboxSession, StoreObjectId rootFolderId, string folderName)
        {
            AnchorUtil.ThrowOnNullArgument(mailboxSession, "mailboxSession");
            AnchorUtil.ThrowOnNullArgument(rootFolderId, "rootFolderId");
            AnchorUtil.ThrowOnNullArgument(folderName, "folderName");
            Folder result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                Folder        folder        = null;
                StoreObjectId storeObjectId = AnchorFolder.GetFolderId(context, mailboxSession, rootFolderId, folderName);
                if (storeObjectId == null)
                {
                    folder = Folder.Create(mailboxSession, rootFolderId, StoreObjectType.Folder, folderName, CreateMode.OpenIfExists);
                    disposeGuard.Add <Folder>(folder);
                    folder.Save();
                    folder.Load(AnchorFolder.FolderIdPropertyDefinition);
                    storeObjectId = folder.Id.ObjectId;
                }
                if (folder == null)
                {
                    folder = Folder.Bind(mailboxSession, storeObjectId, AnchorFolder.FolderIdPropertyDefinition);
                    disposeGuard.Add <Folder>(folder);
                }
                disposeGuard.Success();
                result = folder;
            }
            return(result);
        }
Example #7
0
        public static RightsManagedMessageItem ReBind(MessageItem item, OutboundConversionOptions options, bool acquireLicense)
        {
            Util.ThrowOnNullArgument(item, "item");
            Util.ThrowOnNullArgument(options, "options");
            StoreSession storeSession = item.Session ?? ((item.CoreItem.TopLevelItem != null) ? item.CoreItem.TopLevelItem.Session : null);

            if (storeSession == null)
            {
                throw new ArgumentException("Cannot use ReBind() for in-memory message.", "item");
            }
            RightsManagedMessageItem.CheckSession(storeSession);
            if (!item.IsRestricted)
            {
                throw new ArgumentException("Only protected messages can be used for ReBind()");
            }
            RightsManagedMessageItem result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                RightsManagedMessageItem rightsManagedMessageItem = new RightsManagedMessageItem(new CoreItemWrapper(item.CoreItem));
                disposeGuard.Add <RightsManagedMessageItem>(rightsManagedMessageItem);
                rightsManagedMessageItem.Decode(options, acquireLicense);
                disposeGuard.Success();
                rightsManagedMessageItem.originalItem = item;
                result = rightsManagedMessageItem;
            }
            return(result);
        }
Example #8
0
        private static BodyReadStream InternalTryCreateBodyStream(ICoreItem coreItem, BodyReadConfiguration configuration, bool createEmtpyStreamIfNotFound, long?length)
        {
            BodyReadStream result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                Stream stream = BodyReadStream.OpenBodyStream(coreItem);
                disposeGuard.Add <Stream>(stream);
                Stream stream2 = stream;
                if (stream2 == null)
                {
                    if (!createEmtpyStreamIfNotFound)
                    {
                        return(null);
                    }
                    stream2 = Body.GetEmptyStream();
                }
                ConversionCallbackBase conversionCallbackBase;
                Stream disposable = BodyReadDelegates.CreateStream(coreItem, configuration, stream2, out conversionCallbackBase);
                disposeGuard.Add <Stream>(disposable);
                BodyReadStream bodyReadStream = new BodyReadStream(stream, disposable, conversionCallbackBase, length);
                disposeGuard.Add <BodyReadStream>(bodyReadStream);
                disposeGuard.Success();
                result = bodyReadStream;
            }
            return(result);
        }
Example #9
0
 internal CoreObject(StoreSession session, PersistablePropertyBag propertyBag, StoreObjectId storeObjectId, byte[] changeKey, Origin origin, ItemLevel itemLevel, ICollection <PropertyDefinition> prefetchProperties)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         this.session     = session;
         this.propertyBag = propertyBag;
         this.itemLevel   = itemLevel;
         this.Origin      = origin;
         if (propertyBag.DisposeTracker != null)
         {
             propertyBag.DisposeTracker.AddExtraDataWithStackTrace("CoreObject owns PersistablePropertyBag propertyBag at");
         }
         ((IDirectPropertyBag)CoreObject.GetPersistablePropertyBag(this)).Context.CoreObject = this;
         ((IDirectPropertyBag)CoreObject.GetPersistablePropertyBag(this)).Context.Session    = this.Session;
         if (prefetchProperties != null)
         {
             if (prefetchProperties == CoreObjectSchema.AllPropertiesOnStore)
             {
                 this.propertyBag.PrefetchPropertyArray = CoreObjectSchema.AllPropertiesOnStore;
             }
             else
             {
                 this.propertyBag.PrefetchPropertyArray = StorePropertyDefinition.GetNativePropertyDefinitions <PropertyDefinition>(PropertyDependencyType.AllRead, prefetchProperties).ToArray <NativeStorePropertyDefinition>();
             }
             this.propertyBag.Load(prefetchProperties);
         }
         this.storeObjectId = storeObjectId;
         this.id            = ((changeKey != null) ? new VersionedId(this.storeObjectId, changeKey) : null);
         disposeGuard.Success();
     }
 }
Example #10
0
 protected XsoMailboxDataProviderBase(ExchangePrincipal mailboxOwner, ISecurityAccessToken userToken, string action)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         Util.ThrowOnNullArgument(mailboxOwner, "mailboxOwner");
         Util.ThrowOnNullOrEmptyArgument(action, "action");
         if (userToken == null)
         {
             this.MailboxSession = MailboxSession.Open(mailboxOwner, new WindowsPrincipal(WindowsIdentity.GetCurrent()), CultureInfo.InvariantCulture, string.Format("Client=Management;Action={0}", action));
         }
         else
         {
             try
             {
                 using (ClientSecurityContext clientSecurityContext = new ClientSecurityContext(userToken, AuthzFlags.AuthzSkipTokenGroups))
                 {
                     clientSecurityContext.SetSecurityAccessToken(userToken);
                     this.MailboxSession = MailboxSession.Open(mailboxOwner, clientSecurityContext, CultureInfo.InvariantCulture, string.Format("Client=Management;Action={0}", action));
                 }
             }
             catch (AuthzException ex)
             {
                 throw new AccessDeniedException(new LocalizedString(ex.Message));
             }
         }
         disposeGuard.Success();
     }
 }
        internal static ActivityScope AddActivityScope(ActivityContextState activityContextState)
        {
            Guid          guid = Guid.NewGuid();
            ActivityScope result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                try
                {
                    ActivityScopeImpl.scopeCacheLock.EnterWriteLock();
                    ActivityScopeImpl activityScopeImpl = new ActivityScopeImpl(guid);
                    disposeGuard.Add <ActivityScopeImpl>(activityScopeImpl);
                    ActivityScopeImpl.scopeCache.Add(guid, activityScopeImpl);
                    ActivityScope activityScope = new ActivityScope(activityScopeImpl);
                    disposeGuard.Add <ActivityScope>(activityScope);
                    activityScopeImpl.UpdateFromState(activityContextState);
                    SingleContext.Singleton.LocalId = new Guid?(guid);
                    SingleContext.Singleton.SetId();
                    disposeGuard.Success();
                    result = activityScope;
                }
                finally
                {
                    try
                    {
                        ActivityScopeImpl.scopeCacheLock.ExitWriteLock();
                    }
                    catch (SynchronizationLockException)
                    {
                    }
                }
            }
            return(result);
        }
        private ISourceMailbox GetSourceMailbox()
        {
            ISourceMailbox result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                ExchangePrincipal exchangePrincipal;
                if (!PublicFolderSession.TryGetPublicFolderMailboxPrincipal(this.OrganizationId, PublicFolderSession.HierarchyMailboxGuidAlias, true, out exchangePrincipal))
                {
                    throw new StoragePermanentException(PublicFolderSession.GetNoPublicFoldersProvisionedError(this.OrganizationId));
                }
                ISourceMailbox sourceMailbox = new RemoteSourceMailbox(exchangePrincipal.MailboxInfo.Location.ServerFqdn, null, null, this.isSingleFolderSync ? ProxyControlFlags.SkipWLMThrottling : ProxyControlFlags.None, PublicFolderSynchronizerContext.RequiredCapabilities, false, LocalMailboxFlags.None);
                disposeGuard.Add <ISourceMailbox>(sourceMailbox);
                TenantPartitionHint partitionHint = CommonUtils.GetPartitionHint(this.OrganizationId);
                if (this.Logger != null)
                {
                    this.Logger.LogEvent(LogEventType.Verbose, string.Format("Connecting to Primary Hierarchy. [Mailbox:{0}; Server:{1}; Database:{2}; PartitionHint:{3}]", new object[]
                    {
                        exchangePrincipal.MailboxInfo.MailboxGuid,
                        exchangePrincipal.MailboxInfo.Location.ServerFqdn,
                        exchangePrincipal.MailboxInfo.GetDatabaseGuid(),
                        partitionHint
                    }));
                }
                sourceMailbox.Config(null, exchangePrincipal.MailboxInfo.MailboxGuid, exchangePrincipal.MailboxInfo.MailboxGuid, partitionHint, exchangePrincipal.MailboxInfo.GetDatabaseGuid(), MailboxType.SourceMailbox, null);
                sourceMailbox.Connect(MailboxConnectFlags.PublicFolderHierarchyReplication);
                disposeGuard.Success();
                result = sourceMailbox;
            }
            return(result);
        }
Example #13
0
        private static CalendarGroup CreateMyCalendarsGroup(MailboxSession session)
        {
            CalendarGroup calendarGroup = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                calendarGroup = CalendarGroup.InternalCreateGroup(session, CalendarGroupType.MyCalendars);
                disposeGuard.Add <CalendarGroup>(calendarGroup);
                using (CalendarGroupEntry calendarGroupEntry = CalendarGroupEntry.Create(session, session.GetDefaultFolderId(DefaultFolderType.Calendar), FolderTreeData.MyFoldersClassId, calendarGroup.GroupName))
                {
                    calendarGroupEntry.CalendarName = ClientStrings.Calendar.ToString(session.InternalCulture);
                    ConflictResolutionResult conflictResolutionResult = calendarGroupEntry.Save(SaveMode.NoConflictResolution);
                    if (conflictResolutionResult.SaveStatus != SaveResult.Success)
                    {
                        ExTraceGlobals.StorageTracer.TraceWarning <SmtpAddress>(0L, "Unable to associate default calendar with the MyCalendars group for user: {0}. Attempting to delete default calendars group.", session.MailboxOwner.MailboxInfo.PrimarySmtpAddress);
                        AggregateOperationResult aggregateOperationResult = session.Delete(DeleteItemFlags.HardDelete, new StoreId[]
                        {
                            calendarGroup.Id
                        });
                        if (aggregateOperationResult.OperationResult != OperationResult.Succeeded)
                        {
                            ExTraceGlobals.StorageTracer.TraceWarning <SmtpAddress>(0L, "Unable to delete default calendar group after failing to add the default calendar to it. User: {0}", session.MailboxOwner.MailboxInfo.PrimarySmtpAddress);
                        }
                        throw new DefaultCalendarNodeCreationException();
                    }
                }
                disposeGuard.Success();
            }
            return(calendarGroup);
        }
Example #14
0
 // Token: 0x06001173 RID: 4467 RVA: 0x0006987C File Offset: 0x00067A7C
 internal OwaStoreObjectIdSessionHandle(ExchangePrincipal exchangePrincipal, UserContext userContext)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         if (exchangePrincipal == null)
         {
             throw new ArgumentNullException("exchangePrincipal");
         }
         if (userContext == null)
         {
             throw new ArgumentNullException("userContext");
         }
         if (exchangePrincipal.MailboxInfo.IsArchive)
         {
             throw new ArgumentException("exchangePrincipal is archive mailbox");
         }
         if (exchangePrincipal.MailboxInfo.IsAggregated)
         {
             throw new ArgumentException("exchangePrincipal is aggregated mailbox");
         }
         this.owaStoreObjectId     = null;
         this.userContext          = userContext;
         this.owaStoreObjectIdType = OwaStoreObjectIdType.OtherUserMailboxObject;
         this.InitializeDelegateSessionHandle(exchangePrincipal, userContext);
         disposeGuard.Success();
     }
 }
        Stream ISupportMime.GetMimeStream(MessageRec message, out PropValueData[] extraPropValues)
        {
            extraPropValues = null;
            Properties properties = this.FetchMessageItem(message);

            if (properties == null || properties.Body == null || string.IsNullOrEmpty(properties.Body.Data))
            {
                throw new UnableToFetchMimeStreamException(EasMailbox.GetStringId(message.EntryId));
            }
            if (properties.Flag != null)
            {
                extraPropValues = new PropValueData[]
                {
                    new PropValueData((PropTag)277872643U, properties.Flag.Status)
                };
            }
            string       data         = properties.Body.Data;
            MemoryStream memoryStream = new MemoryStream(data.Length);
            Stream       result;

            using (DisposeGuard disposeGuard = memoryStream.Guard())
            {
                using (StreamWriter streamWriter = new StreamWriter(memoryStream, Encoding.UTF8, 1024, true))
                {
                    streamWriter.Write(data);
                }
                memoryStream.Seek(0L, SeekOrigin.Begin);
                disposeGuard.Success();
                result = memoryStream;
            }
            return(result);
        }
Example #16
0
        // Token: 0x06000310 RID: 784 RVA: 0x000132E8 File Offset: 0x000114E8
        private static RfriContext CreateRfriContext(ClientBinding clientBinding)
        {
            RfriContext rfriContext = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                ClientSecurityContext clientSecurityContext = null;
                bool   isAnonymous = false;
                string text        = null;
                string userDomain  = null;
                RpcHttpConnectionProperties rpcHttpConnectionProperties = null;
                if (!RpcDispatch.TryGetAuthContextInfo(clientBinding, out clientSecurityContext, out isAnonymous, out text, out userDomain, out rpcHttpConnectionProperties))
                {
                    ExTraceGlobals.ReferralTracer.TraceError <Guid>(0L, "Could not resolve anonymous user for session id: {0}", clientBinding.AssociationGuid);
                    throw new RfriException(RfriStatus.LogonFailed, "Could not resolve anonymous user.");
                }
                disposeGuard.Add <ClientSecurityContext>(clientSecurityContext);
                Guid empty = Guid.Empty;
                if (rpcHttpConnectionProperties != null && rpcHttpConnectionProperties.RequestIds.Length > 0)
                {
                    Guid.TryParse(rpcHttpConnectionProperties.RequestIds[rpcHttpConnectionProperties.RequestIds.Length - 1], out empty);
                }
                rfriContext = new RfriContext(clientSecurityContext, userDomain, clientBinding.ClientAddress, clientBinding.ServerAddress, clientBinding.ProtocolSequence, clientBinding.AuthenticationType.ToString(), clientBinding.IsEncrypted, isAnonymous, empty);
                disposeGuard.Add <RfriContext>(rfriContext);
                if (!rfriContext.TryAcquireBudget())
                {
                    ExTraceGlobals.ReferralTracer.TraceError((long)rfriContext.ContextHandle, "Could not acquire budget");
                    throw new RfriException(RfriStatus.GeneralFailure, "Failed to acquire budget.");
                }
                disposeGuard.Success();
            }
            return(rfriContext);
        }
 public PublicFolderDataProvider(IConfigurationSession configurationSession, string action, Guid mailboxGuid)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         Util.ThrowOnNullArgument(configurationSession, "configurationSession");
         Util.ThrowOnNullOrEmptyArgument(action, "action");
         this.currentOrganizationId = configurationSession.GetOrgContainer().OrganizationId;
         TenantPublicFolderConfiguration value = TenantPublicFolderConfigurationCache.Instance.GetValue(this.currentOrganizationId);
         if (mailboxGuid == Guid.Empty)
         {
             Organization orgContainer = configurationSession.GetOrgContainer();
             if (orgContainer.DefaultPublicFolderMailbox.HierarchyMailboxGuid != value.GetHierarchyMailboxInformation().HierarchyMailboxGuid)
             {
                 TenantPublicFolderConfigurationCache.Instance.RemoveValue(this.currentOrganizationId);
             }
         }
         else if (value.GetLocalMailboxRecipient(mailboxGuid) == null)
         {
             TenantPublicFolderConfigurationCache.Instance.RemoveValue(this.currentOrganizationId);
         }
         this.publicFolderSessionCache = new PublicFolderSessionCache(configurationSession.SessionSettings.CurrentOrganizationId, null, null, CultureInfo.InvariantCulture, string.Format("Client=Management;Action={0}", action), null, null, true);
         this.PublicFolderSession      = this.publicFolderSessionCache.GetPublicFolderSession(mailboxGuid);
         disposeGuard.Success();
     }
 }
Example #18
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);
        }
Example #19
0
        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);
        }
Example #20
0
 // Token: 0x06001174 RID: 4468 RVA: 0x00069928 File Offset: 0x00067B28
 internal OwaStoreObjectIdSessionHandle(OwaStoreObjectId owaStoreObjectId, UserContext userContext)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         if (owaStoreObjectId == null)
         {
             throw new ArgumentNullException("owaStoreObjectId");
         }
         if (userContext == null)
         {
             throw new ArgumentNullException("userContext");
         }
         this.owaStoreObjectId     = owaStoreObjectId;
         this.userContext          = userContext;
         this.owaStoreObjectIdType = owaStoreObjectId.OwaStoreObjectIdType;
         if (owaStoreObjectId.OwaStoreObjectIdType == OwaStoreObjectIdType.OtherUserMailboxObject || owaStoreObjectId.OwaStoreObjectIdType == OwaStoreObjectIdType.GSCalendar)
         {
             ExchangePrincipal exchangePrincipal = null;
             if (!userContext.DelegateSessionManager.TryGetExchangePrincipal(owaStoreObjectId.MailboxOwnerLegacyDN, out exchangePrincipal))
             {
                 throw new ObjectNotFoundException(ServerStrings.CannotFindExchangePrincipal);
             }
             this.InitializeDelegateSessionHandle(exchangePrincipal, userContext);
         }
         disposeGuard.Success();
     }
 }
Example #21
0
        internal static bool IsSmimeMessage(ICoreItem coreItem, out bool isMultipartSigned, out bool isOpaqueSigned, out StreamAttachment attachment)
        {
            isMultipartSigned = false;
            isOpaqueSigned    = false;
            attachment        = null;
            string valueOrDefault = coreItem.PropertyBag.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty);

            if (!ObjectClass.IsSmime(valueOrDefault))
            {
                return(false);
            }
            IList <AttachmentHandle> allHandles = coreItem.AttachmentCollection.GetAllHandles();

            if (allHandles.Count != 1)
            {
                return(false);
            }
            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                CoreAttachment coreAttachment = coreItem.AttachmentCollection.Open(allHandles[0]);
                disposeGuard.Add <CoreAttachment>(coreAttachment);
                StreamAttachment streamAttachment = (StreamAttachment)AttachmentCollection.CreateTypedAttachment(coreAttachment, new AttachmentType?(AttachmentType.Stream));
                if (streamAttachment == null)
                {
                    return(false);
                }
                disposeGuard.Add <StreamAttachment>(streamAttachment);
                if (ObjectClass.IsSmimeClearSigned(valueOrDefault))
                {
                    isMultipartSigned = ConvertUtils.IsMessageMultipartSigned(coreItem, streamAttachment);
                    if (isMultipartSigned)
                    {
                        attachment = streamAttachment;
                        disposeGuard.Success();
                        return(true);
                    }
                }
                isOpaqueSigned = ConvertUtils.IsMessageOpaqueSigned(coreItem, streamAttachment);
                if (isOpaqueSigned)
                {
                    attachment = streamAttachment;
                    disposeGuard.Success();
                    return(true);
                }
            }
            return(false);
        }
Example #22
0
        // Token: 0x06000313 RID: 787 RVA: 0x0001366C File Offset: 0x0001186C
        private ICancelableAsyncResult BeginWrapper(string methodName, CancelableAsyncCallback asyncCallback, object asyncState, ClientBinding clientBinding, string legacyDn, Func <RfriContext, RfriDispatchTask> beginDelegate)
        {
            ICancelableAsyncResult asyncResult = null;

            RfriAsyncDispatch.ConditionalExceptionWrapper(ExTraceGlobals.ReferralTracer.IsTraceEnabled(TraceType.DebugTrace), delegate
            {
                if (ExTraceGlobals.ReferralTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    using (ClientSecurityContext clientSecurityContext = clientBinding.GetClientSecurityContext())
                    {
                        ExTraceGlobals.ReferralTracer.TraceDebug(0, 0L, "{0} started. LegacyDn={1}. ClientAddress={2}. ServerAddress={3}. ProtocolSequence={4}. EndPoint={5}. IsEncrypted={6}. ClientSecurityContext={7}.", new object[]
                        {
                            methodName,
                            legacyDn,
                            clientBinding.ClientAddress,
                            clientBinding.ServerAddress,
                            clientBinding.ProtocolSequence,
                            clientBinding.ClientEndpoint,
                            clientBinding.IsEncrypted,
                            clientSecurityContext
                        });
                    }
                }
                FailureAsyncResult <RfriStatus> failureAsyncResult = null;
                this.CheckShuttingDown();
                try
                {
                    using (DisposeGuard disposeGuard = default(DisposeGuard))
                    {
                        RfriContext rfriContext = RfriAsyncDispatch.CreateRfriContext(clientBinding);
                        disposeGuard.Add <RfriContext>(rfriContext);
                        RfriDispatchTask rfriDispatchTask = beginDelegate(rfriContext);
                        disposeGuard.Add <RfriDispatchTask>(rfriDispatchTask);
                        asyncResult = rfriDispatchTask.AsyncResult;
                        this.SubmitTask(rfriDispatchTask);
                        disposeGuard.Success();
                    }
                }
                catch (FailRpcException ex)
                {
                    failureAsyncResult = new FailureAsyncResult <RfriStatus>((RfriStatus)ex.ErrorCode, IntPtr.Zero, ex, asyncCallback, asyncState);
                    asyncResult        = failureAsyncResult;
                }
                catch (RfriException ex2)
                {
                    failureAsyncResult = new FailureAsyncResult <RfriStatus>(ex2.Status, IntPtr.Zero, ex2, asyncCallback, asyncState);
                    asyncResult        = failureAsyncResult;
                }
                if (failureAsyncResult != null && !ThreadPool.QueueUserWorkItem(RfriAsyncDispatch.FailureWaitCallback, failureAsyncResult))
                {
                    failureAsyncResult.InvokeCallback();
                }
                ExTraceGlobals.ReferralTracer.TraceDebug <string>(0, 0L, "{0} succeeded.", methodName);
            }, delegate(Exception exception)
            {
                ExTraceGlobals.ReferralTracer.TraceDebug <string, Exception>(0, 0L, "{0} failed. Exception={1}.", methodName, exception);
            });
            return(asyncResult);
        }
Example #23
0
        protected override IFxProxyPool GetFxProxyPoolTransmissionPipeline(EntryIdMap <byte[]> sourceMap)
        {
            IFxProxyPool result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                IFxProxyPool fxProxyPool = base.DestMailbox.GetFxProxyPool(sourceMap.Keys);
                disposeGuard.Add <IFxProxyPool>(fxProxyPool);
                IFxProxyPool fxProxyPool2 = new MailboxMerger.SimpleTranslatingProxyPool(fxProxyPool, sourceMap);
                disposeGuard.Success();
                disposeGuard.Add <IFxProxyPool>(fxProxyPool2);
                IFxProxyPool fxProxyPool3 = base.CreateFxProxyPoolTransmissionPipeline(fxProxyPool2);
                disposeGuard.Success();
                result = fxProxyPool3;
            }
            return(result);
        }
Example #24
0
 internal PublishedCalendar(MailboxSession mailboxSession, StoreObjectId folderId) : base(mailboxSession, folderId)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         this.LoadPublishedOptions();
         disposeGuard.Success();
     }
 }
 // Token: 0x06000C8D RID: 3213 RVA: 0x0002E93C File Offset: 0x0002CB3C
 public BrokerHandlerReferenceCounter(Func <BrokerHandler> createHandler)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         this.handler = createHandler();
         this.handler.Subscribe();
         disposeGuard.Success();
     }
 }
Example #26
0
 public PublicFolderStatisticsDataProvider(IConfigurationSession configurationSession, string action, Guid mailboxGuid)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         this.publicFolderDataProvider = new PublicFolderDataProvider(configurationSession, action, mailboxGuid);
         this.mailboxGuid = mailboxGuid;
         disposeGuard.Success();
     }
 }
 // Token: 0x06000CCC RID: 3276 RVA: 0x0002F804 File Offset: 0x0002DA04
 public UnseenCountBrokerHandler(string subscriptionId, SubscriptionParameters parameters, IMailboxContext userContext, IRecipientSession adSession) : base(subscriptionId, parameters, userContext)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         this.adSession          = adSession;
         this.unseenItemNotifier = new UnseenItemNotifier(subscriptionId, userContext, null, null);
         this.unseenItemNotifier.RegisterWithPendingRequestNotifier();
         disposeGuard.Success();
     }
 }
Example #28
0
 public XsoMailboxDataProviderBase(ExchangePrincipal mailboxOwner, string action)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         Util.ThrowOnNullArgument(mailboxOwner, "mailboxOwner");
         Util.ThrowOnNullOrEmptyArgument(action, "action");
         this.MailboxSession = MailboxSession.OpenAsAdmin(mailboxOwner, CultureInfo.InvariantCulture, string.Format("Client=Management;Action={0};Privilege:ActAsAdmin", action));
         disposeGuard.Success();
     }
 }
Example #29
0
 // Token: 0x06000EDA RID: 3802 RVA: 0x000586E0 File Offset: 0x000568E0
 public PublicFolderAssistantLogger(IPublicFolderSession publicFolderSession) : base(publicFolderSession, "PublicFolderAssistantInfo", "PublicFolderLastAssistantCycleLog", null)
 {
     this.logComponent  = "PublicFolderAssistantLog";
     this.logSuffixName = "PublicFolderAssistantLog";
     using (DisposeGuard disposeGuard = this.Guard())
     {
         base.LogEvent(LogEventType.Entry, "Start");
         disposeGuard.Success();
     }
 }
        // Token: 0x060001A5 RID: 421 RVA: 0x00008FA8 File Offset: 0x000071A8
        private ICancelableAsyncResult BeginWrapper(string methodName, CancelableAsyncCallback asyncCallback, object asyncState, bool rundownContextOnFailure, Func <NspiContext, NspiDispatchTask> beginDelegate, Func <NspiContext> contextFactory)
        {
            int contextHandle = 0;
            ICancelableAsyncResult asyncResult = null;

            NspiAsyncDispatch.ConditionalExceptionWrapper(ExTraceGlobals.NspiTracer.IsTraceEnabled(TraceType.DebugTrace), delegate
            {
                bool flag = false;
                FailureAsyncResult <NspiStatus> failureAsyncResult = null;
                try
                {
                    this.CheckShuttingDown();
                    try
                    {
                        using (DisposeGuard disposeGuard = default(DisposeGuard))
                        {
                            NspiContext nspiContext           = contextFactory();
                            contextHandle                     = ((nspiContext != null) ? nspiContext.ContextHandle : 0);
                            NspiDispatchTask nspiDispatchTask = beginDelegate(nspiContext);
                            disposeGuard.Add <NspiDispatchTask>(nspiDispatchTask);
                            asyncResult = nspiDispatchTask.AsyncResult;
                            this.SubmitTask(nspiDispatchTask);
                            disposeGuard.Success();
                        }
                        flag = true;
                    }
                    catch (FailRpcException ex)
                    {
                        failureAsyncResult = new FailureAsyncResult <NspiStatus>((NspiStatus)ex.ErrorCode, new IntPtr(contextHandle), ex, asyncCallback, asyncState);
                        asyncResult        = failureAsyncResult;
                    }
                    catch (NspiException ex2)
                    {
                        failureAsyncResult = new FailureAsyncResult <NspiStatus>(ex2.Status, new IntPtr(contextHandle), ex2, asyncCallback, asyncState);
                        asyncResult        = failureAsyncResult;
                    }
                    if (failureAsyncResult != null && !ThreadPool.QueueUserWorkItem(NspiAsyncDispatch.FailureWaitCallback, failureAsyncResult))
                    {
                        failureAsyncResult.InvokeCallback();
                    }
                    ExTraceGlobals.NspiTracer.TraceDebug <string, int>(0, 0L, "{0} succeeded. ContextHandle={1}", methodName, contextHandle);
                }
                finally
                {
                    if (!flag && rundownContextOnFailure && contextHandle != 0)
                    {
                        this.ContextHandleRundown(new IntPtr(contextHandle));
                    }
                }
            }, delegate(Exception exception)
            {
                ExTraceGlobals.NspiTracer.TraceDebug <string, int, Exception>(0, 0L, "{0} failed. ContextHandle={1}, Exception={2}.", methodName, contextHandle, exception);
            });
            return(asyncResult);
        }