Exemplo n.º 1
0
        public ManagerForm(LogCache logCache, ApiData apiData)
        {
            LogCache = logCache ?? throw new ArgumentNullException(nameof(logCache));
            ApiData  = apiData ?? throw new ArgumentNullException(nameof(apiData));

            // Background processors
            var dpsReportUploader = new DpsReportUploader();

            UploadProcessor  = new UploadProcessor(dpsReportUploader, LogCache);
            ApiProcessor     = new ApiProcessor(ApiData, new Gw2Client());
            LogDataProcessor = new LogDataProcessor(LogCache, ApiProcessor, LogAnalytics);
            LogNameProvider  = new TranslatedLogNameProvider(GameLanguage.English);

            Filters = new LogFilters(new SettingsFilters());
            Filters.PropertyChanged += (sender, args) => logsFiltered.Refresh();

            if (Settings.UseGW2Api)
            {
                ApiProcessor.StartBackgroundTask();
            }

            Settings.UseGW2ApiChanged += (sender, args) =>
            {
                if (Settings.UseGW2Api)
                {
                    ApiProcessor.StartBackgroundTask();
                }
                else
                {
                    ApiProcessor.StopBackgroundTask();
                }
            };

            Settings.DpsReportDomainChanged += (sender, args) => { dpsReportUploader.Domain = Settings.DpsReportDomain; };

            // Form layout
            Icon       = Resources.GetProgramIcon();
            Title      = "arcdps Log Manager";
            ClientSize = new Size(1024, 768);
            var formLayout = new DynamicLayout();

            Content = formLayout;

            Menu = ConstructMenuBar();

            formLayout.BeginVertical(new Padding(5), yscale: false);
            {
                formLayout.Add(ConstructMainSplitter(), yscale: true);
                formLayout.Add(ConstructStatusPanel());
            }
            formLayout.EndVertical();

            // Event handlers
            ApiProcessor.Processed += (sender, args) =>
            {
                bool last = args.CurrentScheduledItems == 0;

                if (last)
                {
                    ApiData.SaveDataToFile();
                }
            };

            Settings.LogRootPathChanged += (sender, args) => Application.Instance.Invoke(ReloadLogs);

            Shown   += (sender, args) => ReloadLogs();
            Closing += (sender, args) =>
            {
                if (LogCache?.ChangedSinceLastSave ?? false)
                {
                    LogCache?.SaveToFile();
                }

                ApiData?.SaveDataToFile();
            };
            LogCollectionsRecreated += (sender, args) =>
            {
                logsFiltered.Filter = Filters.FilterLog;
                logsFiltered.Refresh();
            };
            LogSearchFinished += (sender, args) =>
            {
                var updates = LogDataUpdater.GetUpdates(logs).ToList();
                if (updates.Count > 0)
                {
                    new UpdateDialog(LogDataProcessor, updates).ShowModal(this);
                }
            };

            // Collection initialization
            RecreateLogCollections(new ObservableCollection <LogData>(logs));
        }
