Example #1
0
        private void PostReportsDiscord(object obj)
        {
            _reportPosterFunc().RefreshEmbed();
            Task[] tasks = new Task[DisplayedRaidHerosLogFiles.Count(e => e.ReportPostComplete != true)];
            int    i     = 0;

            foreach (var log in DisplayedRaidHerosLogFiles.Where(e => e.ReportUploadComplete != true))
            {
                if (EncounterGrid.SelectedItems.Contains(log))
                {
                    tasks[i++] = Task.Run(() => _reportUploaderFunc().Upload(log));
                }
            }

            Task.WaitAll(tasks);

            foreach (var log in DisplayedRaidHerosLogFiles.Where(e => e.ReportUploadComplete == true))
            {
                if (EncounterGrid.SelectedItems.Contains(log))
                {
                    _reportPosterFunc().AddReport(log);
                }
            }

            Task.Run(() => _reportPosterFunc().Upload(null));

            foreach (var displayedRaidHerosLogFile in DisplayedRaidHerosLogFiles)
            {
                displayedRaidHerosLogFile.ReportPostComplete = true;
            }
        }
Example #2
0
        public MainViewModel(IFileWatcher fileWatcher, IMessageBus messageBus,
                             IRaidHerosUpdater raidHerosUpdater, IEnumerable <ILogDetectionStrategy> logDetectionStrategies,
                             Func <IRaidarUploader> uploaderFunc)
        {
            _fileWatcher            = fileWatcher;
            _messageBus             = messageBus;
            _logDetectionStrategies = logDetectionStrategies;
            _uploaderFunc           = uploaderFunc;

            _logDetectionStrategies.OrderBy(i => i.Name).ToList().ForEach(s => LogTypes.Add(s.Name));

            messageBus.Listen <NewEncounterMessage>().Subscribe(HandleNewEncounter);
            messageBus.Listen <UpdatedEncounterMessage>().Subscribe(HandleUpdatedEncounter);
            messageBus.Listen <LogMessage>().Subscribe(HandleNewLogMessage);
            messageBus.Listen <UploadedEncounterMessage>().Subscribe(HandleUploadedEncounterMessage);

            Task raidHerosUpdateTask = null;

            if (UseRaidHeros)
            {
                raidHerosUpdateTask = Task.Run(() =>
                {
                    RaidHerosIsUpdating = true;
                    raidHerosUpdater.UpdateRaidHeros();
                });
            }

            var directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            ParseMessages       = new ObservableCollection <string>();
            OpenCommand         = new RelayCommand(OpenLog, _ => SelectedLog != null);
            UploadRaidarCommand = new RelayCommand(UploadRaidar, _ => DisplayedRaidHerosLogFiles.Any(i => i.UploadComplete == false));
            UploadCommand       = new RelayCommand(UploadLogFiles, _ => RaidHerosLogFiles.Any());
            OpenSkillsCommand   = new RelayCommand(ShowSkills);
            ClearCommand        = new RelayCommand(ClearSelectedItem, _ => SelectedLog != null);
            ClearAllCommand     = new RelayCommand(_ =>
            {
                RaidHerosLogFiles.Clear();
                DisplayedRaidHerosLogFiles.Clear();
            }, _ => RaidHerosLogFiles.Any());
            AddCommand = new RelayCommand(AddLog,
                                          _ => _fileWatcher.LogfileWatcher.EnableRaisingEvents && !RaidHerosIsUpdating);
            OpenFilePathCommand = new RelayCommand(_ => { OpenLogFilePath(directoryName); });

            _messageBus.SendMessage(new LogMessage("Waiting for new log."));

            LogFilter = (LogFilterEnum)int.Parse(Settings.Default.LogFilter);
            LogType   = Settings.Default.LogType ?? LogTypes.First();

            _fileWatcher.Run();

            if (UseRaidHeros)
            {
                Task.Run(() =>
                {
                    while (raidHerosUpdateTask != null && !raidHerosUpdateTask.IsCompleted)
                    {
                    }

                    RaidHerosIsUpdating = false;
                    _fileWatcher.LogfileWatcher.EnableRaisingEvents = true;
                });
            }
            else
            {
                _fileWatcher.LogfileWatcher.EnableRaisingEvents = true;
            }
        }