mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-14 04:04:58 +00:00
Merge pull request #88 from PepperDash/feature/fix-get-name-attribute-issue
Feature/fix get name attribute issue
This commit is contained in:
@@ -18,7 +18,7 @@ namespace PepperDash.Essentials.Bridges
|
|||||||
public static void LinkToApi(this PepperDash.Essentials.Devices.Common.Cameras.CameraBase cameraDevice, BasicTriList trilist, uint joinStart, string joinMapKey, EiscApi bridge)
|
public static void LinkToApi(this PepperDash.Essentials.Devices.Common.Cameras.CameraBase cameraDevice, BasicTriList trilist, uint joinStart, string joinMapKey, EiscApi bridge)
|
||||||
{
|
{
|
||||||
CameraControllerJoinMap joinMap = new CameraControllerJoinMap(joinStart);
|
CameraControllerJoinMap joinMap = new CameraControllerJoinMap(joinStart);
|
||||||
|
|
||||||
// Adds the join map to the bridge
|
// Adds the join map to the bridge
|
||||||
bridge.AddJoinMap(cameraDevice.Key, joinMap);
|
bridge.AddJoinMap(cameraDevice.Key, joinMap);
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace PepperDash.Essentials.Bridges
|
|||||||
public JoinDataComplete SupportsPresets = new JoinDataComplete(new JoinData() { JoinNumber = 57, JoinSpan = 1 }, new JoinMetadata() { Label = "Supports Presets", JoinCapabilities = eJoinCapabilities.FromSIMPL, JoinType = eJoinType.Digital });
|
public JoinDataComplete SupportsPresets = new JoinDataComplete(new JoinData() { JoinNumber = 57, JoinSpan = 1 }, new JoinMetadata() { Label = "Supports Presets", JoinCapabilities = eJoinCapabilities.FromSIMPL, JoinType = eJoinType.Digital });
|
||||||
|
|
||||||
public CameraControllerJoinMap(uint joinStart)
|
public CameraControllerJoinMap(uint joinStart)
|
||||||
:base(joinStart)
|
: base(joinStart, typeof(CameraControllerJoinMap))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
using Crestron.SimplSharp.Reflection;
|
using Crestron.SimplSharp.Reflection;
|
||||||
|
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
@@ -26,12 +24,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
var joinMap = ConfigReader.ConfigObject.JoinMaps[joinMapKey];
|
var joinMap = ConfigReader.ConfigObject.JoinMaps[joinMapKey];
|
||||||
|
|
||||||
if (joinMap != null)
|
return joinMap;
|
||||||
{
|
|
||||||
return joinMap;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -46,17 +39,11 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
var joinMapSerialzed = ConfigReader.ConfigObject.JoinMaps[joinMapKey];
|
var joinMapSerialzed = ConfigReader.ConfigObject.JoinMaps[joinMapKey];
|
||||||
|
|
||||||
if (joinMapSerialzed != null)
|
if (joinMapSerialzed == null) return null;
|
||||||
{
|
|
||||||
var joinMapData = JsonConvert.DeserializeObject<Dictionary<string, JoinData>>(joinMapSerialzed);
|
|
||||||
|
|
||||||
if (joinMapData != null)
|
var joinMapData = JsonConvert.DeserializeObject<Dictionary<string, JoinData>>(joinMapSerialzed);
|
||||||
return joinMapData;
|
|
||||||
else
|
return joinMapData;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -83,7 +70,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void PrintJoinMapInfo()
|
public void PrintJoinMapInfo()
|
||||||
{
|
{
|
||||||
Debug.Console(0, "{0}:\n", this.GetType().Name);
|
Debug.Console(0, "{0}:\n", GetType().Name);
|
||||||
|
|
||||||
// Get the joins of each type and print them
|
// Get the joins of each type and print them
|
||||||
Debug.Console(0, "Digitals:");
|
Debug.Console(0, "Digitals:");
|
||||||
@@ -138,10 +125,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public uint GetJoinForKey(string key)
|
public uint GetJoinForKey(string key)
|
||||||
{
|
{
|
||||||
if (Joins.ContainsKey(key))
|
return Joins.ContainsKey(key) ? Joins[key].JoinNumber : 0;
|
||||||
return Joins[key].JoinNumber;
|
|
||||||
|
|
||||||
else return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -151,12 +135,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public uint GetJoinSpanForKey(string key)
|
public uint GetJoinSpanForKey(string key)
|
||||||
{
|
{
|
||||||
if (Joins.ContainsKey(key))
|
return Joins.ContainsKey(key) ? Joins[key].JoinSpan : 0;
|
||||||
return Joins[key].JoinSpan;
|
|
||||||
|
|
||||||
else return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -164,7 +144,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class JoinMapBaseAdvanced
|
public abstract class JoinMapBaseAdvanced
|
||||||
{
|
{
|
||||||
protected uint _joinOffset;
|
protected uint JoinOffset;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The collection of joins and associated metadata
|
/// The collection of joins and associated metadata
|
||||||
@@ -175,36 +155,55 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
Joins = new Dictionary<string, JoinDataComplete>();
|
Joins = new Dictionary<string, JoinDataComplete>();
|
||||||
|
|
||||||
_joinOffset = joinStart - 1;
|
JoinOffset = joinStart - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected JoinMapBaseAdvanced(uint joinStart, Type type):this(joinStart)
|
||||||
|
{
|
||||||
|
AddJoins(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void AddJoins(Type type)
|
||||||
|
{
|
||||||
// Add all the JoinDataComplete properties to the Joins Dictionary and pass in the offset
|
// Add all the JoinDataComplete properties to the Joins Dictionary and pass in the offset
|
||||||
Joins = this.GetType()
|
//Joins = this.GetType()
|
||||||
.GetCType()
|
// .GetCType()
|
||||||
.GetFields(BindingFlags.Public | BindingFlags.Instance)
|
// .GetFields(BindingFlags.Public | BindingFlags.Instance)
|
||||||
.Where(field => field.IsDefined(typeof(JoinNameAttribute), false))
|
// .Where(field => field.IsDefined(typeof(JoinNameAttribute), true))
|
||||||
.Select(prop => (JoinDataComplete)prop.GetValue(this))
|
// .Select(field => (JoinDataComplete)field.GetValue(this))
|
||||||
.ToDictionary(join => join.GetNameAttribute(), join =>
|
// .ToDictionary(join => join.GetNameAttribute(), join =>
|
||||||
{
|
|
||||||
join.SetJoinOffset(_joinOffset);
|
|
||||||
return join;
|
|
||||||
});
|
|
||||||
|
|
||||||
//var type = this.GetType();
|
|
||||||
//var cType = type.GetCType();
|
|
||||||
//var fields = cType.GetFields(BindingFlags.Public | BindingFlags.Instance);
|
|
||||||
//foreach (var field in fields)
|
|
||||||
//{
|
|
||||||
// if (field.IsDefined(typeof(JoinNameAttribute), true))
|
|
||||||
// {
|
|
||||||
// var value = field.GetValue(this) as JoinDataComplete;
|
|
||||||
|
|
||||||
// if (value != null)
|
|
||||||
// {
|
// {
|
||||||
// value.SetJoinOffset(_joinOffset);
|
// join.SetJoinOffset(_joinOffset);
|
||||||
// Joins.Add(value.GetNameAttribute(), value);
|
// return join;
|
||||||
// }
|
// });
|
||||||
// }
|
|
||||||
//}
|
//type = this.GetType(); <- this wasn't working because 'this' was always the base class, never the derived class
|
||||||
|
var fields =
|
||||||
|
type.GetCType()
|
||||||
|
.GetFields(BindingFlags.Public | BindingFlags.Instance)
|
||||||
|
.Where(f => f.IsDefined(typeof (JoinNameAttribute), true));
|
||||||
|
|
||||||
|
foreach (var field in fields)
|
||||||
|
{
|
||||||
|
var childClass = Convert.ChangeType(this, type, null);
|
||||||
|
|
||||||
|
var value = field.GetValue(childClass) as JoinDataComplete; //this here is JoinMapBaseAdvanced, not the child class. JoinMapBaseAdvanced has no fields.
|
||||||
|
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "Unable to caset base class to {0}", type.Name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
value.SetJoinOffset(JoinOffset);
|
||||||
|
|
||||||
|
var joinName = value.GetNameAttribute(field);
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(joinName)) continue;
|
||||||
|
|
||||||
|
Joins.Add(joinName, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PrintJoinMapInfo();
|
PrintJoinMapInfo();
|
||||||
}
|
}
|
||||||
@@ -214,7 +213,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void PrintJoinMapInfo()
|
public void PrintJoinMapInfo()
|
||||||
{
|
{
|
||||||
Debug.Console(0, "{0}:\n", this.GetType().Name);
|
Debug.Console(0, "{0}:\n", GetType().Name);
|
||||||
|
|
||||||
// Get the joins of each type and print them
|
// Get the joins of each type and print them
|
||||||
Debug.Console(0, "Digitals:");
|
Debug.Console(0, "Digitals:");
|
||||||
@@ -435,26 +434,33 @@ namespace PepperDash.Essentials.Core
|
|||||||
_data = customJoinData;
|
_data = customJoinData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetNameAttribute()
|
public string GetNameAttribute(MemberInfo memberInfo)
|
||||||
{
|
{
|
||||||
string name = string.Empty;
|
var name = string.Empty;
|
||||||
JoinNameAttribute attribute = (JoinNameAttribute)Attribute.GetCustomAttribute(typeof(JoinDataComplete), typeof(JoinNameAttribute));
|
var attribute = (JoinNameAttribute)CAttribute.GetCustomAttribute(memberInfo, typeof(JoinNameAttribute));
|
||||||
if (attribute != null)
|
|
||||||
{
|
if (attribute == null) return name;
|
||||||
name = attribute.Name;
|
|
||||||
}
|
name = attribute.Name;
|
||||||
|
Debug.Console(2, "JoinName Attribute value: {0}", name);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Field)]
|
[AttributeUsage(AttributeTargets.All)]
|
||||||
public class JoinNameAttribute : Attribute
|
public class JoinNameAttribute : Attribute
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
private string _Name;
|
||||||
|
|
||||||
public JoinNameAttribute(string name)
|
public JoinNameAttribute(string name)
|
||||||
{
|
{
|
||||||
Name = name;
|
Debug.Console(2, "Setting Attribute Name: {0}", name);
|
||||||
|
_Name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return _Name; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user