Exemplo n.º 2
0
        public ManagerForm(LogCache logCache, ApiData apiData)
        {
            LogCache = logCache ?? throw new ArgumentNullException(nameof(logCache));
            ApiData  = apiData ?? throw new ArgumentNullException(nameof(apiData));

            // Background processors
            var dpsReportUploader = new DpsReportUploader();

            UploadProcessor   = new UploadProcessor(dpsReportUploader, LogCache);
            ApiProcessor      = new ApiProcessor(ApiData, new Gw2Client());
            LogDataProcessor  = new LogDataProcessor(LogCache, ApiProcessor, LogAnalytics);
            LogNameProvider   = new TranslatedLogNameProvider(GameLanguage.English);
            LogCacheAutoSaver = LogCacheAutoSaver.StartNew(logCache, LogCacheAutoSavePeriod);

            LogDataProcessor.StoppingWithError += (sender, args) =>
            {
                Application.Instance.InvokeAsync(() => MessageBox.Show(this,
                                                                       $"The background processor for logs has failed critically. " +
                                                                       $"Please report the following error:\n\nException: {args.Exception}", "Error", MessageBoxType.Error));
            };

            ApiProcessor.StoppingWithError += (sender, args) =>
            {
                Application.Instance.InvokeAsync(() => MessageBox.Show(this,
                                                                       $"The background processor for API requests has failed critically. " +
                                                                       $"Please report the following error:\n\nException: {args.Exception}", "Error", MessageBoxType.Error));
            };

            UploadProcessor.StoppingWithError += (sender, args) =>
            {
                Application.Instance.InvokeAsync(() => MessageBox.Show(this,
                                                                       $"The background processor for log uploads has failed critically. " +
                                                                       $"Please report the following error:\n\nException: {args.Exception}", "Error", MessageBoxType.Error));
            };

            Filters = new LogFilters(new SettingsFilters());
            Filters.PropertyChanged += (sender, args) => logsFiltered.Refresh();

            if (Settings.UseGW2Api)
            {
                ApiProcessor.StartBackgroundTask();
            }

            Settings.UseGW2ApiChanged += (sender, args) =>
            {
                if (Settings.UseGW2Api)
                {
                    ApiProcessor.StartBackgroundTask();
                }
                else
                {
                    ApiProcessor.StopBackgroundTask();
                }
            };

            Settings.DpsReportDomainChanged += (sender, args) => { dpsReportUploader.Domain = Settings.DpsReportDomain; };

            // Form layout
            Icon       = Resources.GetProgramIcon();
            Title      = "arcdps Log Manager";
            ClientSize = new Size(1300, 768);
            var formLayout = new DynamicLayout();

            Content = formLayout;

            Menu = ConstructMenuBar();

            formLayout.BeginVertical(new Padding(5), yscale: false);
            {
                formLayout.Add(ConstructMainSplitter(), yscale: true);
                formLayout.Add(ConstructStatusPanel());
            }
            formLayout.EndVertical();

            // Event handlers
            ApiProcessor.Processed += (sender, args) =>
            {
                bool last = args.CurrentScheduledItems == 0;

                if (last)
                {
                    ApiData.SaveDataToFile();
                }
            };

            Settings.LogRootPathChanged += (sender, args) => Application.Instance.Invoke(ReloadLogs);

            Closing += (sender, args) =>
            {
                if (LogCache?.ChangedSinceLastSave ?? false)
                {
                    LogCache?.SaveToFile();
                }

                ApiData?.SaveDataToFile();
            };
            LogSearchFinished += (sender, args) =>
            {
                var updates = LogDataUpdater.GetUpdates(logs).ToList();
                if (updates.Count > 0)
                {
                    new ProcessingUpdateDialog(LogDataProcessor, updates).ShowModal(this);
                }
            };

            // Collection initialization
            logsFiltered = new FilterCollection <LogData>(logs);
            logsFiltered.CollectionChanged += (sender, args) => FilteredLogsUpdated?.Invoke(this, EventArgs.Empty);
            logsFiltered.Filter             = Filters.FilterLog;
            LogCollectionsInitialized?.Invoke(this, EventArgs.Empty);
            LogDataProcessor.Processed += (sender, args) =>
            {
                bool last = args.CurrentScheduledItems == 0;
                if (last)
                {
                    Application.Instance.AsyncInvoke(logsFiltered.Refresh);
                }
            };

            Shown += (sender, args) => ReloadLogs();
            Shown += (sender, args) => CheckUpdates();
        }
Exemplo n.º 3
0
        public ApiDialog(ApiData apiData)
        {
            Title      = "API data - arcdps Log Manager";
            ClientSize = new Size(300, -1);
            var formLayout = new DynamicLayout();

            Content = formLayout;

            var item = new Button {
                Text = "Close"
            };

            item.Click += (sender, args) => Close();
            PositiveButtons.Add(item);

            var deleteButton = new Button
            {
                Text = "Delete the cache",
            };

            var enableCheckbox = new CheckBox {
                Text = "Use the GW2 API", Checked = Settings.UseGW2Api
            };

            enableCheckbox.CheckedChanged += (sender, args) => Settings.UseGW2Api = enableCheckbox.Checked ?? false;

            var guildCountLabel = new Label {
                Text = "Not loaded"
            };
            var sizeLabel = new Label {
                Text = "No file"
            };

            UpdateLabelTexts(apiData, guildCountLabel, sizeLabel);

            formLayout.BeginVertical(new Padding(10), new Size(5, 5));
            {
                formLayout.AddRow(new Label
                {
                    Text = "Guild names and tags have to be loaded from the official GW2 API as\n" +
                           "the EVTC logs only contain GUID values."
                });
            }
            formLayout.EndVertical();
            formLayout.BeginVertical(new Padding(10), new Size(5, 5));
            {
                formLayout.AddRow(new Label {
                    Text = "Guilds:"
                }, guildCountLabel);
                formLayout.AddRow(new Label {
                    Text = "Cache file size:"
                }, sizeLabel);
            }
            formLayout.EndVertical();
            formLayout.BeginVertical(new Padding(10), new Size(5, 5));
            {
                formLayout.AddRow(enableCheckbox);
                formLayout.AddRow(deleteButton);
            }
            formLayout.EndVertical();

            void OnGuildAdded(object sender, EventArgs _)
            {
                Application.Instance.AsyncInvoke(() => { UpdateLabelTexts(apiData, guildCountLabel, sizeLabel); });
            }

            deleteButton.Click += (sender, args) =>
            {
                if (MessageBox.Show(
                        $"Delete the API cache? The API data of all {apiData.CachedGuildCount} guilds will be " +
                        "forgotten. Renamed guilds will have their names/tags updated, but data of disbanded " +
                        "guilds won't be retrievable anymore. You may have to restart the program for " +
                        "everything to update.",
                        MessageBoxButtons.OKCancel) == DialogResult.Ok)
                {
                    apiData.Clear();
                    apiData.SaveDataToFile();
                    MessageBox.Show("API Cache deleted.");
                    UpdateLabelTexts(apiData, guildCountLabel, sizeLabel);
                }
            };

            apiData.GuildAdded += OnGuildAdded;

            Closed += (sender, args) => apiData.GuildAdded -= OnGuildAdded;
        }