private void PerformLiveIdAuthenticationTest(ref LiveIdAuthenticationOutcome result)
        {
            bool                      flag                      = false;
            string                    empty                     = string.Empty;
            StringBuilder             stringBuilder             = new StringBuilder();
            LiveIdAuthenticationError liveIdAuthenticationError = LiveIdAuthenticationError.None;
            TimeSpan                  latency                   = new TimeSpan(0, 0, 0);

            for (int i = 0; i < 3; i++)
            {
                this.InternalPerformLiveIdAuthentication(out flag, out liveIdAuthenticationError, out empty, out latency);
                if (liveIdAuthenticationError == LiveIdAuthenticationError.LoginFailure || liveIdAuthenticationError == LiveIdAuthenticationError.None)
                {
                    break;
                }
                stringBuilder.AppendLine(" Retrying: " + empty);
                base.WriteVerbose(new LocalizedString(string.Format("Failed with Error {0}. Trying to Kill and Restart.", empty)));
                this.KillAndStartService();
            }
            stringBuilder.AppendLine(empty);
            result.Update(flag ? LiveIdAuthenticationResultEnum.Success : LiveIdAuthenticationResultEnum.Failure, latency, stringBuilder.ToString());
            liveIdAuthenticationError = (flag ? LiveIdAuthenticationError.None : LiveIdAuthenticationError.LoginFailure);
            if (this.MonitoringContext)
            {
                this.monitoringData.Events.Add(new MonitoringEvent(TestLiveIdAuthenticationTask.CmdletMonitoringEventSource, (int)((flag ? 1000 : 2000) + this.UserType + (int)liveIdAuthenticationError), flag ? EventTypeEnumeration.Success : EventTypeEnumeration.Error, flag ? Strings.LiveIdAuthenticationSuccess(this.UserType.ToString()) : Strings.LiveIdAuthenticationFailed(this.UserType.ToString(), stringBuilder.ToString())));
            }
        }
        private void InternalPerformLiveIdAuthentication(out bool success, out LiveIdAuthenticationError error, out string iisLogs, out TimeSpan latency)
        {
            int             num           = 1009;
            string          uri           = string.Format("net.tcp://{0}:{1}/Microsoft.Exchange.Security.Authentication.FederatedAuthService", this.Server.ToString(), num);
            NetTcpBinding   binding       = new NetTcpBinding(SecurityMode.Transport);
            EndpointAddress remoteAddress = new EndpointAddress(uri);

            using (AuthServiceClient authServiceClient = new AuthServiceClient(binding, remoteAddress))
            {
                error = LiveIdAuthenticationError.None;
                byte[]    bytes     = Encoding.Default.GetBytes(this.MailboxCredential.UserName);
                byte[]    bytes2    = Encoding.Default.GetBytes(this.ConvertToUnsecureString(this.MailboxCredential.Password));
                Stopwatch stopwatch = Stopwatch.StartNew();
                try
                {
                    TestFailoverFlags testFailoverFlags;
                    if (this.TestFailOver == FailoverFlags.Random)
                    {
                        if (!this.PreferOfflineAuth)
                        {
                            TestFailoverFlags[] array;
                            if (this.UserType == LiveIdAuthenticationUserTypeEnum.ManagedConsumer)
                            {
                                array = new TestFailoverFlags[]
                                {
                                    TestFailoverFlags.HRDRequest,
                                    TestFailoverFlags.HRDResponse,
                                    TestFailoverFlags.LiveIdRequest,
                                    TestFailoverFlags.LiveIdResponse,
                                    TestFailoverFlags.OrgIdRequest,
                                    TestFailoverFlags.OrgIdResponse,
                                    TestFailoverFlags.HRDRequestTimeout,
                                    TestFailoverFlags.LiveIdRequestTimeout,
                                    TestFailoverFlags.OrgIdRequestTimeout
                                };
                            }
                            else
                            {
                                array = new TestFailoverFlags[]
                                {
                                    TestFailoverFlags.HRDRequest,
                                    TestFailoverFlags.HRDResponse,
                                    TestFailoverFlags.OrgIdRequest,
                                    TestFailoverFlags.OrgIdResponse,
                                    TestFailoverFlags.HRDRequestTimeout,
                                    TestFailoverFlags.OrgIdRequestTimeout
                                };
                            }
                            testFailoverFlags = array[new Random().Next(0, array.Length)];
                        }
                        else
                        {
                            TestFailoverFlags[] array2;
                            if (this.UserType == LiveIdAuthenticationUserTypeEnum.ManagedConsumer)
                            {
                                array2 = new TestFailoverFlags[]
                                {
                                    TestFailoverFlags.OfflineHRD,
                                    TestFailoverFlags.OfflineAuthentication,
                                    TestFailoverFlags.LowPasswordConfidence,
                                    TestFailoverFlags.LiveIdRequest,
                                    TestFailoverFlags.LiveIdResponse
                                };
                            }
                            else
                            {
                                array2 = new TestFailoverFlags[]
                                {
                                    TestFailoverFlags.OfflineHRD,
                                    TestFailoverFlags.OfflineAuthentication,
                                    TestFailoverFlags.LowPasswordConfidence
                                };
                            }
                            testFailoverFlags = array2[new Random().Next(0, array2.Length)];
                        }
                    }
                    else
                    {
                        testFailoverFlags = (TestFailoverFlags)this.TestFailOver;
                    }
                    AuthOptions authOptions = AuthOptions.SyncAD;
                    if (this.TestLegacyAPI)
                    {
                        authOptions |= AuthOptions.ReturnWindowsIdentity;
                    }
                    if (this.SyncADBackendOnly)
                    {
                        authOptions |= AuthOptions.SyncADBackEndOnly;
                    }
                    if (this.LiveIdXmlAuth)
                    {
                        authOptions |= AuthOptions.LiveIdXmlAuth;
                    }
                    string     text;
                    AuthStatus authStatus = authServiceClient.LogonCommonAccessTokenFederationCredsTest(uint.MaxValue, bytes, bytes2, authOptions, null, null, null, null, Guid.NewGuid(), new bool?(this.PreferOfflineAuth), testFailoverFlags, out text, out iisLogs);
                    if (this.TestFailOver != FailoverFlags.None)
                    {
                        iisLogs = testFailoverFlags.ToString() + "." + iisLogs;
                    }
                    error = ((authStatus == AuthStatus.LogonSuccess) ? LiveIdAuthenticationError.None : LiveIdAuthenticationError.LoginFailure);
                    if (this.IgnoreLowPasswordConfidence && iisLogs != null && iisLogs.IndexOf("low confidence") > 0)
                    {
                        error = LiveIdAuthenticationError.None;
                    }
                }
                catch (CommunicationException ex)
                {
                    iisLogs = ex.Message;
                    error   = LiveIdAuthenticationError.CommunicationException;
                }
                catch (InvalidOperationException ex2)
                {
                    iisLogs = ex2.Message;
                    error   = LiveIdAuthenticationError.InvalidOperationException;
                }
                catch (Exception ex3)
                {
                    iisLogs = ex3.Message;
                    error   = LiveIdAuthenticationError.OtherException;
                }
                stopwatch.Stop();
                success = (error == LiveIdAuthenticationError.None);
                latency = stopwatch.Elapsed;
            }
        }