Start work towards manually added servers

This commit is contained in:
2021-03-28 16:28:39 -05:00
parent ce64f24b4b
commit e08ba30d91
7 changed files with 202 additions and 33 deletions
@@ -15,7 +15,7 @@ namespace qController
static QStorage(){
qInstances = (ObservableCollection<QInstance>)CrossSettings.Current.GetValue(new ObservableCollection<QInstance>().GetType(), "qInstances", null);
qStoredServers = (ObservableCollection<QServerInfo>)CrossSettings.Current.GetValue(new ObservableCollection<QInstance>().GetType(), "qStoredServers", null);
qStoredServers = (ObservableCollection<QServerInfo>)CrossSettings.Current.GetValue(new ObservableCollection<QServerInfo>().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;
}
}
}
@@ -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!");
}
});
};
}
}
@@ -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();
}
}
}
}
+3 -2
View File
@@ -134,12 +134,13 @@
</ListView.ItemTemplate>
</ListView>
<Button Text="Manually Add..."
<!--TODO: Manually add "servers" -->
<!--<Button Text="Manually Add..."
VerticalOptions="Center"
HorizontalOptions="FillAndExpand"
Clicked="AddInstance"
BackgroundColor="White"
StyleClass="PrimaryButton"/>
StyleClass="PrimaryButton"/>-->
</StackLayout>
</Frame>
@@ -19,22 +19,9 @@ namespace qController.Pages
SetupTopBar();
qBrowserViewModel = new QBrowserViewModel(new QBrowser());
qBrowserViewModel.autoUpdate = true;
serverListView.BindingContext = qBrowserViewModel;
serverListView.ItemSelected += QWorkspaceSelected;
//Old way of displaying "QInstances"
//storageListView.ItemsSource = QStorage.qInstances;
//storageListView.ItemTemplate = new DataTemplate(typeof(QInstanceCell));
//storageListView.ItemTapped += (object sender, ItemTappedEventArgs e) =>
//{
// // don't do anything if we just de-selected the row
// if (e.Item == null) return;
// // do something with e.SelectedItem
// ((ListView)sender).SelectedItem = null; // de-select the row
//};
}
private void SetupTopBar()
@@ -96,6 +83,10 @@ namespace qController.Pages
else if (args.Command == "support")
{
UserDialogs.Instance.Confirm(new DonatePrompt());
}else if(args.Command == "scan")
{
qBrowserViewModel.InitiateScan();
App.showToast("Scan Initiated.........");
}
}
@@ -14,6 +14,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="200"/>
<RowDefinition Height="*"/>
<RowDefinition Height="75"/>
</Grid.RowDefinitions>
<!--Ordering is based on the order last is on top seems pretty backwards to me-->
@@ -35,5 +36,60 @@
<qui:QNavBar x:Name="qNavBar"
Grid.Row="0"/>
<Grid Grid.Row="3"
RowSpacing="0"
ColumnSpacing="0"
BackgroundColor="#808080">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Row="0"
Grid.Column="0"
Clicked="GoButtonClicked"
BackgroundColor="SeaGreen"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
TextColor="Black"
Text="Go"/>
<Button Grid.Row="0"
Grid.Column="1"
Clicked="PauseButtonClicked"
BackgroundColor="LightYellow"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
TextColor="Black"
Text="Pause"/>
<Button Grid.Row="0"
Grid.Column="2"
Clicked="ResumeButtonClicked"
BackgroundColor="DarkSlateGray"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
TextColor="Black"
Text="Resume"/>
<Button Grid.Row="0"
Grid.Column="3"
Clicked="PanicButtonClicked"
BackgroundColor="IndianRed"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
TextColor="Black"
Text="Panic"/>
</Grid>
</Grid>
</ContentPage>
@@ -200,5 +200,51 @@ namespace qController
await Task.Delay(milisec);
actionToExecute();
}
void GoButtonClicked(System.Object sender, System.EventArgs e)
{
if(this.connectedWorkspace != null)
{
if (this.connectedWorkspace.connected)
{
this.connectedWorkspace.go();
}
}
}
void PauseButtonClicked(System.Object sender, System.EventArgs e)
{
if (this.connectedWorkspace != null)
{
if (this.connectedWorkspace.connected)
{
QCue selectedCue = ((QCueViewModel)this.selectedCueFrame.BindingContext).cue;
selectedCue.pause();
}
}
}
void ResumeButtonClicked(System.Object sender, System.EventArgs e)
{
if (this.connectedWorkspace != null)
{
if (this.connectedWorkspace.connected)
{
QCue selectedCue = ((QCueViewModel)this.selectedCueFrame.BindingContext).cue;
selectedCue.resume();
}
}
}
void PanicButtonClicked(System.Object sender, System.EventArgs e)
{
if (this.connectedWorkspace != null)
{
if (this.connectedWorkspace.connected)
{
this.connectedWorkspace.panicAll();
}
}
}
}
}