Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 8
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();
     }
 }
Ejemplo n.º 9
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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 11
0
        // Token: 0x06000314 RID: 788 RVA: 0x000137EC File Offset: 0x000119EC
        private RfriStatus EndWrapper(string methodName, ICancelableAsyncResult asyncResult, Func <RfriDispatchTask, RfriStatus> endDelegate)
        {
            RfriStatus rfriStatus = RfriStatus.Success;

            RfriAsyncDispatch.ConditionalExceptionWrapper(ExTraceGlobals.ReferralTracer.IsTraceEnabled(TraceType.DebugTrace), delegate
            {
                DispatchTaskAsyncResult dispatchTaskAsyncResult = asyncResult as DispatchTaskAsyncResult;
                if (dispatchTaskAsyncResult != null)
                {
                    RfriDispatchTask rfriDispatchTask = (RfriDispatchTask)dispatchTaskAsyncResult.DispatchTask;
                    using (DisposeGuard disposeGuard = default(DisposeGuard))
                    {
                        disposeGuard.Add <RfriDispatchTask>(rfriDispatchTask);
                        rfriStatus = endDelegate(rfriDispatchTask);
                    }
                    ExTraceGlobals.ReferralTracer.TraceDebug <string, RfriStatus>(0, 0L, "{0} succeeded. RfriStatus={1}.", methodName, rfriStatus);
                    return;
                }
                FailureAsyncResult <RfriStatus> failureAsyncResult = asyncResult as FailureAsyncResult <RfriStatus>;
                if (failureAsyncResult != null)
                {
                    rfriStatus = failureAsyncResult.ErrorCode;
                    ExTraceGlobals.ReferralTracer.TraceDebug <string, RfriStatus, Exception>(0, 0L, "{0} failed. RfriStatus={1}. Exception={2}.", methodName, rfriStatus, failureAsyncResult.Exception);
                    return;
                }
                throw new InvalidOperationException(string.Format("Invalid IAsyncResult encountered; {0}", asyncResult));
            }, delegate(Exception exception)
            {
                ExTraceGlobals.ReferralTracer.TraceDebug <string, Exception>(0, 0L, "{0} failed. Exception={1}.", methodName, exception);
            });
            return(rfriStatus);
        }
