Beispiel #1
0
        private static void StartBridgeInternal(MainWindow t, int port, string domainName)
        {
            string authenticationTicket = null;

            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);

            // Create the forums-ServiceProvider
            Traces.Main_TraceEvent(TraceEventType.Verbose, 1, "Create forums service provider: {0}", "social");

#if true
            var provider = new WebServiceAnswers.SwaggerAccess();
            provider.UpdateAuthTicket(authenticationTicket);

            WebServiceAnswers.SwaggerAccess.Log    = SwaggerLog;
            WebServiceAnswers.SwaggerAccess.LogExp = SwaggerLogExp;
#else
            WebServiceAnswers.IForumData provider = new QnAClient("httpLiveAuth");
#endif
            t._Provider = provider;


            //if (provider.Endpoint.Behaviors.Contains(typeof(Microsoft.Support.Community.CpsAuthHeaderBehavior)))
            //{
            //  provider.Endpoint.Behaviors.Remove(typeof(Microsoft.Support.Community.CpsAuthHeaderBehavior));
            //}
            //t._answersAuthHeader = new Microsoft.Support.Community.CpsAuthHeaderBehavior(authenticationTicket);
            //provider.Endpoint.Behaviors.Add(t._answersAuthHeader);

            //foreach (var op in provider.Endpoint.Contract.Operations)
            //{
            //  var dcsb =
            //    op.Behaviors.Find<System.ServiceModel.Description.DataContractSerializerOperationBehavior>();
            //  //if (dcsb == null)
            //  //{
            //  //  dcsb = new System.ServiceModel.Description.DataContractSerializerOperationBehavior(op);
            //  //}
            //  if (dcsb != null)
            //  {
            //    const int maxObj = 65536*100;
            //    if (dcsb.MaxItemsInObjectGraph < maxObj)
            //    dcsb.MaxItemsInObjectGraph = maxObj; // Default is 65536; increase it...
            //    //dcsb.IgnoreExtensionDataObject = true;
            //  }
            //}


            // Try to test the provider once:
            try
            {
                provider.GetSupportedLocales();
            }
            catch (Exception exp)
            {
                Traces.Main_TraceEvent(TraceEventType.Error, 1, NNTPServer.Traces.ExceptionToString(exp));
                throw;
            }

            // Create our DataSource for the forums
            Traces.Main_TraceEvent(TraceEventType.Verbose, 1, "Creating datasource for NNTP server");
            t._forumsDataSource = new Answers.ForumDataSource(provider, 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;

            t._forumsDataSource.ProgressData += t._forumsDataSource_ProgressData;


            // 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);
            }
        }