public static EnqueueResult EnqueueTeamMailboxSyncRequest(string targetServer, Guid mailboxGuid, QueueType queueType, OrganizationId orgId, string clientString, string domainController, SyncOption syncOption = SyncOption.Default)
        {
            if (mailboxGuid == Guid.Empty)
            {
                throw new ArgumentNullException("mailboxGuid");
            }
            if (orgId == null)
            {
                throw new ArgumentNullException("orgId");
            }
            if (queueType != QueueType.TeamMailboxDocumentSync && queueType != QueueType.TeamMailboxMembershipSync && queueType != QueueType.TeamMailboxMaintenanceSync)
            {
                throw new ArgumentException("queueType");
            }
            RpcClientWrapper.InitializeIfNeeded();
            if (!RpcClientWrapper.instance.initialized)
            {
                return(new EnqueueResult(EnqueueResultType.ClientInitError, ClientStrings.RpcClientInitError));
            }
            EnqueueResult result;

            try
            {
                using (JobQueueRpcClient jobQueueRpcClient = new JobQueueRpcClient(targetServer ?? RpcClientWrapper.instance.localServer.Fqdn))
                {
                    TeamMailboxSyncRpcInParameters teamMailboxSyncRpcInParameters = new TeamMailboxSyncRpcInParameters(mailboxGuid, orgId, clientString, syncOption, domainController);
                    byte[] data = jobQueueRpcClient.EnqueueRequest(1, (int)queueType, teamMailboxSyncRpcInParameters.Serialize());
                    EnqueueRequestRpcOutParameters enqueueRequestRpcOutParameters = new EnqueueRequestRpcOutParameters(data);
                    result = enqueueRequestRpcOutParameters.Result;
                }
            }
            catch (RpcException ex)
            {
                result = new EnqueueResult(EnqueueResultType.RpcError, ClientStrings.RpcClientRequestError(ex.Message));
            }
            return(result);
        }
Beispiel #2
0
        protected override bool TryCreateJob(byte[] data, out Job job, out EnqueueResult result)
        {
            result = EnqueueResult.Success;
            job    = null;
            string server = null;
            TeamMailboxSyncRpcInParameters teamMailboxSyncRpcInParameters = null;
            TeamMailboxSyncInfo            teamMailboxSyncInfo            = null;

            try
            {
                teamMailboxSyncRpcInParameters = new TeamMailboxSyncRpcInParameters(data);
            }
            catch (SerializationException ex)
            {
                result = new EnqueueResult(EnqueueResultType.InvalidData, ServerStrings.RpcServerParameterSerializationError(ex.Message));
                return(false);
            }
            catch (ArgumentNullException ex2)
            {
                result = new EnqueueResult(EnqueueResultType.InvalidData, ServerStrings.RpcServerParameterInvalidError(ex2.Message));
                return(false);
            }
            OrganizationId    orgId             = teamMailboxSyncRpcInParameters.OrgId.Equals(OrganizationId.ForestWideOrgId) ? OrganizationId.ForestWideOrgId : teamMailboxSyncRpcInParameters.OrgId;
            TeamMailboxSyncId teamMailboxSyncId = new TeamMailboxSyncId(teamMailboxSyncRpcInParameters.MailboxGuid, orgId, teamMailboxSyncRpcInParameters.DomainController);
            bool flag = (teamMailboxSyncRpcInParameters.SyncOption & SyncOption.RefreshTeamMailboxCacheEntry) == SyncOption.RefreshTeamMailboxCacheEntry || !string.IsNullOrEmpty(teamMailboxSyncRpcInParameters.DomainController);

            try
            {
                bool flag2 = this.teamMailboxSyncInfoCache.Contains(teamMailboxSyncId);
                teamMailboxSyncInfo = this.teamMailboxSyncInfoCache.Get(teamMailboxSyncId);
                if (this.ShouldSkipSync(teamMailboxSyncId, teamMailboxSyncInfo, out result))
                {
                    return(false);
                }
                if ((teamMailboxSyncInfo.MailboxSession != null && (teamMailboxSyncInfo.MailboxSession.IsDisposed || teamMailboxSyncInfo.MailboxSession.IsDead)) || ExDateTime.UtcNow - teamMailboxSyncInfo.WhenCreatedUtcTime > ((TeamMailboxSyncConfiguration)base.Configuration).CacheAbsoluteExpiry || (flag && flag2))
                {
                    TeamMailboxSyncInfo info = this.teamMailboxSyncInfoCache.Remove(teamMailboxSyncId);
                    this.CleanupSyncInfo(info);
                    teamMailboxSyncInfo = this.teamMailboxSyncInfoCache.Get(teamMailboxSyncId);
                    if (this.ShouldSkipSync(teamMailboxSyncId, teamMailboxSyncInfo, out result))
                    {
                        return(false);
                    }
                }
                server = TeamMailboxSyncInfoCache.LocalServerFqdn;
            }
            catch (ADTransientException ex3)
            {
                result = new EnqueueResult(EnqueueResultType.DirectoryError, ServerStrings.RpcServerDirectoryError(teamMailboxSyncId.MailboxGuid.ToString(), ex3.Message));
                return(false);
            }
            catch (DataSourceOperationException ex4)
            {
                result = new EnqueueResult(EnqueueResultType.DirectoryError, ServerStrings.RpcServerDirectoryError(teamMailboxSyncId.MailboxGuid.ToString(), ex4.Message));
                return(false);
            }
            catch (DataValidationException ex5)
            {
                result = new EnqueueResult(EnqueueResultType.DirectoryError, ServerStrings.RpcServerDirectoryError(teamMailboxSyncId.MailboxGuid.ToString(), ex5.Message));
                return(false);
            }
            catch (StorageTransientException ex6)
            {
                result = new EnqueueResult(EnqueueResultType.StorageError, ServerStrings.RpcServerStorageError(teamMailboxSyncId.MailboxGuid.ToString(), ex6.Message));
                return(false);
            }
            catch (WrongServerException ex7)
            {
                result = new EnqueueResult(EnqueueResultType.WrongServer, ServerStrings.RpcServerWrongRequestServer(teamMailboxSyncId.MailboxGuid.ToString(), ex7.Message));
                return(false);
            }
            catch (StoragePermanentException ex8)
            {
                result = new EnqueueResult(EnqueueResultType.StorageError, ServerStrings.RpcServerStorageError(teamMailboxSyncId.MailboxGuid.ToString(), ex8.Message));
                return(false);
            }
            if ((teamMailboxSyncRpcInParameters.SyncOption & SyncOption.IgnoreNextAllowedSyncTimeRestriction) == SyncOption.Default && teamMailboxSyncInfo.NextAllowedSyncUtcTime > ExDateTime.UtcNow)
            {
                result = new EnqueueResult(EnqueueResultType.RequestThrottled, ServerStrings.RpcServerRequestThrottled(teamMailboxSyncId.MailboxGuid.ToString(), teamMailboxSyncInfo.NextAllowedSyncUtcTime.ToString()));
                return(false);
            }
            teamMailboxSyncInfo.IsPending                = true;
            teamMailboxSyncInfo.PendingClientString      = teamMailboxSyncRpcInParameters.ClientString;
            teamMailboxSyncInfo.PendingClientRequestTime = ExDateTime.UtcNow;
            job = this.InternalCreateJob(teamMailboxSyncInfo, teamMailboxSyncRpcInParameters.ClientString, teamMailboxSyncRpcInParameters.SyncOption);
            result.ResultDetail = ServerStrings.RpcServerRequestSuccess(server);
            return(true);
        }