Ejemplo n.º 12
0
        public override IAttachment Read(string attachmentId)
        {
            IList <AttachmentId> attachmentIds = IdConverter.GetAttachmentIds(attachmentId);
            IAttachment          result;

            using (IItem item = this.BindToParentItem())
            {
                using (DisposeGuard disposeGuard = default(DisposeGuard))
                {
                    IItem      item2      = item;
                    Attachment attachment = null;
                    for (int i = 0; i < attachmentIds.Count; i++)
                    {
                        attachment = IrmUtils.GetAttachmentCollection(item2).Open(attachmentIds[i]);
                        disposeGuard.Add <Attachment>(attachment);
                        if (i < attachmentIds.Count - 1)
                        {
                            if (!(attachment is ItemAttachment))
                            {
                                throw new CorruptDataException(Strings.ErrorAllButLastNestedAttachmentMustBeItemAttachment);
                            }
                            ItemAttachment itemAttachment = attachment as ItemAttachment;
                            item2 = itemAttachment.GetItem();
                            disposeGuard.Add <IItem>(item2);
                        }
                    }
                    StorageTranslator <IAttachment, IAttachment> attachmentTranslator = this.GetAttachmentTranslator(attachment.AttachmentType, false);
                    IAttachment attachment2 = attachmentTranslator.ConvertToEntity(attachment);
                    attachment2.Id = attachmentId;
                    result         = attachment2;
                }
            }
            return(result);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        private void VerifyLegacyPublicFolderDatabaseLocked()
        {
            PublicFolderEndpoint publicFolderEndpoint = (PublicFolderEndpoint)this.DataObject.SourceEndpoint;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                IMailbox mailbox;
                if (publicFolderEndpoint != null)
                {
                    mailbox = disposeGuard.Add <IMailbox>(publicFolderEndpoint.ConnectToSourceDatabase());
                }
                else
                {
                    DatabaseIdParameter  id = DatabaseIdParameter.Parse(this.DataObject.SourcePublicFolderDatabase);
                    PublicFolderDatabase publicFolderDatabase = (PublicFolderDatabase)base.GetDataObject <PublicFolderDatabase>(id, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(this.DataObject.SourcePublicFolderDatabase)), new LocalizedString?(Strings.ErrorDatabaseNotUnique(this.DataObject.SourcePublicFolderDatabase)));
                    mailbox = disposeGuard.Add <IMailbox>(PublicFolderEndpoint.ConnectToLocalSourceDatabase(publicFolderDatabase.ExchangeObjectId));
                }
                try
                {
                    bool flag;
                    mailbox.SetInTransitStatus(InTransitStatus.MoveSource, out flag);
                    mailbox.SetInTransitStatus(InTransitStatus.NotInTransit, out flag);
                }
                catch (SourceMailboxAlreadyBeingMovedTransientException)
                {
                    base.WriteError(new MigrationBatchCannotBeCompletedException(Strings.CompletePublicFolderMigrationBatchRequiresSourceLockDown));
                }
            }
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
 // Token: 0x06000714 RID: 1812 RVA: 0x00015830 File Offset: 0x00013A30
 internal void CompleteBuilding()
 {
     try
     {
         Monitor.Enter(this.lockObject);
         ExAssert.RetailAssert(this.state == SessionDataCacheState.Building || this.state == SessionDataCacheState.Obsolete, "Ready building session data in an invalid state: " + this.state);
         if (this.state == SessionDataCacheState.Obsolete)
         {
             this.InternalDispose(true);
         }
         else
         {
             this.lastSessionDataBuildEndTime = ExDateTime.Now;
             this.state = SessionDataCacheState.Ready;
             this.signalEvent.Set();
             Timer staleTimer = null;
             staleTimer = new Timer(delegate(object param0)
             {
                 this.Dispose();
                 DisposeGuard.DisposeIfPresent(staleTimer);
             }, null, SessionDataCache.FreshnessTime, Timeout.InfiniteTimeSpan);
         }
     }
     finally
     {
         if (Monitor.IsEntered(this.lockObject))
         {
             Monitor.Exit(this.lockObject);
         }
         ExTraceGlobals.SessionDataHandlerTracer.TraceDebug((long)this.GetHashCode(), string.Format("[SessionDataCache] Ready building session data cache. StartTime = {0}, EndTime = {1}, state = {2}", this.lastSessionDataBuildStartTime.ToString(), this.lastSessionDataBuildEndTime.ToString(), this.state));
         OwaSingleCounters.SessionDataCacheBuildsCompleted.Increment();
     }
 }
Ejemplo n.º 19
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();
     }
 }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
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);
        }
 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();
     }
 }
        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);
        }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
0
 internal PublishedCalendar(MailboxSession mailboxSession, StoreObjectId folderId) : base(mailboxSession, folderId)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         this.LoadPublishedOptions();
         disposeGuard.Success();
     }
 }
 // Token: 0x06001C0A RID: 7178 RVA: 0x0006DE44 File Offset: 0x0006C044
 private static void AggregationContextRemoved(string key, object value, CacheItemRemovedReason reason)
 {
     if (reason == CacheItemRemovedReason.Expired)
     {
         ExTraceGlobals.CoreTracer.TraceWarning(0L, "an aggregation context expired before being revalidated!");
         DisposeGuard.DisposeIfPresent(value as IDisposable);
     }
 }
 // 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();
     }
 }
Ejemplo n.º 29
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();
     }
 }
Ejemplo n.º 30
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();
     }
 }