コード例 #1
0
 public void Launch()
 {
     if (!checkController())
         return;
     stopMediaPlayback();
     OnStarted();
     launcher = new GameLauncher(game);
     BackgroundTaskHandler handler = new BackgroundTaskHandler();
     handler.ActionDelegate = () =>
     {
         launcher.ExtractionProgress += (s, e) =>
             {
                 beginInvoke(() =>
                     {
                         handler.ExecuteProgressHandler(string.Format("Extracting {0}%", e.Percent), e.Percent);
                     });
             };
         launcher.ExtractionFailed += launcher_ExtractionFailed;
         launcher.Starting += launcher_Starting;
         launcher.StartFailed += launcher_StartFailed;
         launcher.Exited += launcher_Exited;
         launcher.Launch();
     };
     MP1Utils.ShowProgressDialog(handler);
 }
コード例 #2
0
        static PlatformInfo getPlatformInfo(string platform, Platform selectedPlatform, IPlatformImporter importer, Func<PlatformInfo, bool> completedDelegate)
        {
            PlatformInfo platformInfo = null;
            bool completed = false;

            BackgroundTaskHandler handler = new BackgroundTaskHandler();
            handler.ActionDelegate = () =>
            {
                handler.ExecuteProgressHandler("Looking up platforms...", 0);
                if (selectedPlatform == null)
                    selectedPlatform = importer.GetPlatformByName(platform);
                if (selectedPlatform != null)
                {
                    handler.ExecuteProgressHandler("Retrieving info for " + platform, 33);
                    platformInfo = importer.GetPlatformInfo(selectedPlatform.Id);
                    if (platformInfo != null)
                    {
                        handler.ExecuteProgressHandler("Updating " + platformInfo.Title, 67);
                        completed = completedDelegate == null ? true : completedDelegate(platformInfo);
                    }
                }
            };

            using (Conf_ProgressDialog progressDlg = new Conf_ProgressDialog(handler))
                progressDlg.ShowDialog();

            if (completed)
                return platformInfo;

            if (selectedPlatform == null)
            {
                var platforms = importer.GetPlatformList();
                if (platforms.Count != 0)
                {
                    using (Conf_EmuLookupDialog lookupDlg = new Conf_EmuLookupDialog(platforms))
                    {
                        if (lookupDlg.ShowDialog() == DialogResult.OK && lookupDlg.SelectedPlatform != null)
                            return getPlatformInfo(lookupDlg.SelectedPlatform.Name, lookupDlg.SelectedPlatform, importer, completedDelegate);
                    }
                }
            }
            else
            {
                MessageBox.Show("Error retrieving online info.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return null;
        }
コード例 #3
0
        void updatePositions()
        {
            if (!updateEmuPositions)
                return;

            List<Emulator> emus = new List<Emulator>();
            foreach (ListViewItem item in emulatorListView.Items)
            {
                Emulator emu = item.Tag as Emulator;
                if (emu.Position != item.Index)
                {
                    emu.Position = item.Index;
                    emus.Add(emu);
                }
            }
            var handler = new BackgroundTaskHandler<Emulator>() { Items = emus };
            handler.StatusDelegate = o => { return string.Format("Updating {0} position...", o.Title); };
            handler.ActionDelegate = o =>
                {
                    o.SavePosition();
                };

            using (Conf_ProgressDialog dlg = new Conf_ProgressDialog(handler))
                dlg.ShowDialog();
            updateEmuPositions = false;
        }
コード例 #4
0
        public static async Task Start(string baseUrl, int processId)
        {
            var hasDebugEnabled = ApplicationDataHelper.HasDebugEnabled(Constants.AppName);

#if RELEASE
            SetupReleaseLogging(hasDebugEnabled);
#else
            SetupDebugLogging();
#endif

            var serviceCollection = new ServiceCollection();
            ConfigureServices(serviceCollection);

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var loggerFactory   = serviceProvider.GetService <ILoggerFactory>();
            var logger          = serviceProvider.GetService <ILogger <Program> >();

            if (processId > 0)
            {
                KillOtherWorkers(logger, processId);
            }

            logger.LogDebug($"Connecting to base url '{baseUrl}'");

            var progressHubConnection = new HubConnectionBuilder()
                                        .WithUrl($"{baseUrl}/hubs/progress")
                                        .WithAutomaticReconnect()
                                        .ConfigureLogging(logging =>
            {
                if (!hasDebugEnabled)
                {
                    return;
                }

                logging.AddSerilog();
            })
                                        .Build();

            var errorHubConnection = new HubConnectionBuilder()
                                     .WithUrl($"{baseUrl}/hubs/error")
                                     .WithAutomaticReconnect()
                                     .ConfigureLogging(logging =>
            {
                if (!hasDebugEnabled)
                {
                    return;
                }

                logging.AddSerilog();
            })
                                     .Build();

            var workerHubConnection = new HubConnectionBuilder()
                                      .WithUrl($"{baseUrl}/hubs/worker")
                                      .WithAutomaticReconnect()
                                      .ConfigureLogging(logging =>
            {
                if (!hasDebugEnabled)
                {
                    return;
                }

                logging.AddSerilog();
            })
                                      .Build();

            var resultHubConnection = new HubConnectionBuilder()
                                      .WithUrl($"{baseUrl}/hubs/result")
                                      .WithAutomaticReconnect()
                                      .ConfigureLogging(logging =>
            {
                if (!hasDebugEnabled)
                {
                    return;
                }

                logging.AddSerilog();
            })
                                      .Build();

            await progressHubConnection.StartAsync();

            await errorHubConnection.StartAsync();

            await workerHubConnection.StartAsync();

            await resultHubConnection.StartAsync();

            logger.LogDebug($"ProgressHubConnection = {progressHubConnection.State}");
            logger.LogDebug($"ErrorHubConnection = {errorHubConnection.State}");
            logger.LogDebug($"WorkerHubConnection = {workerHubConnection.State}");
            logger.LogDebug($"ResultHubConnection = {resultHubConnection.State}");

            var physicalDriveManagerFactory = new PhysicalDriveManagerFactory(loggerFactory);

            var backgroundTaskQueue      = new BackgroundTaskQueue(100);
            var activeBackgroundTaskList = new ActiveBackgroundTaskList();
            var queuedHostedService      = new QueuedHostedService(backgroundTaskQueue, activeBackgroundTaskList,
                                                                   loggerFactory.CreateLogger <QueuedHostedService>());

            var backgroundTaskHandler = new BackgroundTaskHandler(
                loggerFactory.CreateLogger <BackgroundTaskHandler>(),
                loggerFactory,
                progressHubConnection,
                errorHubConnection,
                resultHubConnection,
                physicalDriveManagerFactory.Create(),
                activeBackgroundTaskList,
                backgroundTaskQueue);

            await queuedHostedService.StartAsync(CancellationToken.None);

            workerHubConnection.On <BackgroundTask>(Constants.HubMethodNames.RunBackgroundTask, async(task) =>
            {
                logger.LogDebug($"Start handle background task type '{task.Type}' with payload '{task.Payload}'");
                try
                {
                    await backgroundTaskHandler.Handle(task);
                    logger.LogDebug($"End handle background task type '{task.Type}' with payload '{task.Payload}'");
                }
                catch (Exception e)
                {
                    logger.LogError(e,
                                    $"Failed to handle background task '{task.Type}' with payload '{task.Payload}'");
                }
            });

            workerHubConnection.On(Constants.HubMethodNames.CancelBackgroundTask, () =>
            {
                logger.LogDebug("Cancel background task");
                try
                {
                    activeBackgroundTaskList.CancelAll();
                }
                catch (Exception e)
                {
                    logger.LogError(e,
                                    "Failed to cancel background task");
                }
            });

            var workerProcessId = Process.GetCurrentProcess().Id;
            logger.LogDebug($"Worker process id '{workerProcessId}'");

            await workerHubConnection.WorkerProcess(workerProcessId);

            logger.LogDebug("Worker is ready");

            var pingFailed    = 0;
            var maxPingFailed = 3;
            while (true)
            {
                await Task.Delay(5000);

                try
                {
                    await workerHubConnection.WorkerPing();

                    pingFailed = 0;
                }
                catch (Exception)
                {
                    pingFailed++;
                }

                if (pingFailed <= maxPingFailed)
                {
                    continue;
                }
                logger.LogInformation($"Stopping worker after ping failed {maxPingFailed} times");
                return;
            }
        }
コード例 #5
0
        void delRomButton_Click(object sender, EventArgs e)
        {
            if (dBListView.SelectedItems.Count == 0)
                return;

            DialogResult dlg = MessageBox.Show(
                "Are you sure you want to delete the selected Game(s) and add them to the ignored files list?",
                "Delete Game(s)?",
                MessageBoxButtons.YesNo );

            if (dlg != DialogResult.Yes)
                return;

            selectedListItem = null;
            saveSelectedGame = false;
            saveThumbs = false;
            savePCSettings = false;
            saveDiscs = false;

            List<Game> games = new List<Game>();
            foreach (ListViewItem item in dBListView.SelectedItems)
                games.Add((Game)item.Tag);

            BackgroundTaskHandler<Game> handler = new BackgroundTaskHandler<Game>() { Items = games };
            handler.StatusDelegate = game => { return "removing " + game.Title; };
            handler.ActionDelegate = game =>
            {
                foreach (GameDisc disc in game.Discs)
                    EmulatorsCore.Options.AddIgnoreFile(disc.Path);
                game.Delete();
            };

            using (Conf_ProgressDialog progressDlg = new Conf_ProgressDialog(handler))
                progressDlg.ShowDialog();

            dBListView.SelectedItems.Clear();
            UpdatePanel();
        }
コード例 #6
0
        void sendToImporter(IEnumerable<Game> games)
        {
            Importer importer = Importer;
            if (importer == null)
                return;

            BackgroundTaskHandler handler = new BackgroundTaskHandler();
            handler.StatusDelegate = () => { return "sending to Importer..."; };
            handler.ActionDelegate = () =>
                {
                    importer.AddGames(games);
                };
            using (Conf_ProgressDialog progressDlg = new Conf_ProgressDialog(handler))
                progressDlg.ShowDialog();
        }
コード例 #7
0
        void delRomButton_Click(object sender, EventArgs e)
        {
            if (importGridView.SelectedRows.Count < 1)
                return;

            if (MessageBox.Show(
                "Are you sure you want to delete the selected Game(s) and add them to the ignored files list?",
                "Delete Game(s)?",
                MessageBoxButtons.YesNo) != DialogResult.Yes)
                return;

            List<Game> games = new List<Game>();
            foreach (DataGridViewRow row in importGridView.SelectedRows)
            {
                RomMatch match = row.DataBoundItem as RomMatch;
                if (match != null && match.Game != null)
                    games.Add(match.Game);
            }

            BackgroundTaskHandler<Game> handler = new BackgroundTaskHandler<Game>() { Items = games };
            handler.StatusDelegate = game => { return "removing " + game.Title; };
            handler.ActionDelegate = game =>
            {                
                foreach (GameDisc disc in game.Discs)
                    EmulatorsCore.Options.AddIgnoreFile(disc.Path);                    
                game.Delete();
            };

            using (Conf_ProgressDialog progressDlg = new Conf_ProgressDialog(handler))
                progressDlg.ShowDialog();
        }
コード例 #8
0
        void ignoreButton_Click(object sender, EventArgs e)
        {
            if (importGridView.SelectedRows.Count < 1)
                return;

            List<RomMatch> matches = new List<RomMatch>();
            foreach (DataGridViewRow row in importGridView.SelectedRows)
            {
                RomMatch match = row.DataBoundItem as RomMatch;
                if (match != null)
                    matches.Add(match);
            }

            if (matches.Count == 0)
                return;
            else if (matches.Count == 1)
                importer.Ignore(matches[0]);
            else
            {
                BackgroundTaskHandler handler = new BackgroundTaskHandler();
                handler.StatusDelegate = () => { return "Ignoring roms..."; };
                handler.ActionDelegate = () =>
                {
                    importer.Ignore(matches);
                };
                using (Conf_ProgressDialog dlg = new Conf_ProgressDialog(handler))
                    dlg.ShowDialog();
            }

            updateButtons();
        }