mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 13:15:03 +00:00
updated methods for creating joinMap dict
This commit is contained in:
@@ -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>
|
||||||
@@ -197,17 +177,17 @@ namespace PepperDash.Essentials.Core
|
|||||||
// return join;
|
// return join;
|
||||||
// });
|
// });
|
||||||
|
|
||||||
//type = this.GetType(); <- this wasn't working because 'this' was always the base class, never the derived class
|
//type = this.GetType(); <- this wasn'memberInfo working because 'this' was always the base class, never the derived class
|
||||||
var cType = type.GetCType();
|
var fields =
|
||||||
var fields = cType.GetFields(BindingFlags.Public | BindingFlags.Instance);
|
type.GetCType()
|
||||||
|
.GetFields(BindingFlags.Public | BindingFlags.Instance)
|
||||||
|
.Where(f => f.IsDefined(typeof (JoinNameAttribute), true));
|
||||||
|
|
||||||
foreach (var field in fields)
|
foreach (var field in fields)
|
||||||
{
|
{
|
||||||
if (!field.IsDefined(typeof (JoinNameAttribute), true)) continue;
|
|
||||||
|
|
||||||
var childClass = Convert.ChangeType(this, type, null);
|
var childClass = Convert.ChangeType(this, type, null);
|
||||||
|
|
||||||
var value = field.GetValue(childClass) as JoinDataComplete; //this here is JoinMapBaseAdvanced, not the child class...which has no fields.
|
var value = field.GetValue(childClass) as JoinDataComplete; //this here is JoinMapBaseAdvanced, not the child class. JoinMapBaseAdvanced has no fields.
|
||||||
|
|
||||||
if (value == null)
|
if (value == null)
|
||||||
{
|
{
|
||||||
@@ -216,7 +196,12 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
value.SetJoinOffset(JoinOffset);
|
value.SetJoinOffset(JoinOffset);
|
||||||
Joins.Add(value.GetNameAttribute(typeof(JoinDataComplete)), value);
|
|
||||||
|
var joinName = value.GetNameAttribute(field);
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(joinName)) continue;
|
||||||
|
|
||||||
|
Joins.Add(joinName, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -228,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:");
|
||||||
@@ -449,15 +434,15 @@ namespace PepperDash.Essentials.Core
|
|||||||
_data = customJoinData;
|
_data = customJoinData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetNameAttribute(Type t)
|
public string GetNameAttribute(MemberInfo memberInfo)
|
||||||
{
|
{
|
||||||
string name = string.Empty;
|
var name = string.Empty;
|
||||||
JoinNameAttribute attribute = (JoinNameAttribute)Attribute.GetCustomAttribute(t, typeof(JoinNameAttribute));
|
var attribute = (JoinNameAttribute)CAttribute.GetCustomAttribute(memberInfo, typeof(JoinNameAttribute));
|
||||||
if (attribute != null)
|
|
||||||
{
|
if (attribute == null) return name;
|
||||||
name = attribute.Name;
|
|
||||||
Debug.Console(2, "JoinName Attribute value: {0}", name);
|
name = attribute.Name;
|
||||||
}
|
Debug.Console(2, "JoinName Attribute value: {0}", name);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user