示例#1
0
        internal MailboxAssociationEwsBinding(ADUser user, OpenAsAdminOrSystemServiceBudgetTypeType budgetType) : base("GroupMailboxAccessLayer", new RemoteCertificateValidationCallback(CommonCertificateValidationCallbacks.InternalServerToServer))
        {
            ArgumentValidator.ThrowIfNull("user", user);
            ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(user, null);

            MailboxAssociationEwsBinding.Tracer.TraceDebug <bool>((long)this.GetHashCode(), "MailboxAssociationEwsBinding.ctor - ExchangePrincipal.MailboxInfo.Location is null? {0}", exchangePrincipal.MailboxInfo.Location == null);
            Uri ewsEndpoint = null;

            MailboxAssociationEwsBinding.ExecuteEwsOperationWithRetry("GetBackEndWebServicesUrl", delegate
            {
                ewsEndpoint = BackEndLocator.GetBackEndWebServicesUrl(exchangePrincipal.MailboxInfo);
            });
            if (ewsEndpoint == null)
            {
                throw new MailboxNotFoundException(Strings.EwsUrlDiscoveryFailed(user.PrimarySmtpAddress.ToString()));
            }
            base.Url = ewsEndpoint.ToString();
            if (string.IsNullOrEmpty(base.Url))
            {
                throw new MailboxNotFoundException(Strings.EwsUrlDiscoveryFailed(user.PrimarySmtpAddress.ToString()));
            }
            base.HttpHeaders[WellKnownHeader.EWSTargetVersion] = EwsTargetVersion.V2_7;
            base.UserAgent = "GroupMailboxAccessLayer";
            base.Proxy     = new WebProxy();
            base.SetClientRequestIdHeaderFromActivityId();
            base.Authenticator = SoapHttpClientAuthenticator.CreateNetworkService();
            base.Authenticator.AdditionalSoapHeaders.Add(new OpenAsAdminOrSystemServiceType
            {
                ConnectingSID = new ConnectingSIDType
                {
                    Item = new SmtpAddressType
                    {
                        Value = user.PrimarySmtpAddress.ToString()
                    }
                },
                LogonType           = SpecialLogonType.Admin,
                BudgetType          = (int)budgetType,
                BudgetTypeSpecified = true
            });
            NetworkServiceImpersonator.Initialize();
        }
示例#2
0
        private bool ExecuteReplicationToMailbox(IAssociationAdaptor masterAdaptor, MailboxAssociation association)
        {
            bool      replicationSucceeded = false;
            Exception exception            = null;

            try
            {
                GrayException.MapAndReportGrayExceptions(delegate()
                {
                    try
                    {
                        MailboxAssociationEwsBinding.ExecuteEwsOperationWithRetry("ReplicateAssociation", delegate
                        {
                            using (MailboxAssociationEwsBinding mailboxAssociationEwsBinding = this.CreateMailboxAssociationEwsBinding(masterAdaptor.MasterLocator, association))
                            {
                                UpdateMailboxAssociationType updateMailboxAssociation = InProcessAssociationReplicator.CreateUpdateMailboxAssociationType(masterAdaptor.MasterLocator, association);
                                UpdateMailboxAssociationResponseType response         = mailboxAssociationEwsBinding.UpdateMailboxAssociation(updateMailboxAssociation);
                                replicationSucceeded = this.ProcessResponse(mailboxAssociationEwsBinding, response, association, masterAdaptor.AssociationStore.MailboxLocator);
                            }
                        });
                    }
                    catch (MailboxNotFoundException exception4)
                    {
                        replicationSucceeded = this.DeleteMailboxNotFoundAssociation(association, masterAdaptor, exception4);
                        if (!replicationSucceeded)
                        {
                            exception = exception4;
                        }
                    }
                    catch (BackEndLocatorException exception5)
                    {
                        exception = exception5;
                    }
                    catch (WebException exception6)
                    {
                        exception = exception6;
                    }
                    catch (InvalidOperationException exception7)
                    {
                        exception = exception7;
                    }
                    catch (LogonAsNetworkServiceException exception8)
                    {
                        if (!ExEnvironment.IsTest)
                        {
                            throw;
                        }
                        exception = exception8;
                    }
                });
            }
            catch (GrayException exception)
            {
                GrayException exception9;
                exception = exception9;
            }
            catch (SoapException exception2)
            {
                exception = exception2;
            }
            catch (IOException exception3)
            {
                exception = exception3;
            }
            if (exception != null)
            {
                this.ProcessFailure(association, exception.ToString());
                replicationSucceeded = false;
            }
            return(replicationSucceeded);
        }