added classes for support of destination lists in configuration.

This commit is contained in:
Andrew Welker
2020-06-24 15:28:53 -06:00
parent f01ed3d876
commit 6f300402aa
3 changed files with 49 additions and 30 deletions

View File

@@ -6,6 +6,7 @@ using Crestron.SimplSharp;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash_Essentials_Core.Devices;
namespace PepperDash.Essentials.Core.Config
{
@@ -23,7 +24,10 @@ namespace PepperDash.Essentials.Core.Config
[JsonProperty("sourceLists")]
public Dictionary<string, Dictionary<string, SourceListItem>> SourceLists { get; set; }
[JsonProperty("tieLines")]
[JsonProperty("destinationLists")]
public Dictionary<string, Dictionary<string, DestinationListItem>> DestinationLists { get; set; }
[JsonProperty("tieLines")]
public List<TieLineConfig> TieLines { get; set; }
[JsonProperty("joinMaps")]
@@ -40,6 +44,14 @@ namespace PepperDash.Essentials.Core.Config
return SourceLists[key];
}
public Dictionary<string, DestinationListItem> GetDestinationListForKey(string key)
{
if (string.IsNullOrEmpty(key) || !SourceLists.ContainsKey(key))
return null;
return DestinationLists[key];
}
/// <summary>
/// Checks Devices for an item with a Key that matches and returns it if found. Otherwise, retunes null
/// </summary>
@@ -52,12 +64,9 @@ namespace PepperDash.Essentials.Core.Config
var deviceConfig = Devices.FirstOrDefault(d => d.Key.Equals(key));
if (deviceConfig != null)
return deviceConfig;
else
{
return null;
}
//removed if statement that was here...
//DeviceConfig will be null if it's not found in the list
return deviceConfig;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Newtonsoft.Json;
using PepperDash.Essentials.Core;
namespace PepperDash_Essentials_Core.Devices
{
public class DestinationListItem
{
[JsonProperty("sinkYey")]
public string SinkKey { get; set; }
private EssentialsDevice _sinkDevice;
public EssentialsDevice SinkDevice
{
get { return _sinkDevice ?? (_sinkDevice = DeviceManager.GetDeviceForKey(SinkKey) as EssentialsDevice); }
}
}
}

View File

@@ -1,13 +1,6 @@
using System;
using System.Collections.Generic;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharpPro;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
@@ -31,16 +24,11 @@ namespace PepperDash.Essentials.Core
/// Returns the source Device for this, if it exists in DeviceManager
/// </summary>
[JsonIgnore]
public Device SourceDevice
public EssentialsDevice SourceDevice
{
get
{
if (_SourceDevice == null)
_SourceDevice = DeviceManager.GetDeviceForKey(SourceKey) as Device;
return _SourceDevice;
}
get { return _sourceDevice ?? (_sourceDevice = DeviceManager.GetDeviceForKey(SourceKey) as EssentialsDevice); }
}
Device _SourceDevice;
private EssentialsDevice _sourceDevice;
/// <summary>
/// Gets either the source's Name or this AlternateName property, if
@@ -51,13 +39,12 @@ namespace PepperDash.Essentials.Core
{
get
{
if (string.IsNullOrEmpty(Name))
{
if (SourceDevice == null)
return "---";
return SourceDevice.Name;
}
return Name;
if (!string.IsNullOrEmpty(Name))
{
return Name;
}
return SourceDevice == null ? "---" : SourceDevice.Name;
}
}