Exemplo n.º 1
0
        public void RemoveStalePaths()
        {
            Assert.IsEmpty(_paths);

            var path1 = Path.Combine(_mruFileFolder, "mru1.tmp");

            File.CreateText(path1).Close();
            MruFiles.AddNewPath(path1);

            var path2 = Path.Combine(_mruFileFolder, "mru2.tmp");

            File.CreateText(path2).Close();
            MruFiles.AddNewPath(path2);

            Assert.AreEqual(2, _paths.Count);
            Assert.Contains(path1, _paths);
            Assert.Contains(path2, _paths);

            File.Delete(path1);
            ReflectionHelper.CallMethod(typeof(MruFiles), "RemoveStalePaths", null);
            Assert.AreEqual(1, _paths.Count);
            Assert.IsFalse(_paths.Contains(path1));
            Assert.Contains(path2, _paths);

            File.Delete(path2);
            ReflectionHelper.CallMethod(typeof(MruFiles), "RemoveStalePaths", null);
            Assert.IsEmpty(_paths);
        }
Exemplo n.º 2
0
        public void AddNewPath_AddMoreThanMax()
        {
            Assert.IsEmpty(_paths);

            var path1 = Path.Combine(_mruFileFolder, "mru1.tmp");

            File.CreateText(path1).Close();
            Assert.IsTrue(MruFiles.AddNewPath(path1));

            var path2 = Path.Combine(_mruFileFolder, "mru2.tmp");

            File.CreateText(path2).Close();
            Assert.IsTrue(MruFiles.AddNewPath(path2));

            var path3 = Path.Combine(_mruFileFolder, "mru3.tmp");

            File.CreateText(path3).Close();
            Assert.IsTrue(MruFiles.AddNewPath(path3));

            var path4 = Path.Combine(_mruFileFolder, "mru4.tmp");

            File.CreateText(path4).Close();
            Assert.IsTrue(MruFiles.AddNewPath(path4));

            Assert.AreEqual(3, _paths.Count);
            Assert.AreEqual(path2, _paths[2]);
            Assert.AreEqual(path3, _paths[1]);
            Assert.AreEqual(path4, _paths[0]);
        }
Exemplo n.º 3
0
 public void TestSetup()
 {
     _paths = new StringCollection();
     MruFiles.Initialize(_paths, 3);
     _mruFileFolder = Path.Combine(Path.GetTempPath(), "~mrufolder~");
     Directory.CreateDirectory(_mruFileFolder);
 }
Exemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        private static void HandleErrorOpeningProjectWindow(Exception error, string projectPath)
        {
            var localCopy = _projectContext;

            if (localCopy != null)
            {
                lock (localCopy)
                {
                    localCopy.ProjectWindow.Closed -= HandleProjectWindowClosed;
                    localCopy.ProjectWindow.Close();
                    localCopy.Dispose();
                    _projectContext = null;
                }
            }

            _applicationContainer.CloseSplashScreen();

            var msg = Format(LocalizationManager.GetString("MainWindow.LoadingProjectErrorMsg",
                                                           "{0} had a problem loading the {1} project. Please report this problem " +
                                                           "to the developers by clicking 'Details' below."),
                             Application.ProductName, Path.GetFileNameWithoutExtension(projectPath));

            Logger.WriteEvent(msg);
            Logger.WriteEvent("Details:\r\n{0}", error);

            ErrorReport.NotifyUserOfProblem(new ShowAlwaysPolicy(), error, msg);

            Settings.Default.MRUList.Remove(projectPath);
            MruFiles.Initialize(Settings.Default.MRUList);
        }
Exemplo n.º 5
0
        public void TestSetup()
        {
            SIL.Reporting.ErrorReport.IsOkToInteractWithUser = false;

            _projectsFolder = new TemporaryFolder("SayMoreSmokeTest");
            PortableSettingsProvider.SettingsFileFolder = _projectsFolder.Combine("Settings");
            Settings.Default.MRUList = MruFiles.Initialize(Settings.Default.MRUList, 4);
            Settings.Default.DefaultFolderForNewProjects = _projectsFolder.Path;

            _applicationContainer = new ApplicationContainer();
        }
Exemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
//		public bool CreateNewProject(string prjFolder)
//		{
//			int isep = prjFolder.LastIndexOf(Path.DirectorySeparatorChar);
//			var prjFile = (isep >= 0 ? prjFolder.Substring(isep + 1) : prjFolder) + ".sprj";
//			prjFile = prjFile.Replace(" ", string.Empty);
//
//			ProjectSettingsFilePath = Path.Combine(prjFolder, prjFile);
//
//			// Review: do we care if their is already an .sprj file
//			// in the folder having a different name?
//
//			if (!File.Exists(ProjectSettingsFilePath))
//				return false; // Project.CreateAtLocation(ProjectSettingsFilePath);
//
//			var msg = LocalizationManager.LocalizeString(
//				"WelcomeDialog.ProjectAlreadyExistsMsg",
//				"A project already exists in the folder '{0}'.", "Dialog Boxes");
//
//			Utils.MsgBox(string.Format(msg, prjFolder), MessageBoxIcon.Exclamation);
//			ProjectSettingsFilePath = null;
//			return false;
//		}

        /// ------------------------------------------------------------------------------------
        public WelcomeDialogViewModel()
        {
            if (!Settings.Default.FirstTimeRun)
            {
                return;
            }

            // If this is the first time the program has been run, then stuff
            // the sample project(s) into the MRU list.
            var path = Path.Combine(Program.CommonAppDataFolder, "Samples");

            if (Directory.Exists(path))
            {
                foreach (var sampleProjectFile in Project.GetAllProjectSettingsFiles(path))
                {
                    MruFiles.AddNewPath(sampleProjectFile);
                }

                Settings.Default.FirstTimeRun = false;
            }
        }
Exemplo n.º 7
0
        public void Latest()
        {
            Assert.IsEmpty(_paths);

            var path1 = Path.Combine(_mruFileFolder, "mru1.tmp");

            File.CreateText(path1).Close();
            MruFiles.AddNewPath(path1);
            Assert.AreEqual(path1, MruFiles.Latest);

            var path2 = Path.Combine(_mruFileFolder, "mru2.tmp");

            File.CreateText(path2).Close();
            MruFiles.AddNewPath(path2);
            Assert.AreEqual(path2, MruFiles.Latest);

            var path3 = Path.Combine(_mruFileFolder, "mru3.tmp");

            File.CreateText(path3).Close();
            MruFiles.AddNewPath(path3, true);
            Assert.AreEqual(path2, MruFiles.Latest);
        }
Exemplo n.º 8
0
        public void AddNewPath()
        {
            Assert.IsEmpty(_paths);

            var path1 = Path.Combine(_mruFileFolder, "mru1.tmp");

            File.CreateText(path1).Close();
            Assert.IsTrue(MruFiles.AddNewPath(path1));
            Assert.AreEqual(1, _paths.Count);
            Assert.Contains(path1, _paths);

            var path2 = Path.Combine(_mruFileFolder, "mru2.tmp");

            MruFiles.AddNewPath(path2);
            Assert.IsFalse(MruFiles.AddNewPath(path2));
            Assert.AreEqual(1, _paths.Count);
            Assert.Contains(path1, _paths);

            // Readd a path that already exists.
            Assert.IsTrue(MruFiles.AddNewPath(path1));
            Assert.AreEqual(1, _paths.Count);
            Assert.Contains(path1, _paths);
        }
Exemplo n.º 9
0
 public void AddNewNullPath()
 {
     MruFiles.AddNewPath(null);
 }
Exemplo n.º 10
0
        static void Main()
        {
            // I had put the following line of code in to fix a SP-436 after reading this article:
            // http://stackoverflow.com/questions/4077822/net-4-0-and-the-dreaded-onuserpreferencechanged-hang
            // Microsoft.Win32.SystemEvents.UserPreferenceChanged += delegate { };
            // But then I found this page: http://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: http://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 http://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();

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

                Sldr.Initialize();

                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();
                }
            }
        }
Exemplo n.º 11
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// By the time we get here, we know the app. has settled down after loading a project.
 /// Now that the project has been loaded without crashing, save the project as the
 /// most recently opened project. xref: SP-186.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private static void SaveLastOpenedProjectInMRUList(object sender, EventArgs e)
 {
     Application.Idle -= SaveLastOpenedProjectInMRUList;
     MruFiles.AddNewPath(_pathOfLoadedProjectFile);
     Settings.Default.Save();
 }