Files
qController/qController.Standard/Classes/Settings/QStorage.cs
T
jwetzell cebf5425f8 * QStorage.cs: Fix AddInstance to actually check Contains
* MenuPage.xaml.cs:
* ControlPage.xaml.cs:
* qConnectionPage.xaml.cs: Add ability to change cue name in menu
2019-07-10 22:17:29 -05:00

70 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Acr.Settings;
namespace qController
{
public class QStorage
{
public static ObservableCollection<QInstance> qInstances;
static QStorage(){
qInstances = (ObservableCollection<QInstance>)CrossSettings.Current.GetValue(new ObservableCollection<QInstance>().GetType(), "qInstances", null);
if (qInstances == null)
{
Console.WriteLine("No qInstance exists creating one");
qInstances = new ObservableCollection<QInstance>();
updateStorage();
}
}
public static bool AddInstance(string name, string address){
return AddInstance(new QInstance(name, address));
}
public static bool AddInstance(QInstance q){
if(!Contains(q.name, q.address)){
qInstances.Add(q);
updateStorage();
return true;
}else{
return false;
}
}
public static void RemoveInstance(string name, string address){
foreach (var item in qInstances)
{
if(item.address == address && item.name == name){
RemoveInstance(item);
return;
}
}
}
public static void RemoveInstance(QInstance q){
qInstances.Remove(q);
updateStorage();
}
private static void updateStorage(){
CrossSettings.Current.SetValue("qInstances", qInstances);
}
public static bool Contains(string name, string address){
foreach (var item in qInstances)
{
//Console.WriteLine("Item name: " + item.name + " Found Name: " + name);
if (item.address == address)
{
return true;
}
}
return false;
}
public bool IsEmpty(){
return qInstances.Count == 0;
}
}
}