static public UICache Load(string fileName)
        {
            try
            {
                if (Directory.Exists(Path.GetDirectoryName(fileName)) == false)
                {
                    return(null);
                }
                if (File.Exists(fileName) == false)
                {
                    return(null);
                }

                var ser = new XmlSerializer(typeof(UICache));
                using (var sr = new StreamReader(fileName))
                {
                    var res = ser.Deserialize(sr) as UICache;
                    return(res);
                }
            }
            catch (Exception exp)
            {
                AppInsights.TrackException(exp, true);
                Traces.Main_TraceEvent(TraceEventType.Critical, 1, "Error while deserializing UICache: {0}\r\n{1}", fileName, NNTPServer.Traces.ExceptionToString(exp));
            }
            return(null);
        }
 public void Save(string filename)
 {
     try
     {
         var path = Path.GetDirectoryName(filename);
         if (Directory.Exists(Path.GetDirectoryName(path)) == false)
         {
             Directory.CreateDirectory(path);
         }
         if (Directory.Exists(path) == false)
         {
             Directory.CreateDirectory(path);
         }
         var ser = new XmlSerializer(typeof(UICache));
         using (var sw = new StreamWriter(filename))
         {
             ser.Serialize(sw, this);
         }
     }
     catch (Exception exp)
     {
         AppInsights.TrackException(exp, true);
         Traces.Main_TraceEvent(TraceEventType.Critical, 1, "Error while serializing UICache: {0}", NNTPServer.Traces.ExceptionToString(exp));
     }
 }
        private void StartBridgeAsync(Action <bool, string> onFinishedCallback)
        {
            int port = 119;
            int parsedPort;

            if (int.TryParse(txtPort.Text, out parsedPort))
            {
                port = parsedPort;
            }

            //bool detailedErrorResponse = UserSettings.Default.DetailedErrorResponse;
            string domainName = UserSettings.Default.DomainName;

            lblInfo.Text       = "Starting server... please wait...";
            cmdStart.IsEnabled = false;

            //System.Threading.ThreadPool.QueueUserWorkItem(delegate(object o)
            var thread = new System.Threading.Thread(
                delegate(object o)
            {
                var t     = o as MainWindow;
                var bRes  = false;
                var error = string.Empty;
                try
                {
                    StartBridgeInternal(t, port, domainName);
                    bRes = true;
                }
                catch (Exception exp)
                {
                    AppInsights.TrackException(exp, true);
                    error = exp.Message;
                }
                t.Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(
                        delegate
                {
                    if (bRes)
                    {
                        t.Started = true;
                    }
                    else
                    {
                        t.lblInfo.Text = error;
                        t.ApplySettings();              // for correcting the "LiveId auologin" menu entry
                    }
                    t.cmdStart.IsEnabled = true;
                    if (onFinishedCallback != null)
                    {
                        onFinishedCallback(bRes, error);
                    }
                }));
            });

            thread.IsBackground = true;
            thread.SetApartmentState(System.Threading.ApartmentState.STA);
            thread.Start(this);
        }
        public MainWindow()
        {
            InitializeComponent();

            // Set Icon explizit, because of a Bug in WindowsXP:
            // https://communitybridge.codeplex.com/workitem/11374
            try
            {
                var logo = new BitmapImage();
                logo.BeginInit();
                logo.UriSource =
                    new Uri(
                        "pack://application:,,,/CommunityForumsNNTPServer;component/Resources/CommunityForumsNNTPServer.ico");
                logo.EndInit();

                Icon = logo;
            }
            catch (Exception exp)
            {
                AppInsights.TrackException(exp, true);
                Traces.Main_TraceEvent(TraceEventType.Error, 1, NNTPServer.Traces.ExceptionToString(exp));
            }

            if (Icon == null)
            {
                // Fallback fo XP:
                var logo = new BitmapImage();
                logo.BeginInit();
                logo.UriSource =
                    new Uri(
                        "pack://application:,,,/CommunityForumsNNTPServer;component/Resources/CommunityForumsNNTPServer.png");
                logo.EndInit();
                Icon = logo;
            }

            this.DataContext = this;

            var v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            Title = Title + " (" + v + ")";

            ApplySettings();

            cmdLoadNewsgroupList.IsEnabled = false;

#if LIVECONNECT
            mnuCreateLiveAutoLogin.Visibility = Visibility.Collapsed;
#endif


            Loaded += MainWindow_Loaded;
        }
Ejemplo n.º 5
0
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var exp = e.ExceptionObject as Exception;

            if (exp == null)
            {
                exp = new ApplicationException("<Unknown Exception>");
            }
            AppInsights.TrackException(exp);
            string expMsg = NNTPServer.Traces.ExceptionToString(exp);

            Traces.Main_TraceEvent(System.Diagnostics.TraceEventType.Critical, 1, "UnhandledException: {0}",
                                   expMsg);

            MessageBox.Show(string.Format("UnhandledException occured: {0}", NNTPServer.Traces.ExceptionToString(e.ExceptionObject as Exception)));
        }
 private void CmdLoadNewsgroupListClick(object sender, RoutedEventArgs e)
 {
     cmdLoadNewsgroupList.IsEnabled = false;
     System.Threading.ThreadPool.QueueUserWorkItem(delegate(object o)
     {
         var t = o as MainWindow;
         try
         {
             var idx = 0;
             SetPrefetchInfo(t, "Start prefetching newsgroup list", false);
             t._forumsDataSource.PrefetchNewsgroupList(
                 p => SetPrefetchInfo(t, string.Format("Group {0}: {1}", ++idx, p.GroupName), false));
             SetPrefetchInfo(t, string.Format("DONE: ({0} newsgroups)", idx), true);
         }
         catch (Exception exp)
         {
             AppInsights.TrackException(exp, true);
             SetPrefetchInfo(t, string.Format("Exception: {0}", NNTPServer.Traces.ExceptionToString(exp)), true);
         }
     }, this);
 }
Ejemplo n.º 7
0
        protected override void OnStartup(StartupEventArgs e)
        {
            bool ok;

            _singleInstanceMutex = new Mutex(true, "CommunityForumsNNTPBridge", out ok);

            if (!ok)
            {
                // Programm is already running, shutdown the current...
                Current.Shutdown();
                return;
            }

            _AppInsights = new AppInsights("a99ceec1-6478-4a94-bca1-874613b380f9", "CommunityBridge", UserSettings.Default.AppAccountId, UserSettings.Default.UseAppInsights);

            // Initialize logging and exception handling...
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            _logFile = new LogFile(UserSettings.Default.BasePath);

            base.OnStartup(e);
        }
 private void mnuDebugWindow_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (mnuDebugWindow.IsChecked)
         {
             _debugWindow       = new DebugWindow();
             _debugWindow.Owner = this;
             _debugWindow.Show();
             _debugWindow.Closed += new EventHandler(_debugWindow_Closed);
         }
         else
         {
             _debugWindow.Close();
             _debugWindow = null;
         }
     }
     catch (Exception exp)
     {
         AppInsights.TrackException(exp, true);
         Traces.Main_TraceEvent(TraceEventType.Error, 1, "Error in mnuDebugWindow_click: {0}", NNTPServer.Traces.ExceptionToString(exp));
     }
 }