Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            initialiseFiles();

            Updater.MakeSquirrelAware();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            delayStartup();
            Splash.ShowMe();

            log.Debug("Loading settings from file.");
            Settings.Load();

            Updater = new Updater();
            isNewVersion(Updater.IsSquirrelInstall());
            Updater.CheckForUpdate();

            TimezoneDB.Instance.CheckForUpdate();

            try {
                try {
                    Application.Run(new MainForm(startingTab));
                } catch (ApplicationException ex) {
                    log.Fatal(ex.Message);
                    MessageBox.Show(ex.Message, "Application terminated!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    throw new ApplicationException();
                } catch (System.Runtime.InteropServices.COMException ex) {
                    if (OGCSexception.GetErrorCode(ex, 0x000FFFFF) == "0x00040115")
                    {
                        log.Error(ex.Message);
                        MessageBox.Show("OGCS is not able to run as Outlook is not properly connected to the Exchange server.\r\n" +
                                        "Please try again later.", "Application cannot initialise!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        OGCSexception.Analyse(ex);
                    }
                    throw new ApplicationException();
                } catch (System.Exception ex) {
                    OGCSexception.Analyse(ex);
                    log.Fatal("Application unexpectedly terminated!");
                    MessageBox.Show(ex.Message, "Application unexpectedly terminated!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new ApplicationException();
                }
            } catch (ApplicationException) {
                log.Warn("Tidying down any remaining Outlook references, as OGCS crashed out.");
                try {
                    OutlookCalendar.InstanceConnect = false;
                    OutlookCalendar.Instance.IOutlook.Disconnect();
                } catch { }
            }
            Splash.CloseMe();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            while (Updater.IsBusy)
            {
                Application.DoEvents();
                System.Threading.Thread.Sleep(100);
            }
            log.Info("Application closed.");
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try {
                setSecurityProtocols();
                GoogleOgcs.ErrorReporting.Initialise();

                RoamingProfileOGCS = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Application.ProductName);
                parseArgumentsAndInitialise(args);

                Updater.MakeSquirrelAware();
                Forms.Splash.ShowMe();

                SettingsStore.Upgrade.Check();
                log.Debug("Loading settings from file.");
                Settings.Load();
                Settings.Instance.Proxy.Configure();

                Updater = new Updater();
                isNewVersion(Program.IsInstalled);
                Updater.CheckForUpdate();

                TimezoneDB.Instance.CheckForUpdate();

                try {
                    String startingTab = Settings.Instance.CompletedSyncs == 0 ? "Help" : null;
                    Application.Run(new Forms.Main(startingTab));
                } catch (ApplicationException ex) {
                    String reportError = ex.Message;
                    log.Fatal(reportError);
                    if (ex.InnerException != null)
                    {
                        reportError = ex.InnerException.Message;
                        log.Fatal(reportError);
                    }
                    MessageBox.Show(reportError, "Application terminated!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    throw new ApplicationException(ex.Message.StartsWith("COM error") ? "Suggest startup delay" : "");
                } catch (System.Runtime.InteropServices.COMException ex) {
                    OGCSexception.Analyse(ex);
                    MessageBox.Show(ex.Message, "Application terminated!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new ApplicationException("Suggest startup delay");
                }
            } catch (ApplicationException aex) {
                if (aex.Message == "Suggest startup delay")
                {
                    if (isCLIstartup() && Settings.Instance.StartOnStartup)
                    {
                        log.Debug("Suggesting to set a startup delay.");
                        MessageBox.Show("If this error only happens when logging in to Windows, try " +
                                        ((Settings.Instance.StartupDelay == 0) ? "setting a" : "increasing the") + " delay for OGCS on startup.",
                                        "Set a delay on startup", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (!string.IsNullOrEmpty(aex.Message))
                {
                    MessageBox.Show(aex.Message, "Application terminated!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                log.Warn("OGCS has crashed out.");
            } catch (System.Exception ex) {
                OGCSexception.Analyse(ex, true);
                log.Fatal("Application unexpectedly terminated!");
                MessageBox.Show(ex.Message, "Application unexpectedly terminated!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                log.Warn("OGCS has crashed out.");
            } finally {
                log.Debug("Shutting down application.");
                OutlookOgcs.Calendar.Disconnect();
                Forms.Splash.CloseMe();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                while (Updater != null && Updater.IsBusy)
                {
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(100);
                }
                log.Info("Application closed.");
            }
        }