Exemplo n.º 1
0
        private Uri Discover()
        {
            string sharerIdentity = this.subscription.SharerIdentity;
            Uri    result;

            using (AutodiscoverClient autodiscoverClient = new AutodiscoverClient())
            {
                autodiscoverClient.RequestedServerVersion = DefaultBinding_Autodiscover.Exchange2010RequestedServerVersion;
                autodiscoverClient.Authenticator          = this.CreateAuthenticator(Offer.Autodiscover);
                autodiscoverClient.Proxy     = this.WebProxy;
                autodiscoverClient.UserAgent = "ExchangeSharingSync";
                ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 1351, "Discover", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\Sharing\\SharingEngine.cs");
                string[] autodiscoverTrustedHosters = topologyConfigurationSession.GetAutodiscoverTrustedHosters();
                if (autodiscoverTrustedHosters != null)
                {
                    autodiscoverClient.AllowedHostnames.AddRange(autodiscoverTrustedHosters);
                }
                UserSettings userSettings = SharingEngine.SingleGetUserSettings.Discover(autodiscoverClient, sharerIdentity);
                if (userSettings.IsSettingError("ExternalEwsUrl"))
                {
                    SharingEngine.Tracer.TraceError <UserSettings>((long)this.GetHashCode(), "ExternalEwsUrl not present in response: {0}", userSettings);
                    throw new AutodiscoverException(Strings.UnexpectedUserResponses, userSettings);
                }
                UserSetting setting = userSettings.GetSetting("ExternalEwsUrl");
                if (setting == null)
                {
                    SharingEngine.Tracer.TraceError <UserSettings>((long)this.GetHashCode(), "ExternalEwsUrl not present in response: {0}", userSettings);
                    throw new AutodiscoverException(Strings.UnexpectedUserResponses, userSettings);
                }
                StringSetting stringSetting = setting as StringSetting;
                if (stringSetting == null)
                {
                    SharingEngine.Tracer.TraceError <Type>((long)this.GetHashCode(), "Unexpected type for ExternalEwsUrl in response. Type is {0}", setting.GetType());
                    throw new AutodiscoverException(Strings.UnexpectedUserResponses, userSettings);
                }
                if (string.IsNullOrEmpty(stringSetting.Value))
                {
                    SharingEngine.Tracer.TraceError((long)this.GetHashCode(), "Empty value returned for ExternalEwsUrl in response.");
                    throw new AutodiscoverException(Strings.UnexpectedUserResponses, userSettings);
                }
                if (!Uri.IsWellFormedUriString(stringSetting.Value, UriKind.Absolute))
                {
                    SharingEngine.Tracer.TraceError <string>((long)this.GetHashCode(), "Value returned for ExternalEwsUrl is not well-formed URL: {0}", stringSetting.Value);
                    throw new AutodiscoverException(Strings.UnexpectedUserResponses, userSettings);
                }
                Uri uri = new Uri(EwsWsSecurityUrl.Fix(stringSetting.Value));
                if (uri.Scheme != Uri.UriSchemeHttps)
                {
                    SharingEngine.Tracer.TraceError <string>((long)this.GetHashCode(), "Response has non-HTTPS ExternalEwsUrl: {0}", stringSetting.Value);
                    throw new AutodiscoverException(Strings.UnexpectedUserResponses, userSettings);
                }
                SharingEngine.Tracer.TraceDebug <Uri>((long)this.GetHashCode(), "Received valid response: {0}", uri);
                result = uri;
            }
            return(result);
        }
Exemplo n.º 2
0
        private string GetStringSettingFromResponse(UserResponse userResponse, string emailAddress, string settingName)
        {
            if (userResponse.UserSettings == null)
            {
                return(null);
            }
            UserSetting userSetting = null;

            foreach (UserSetting userSetting2 in userResponse.UserSettings)
            {
                if (StringComparer.InvariantCulture.Equals(userSetting2.Name, settingName))
                {
                    userSetting = userSetting2;
                    break;
                }
            }
            if (userSetting == null)
            {
                SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError((long)this.GetHashCode(), "{0}: Request '{1}' for user {2} got response without setting {3}.", new object[]
                {
                    TraceContext.Get(),
                    this,
                    emailAddress,
                    settingName
                });
                return(null);
            }
            StringSetting stringSetting = userSetting as StringSetting;

            if (stringSetting == null)
            {
                SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError((long)this.GetHashCode(), "{0}: Request '{1}' for user {2} got response for setting {3} of unexpected type: {4}", new object[]
                {
                    TraceContext.Get(),
                    this,
                    emailAddress,
                    settingName,
                    userSetting.GetType().Name
                });
                return(null);
            }
            if (string.IsNullOrEmpty(stringSetting.Value))
            {
                SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError((long)this.GetHashCode(), "{0}: Request '{1}' for user {2} got response with empty value for setting {3}", new object[]
                {
                    TraceContext.Get(),
                    this,
                    emailAddress,
                    settingName
                });
                return(null);
            }
            SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceDebug((long)this.GetHashCode(), "{0}: Request '{1}' for user {2} got response for setting {3} with value: {4}", new object[]
            {
                TraceContext.Get(),
                this,
                emailAddress,
                settingName,
                stringSetting.Value
            });
            return(stringSetting.Value);
        }
Exemplo n.º 3
0
        private string GetStringSettingFromResponse(UserResponse userResponse, MailboxInfo mailbox, string settingName)
        {
            if (userResponse.UserSettings == null)
            {
                return(null);
            }
            UserSetting userSetting = null;

            foreach (UserSetting userSetting2 in userResponse.UserSettings)
            {
                if (StringComparer.InvariantCulture.Equals(userSetting2.Name, settingName))
                {
                    userSetting = userSetting2;
                    break;
                }
            }
            if (userSetting == null)
            {
                Factory.Current.AutodiscoverTracer.TraceError((long)this.GetHashCode(), "Correlation Id:{0}. {1}: Request '{2}' for user {3} got response without setting {4}.", new object[]
                {
                    this.callerInfo.QueryCorrelationId,
                    TraceContext.Get(),
                    this,
                    mailbox.ToString(),
                    settingName
                });
                return(null);
            }
            StringSetting stringSetting = userSetting as StringSetting;

            if (stringSetting == null)
            {
                Factory.Current.AutodiscoverTracer.TraceError((long)this.GetHashCode(), "Correlation Id:{0}. {1}: Request '{2}' for user {3} got response for setting {4} of unexpected type: {5}", new object[]
                {
                    this.callerInfo.QueryCorrelationId,
                    TraceContext.Get(),
                    this,
                    mailbox.ToString(),
                    settingName,
                    userSetting.GetType().Name
                });
                return(null);
            }
            if (string.IsNullOrEmpty(stringSetting.Value))
            {
                Factory.Current.AutodiscoverTracer.TraceError((long)this.GetHashCode(), "Correlation Id:{0}. {1}: Request '{2}' for user {3} got response with empty value for setting {4}", new object[]
                {
                    this.callerInfo.QueryCorrelationId,
                    TraceContext.Get(),
                    this,
                    mailbox.ToString(),
                    settingName
                });
                return(null);
            }
            Factory.Current.AutodiscoverTracer.TraceDebug((long)this.GetHashCode(), "Correlation Id:{0}. {1}: Request '{2}' for user {3} got response for setting {4} with value: {5}", new object[]
            {
                this.callerInfo.QueryCorrelationId,
                TraceContext.Get(),
                this,
                mailbox.ToString(),
                settingName,
                stringSetting.Value
            });
            return(stringSetting.Value);
        }