예제 #1
0
        public void StopClient_OneDrive_KillAndStart()
        {
            if (!FileSyncHelper.ClientIsRunning(FileSyncHelper.SyncClient.OneDrive))
            {
                Assert.Ignore("OneDrive is not running. Ignoring.");
            }

            FileSyncHelper.StopClient(FileSyncHelper.SyncClient.OneDrive);

            Thread.Sleep(2000);

            Assert.False(FileSyncHelper.ClientIsRunning(FileSyncHelper.SyncClient.OneDrive));

            FileSyncHelper.RestartAllStoppedClients();

            Thread.Sleep(2000);

            Assert.True(FileSyncHelper.ClientIsRunning(FileSyncHelper.SyncClient.OneDrive));
        }
예제 #2
0
        static void Main()
        {
            // I had put the following line of code in to fix SP-436 after reading this article:
            // https://stackoverflow.com/questions/4077822/net-4-0-and-the-dreaded-onuserpreferencechanged-hang
            // Microsoft.Win32.SystemEvents.UserPreferenceChanged += delegate { };
            // But then I found this page: https://www.aaronlerch.com/blog/2008/12/15/debugging-ui/
            // which describes how to find out where the actual problem is.
            Thread.CurrentThread.Name = "UI";

            // This is pretty annoying: When, because .Net doesn't have a font style of SemiBold
            // (e.g. Segoe UI SemiBold), fonts having that style are assumed to be bold, but
            // when some controls (e.g. Label) are set to a SemiBold font, they are displayed as
            // bold, so we'll create our own, forcing the style to regular, which seems to work.
            // Don't use SystemFonts.DefaultFont because that always returns "Microsoft Sans Serif"
            // and SystemFonts.DialogFont always returns "Tahoma", regardless of OS.
            // See: https://benhollis.net/blog/2007/04/11/setting-the-correct-default-font-in-net-windows-forms-apps/
            _dialogFont = new Font(SystemFonts.MessageBoxFont, FontStyle.Regular);

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

            // The following not only get the location of the settings file used for the analytics stuff. It also
            // detects corruption and deletes it if needed so SayMore doesn't crash.
            var analyticsConfigFilePath = GetAnalyticsConfigFilePath();             // Analytics settings.

            if ((Control.ModifierKeys & Keys.Shift) > 0 && !IsNullOrEmpty(analyticsConfigFilePath))
            {
                var confirmationString = LocalizationManager.GetString("MainWindow.ConfirmDeleteUserSettingsFile",
                                                                       "Do you want to delete your user settings? (This will clear your most-recently-used project list, window positions, UI language settings, etc. It will not affect your SayMore project data.)");

                if (DialogResult.Yes ==
                    MessageBox.Show(confirmationString, ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                {
                    File.Delete(analyticsConfigFilePath);
                    File.Delete(new PortableSettingsProvider().GetFullSettingsFilePath());
                }
            }

            //bring in settings from any previous version
            //NB: this code doesn't actually work, because for some reason Saymore uses its own settings code,
            //(which emits a "settings" file rather than "user.config"),
            //and which apparently doesn't use the application version to trigger the following technique:
            // Insight from Tom: Looks like ALL user settings in SayMore use the PortableSettingsProvider. I think the
            // idea of this was to facilitate installing SayMore to a thumb drive or whatever, so it could be totally
            // portable. This provider does not attach version numbers to the settings files (or the cryptic GUIDs or
            // whatever to their containing folders), so once NeedUpgrade gets set to false (the very first time SayMore
            // is run), it will never again be true. It's easy enough to store NeedUpgrade in the normal
            // user.config file by removing the attribute in Settings.Designer.cs that causes it to be handled by the
            // custom provider. But PortableSettingsProvider would need to implement IApplicationSettingsProvider and
            // implement Upgrade in an appropriate way to handle this.
            if (Settings.Default.NeedUpgrade)             //TODO: this doesn't get triggered with David's custom settings
            {
                //see https://stackoverflow.com/questions/3498561/net-applicationsettingsbase-should-i-call-upgrade-every-time-i-load
                Settings.Default.Upgrade();                     //TODO: and this doesn't seem to actually do anything with David's custom settings
                Settings.Default.NeedUpgrade = false;
                Settings.Default.Save();
            }
            //so, as a hack because this is biting our users *now*.
            //this hack begins the damage control started above, when from 1.6.52 to 1.6.53, we changed the namespace
            //of the grid settings. It removes the old settings, talks to the user, and waits for the user to restart.
            else
            {
                try
                {
                    // ReSharper disable once NotAccessedVariable
                    var x = Settings.Default.SessionsListGrid;                     //we want this to throw if the last version used the SILGrid, and this one uses the BetterGrid
                    // ReSharper disable once RedundantAssignment
                    x = Settings.Default.PersonListGrid;
                }
                catch (Exception)
                {
                    string path = "";
                    try
                    {
                        ErrorReport.NotifyUserOfProblem("We apologize for the inconvenience, but to complete this upgrade, SayMore needs to exit. Please run it again to complete the upgrade.");

                        var s = Application.LocalUserAppDataPath;
                        s    = s.Substring(0, s.IndexOf("Local", StringComparison.InvariantCultureIgnoreCase) + 5);
                        path = s.CombineForPath("SayMore", "SayMore.Settings");
                        File.Delete(path);

                        Settings.Default.MRUList = MruFiles.Initialize(Settings.Default.MRUList, 4);
                        //leave this reminder to our post-restart self
                        if (MruFiles.Latest != null)
                        {
                            File.WriteAllText(MRULatestReminderFilePath, MruFiles.Latest);
                        }

                        //Application.Restart(); won't work, because the settings will still get saved

                        Environment.FailFast("SayMore quitting hard to prevent old settings from being saved again.");
                    }
                    catch (Exception error)
                    {
                        ErrorReport.NotifyUserOfProblem(error,
                                                        "SayMore was unable to find or delete the settings file from the old version of SayMore. Normally, this would be found at " + path);
                        Application.Exit();
                    }
                }
            }

            //this hack is a continuation of the damage control started above, when from 1.6.52 to 1.6.53, we changed the namespace
            //of the grid settings.
            if (File.Exists(MRULatestReminderFilePath))
            {
                var path = File.ReadAllText(MRULatestReminderFilePath).Trim();
                if (File.Exists(path))
                {
                    Settings.Default.MRUList = new StringCollection();
                    Settings.Default.MRUList.Add(path);
                }
                File.Delete(MRULatestReminderFilePath);
            }

            Settings.Default.MRUList = MruFiles.Initialize(Settings.Default.MRUList, 4);
            _applicationContainer    = new ApplicationContainer(false);

            Logger.Init();
            AppDomain.CurrentDomain.FirstChanceException += FirstChanceHandler;
            Logger.WriteEvent(ApplicationContainer.GetVersionInfo("SayMore version {0}.{1}.{2} {3}    Built on {4}", BuildType.Current));
            Logger.WriteEvent("Visual Styles State: {0}", Application.VisualStyleState);
            SetUpErrorHandling();
            Sldr.Initialize();

            var userInfo = new UserInfo();

#if DEBUG
            // Always track if this is a debug build, but track to a different segment.io project
            using (new Analytics("twa75xkko9", userInfo))
#else
            // If this is a release build, then allow an environment variable to be set to false
            // so that testers aren't generating false analytics
            string feedbackSetting = System.Environment.GetEnvironmentVariable("FEEDBACK");

            var allowTracking = IsNullOrEmpty(feedbackSetting) || feedbackSetting.ToLower() == "yes" || feedbackSetting.ToLower() == "true";

            using (new Analytics("jtfe7dyef3", userInfo, allowTracking))
#endif
            {
                foreach (var exception in _pendingExceptionsToReportToAnalytics)
                {
                    Analytics.ReportException(exception);
                }

                bool startedWithCommandLineProject = false;
                var  args = Environment.GetCommandLineArgs();
                if (args.Length > 1)
                {
                    var possibleProjFile = args[1];
                    startedWithCommandLineProject =
                        possibleProjFile.EndsWith(Settings.Default.ProjectFileExtension) &&
                        File.Exists(possibleProjFile) &&
                        OpenProjectWindow(possibleProjFile);
                }

                if (!startedWithCommandLineProject)
                {
                    StartUpShellBasedOnMostRecentUsedIfPossible();
                }

                try
                {
                    Application.Run();
                    Settings.Default.Save();
                    Logger.WriteEvent("SayMore shutting down");
                    if (s_countOfContiguousFirstChanceOutOfMemoryExceptions > 1)
                    {
                        Logger.WriteEvent("Total number of contiguous OutOfMemoryExceptions: {0}", s_countOfContiguousFirstChanceOutOfMemoryExceptions);
                    }
                    Logger.ShutDown();

                    SafelyDisposeProjectContext();
                }
                finally
                {
                    ReleaseMutexForThisProject();
                    Sldr.Cleanup();
                    FileSyncHelper.RestartAllStoppedClients();
                }
            }
        }