Bloom.Shell.OnClosing C# (CSharp) Method

OnClosing() protected method

protected OnClosing ( CancelEventArgs e ) : void
e CancelEventArgs
return void
        protected override void OnClosing(CancelEventArgs e)
        {
            //get everything saved (under the old collection name, if we are changing the name and restarting)
            _libraryClosingEvent.Raise(null);

            if (!string.IsNullOrEmpty(_nameToChangeCollectionUponClosing) &&
                _nameToChangeCollectionUponClosing != _collectionSettings.CollectionName)
            {
                //Actually restart Bloom with a parameter requesting this name change. It's way more likely to succeed
                //when this run isn't holding onto anything.
                try
                {
                    var existingDirectoryPath = Path.GetDirectoryName(_collectionSettings.SettingsFilePath);
                    var parentDirectory = Path.GetDirectoryName(existingDirectoryPath);
                    var newDirectoryPath = Path.Combine(parentDirectory, _nameToChangeCollectionUponClosing);

                    Process.Start(Application.ExecutablePath,
                        string.Format("--rename \"{0}\" \"{1}\" ", existingDirectoryPath, newDirectoryPath));

                    //give some time for that process.start to finish staring the new instance, which will see
                    //we have a mutex and wait for us to die, then see the --rename, and do its work.

                    Thread.Sleep(2000);
                    Environment.Exit(-1); //Force termination of the current process.
                }
                catch (Exception error)
                {
                    SIL.Reporting.ErrorReport.NotifyUserOfProblem(error,
                        "Sorry, Bloom failed to even prepare for the rename of the project to '{0}'", _nameToChangeCollectionUponClosing);
                }
            }

            base.OnClosing(e);
        }