using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using System.Diagnostics; using System.Linq; using Avalonia.Controls; using Observatory.Framework.Interfaces; using Observatory.UI.Models; using ReactiveUI; namespace Observatory.UI.ViewModels { public class CoreViewModel : ViewModelBase { private readonly ObservableCollection notifiers; private readonly ObservableCollection workers; private readonly ObservableCollection tabs; private string toggleButtonText; public CoreViewModel(IEnumerable<(IObservatoryWorker plugin, PluginManagement.PluginManager.PluginStatus signed)> workers, IEnumerable<(IObservatoryNotifier plugin, PluginManagement.PluginManager.PluginStatus signed)> notifiers) { this.notifiers = new ObservableCollection(notifiers.Select(p => p.plugin)); this.workers = new ObservableCollection(workers.Select(p => p.plugin)); ToggleButtonText = "Start Monitor"; tabs = new ObservableCollection(); foreach(var worker in workers.Select(p => p.plugin)) { if (worker.PluginUI.PluginUIType == Framework.PluginUI.UIType.Basic) { CoreModel coreModel = new(); coreModel.Name = worker.ShortName; coreModel.UI = new BasicUIViewModel(worker.PluginUI.DataGrid) { UIType = worker.PluginUI.PluginUIType }; tabs.Add(coreModel); } } foreach(var notifier in notifiers.Select(p => p.plugin)) { Panel notifierPanel = new Panel(); TextBlock notifierTextBlock = new TextBlock(); notifierTextBlock.Text = notifier.Name; notifierPanel.Children.Add(notifierTextBlock); //tabs.Add(new CoreModel() { Name = notifier.ShortName, UI = (ViewModelBase)notifier.UI }); } tabs.Add(new CoreModel() { Name = "Core", UI = new BasicUIViewModel(new ObservableCollection()) { UIType = Framework.PluginUI.UIType.Core } }); } public void ReadAll() { SetWorkerReadAllState(true); LogMonitor.GetInstance.ReadAllJournals(); SetWorkerReadAllState(false); } public void ToggleMonitor() { var logMonitor = LogMonitor.GetInstance; if (logMonitor.IsMonitoring()) { logMonitor.Stop(); ToggleButtonText = "Start Monitor"; } else { // HACK: Find a better way of suppressing notifications when pre-reading. SetWorkerReadAllState(true); logMonitor.Start(); SetWorkerReadAllState(false); ToggleButtonText = "Stop Monitor"; } } public void OpenGithub() { ProcessStartInfo githubOpen = new("https://github.com/Xjph/ObservatoryCore"); githubOpen.UseShellExecute = true; Process.Start(githubOpen); } public void OpenDonate() { ProcessStartInfo donateOpen = new("https://paypal.me/eliteobservatory"); donateOpen.UseShellExecute = true; Process.Start(donateOpen); } public string ToggleButtonText { get => toggleButtonText; set { if (toggleButtonText != value) { toggleButtonText = value; this.RaisePropertyChanged(nameof(ToggleButtonText)); } } } public ObservableCollection Workers { get { return workers; } } public ObservableCollection Notifiers { get { return notifiers; } } public ObservableCollection Tabs { get { return tabs; } } private void SetWorkerReadAllState(bool isReadingAll) { foreach (var worker in workers) { if (isReadingAll) { worker.ReadAllStarted(); } else { worker.ReadAllFinished(); } } } } }