Exemplo n.º 1
0
 public MtgaOutputLogResultsPreparer(
     CacheSingleton <Dictionary <int, Card> > cacheCards,
     IMapper mapper,
     IEventTypeCache eventsScheduleManager,
     InGameTracker2 inGameTracker
     )
 {
     dictAllCards = cacheCards.Get();
     this.mapper  = mapper;
     this.eventsScheduleManager = eventsScheduleManager;
     this.inGameTracker         = inGameTracker;
     Reset();
 }
        public MainWindow(
            ConfigModel configApp,
            ICollection <Card> allCards,
            MainWindowVM viewModel,
            ProcessMonitor processMonitor,
            LogFileZipper zipper,
            ServerApiCaller api,
            StartupShortcutManager startupManager,
            LogSplitter logSplitter,
            MtgaResourcesLocator resourcesLocator,
            FileMonitor fileMonitor,
            DraftCardsPicker draftHelper,
            ReaderMtgaOutputLog readerMtgaOutputLog,
            InGameTracker2 inMatchTracker,
            ExternalProviderTokenManager tokenManager,
            PasswordHasher passwordHasher,
            CacheSingleton <Dictionary <string, DraftRatings> > draftRatings,
            DraftHelperRunner draftHelperRunner)
        {
            // Set the config model reference
            ConfigModel = configApp;


            Reader = readerMtgaOutputLog;
            processMonitor.OnProcessMonitorStatusChanged += OnProcessMonitorStatusChanged;
            Zipper           = zipper;
            Api              = api;
            StartupManager   = startupManager;
            LogSplitter      = logSplitter;
            ResourcesLocator = resourcesLocator;
            FileMonitor      = fileMonitor;
            fileMonitor.OnFileSizeChangedNewText += OnFileSizeChangedNewText;
            DraftHelper = draftHelper;
            //this.logProcessor = logProcessor;
            InGameTracker     = inMatchTracker;
            TokenManager      = tokenManager;
            PasswordHasher    = passwordHasher;
            DraftRatings      = draftRatings;
            DraftHelperRunner = draftHelperRunner;
            ResourcesLocator.LocateLogFilePath(ConfigModel);
            ResourcesLocator.LocateGameClientFilePath(ConfigModel);

            fileMonitor.SetFilePath(ConfigModel.LogFilePath);

            // Set the view model
            MainWindowVM = viewModel;

            // Set the data context to the view model
            DataContext = MainWindowVM;

            InitializeComponent();

            WelcomeControl.Init(tokenManager);
            PlayingControl.Init(MainWindowVM);
            StatusBarTop.Init(this, MainWindowVM);
            ReadyControl.Init(ConfigModel.GameFilePath);
            DraftingControl.Init(allCards, MainWindowVM.DraftingVM);

            DraftingControl.SetPopupRatingsSource(ConfigModel.ShowLimitedRatings, ConfigModel.ShowLimitedRatingsSource);

            processMonitor.Start(new System.Threading.CancellationToken());

            FileMonitor.Start(new System.Threading.CancellationToken());

            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(200)
            };

            timer.Tick += (sender, e) =>
            {
                MainWindowVM.SetCardsDraftFromBuffered();
                MainWindowVM.SetCardsInMatchTrackingFromBuffered();
            };
            timer.Start();

            var timerTokenRefresh = new DispatcherTimer {
                Interval = TimeSpan.FromMinutes(9)
            };

            timerTokenRefresh.Tick += (sender, e) =>
            {
                RefreshAccessToken();
            };
            timerTokenRefresh.Start();
        }
        public MainWindowVM(StatusBlinker statusBlinker, InMatchTrackerStateVM inMatchState, ConfigModel config, DraftingVM draftingVM,
                            IMapper mapper,
                            ICacheLoader <Dictionary <int, Set> > cacheSets,
                            ProcessMonitor processMonitor,
                            ServerApiCaller api,
                            StartupShortcutManager startupManager,
                            MtgaResourcesLocator resourcesLocator,
                            FileMonitor fileMonitor,
                            DraftCardsPicker draftHelper,
                            ReaderMtgaOutputLog readerMtgaOutputLog,
                            InGameTracker2 inMatchTracker,
                            ExternalProviderTokenManager tokenManager,
                            PasswordHasher passwordHasher,
                            CacheSingleton <Dictionary <string, DraftRatings> > draftRatings,
                            DraftHelperRunner draftHelperRunner,
                            //IEmailProvider emailProvider,
                            ICollection <Card> allCards,
                            CardThumbnailDownloader cardThumbnailDownloader,
                            ServerApiCaller serverApiCaller
                            )
        {
            // Set the status blinker reference
            StatusBlinker = statusBlinker;
            // Set the network status emission handler
            StatusBlinker.EmitStatus += status => { NetworkStatus = status; };

            Sets                               = cacheSets.LoadData().Values.ToArray();
            InMatchState                       = inMatchState;
            Config                             = config;
            DraftingVM                         = draftingVM;
            Mapper                             = mapper;
            ProcessMonitor                     = processMonitor;
            Api                                = api;
            StartupManager                     = startupManager;
            ResourcesLocator                   = resourcesLocator;
            FileMonitor                        = fileMonitor;
            DraftHelper                        = draftHelper;
            ReaderMtgaOutputLog                = readerMtgaOutputLog;
            InMatchTracker                     = inMatchTracker;
            InMatchState.GameEnded            += OnGameEnded;
            InMatchState.OpponentCardsUpdated += OnOpponentCardsUpdated;

            TokenManager      = tokenManager;
            PasswordHasher    = passwordHasher;
            DraftRatings      = draftRatings;
            DraftHelperRunner = draftHelperRunner;
            //this.emailProvider = emailProvider;
            AllCards = allCards;
            CardThumbnailDownloader = cardThumbnailDownloader;
            this.serverApiCaller    = serverApiCaller;

            // Set the library order from the config
            OrderLibraryCardsBy = config.OrderLibraryCardsBy == "Converted Mana Cost"
                ? CardsListOrder.ManaCost
                : CardsListOrder.DrawChance;

            // Create the opponent window view model
            OpponentWindowVM = new OpponentWindowVM("Opponent Cards", this, serverApiCaller);

            // Subscribe to property changes
            PropertyChanged += OnPropertyChanged;

            // Set the animated icon state
            AnimatedIcon = Config?.AnimatedIcon ?? false;

            // Set the initial window settings
            PositionTop   = WindowSettings?.Position.Y ?? 0;
            PositionLeft  = WindowSettings?.Position.X ?? 0;
            WindowOpacity = WindowSettings?.Opacity ?? 0.9;
            WindowTopmost = WindowSettings?.Topmost ?? true;

            // Set the initial window size
            WindowWidth = WindowSettings != null && WindowSettings.Size.X > double.Epsilon
                ? WindowSettings.Size.X
                : 340;
            WindowHeight = WindowSettings != null && WindowSettings.Size.Y > double.Epsilon
                ? WindowSettings.Size.Y
                : 500;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Complete constructor
        /// </summary>
        public MainWindow(MainWindowVM viewModel)
        {
            mapper    = viewModel.Mapper;
            ViewModel = viewModel;

            // Set the main window view model actions
            ViewModel.UploadLogAction    = UploadLogAction;
            ViewModel.ShowOptionsAction  = ShowOptionsWindow;
            ViewModel.LaunchArenaAction  = LaunchArenaAction;
            ViewModel.ValidateUserAction = ValidateUserAction;

            // Set the resource locator
            ResourcesLocator = viewModel.ResourcesLocator;

            // Set the problem action
            ResourcesLocator.SetProblem = ViewModel.SetProblem;

            // Locate the log file
            ResourcesLocator.LocateLogFilePath(ViewModel.Config);

            // Locate the game path
            ResourcesLocator.LocateGameClientFilePath(ViewModel.Config);

            // Set the reference to the draft helper
            DraftHelperRunner = viewModel.DraftHelperRunner;


            Reader         = viewModel.ReaderMtgaOutputLog;
            Api            = viewModel.Api;
            StartupManager = viewModel.StartupManager;
            FileMonitor    = viewModel.FileMonitor;
            FileMonitor.OnFileSizeChangedNewText += OnFileSizeChangedNewText;
            DraftHelper = viewModel.DraftHelper;
            //this.logProcessor = logProcessor;
            InGameTracker  = viewModel.InMatchTracker;
            TokenManager   = viewModel.TokenManager;
            PasswordHasher = viewModel.PasswordHasher;
            DraftRatings   = viewModel.DraftRatings;

            FileMonitor.SetFilePath(ViewModel.Config.LogFilePath);

            // Set the data context to the view model
            DataContext = ViewModel;

            InitializeComponent();

            PlayingControl.Init(ViewModel);
            DraftingControl.Init(ViewModel.DraftingVM, ViewModel.Config.LimitedRatingsSource);
            DraftingControl.SetPopupRatingsSource(ViewModel.Config.ShowLimitedRatings, ViewModel.Config.LimitedRatingsSource);

            // Set the process monitor status changed action
            viewModel.ProcessMonitor.OnProcessMonitorStatusChanged = OnProcessMonitorStatusChanged;

            // Start the process monitor without awaiting the task completion
            _ = viewModel.ProcessMonitor.Start(new System.Threading.CancellationToken());

            // Start the file monitor without awaiting the task completion
            _ = FileMonitor.Start(new System.Threading.CancellationToken());

            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(200)
            };

            timer.Tick += (sender, e) =>
            {
                ViewModel.DraftingVM.SetCardsDraftFromBuffered();
                ViewModel.InMatchState.SetInMatchStateFromBuffered();
            };
            timer.Start();

            var timerTokenRefresh = new DispatcherTimer {
                Interval = TimeSpan.FromMinutes(9)
            };

            timerTokenRefresh.Tick += (sender, e) =>
            {
                RefreshAccessToken();
            };
            timerTokenRefresh.Start();
        }