From 924a8e7af0eed2336b9dfaff01e1c18a7c9b3a7d Mon Sep 17 00:00:00 2001 From: jwetzell Date: Tue, 23 Apr 2019 11:05:28 -0500 Subject: [PATCH] Work on Workspace loading --- qController.Standard/App.xaml.cs | 11 +++++++- .../Classes/Cell/QInstance.cs | 2 ++ .../Classes/Cell/QSelectedCueCell.cs | 2 ++ .../Classes/Communication/QClient.cs | 10 ++------ .../Classes/Communication/QParser.cs | 19 +++++++++++++- .../Classes/Communication/QUpdater.cs | 19 +++++++++++--- .../Communication/SharpOSC/TCPSender.cs | 4 +-- .../Classes/Cues/QWorkSpace.cs | 3 ++- .../Pages/ControlPage.xaml.cs | 25 ++++++++++++++----- .../Pages/qConnectionPage.xaml.cs | 13 +++++----- 10 files changed, 79 insertions(+), 29 deletions(-) diff --git a/qController.Standard/App.xaml.cs b/qController.Standard/App.xaml.cs index 60c4673..ef3cdfe 100644 --- a/qController.Standard/App.xaml.cs +++ b/qController.Standard/App.xaml.cs @@ -1,4 +1,5 @@ -using Xamarin.Forms; +using Acr.UserDialogs; +using Xamarin.Forms; namespace qController { @@ -63,5 +64,13 @@ namespace qController { // Handle when your app resumes } + + public static void showToast(string message) + { + var toastConfig = new ToastConfig(message); + toastConfig.SetDuration(3000); + toastConfig.SetPosition(ToastPosition.Bottom); + UserDialogs.Instance.Toast(toastConfig); + } } } diff --git a/qController.Standard/Classes/Cell/QInstance.cs b/qController.Standard/Classes/Cell/QInstance.cs index e063977..566a957 100644 --- a/qController.Standard/Classes/Cell/QInstance.cs +++ b/qController.Standard/Classes/Cell/QInstance.cs @@ -2,6 +2,8 @@ using System.Net; using System.Net.NetworkInformation; using Xamarin.Forms; +using SharpOSC; +using System.Threading; namespace qController { diff --git a/qController.Standard/Classes/Cell/QSelectedCueCell.cs b/qController.Standard/Classes/Cell/QSelectedCueCell.cs index 206e16a..1bd9641 100644 --- a/qController.Standard/Classes/Cell/QSelectedCueCell.cs +++ b/qController.Standard/Classes/Cell/QSelectedCueCell.cs @@ -9,6 +9,7 @@ namespace qController Label number; Label type; Label notes; + public QCue activeCue; public QSelectedCueCell() { Padding = new Thickness(5); @@ -115,6 +116,7 @@ namespace qController public void UpdateSelectedCue(QCue cue) { + activeCue = cue; name.Text = cue.listName; number.Text = cue.number; type.Text = cue.getIconString(); diff --git a/qController.Standard/Classes/Communication/QClient.cs b/qController.Standard/Classes/Communication/QClient.cs index 9a2c64c..431e3be 100644 --- a/qController.Standard/Classes/Communication/QClient.cs +++ b/qController.Standard/Classes/Communication/QClient.cs @@ -16,8 +16,7 @@ namespace qController int Port; - public delegate void WorkspaceDisconnectHandler(object source, EventArgs args); - public event WorkspaceDisconnectHandler WorkspaceDisconnect; + public QClient(string address, int port) { @@ -77,7 +76,7 @@ namespace qController { if (msg.Address.Contains("disconnect")) { - OnWorkspaceDisconnect(); + qParser.ParseMessage(msg); } else if (msg.Address.Contains("cue_id")) { @@ -118,11 +117,6 @@ namespace qController Console.WriteLine("Workspace needs to be updated: " + ws_id); } - protected virtual void OnWorkspaceDisconnect() - { - if (WorkspaceDisconnect != null) - WorkspaceDisconnect(this, new EventArgs()); - } public void Close() { diff --git a/qController.Standard/Classes/Communication/QParser.cs b/qController.Standard/Classes/Communication/QParser.cs index 3097072..5a5ff71 100644 --- a/qController.Standard/Classes/Communication/QParser.cs +++ b/qController.Standard/Classes/Communication/QParser.cs @@ -70,6 +70,8 @@ namespace qController public delegate void PlaybackPositionUpdatedHandler(object source, PlaybackPositionArgs args); public delegate void ConnectionStatusHandler(object source, ConnectEventArgs args); public delegate void ChildrenUpdateHandler(object source, ChildrenEventArgs args); + public delegate void WorkspaceDisconnectHandler(object source, EventArgs args); + public event WorkspaceDisconnectHandler WorkspaceDisconnect; public event ChildrenUpdateHandler ChildrenUpdated; public event ConnectionStatusHandler ConnectionStatusChanged; public event SelectedCueUpdatedHandler SelectedCueUpdated; @@ -96,6 +98,10 @@ namespace qController ParseConnectInfo(msg); else if (msg.Address.Contains("children")) ParseChildrenInfo(msg); + else if (msg.Address.Contains("workspaces")) + ParseInstanceInfo(msg); + else if (msg.Address.Contains("disconnect")) + OnWorkspaceDisconnect(); else { Console.WriteLine("Unknown message type"); @@ -125,7 +131,6 @@ namespace qController public void ParseCueUpdateInfo(OscMessage msg) { JToken cueUpdate = OSC2JSON(msg); - Console.WriteLine(OSC2JSON(msg).ToString()); QCue cue = JsonConvert.DeserializeObject(cueUpdate.ToString()); OnCueInfoUpdated(cue); } @@ -136,8 +141,15 @@ namespace qController OnSelectedCueUpdated(cue); } + public void ParseInstanceInfo(OscMessage msg) + { + //Console.WriteLine(OSC2JSON(msg)); + return; + } + public void ParseNoteInfo(OscMessage msg){ //JToken cueInfo = OSC2JSON(msg); + return; } public void ParseWorkspaceInfo(OscMessage msg) @@ -197,6 +209,11 @@ namespace qController if (ChildrenUpdated != null) ChildrenUpdated(this, new ChildrenEventArgs() { cue_id = id, children = cues }); } + protected virtual void OnWorkspaceDisconnect() + { + if (WorkspaceDisconnect != null) + WorkspaceDisconnect(this, new EventArgs()); + } } } diff --git a/qController.Standard/Classes/Communication/QUpdater.cs b/qController.Standard/Classes/Communication/QUpdater.cs index 79f9a36..43e9a7b 100644 --- a/qController.Standard/Classes/Communication/QUpdater.cs +++ b/qController.Standard/Classes/Communication/QUpdater.cs @@ -47,7 +47,7 @@ namespace qController private void OnChildrenUpdated(object source, ChildrenEventArgs args) { qController.qWorkspace.UpdateChildren(args.cue_id, args.children); - + Console.WriteLine("Populated: " + qController.qWorkspace.IsPopulated); if (!qController.qWorkspace.IsPopulated) { QCue cue = qController.qWorkspace.GetEmptyGroup(); @@ -56,13 +56,20 @@ namespace qController qController.qClient.sendStringUDP("/cue_id/" + cue.uniqueID + "/children"); } } + else + { + qController.qClient.UpdateSelectedCue(); + } } public void OnWorkspaceUpdated(object source, WorkspaceEventArgs args) { qController.qWorkspace = args.UpdatedWorkspace; qController.playbackPosition = null; - qController.qClient.UpdateSelectedCue(); + qController.qWorkspace.CheckPopulated(); + RefreshGroupCues(); + //qController.qClient.UpdateSelectedCue(); + } public void OnPlaybackPositionUpdated(object source, PlaybackPositionArgs args) @@ -72,8 +79,14 @@ namespace qController public void RefreshGroupCues() { - if (qController.qWorkspace.ChildrenPopulated()) + if (qController.qWorkspace.IsPopulated) + { + Console.WriteLine("Workspace group cues are already populated"); + App.showToast("Workspace cues have been loaded...."); + qController.qClient.UpdateSelectedCue(); return; + } + Console.WriteLine("Workspace group cues are not populated"); foreach (var cueList in qController.qWorkspace.data) { foreach (var cue in cueList.cues) diff --git a/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs b/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs index 9279821..4e23a36 100644 --- a/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs +++ b/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs @@ -53,7 +53,6 @@ namespace SharpOSC NetworkStream netStream = client.GetStream(); netStream.Write(slipData.ToArray(), 0, slipData.ToArray().Length); netStream.Close(); - client.Close(); } public async void Receive() @@ -80,7 +79,7 @@ namespace SharpOSC //Console.WriteLine( "Thread " + num + ": Bytes read: " + bytesRead + " - " + Encoding.ASCII.GetString(buffer)); } while (netStream.DataAvailable); - Console.WriteLine("Raw TCP In: " + System.Text.Encoding.ASCII.GetString(responseData.ToArray())); + //Console.WriteLine("Raw TCP In: " + System.Text.Encoding.ASCII.GetString(responseData.ToArray())); response = (OscMessage)OscPacket.GetPacket(responseData.Skip(1).ToArray()); } } catch(Exception e) @@ -88,7 +87,6 @@ namespace SharpOSC Console.WriteLine(e.ToString()); } netStream.Close(); - client.Close(); OnMessageReceived(response); } diff --git a/qController.Standard/Classes/Cues/QWorkSpace.cs b/qController.Standard/Classes/Cues/QWorkSpace.cs index 3f1906a..f3fc82c 100644 --- a/qController.Standard/Classes/Cues/QWorkSpace.cs +++ b/qController.Standard/Classes/Cues/QWorkSpace.cs @@ -51,6 +51,7 @@ namespace qController if(data[i].cues[j].type == "Group") { data[i].cues[j].cues = children; + CheckPopulated(); return; } } @@ -75,7 +76,7 @@ namespace qController return null; } - public bool ChildrenPopulated() + public bool CheckPopulated() { for (int i = 0; i < data.Count; i++) { diff --git a/qController.Standard/Pages/ControlPage.xaml.cs b/qController.Standard/Pages/ControlPage.xaml.cs index d7eb46d..89baa97 100644 --- a/qController.Standard/Pages/ControlPage.xaml.cs +++ b/qController.Standard/Pages/ControlPage.xaml.cs @@ -84,7 +84,8 @@ namespace qController new ColumnDefinition{Width = new GridLength(1,GridUnitType.Star)}, new ColumnDefinition{Width = new GridLength(1,GridUnitType.Star)} }, - Margin = new Thickness(10) + Margin = new Thickness(10), + IsVisible = false }; @@ -143,10 +144,21 @@ namespace qController { if(e.UpdatedWorkspace.data.Count > 0) { - App.rootPage.MenuPage.ChangeToWorkspace(e.UpdatedWorkspace); qController.qWorkspace = e.UpdatedWorkspace; - //qController.RefreshGroupCues(); + qController.qWorkspace.CheckPopulated(); + if (qController.qWorkspace.IsPopulated) + { + if (qCell.activeCue == null) + { + QCue noSelect = new QCue(); + noSelect.listName = "No Cue Selected"; + noSelect.type = ""; + noSelect.notes = "Workspace has loaded but no cue is selected"; + noSelect.number = "!"; + qCell.UpdateSelectedCue(noSelect); + } + } Console.WriteLine("Workspace updated in ControlPage: " + qController.qWorkspace.workspace_id); } } @@ -182,6 +194,8 @@ namespace qController else sLayout.Children.Remove(qSelectedCueOptions); qCell.UpdateSelectedCue(args.Cue); + if (!mainG.IsVisible) + mainG.IsVisible = true; }); } } @@ -190,15 +204,13 @@ namespace qController { Console.WriteLine("Children Updated in ControlPage: " + args.cue_id); qController.qWorkspace.UpdateChildren(args.cue_id, args.children); - if (qController.qWorkspace.ChildrenPopulated()) + if (qController.qWorkspace.IsPopulated) { Device.BeginInvokeOnMainThread(() => { if (App.MenuIsPresented) { - //App.MenuIsPresented = false; App.rootPage.MenuPage.ChangeToWorkspace(qController.qWorkspace); - //App.MenuIsPresented = true; } else { @@ -207,6 +219,7 @@ namespace qController } }); qController.qClient.UpdateSelectedCue(); + App.showToast("Workspace cues loaded..."); } } diff --git a/qController.Standard/Pages/qConnectionPage.xaml.cs b/qController.Standard/Pages/qConnectionPage.xaml.cs index 2c31b95..17978a7 100644 --- a/qController.Standard/Pages/qConnectionPage.xaml.cs +++ b/qController.Standard/Pages/qConnectionPage.xaml.cs @@ -5,6 +5,7 @@ using Acr.UserDialogs; using Acr.Settings; using Zeroconf; using System.Collections.Generic; +using System.Collections.Specialized; namespace qController { @@ -38,7 +39,6 @@ namespace qController NavigationPage.SetHasNavigationBar(this, false); lstView.ItemsSource = QStorage.qInstances; - lstView.ItemTemplate = new DataTemplate(typeof(QInstanceCell)); lstView.SeparatorVisibility = SeparatorVisibility.None; lstView.ItemTapped += (object sender, ItemTappedEventArgs e) => @@ -98,7 +98,7 @@ namespace qController if (!qName.Ok) return; QStorage.AddInstance(qName.Text,qAddress.Text); - showToast("Manual Workspace Added!"); + App.showToast("Manual Workspace Added!"); } }); @@ -109,7 +109,7 @@ namespace qController async void Scan(){ bool workspacesFound = false; - showToast("Scanning for Workspaces..."); + App.showToast("Scanning for Workspaces..."); Console.WriteLine("Begin Scanning"); IReadOnlyList results = await ZeroconfResolver.ResolveAsync("_qlab._udp.local.",TimeSpan.FromSeconds(3)); @@ -118,7 +118,8 @@ namespace qController { if (result != null) { - QStorage.AddInstance(result.DisplayName, result.IPAddress); + QInstance instance = new QInstance(result.DisplayName, result.IPAddress); + QStorage.AddInstance(instance); Console.WriteLine(result.DisplayName + " @ " + result.IPAddress + " added"); workspacesFound = true; } @@ -126,9 +127,9 @@ namespace qController } if(workspacesFound){ - showToast("Workspace Found and Added!"); + App.showToast("Workspace Found and Added!"); }else{ - showToast("No Workspaces Found!"); + App.showToast("No Workspaces Found!"); } }