public static void TryRestartApplication()
 {
     if (AppSettings.Side == ScriptSide.Client &&
         DatabaseConnectionPersister.GetLastSuccessfulDatabaseConnection().AddSeconds(ConnectionIdleInSeconds) < DateTime.Now)
     {
         ApplicationRestarter.RestartAppPool();
     }
 }
Beispiel #2
0
        private void restartApplicationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (UserSettings.ConfirmApplicationExiting && Activator.Confirm("Restart Application?", "Confirm Restart") == false)
            {
                return;
            }


            ApplicationRestarter.Restart();
        }
Beispiel #3
0
        private void btnAttemptPatching_Click(object sender, EventArgs e)
        {
            try
            {
                var toMem = new ToMemoryCheckNotifier(checksUI1);

                var mds = new MasterDatabaseScriptExecutor(_database);


                mds.PatchDatabase(_patcher, toMem, PreviewPatch,
                                  () => MessageBox.Show("Backup Database First", "Backup", MessageBoxButtons.YesNo) == DialogResult.Yes);

                //if it crashed during patching
                if (toMem.GetWorst() == CheckResult.Fail)
                {
                    btnAttemptPatching.Enabled = true;
                    return;
                }

                toMem.OnCheckPerformed(new CheckEventArgs("Patching completed without exception, disabling the patching button", CheckResult.Success, null));
                //patching worked so prevent them doing it again!
                btnAttemptPatching.Enabled = false;

                if (_repository != null)
                {
                    _repository.ClearUpdateCommandCache();
                    checksUI1.OnCheckPerformed(new CheckEventArgs("Cleared UPDATE commands cache", CheckResult.Success, null));
                }

                checksUI1.OnCheckPerformed(new CheckEventArgs("Patching Succesful", CheckResult.Success, null));

                if (MessageBox.Show("Application will now restart", "Close?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    ApplicationRestarter.Restart();
                }
            }
            catch (Exception exception)
            {
                checksUI1.OnCheckPerformed(new CheckEventArgs("Patching failed", CheckResult.Fail, exception));
            }
        }
Beispiel #4
0
        private void RDMPMainForm_Load(object sender, EventArgs e)
        {
            var exceptionCounter = new ExceptionCounterUI();

            _globalErrorCheckNotifier = exceptionCounter;
            _rdmpTopMenuStrip1.InjectButton(exceptionCounter);

            _windowManager = new WindowManager(_theme, this, _refreshBus, dockPanel1, RepositoryLocator, exceptionCounter);
            SetItemActivator(_windowManager.ActivateItems);

            _rdmpTopMenuStrip1.SetWindowManager(_windowManager);

            //put the version of the software into the window title

            _version = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            //put the current platform database into the window title too
            if (Activator?.RepositoryLocator?.CatalogueRepository is TableRepository connectedTo)
            {
                var database            = connectedTo.DiscoveredServer?.GetCurrentDatabase();
                var instanceDescription = "";

                var connectionStringsFileLoaded = RDMPBootStrapper <RDMPMainForm> .ApplicationArguments?.ConnectionStringsFileLoaded;
                if (connectionStringsFileLoaded != null)
                {
                    instanceDescription = " - " + (connectionStringsFileLoaded.Name ?? connectionStringsFileLoaded.FileLoaded.Name);
                }
                if (database != null)
                {
                    _connectedTo = $"({database.GetRuntimeName()} on {database.Server.Name}){instanceDescription}";
                }
            }

            Text = "Research Data Management Platform";

            var rdmpDir = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RDMP"));

            if (!rdmpDir.Exists)
            {
                rdmpDir.Create();
            }

            _persistenceFile = new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RDMP", "RDMPDockPanelPersist.xml"));

            //if there is no persist file or user wants to show the home screen always on startup
            if (!_persistenceFile.Exists || UserSettings.ShowHomeOnStartup)
            {
                _windowManager.PopHome();
            }
            else
            {
                try
                {
                    if (_persistenceFile.Exists)
                    {
                        LoadFromXml(new FileStream(_persistenceFile.FullName, FileMode.Open));
                    }

                    //load the stateusing the method
                }
                catch (Exception ex)
                {
                    _globalErrorCheckNotifier.OnCheckPerformed(
                        new CheckEventArgs("Could not load window persistence due to error in persistence file",
                                           CheckResult.Fail, ex));

                    //delete the persistence file and try again
                    MessageBox.Show("Persistence file corrupt, application will restart without persistence");
                    _persistenceFile.Delete();
                    ApplicationRestarter.Restart();
                }
            }

            FormClosing += CloseForm;
            Loading      = false;
        }
Beispiel #5
0
        public static async Task DownloadUpdatesAsync(ModelClass model)
        {
            Contract.Requires(model != null);
            model.InformationAndExceptionOutput = Localization.Properties.Resources.StandardOutputCheckingForUpdates;
            model.Log.Information(Localization.Properties.Resources.StandardOutputCheckingForUpdates);
            int configTimeoutSeconds = 40;

            if (int.TryParse(ApplicationSettingsProvider.GetValue("TimeoutInSeconds"), out int timeout))
            {
                configTimeoutSeconds = timeout;
            }
            var updatesCheck = await Task.Run(() => UpdatesNeeded.CheckAsync()).ConfigureAwait(false);

            var pathToExe       = Assembly.GetEntryAssembly().Location;
            var pathToExeFolder = System.IO.Path.GetDirectoryName(pathToExe);
            var client          = new GitHubClient(new ProductHeaderValue("audio-downloader"));

            client.SetRequestTimeout(TimeSpan.FromSeconds(configTimeoutSeconds));
            var releasesYoutubeDl = await client.Repository.Release.GetLatest("ytdl-org", "youtube-dl").ConfigureAwait(false);

            var releasesAudioDl = await client.Repository.Release.GetLatest("ChrisKolan", "audio-downloader").ConfigureAwait(false);

            if (updatesCheck["audio-downloader"] == true)
            {
                model.StandardOutput = Localization.Properties.Resources.StandardOutputDownloadingNewAudioDownloaderVersion;
                model.InformationAndExceptionOutput = Localization.Properties.Resources.StandardOutputDownloadingNewAudioDownloaderVersion;
                model.Log.Information(Localization.Properties.Resources.StandardOutputDownloadingNewAudioDownloaderVersion);
                var pathToAudioDownloaderTempFolder = pathToExeFolder + @"\AudioDownloader.zip";
                var latestAsset = await client.Repository.Release.GetAllAssets("ChrisKolan", "audio-downloader", releasesAudioDl.Id).ConfigureAwait(false);

                var latestUri = latestAsset[0].BrowserDownloadUrl;
                var response  = await client.Connection.Get <object>(new Uri(latestUri), new Dictionary <string, string>(), "application/octet-stream").ConfigureAwait(false);

                var responseData = response.HttpResponse.Body;
                System.IO.File.WriteAllBytes(pathToAudioDownloaderTempFolder, (byte[])responseData);
                model.InformationAndExceptionOutput = Localization.Properties.Resources.DownloadFinished;
                model.Log.Information(Localization.Properties.Resources.DownloadFinished);

                RenameFilesInFolder.Rename(model);
                model.InformationAndExceptionOutput = Localization.Properties.Resources.RenamedFiles;
                model.Log.Information(Localization.Properties.Resources.RenamedFiles);
                Deleter.DeleteBinFolderContents();
                model.InformationAndExceptionOutput = Localization.Properties.Resources.DeletedFiles;
                model.Log.Information(Localization.Properties.Resources.DeletedFiles);
                Unzipper.Unzip();
                model.InformationAndExceptionOutput = Localization.Properties.Resources.UnzippedFiles;
                model.Log.Information(Localization.Properties.Resources.UnzippedFiles);
                ApplicationRestarter.Restart();
                model.InformationAndExceptionOutput = Localization.Properties.Resources.RestartingApplication;
                model.Log.Information(Localization.Properties.Resources.RestartingApplication);
            }
            else if (updatesCheck["youtube-dl"] == true)
            {
                model.StandardOutput = Localization.Properties.Resources.StandardOutputDownloadingNewYoutubeDlVersion;
                model.InformationAndExceptionOutput = Localization.Properties.Resources.StandardOutputDownloadingNewYoutubeDlVersion;
                model.Log.Information(Localization.Properties.Resources.StandardOutputDownloadingNewYoutubeDlVersion);
                var pathToYoutubeDl = pathToExeFolder + @"\bin\youtube-dl.exe";
                var latestAsset     = await client.Repository.Release.GetAllAssets("ytdl-org", "youtube-dl", releasesYoutubeDl.Id).ConfigureAwait(false);

                var latestUri = latestAsset[7].BrowserDownloadUrl;
                var response  = await client.Connection.Get <object>(new Uri(latestUri), new Dictionary <string, string>(), "application/octet-stream").ConfigureAwait(false);

                var responseData = response.HttpResponse.Body;
                System.IO.File.WriteAllBytes(pathToYoutubeDl, (byte[])responseData);
                model.StandardOutput = Localization.Properties.Resources.StandardOutputReadyUpdatedYoutubeDlToLatestVersion;
                model.InformationAndExceptionOutput = Localization.Properties.Resources.StandardOutputReadyUpdatedYoutubeDlToLatestVersion;
                model.Log.Information(Localization.Properties.Resources.StandardOutputReadyUpdatedYoutubeDlToLatestVersion);
            }
        }
Beispiel #6
0
 private void RestartApplication()
 {
     MessageBox.Show("Connection Strings Changed, the application will now restart");
     ApplicationRestarter.Restart();
 }