Beispiel #1
0
        public async Task <bool> Handle(PriceCheckItemCommand request, CancellationToken cancellationToken)
        {
            // Close previously opened price views
            viewLocator.Close(View.ParserError);
            viewLocator.Close(View.Price);

            // Parses the item by copying the item under the cursor
            var item = request.Item;

            if (item == null)
            {
                var itemText = await clipboardProvider.Copy();

                item = await mediator.Send(new ParseItemCommand(itemText));
            }

            if (item == null)
            {
                // If the item can't be parsed, show an error
                viewLocator.Open(View.ParserError);
            }
            else
            {
                // If the item can be parsed, show the view
                viewLocator.Open(View.Price, item);
            }

            return(true);
        }
Beispiel #2
0
        public async Task <bool> Handle(OpenMapInfoCommand request, CancellationToken cancellationToken)
        {
            await mediator.Send(new CloseMapViewCommand());

            // Close previously opened map views
            viewLocator.Close(View.ParserError);
            viewLocator.Close(View.Map);

            // Parses the item by copying the item under the cursor
            var item = await mediator.Send(new ParseItemCommand(await clipboardProvider.Copy()));

            if (item == null)
            {
                // If the item can't be parsed, show an error
                viewLocator.Open(View.ParserError);
            }
            else if (item.Properties.MapTier == 0)
            {
                // If the item is not a map
                viewLocator.Open(View.InvalidItemError);
            }
            else
            {
                // If the item can be parsed, show the view
                viewLocator.Open(View.Map, item);
            }

            return(true);
        }
 public Task Handle(InitializationStarted notification, CancellationToken cancellationToken)
 {
     viewLocator.Close(View.Settings);
     viewLocator.Close(View.Setup);
     if (settings.ShowSplashScreen && !viewLocator.IsOpened(View.Initialization))
     {
         viewLocator.Open(View.Initialization);
     }
     return(Task.CompletedTask);
 }
Beispiel #4
0
        public Task <bool> Handle(CloseMapViewCommand request, CancellationToken cancellationToken)
        {
            var result = viewLocator.IsOpened(View.Map);

            viewLocator.Close(View.Map);

            return(Task.FromResult(result));
        }
Beispiel #5
0
        public Task <bool> Handle(ToggleCheatsheetsCommand request, CancellationToken cancellationToken)
        {
            if (viewLocator.IsOpened(View.League))
            {
                viewLocator.Close(View.League);
            }
            else
            {
                viewLocator.Open(View.League);
            }

            return(Task.FromResult(true));
        }
        public async Task Handle(InitializationCompleted notification, CancellationToken cancellationToken)
        {
            // If we have a successful initialization, we delay for half a second to show the "Ready" label on the UI before closing the view
            await Task.Delay(500);

            // Show a system notification
            await mediator.Send(new OpenNotificationCommand(string.Format(TrayResources.Notification_Message, settings.Price_Key_Check.ToKeybindString(), settings.Price_Key_Close.ToKeybindString()), true)
            {
                Title = TrayResources.Notification_Title,
            });

            viewLocator.Close(View.Initialization);
        }
Beispiel #7
0
 public Task <Unit> Handle(SetupCommand request, CancellationToken cancellationToken)
 {
     viewLocator.Close(View.Initialization);
     viewLocator.Open(View.Setup);
     return(Unit.Task);
 }
Beispiel #8
0
        public async Task <Unit> Handle(InitializeCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Completed = 0;
                Count     = request.FirstRun ? 10 : 7;

                // Report initial progress
                await ReportProgress();

                // Open a clean view of the initialization
                viewLocator.CloseAll();
                if (settings.ShowSplashScreen)
                {
                    await viewLocator.Open(View.Initialization);
                }

                // Set the UI language
                await RunCommandStep(new SetUiLanguageCommand(settings.Language_UI));

                // Check for updates
                if (request.AutoUpdate && await mediator.Send(new CheckForUpdate(), cancellationToken))
                {
                    viewLocator.Close(View.Initialization);
                    return(Unit.Value);
                }

                // Check to see if we should run Setup first before running the rest of the initialization process
                if (string.IsNullOrEmpty(settings.LeagueId) || string.IsNullOrEmpty(settings.Language_Parser) || string.IsNullOrEmpty(settings.Language_UI))
                {
                    viewLocator.Close(View.Initialization);
                    await viewLocator.Open(View.Setup);

                    return(Unit.Value);
                }

                // Set the game language
                await RunCommandStep(new SetGameLanguageCommand(settings.Language_Parser));

                if (request.FirstRun)
                {
                    var leagues = await mediator.Send(new GetLeaguesQuery(false));

                    var leaguesHash = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(leagues)));

                    if (leaguesHash != settings.LeaguesHash)
                    {
                        await mediator.Send(new ClearCacheCommand());

                        await mediator.Send(new SaveSettingCommand(nameof(ISidekickSettings.LeaguesHash), leaguesHash));
                    }

                    // Check to see if we should run Setup first before running the rest of the initialization process
                    if (string.IsNullOrEmpty(settings.LeagueId) || !leagues.Any(x => x.Id == settings.LeagueId))
                    {
                        await mediator.Send(new OpenNotificationCommand(resources.NewLeagues));

                        viewLocator.Close(View.Initialization);
                        await viewLocator.Open(View.Setup);

                        return(Unit.Value);
                    }
                }

                await Run(() => parserPatterns.Initialize());
                await Run(() => itemMetadataProvider.Initialize());
                await Run(() => itemStaticDataProvider.Initialize());
                await Run(() => modifierProvider.Initialize());
                await Run(() => pseudoModifierProvider.Initialize());

                if (request.FirstRun)
                {
                    await Run(() => processProvider.Initialize(cancellationToken));
                    await Run(() => keyboardProvider.Initialize());
                    await Run(() => keybindProvider.Initialize());
                }

                // If we have a successful initialization, we delay for half a second to show the "Ready" label on the UI before closing the view
                Completed = Count;
                await ReportProgress();

                await Task.Delay(500);

                // Show a system notification
                await mediator.Send(new OpenNotificationCommand(string.Format(resources.Notification_Message, settings.Trade_Key_Check.ToKeybindString(), settings.Key_Close.ToKeybindString()),
                                                                resources.Notification_Title));

                viewLocator.Close(View.Initialization);

                return(Unit.Value);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                await mediator.Send(new OpenNotificationCommand(resources.Error));

                await mediator.Send(new ShutdownCommand());

                return(Unit.Value);
            }
        }
Beispiel #9
0
 public Task Execute()
 {
     viewLocator.Close(View.Map);
     viewLocator.Close(View.Trade);
     return(Task.CompletedTask);
 }