From e08ba30d918d431a9727b723a23a8986cb65cc61 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sun, 28 Mar 2021 16:28:39 -0500 Subject: [PATCH] Start work towards manually added servers --- .../Classes/Settings/QStorage.cs | 77 ++++++++++++++++--- .../Classes/UI/Dialogs/AddInstancePrompt.cs | 19 +++-- .../ViewModels/QBrowserViewModel.cs | 15 +++- qController.Standard/Views/QBrowserPage.xaml | 5 +- .../Views/QBrowserPage.xaml.cs | 17 +--- .../Views/QWorkspacePage.xaml | 56 ++++++++++++++ .../Views/QWorkspacePage.xaml.cs | 46 +++++++++++ 7 files changed, 202 insertions(+), 33 deletions(-) diff --git a/qController.Standard/Classes/Settings/QStorage.cs b/qController.Standard/Classes/Settings/QStorage.cs index e963652..5f470f0 100644 --- a/qController.Standard/Classes/Settings/QStorage.cs +++ b/qController.Standard/Classes/Settings/QStorage.cs @@ -15,7 +15,7 @@ namespace qController static QStorage(){ qInstances = (ObservableCollection)CrossSettings.Current.GetValue(new ObservableCollection().GetType(), "qInstances", null); - qStoredServers = (ObservableCollection)CrossSettings.Current.GetValue(new ObservableCollection().GetType(), "qStoredServers", null); + qStoredServers = (ObservableCollection)CrossSettings.Current.GetValue(new ObservableCollection().GetType(), "qStoredServers", null); recentWorkspaceInfo = (QRecentWorkspaceInfo)CrossSettings.Current.GetValue(typeof (QRecentWorkspaceInfo),"recentWorkspaceInfo",null); if (qInstances == null) @@ -36,15 +36,15 @@ namespace qController if (qInstances != null) { - Log.Debug("[QStorage] qInstances exists though so load in those instances as servers"); - foreach (QInstance instance in qInstances) + if(qInstances.Count > 0) { - QServerInfo serverInfo = new QServerInfo(); - serverInfo.host = instance.address.ToString(); - //TODO: port? - qStoredServers.Add(serverInfo); + Log.Debug("[QStorage] qInstances exists though so load in those instances as servers"); + foreach (QInstance instance in qInstances) + { + //TODO: port? + AddServer(instance.address.ToString(), 53000); + } } - UpdateStorage(); } } @@ -59,7 +59,7 @@ namespace qController } public static bool AddInstance(QInstance q){ - if(!Contains(q.name, q.address)){ + if(!Contains(q.address)){ qInstances.Add(q); UpdateStorage(); return true; @@ -82,12 +82,55 @@ namespace qController UpdateStorage(); } + + public static bool AddServer(string host, int port) + { + QServerInfo serverInfo = new QServerInfo(); + serverInfo.host = host; + serverInfo.port = port; + + return AddServer(serverInfo); + } + + public static bool AddServer(QServerInfo q) + { + if (!Contains(q.host)) + { + Log.Debug($"[QStorage] Adding {q.host}:{q.port}"); + qStoredServers.Add(q); + UpdateStorage(); + return true; + } + else + { + return false; + } + } + + public static void RemoveServer(string host) + { + foreach (var item in qStoredServers) + { + if (item.host == host) + { + RemoveServer(item); + return; + } + } + } + + public static void RemoveServer(QServerInfo q) + { + qStoredServers.Remove(q); + UpdateStorage(); + } + private static void UpdateStorage(){ CrossSettings.Current.SetValue("qInstances", qInstances); CrossSettings.Current.SetValue("qStoredServers", qStoredServers); } - public static bool Contains(string name, string address){ + public static bool Contains(string address){ foreach (var item in qInstances) { //Log.Debug("Item name: " + item.name + " Found Name: " + name); @@ -96,10 +139,22 @@ namespace qController return true; } } + + foreach (var item in qStoredServers) + { + //Log.Debug("Item name: " + item.name + " Found Name: " + name); + if (item.host == address) + { + return true; + } + } + return false; } + + public bool IsEmpty(){ - return qInstances.Count == 0; + return qInstances.Count == 0 && qStoredServers.Count == 0; } } } diff --git a/qController.Standard/Classes/UI/Dialogs/AddInstancePrompt.cs b/qController.Standard/Classes/UI/Dialogs/AddInstancePrompt.cs index 304559e..0b8fd99 100644 --- a/qController.Standard/Classes/UI/Dialogs/AddInstancePrompt.cs +++ b/qController.Standard/Classes/UI/Dialogs/AddInstancePrompt.cs @@ -23,17 +23,24 @@ namespace qController.UI.Dialogs UserDialogs.Instance.Prompt(new PromptConfig { - Title = "Enter Name", - Message = "Enter a Name for " + qAddress.Text, + Title = "Enter Port", + Message = "Enter OSC port for " + qAddress.Text, OkText = "Save", - OnAction = (qName) => { - if (!qName.Ok) + InputType = InputType.Number, + OnTextChanged = args => + { + args.IsValid = args.Value.Length > 0; + }, + OnAction = (qPort) => { + if (!qPort.Ok) return; - QStorage.AddInstance(qName.Text, qAddress.Text); - App.showToast("Manual Workspace Added!"); + + QStorage.AddServer(qAddress.Text, int.Parse(qPort.Text)); + App.showToast("Manual QLab Instance Added!"); } }); + }; } } diff --git a/qController.Standard/ViewModels/QBrowserViewModel.cs b/qController.Standard/ViewModels/QBrowserViewModel.cs index 7f630a1..8fadd42 100644 --- a/qController.Standard/ViewModels/QBrowserViewModel.cs +++ b/qController.Standard/ViewModels/QBrowserViewModel.cs @@ -29,8 +29,12 @@ namespace qController.ViewModels { Task.Run(async () => { - if(autoUpdate) + if (autoUpdate) + { + //Log.Debug("[QBrowserViewModel] Auto update scan ran"); this.browser.ProbeForQLabInstances(); + + } }); return true; }); @@ -76,5 +80,14 @@ namespace qController.ViewModels { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } + + public void InitiateScan() + { + if (!autoUpdate) + { + Log.Debug("[QBrowserViewModel] Manual Scan Initiated"); + this.browser.ProbeForQLabInstances(); + } + } } } diff --git a/qController.Standard/Views/QBrowserPage.xaml b/qController.Standard/Views/QBrowserPage.xaml index 7c99bba..0bc71fb 100644 --- a/qController.Standard/Views/QBrowserPage.xaml +++ b/qController.Standard/Views/QBrowserPage.xaml @@ -134,12 +134,13 @@ -