static void ApplyForumsDisabled(MicrosoftForumsServiceProvider p)
 {
     if (string.Compare(p.EndpointConfigurationName, "answers", StringComparison.InvariantCultureIgnoreCase) == 0)
     {
         if (UserSettings.Default.UseAnswersForums)
         {
             p.IsDisabled = false;
         }
         else
         {
             p.IsDisabled = true;
         }
     }
     else if (string.Compare(p.EndpointConfigurationName, "social", StringComparison.InvariantCultureIgnoreCase) == 0)
     {
         if (UserSettings.Default.UseSocialForums)
         {
             p.IsDisabled = false;
         }
         else
         {
             p.IsDisabled = true;
         }
     }
 }
        private static void StartBridgeInternal(MainWindow t, int port, string domainName)
        {
            //var services = new[] { "social", "answers" };
            var services = new[] { "social" };

            //var serviceModel = System.Configuration.ConfigurationManager.GetSection("system.serviceModel");

            string authenticationTicket = null;

#if LIVECONNECT
            Traces.Main_TraceEvent(TraceEventType.Verbose, 1, "LiveConnect: Try authentication");
            t.DoLogin();
            authenticationTicket = t.AccessToken;
            if (string.IsNullOrEmpty(authenticationTicket))
            {
                // Reset the RefreshToken, if the authentication has failed...
                UserSettings.Default.RefreshToken = string.Empty;
                Traces.Main_TraceEvent(TraceEventType.Error, 1, "Could not authenticate with LiveConnect!");
                throw new ApplicationException("Could not authenticate with LiveConnect!");
            }
            Traces.Main_TraceEvent(TraceEventType.Information, 1, "Authenticated: AccessToken: {0}", authenticationTicket);
#else
            // Authenticate with Live Id
            var authenticationData = new AuthenticationInformation();

            Traces.Main_TraceEvent(TraceEventType.Verbose, 1, "LiveId: Try authentication");
            try
            {
                PassportHelper.TryAuthenticate(ref authenticationData, UserSettings.Default.AuthenticationBlob);
            }
            catch
            {
                // Reset the auto login, if the authentication has failed...
                UserSettings.Default.AuthenticationBlob = string.Empty;
                throw;
            }
            Traces.Main_TraceEvent(TraceEventType.Verbose, 1, "LiveId: UserName: {0}, Ticket: {1}", authenticationData.UserName, authenticationData.Ticket);

            if (authenticationData.Ticket == null)
            {
                // Reset the auto login, if the authentication has failed...
                UserSettings.Default.AuthenticationBlob = string.Empty;
                Traces.Main_TraceEvent(TraceEventType.Error, 1, "Could not authenticate with LiveId!");
                throw new ApplicationException("Could not authenticate with LiveId!");
            }
            authenticationTicket = authenticationData.Ticket;
#endif

            t._forumsProviders = new MicrosoftForumsServiceProvider[services.Length];
            for (var i = 0; i < services.Length; i++)
            {
                // Create the forums-ServiceProvider
                Traces.Main_TraceEvent(TraceEventType.Verbose, 1, "Create forums service provider: {0}", services[i]);
                var provider = new MicrosoftForumsServiceProvider(services[i]);
                System.Diagnostics.Debug.WriteLine(string.Format("{0}: Uri: {1}", services[i], provider.Uri));

                // Assigne the authentication ticket
                provider.AuthenticationTicket = authenticationTicket;
                ApplyForumsDisabled(provider);

#if PASSPORT_HEADER_ANALYSIS
                // Register AuthError-Handler
                provider.AuthenticationError += t.provider_AuthenticationError;
#endif

                t._forumsProviders[i] = provider;
            }

            // Create our DataSource for the forums
            Traces.Main_TraceEvent(TraceEventType.Verbose, 1, "Creating datasource for NNTP server");
            t._forumsDataSource = new ForumDataSource(t._forumsProviders, domainName);
            t._forumsDataSource.UsePlainTextConverter      = UserSettings.Default.UsePlainTextConverter;
            t._forumsDataSource.AutoLineWrap               = UserSettings.Default.AutoLineWrap;
            t._forumsDataSource.HeaderEncoding             = UserSettings.Default.EncodingForClientEncoding;
            t._forumsDataSource.InMimeUseHtml              = (UserSettings.Default.InMimeUse == UserSettings.MimeContentType.TextHtml);
            t._forumsDataSource.UserDefinedTags            = UserSettings.Default.UserDefinedTags;
            t._forumsDataSource.ShowUserNamePostfix        = UserSettings.Default.ShowUserNamePostfix;
            t._forumsDataSource.PostsAreAlwaysFormatFlowed = UserSettings.Default.PostsAreAlwaysFormatFlowed;
            t._forumsDataSource.TabAsSpace          = UserSettings.Default.TabAsSpace;
            t._forumsDataSource.UseCodeColorizer    = UserSettings.Default.UseCodeColorizer;
            t._forumsDataSource.AddHistoryToArticle = UserSettings.Default.AddHistoryToArticle;

            // Now start the NNTP-Server
            Traces.Main_TraceEvent(TraceEventType.Verbose, 1, "Starting NNTP server");
            t._nntpServer = new NNTPServer.NntpServer(t._forumsDataSource, true);
            t._nntpServer.EncodingSend      = UserSettings.Default.EncodingForClientEncoding;
            t._nntpServer.ListGroupDisabled = UserSettings.Default.DisableLISTGROUP;
            //t._nntpServer.DetailedErrorResponse = detailedErrorResponse;
            string errorMessage;
            t._nntpServer.Start(port, 64, UserSettings.Default.BindToWorld, out errorMessage);
            if (errorMessage != null)
            {
                throw new ApplicationException(errorMessage);
            }
        }