protected override IConfigurable PrepareDataObject() { CommonLoggingHelper.SyncLogSession.SetBlackBoxCapacity(NewSubscription.IncreasedBlackBoxCapacity); AutoProvisionProgress autoProvisionProgress = delegate(LocalizedString activity, LocalizedString statusDescription) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.AutoProvisionDebug(activity, statusDescription)); } ExProgressRecord record = new ExProgressRecord(0, activity, statusDescription); base.WriteProgress(record); CommonLoggingHelper.SyncLogSession.LogVerbose((TSLID)1271UL, Strings.AutoProvisionDebug(activity, statusDescription), new object[0]); }; IAutoProvision[] array = this.ClientsToUse(); if (array.Length == 0) { base.WriteDebugInfoAndError(new LocalizedException(Strings.AutoProvisionNoProtocols), ErrorCategory.InvalidArgument, null); } Dictionary <Authority, bool> connectiveAuthority = NewSubscription.CheckConnectivity(array, autoProvisionProgress); PimSubscriptionProxy pimSubscriptionProxy; DiscoverSettingsResult discoverSettingsResult = NewSubscription.DiscoverSettings(array, false, connectiveAuthority, autoProvisionProgress, CommonLoggingHelper.SyncLogSession, out pimSubscriptionProxy); if (pimSubscriptionProxy == null && discoverSettingsResult != DiscoverSettingsResult.AuthenticationError && (this.Force == true || base.ShouldContinue(Strings.InsecureConfirmation))) { CommonLoggingHelper.SyncLogSession.LogVerbose((TSLID)1272UL, "Checking for in-secure option.", new object[0]); NewSubscription.DiscoverSettings(array, true, connectiveAuthority, autoProvisionProgress, CommonLoggingHelper.SyncLogSession, out pimSubscriptionProxy); } if (pimSubscriptionProxy == null) { base.WriteDebugInfoAndError(new AutoProvisionFailedException(), ErrorCategory.InvalidArgument, null); } pimSubscriptionProxy.CreationType = SubscriptionCreationType.Auto; this.DataObject = pimSubscriptionProxy; autoProvisionProgress(Strings.AutoProvisionComplete, Strings.AutoProvisionCreate); base.WriteDebugInfo(); return(base.PrepareDataObject()); }
internal static DiscoverSettingsResult DiscoverSettings(IAutoProvision[] clients, bool testOnlyInsecure, Dictionary <Authority, bool> connectiveAuthority, AutoProvisionProgress provisionProgressCallback, SyncLogSession syncLogSession, out PimSubscriptionProxy subscription) { subscription = null; bool flag = false; foreach (IAutoProvision autoProvision in clients) { DiscoverSettingsResult discoverSettingsResult = autoProvision.DiscoverSetting(syncLogSession, testOnlyInsecure, connectiveAuthority, provisionProgressCallback, out subscription); if (discoverSettingsResult == DiscoverSettingsResult.Succeeded) { return(discoverSettingsResult); } if (discoverSettingsResult == DiscoverSettingsResult.AuthenticationError) { syncLogSession.LogDebugging((TSLID)1264UL, "Found an authentication error when trying to discover settings.", new object[0]); flag = true; } } if (flag) { return(DiscoverSettingsResult.AuthenticationError); } return(DiscoverSettingsResult.SettingsNotFound); }
internal static Dictionary <Authority, bool> CheckConnectivity(IAutoProvision[] clients, AutoProvisionProgress provisionProgressCallback) { Dictionary <string, IPAddress[]> dictionary = new Dictionary <string, IPAddress[]>(StringComparer.OrdinalIgnoreCase); foreach (IAutoProvision autoProvision in clients) { foreach (string text in autoProvision.Hostnames) { if (!dictionary.ContainsKey(text)) { if (text.Length > SyncUtilities.MaximumFqdnLength) { CommonLoggingHelper.SyncLogSession.LogError((TSLID)1265UL, "FQDN: [{0}] with length: {1} was too long.", new object[] { text, text.Length }); dictionary.Add(text, null); } else { try { provisionProgressCallback(Strings.AutoProvisionQueryDNS, new LocalizedString(text)); CommonLoggingHelper.SyncLogSession.LogInformation((TSLID)1266UL, "Querying DNS: {0}", new object[] { text }); IPHostEntry hostEntry = Dns.GetHostEntry(text); dictionary.Add(text, hostEntry.AddressList); } catch (SocketException ex) { CommonLoggingHelper.SyncLogSession.LogError((TSLID)1267UL, "DNS Query failed with error: {0}", new object[] { ex }); dictionary.Add(text, null); } } } } } Dictionary <Authority, bool> dictionary2 = new Dictionary <Authority, bool>(); Dictionary <Socket, Authority> dictionary3 = new Dictionary <Socket, Authority>(); try { List <IAsyncResult> list = new List <IAsyncResult>(); List <WaitHandle> list2 = new List <WaitHandle>(); foreach (IAutoProvision autoProvision2 in clients) { foreach (string text2 in autoProvision2.Hostnames) { foreach (int num in autoProvision2.ConnectivePorts) { Authority authority = new Authority(text2, num); if (!dictionary2.ContainsKey(authority)) { dictionary2[authority] = false; if (dictionary[text2] == null) { CommonLoggingHelper.SyncLogSession.LogInformation((TSLID)1268UL, "No valid DNS results exist for fqdn: {0}", new object[] { text2 }); } else { provisionProgressCallback(Strings.AutoProvisionConnectivity, new LocalizedString(authority.ToString())); CommonLoggingHelper.SyncLogSession.LogInformation((TSLID)1269UL, "Connecting to {0} ...", new object[] { authority }); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IAsyncResult asyncResult = null; try { asyncResult = socket.BeginConnect(dictionary[text2], num, null, socket); } catch (SocketException) { socket.Close(); goto IL_284; } dictionary3.Add(socket, authority); list.Add(asyncResult); list2.Add(asyncResult.AsyncWaitHandle); } } IL_284 :; } } } if (list2.Count == 0) { return(dictionary2); } provisionProgressCallback(Strings.AutoProvisionConnectivity, Strings.AutoProvisionResults); WaitHandle.WaitAll(list2.ToArray(), NewSubscription.socketTimeout, false); foreach (IAsyncResult asyncResult2 in list) { if (asyncResult2.IsCompleted) { Socket socket2 = (Socket)asyncResult2.AsyncState; try { socket2.EndConnect(asyncResult2); } catch (SocketException) { } } } } finally { foreach (KeyValuePair <Socket, Authority> keyValuePair in dictionary3) { Socket key = keyValuePair.Key; Authority value = keyValuePair.Value; if (key.Connected) { dictionary2[value] = true; } CommonLoggingHelper.SyncLogSession.LogInformation((TSLID)1270UL, "Connection to {0} succeeded: {1}.", new object[] { value, key.Connected }); key.Close(); } } return(dictionary2); }