Skip to content

Commit

Permalink
feat: Replaces Crestron.SimplSharp.Reflection with System.Reflextion …
Browse files Browse the repository at this point in the history
…and updates the way essentials plugin versions are stored and retrieved
  • Loading branch information
ndorin committed May 23, 2024
1 parent 621d848 commit 0a2aaa6
Show file tree
Hide file tree
Showing 24 changed files with 100 additions and 89 deletions.
4 changes: 2 additions & 2 deletions src/PepperDash.Essentials.Core/Bridges/BridgeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Reflection;
using System.Reflection;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.EthernetCommunication;
Expand Down Expand Up @@ -168,7 +168,7 @@ private void LinkDevices()

Debug.LogMessage(LogEventLevel.Debug, this, "Linking Device: '{0}'", device.Key);

if (!typeof(IBridgeAdvanced).IsAssignableFrom(device.GetType().GetCType()))
if (!typeof(IBridgeAdvanced).IsAssignableFrom(device.GetType().GetType()))
{
Debug.LogMessage(LogEventLevel.Information, this,
"{0} is not compatible with this bridge type. Please use 'eiscapi' instead, or updae the device.",
Expand Down
14 changes: 6 additions & 8 deletions src/PepperDash.Essentials.Core/Config/InfoConfig.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@


using System;
using System.Collections.Generic;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Reflection;

using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace PepperDash.Essentials.Core.Config
{
/// <summary>
/// Represents the info section of a Config file
/// </summary>
public class InfoConfig
/// <summary>
/// Represents the info section of a Config file
/// </summary>
public class InfoConfig
{
[JsonProperty("name")]
public string Name { get; set; }
Expand Down
20 changes: 10 additions & 10 deletions src/PepperDash.Essentials.Core/Devices/DeviceJsonApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Reflection;
using System.Reflection;
using Newtonsoft.Json;

using PepperDash.Core;
Expand Down Expand Up @@ -63,7 +63,7 @@ public static void DoDeviceAction(DeviceActionWrapper action)
action.Params = new object[0];
}

CType t = obj.GetType();
Type t = obj.GetType();
try
{
var methods = t.GetMethods().Where(m => m.Name == action.MethodName).ToList();
Expand Down Expand Up @@ -121,7 +121,7 @@ public static string GetProperties(string deviceObjectPath)
if (obj == null)
return "{ \"error\":\"No Device\"}";

CType t = obj.GetType();
Type t = obj.GetType();
// get the properties and set them into a new collection of NameType wrappers
var props = t.GetProperties().Select(p => new PropertyNameType(p, obj));
return JsonConvert.SerializeObject(props, Formatting.Indented);
Expand All @@ -139,7 +139,7 @@ public static object GetPropertyByName(string deviceObjectPath, string propertyN
if(dev == null)
return "{ \"error\":\"No Device\"}";

object prop = dev.GetType().GetCType().GetProperty(propertyName).GetValue(dev, null);
object prop = dev.GetType().GetType().GetProperty(propertyName).GetValue(dev, null);

// var prop = t.GetProperty(propertyName);
if (prop != null)
Expand All @@ -165,7 +165,7 @@ public static string GetMethods(string deviceObjectPath)
return "{ \"error\":\"No Device\"}";

// Package up method names using helper objects
CType t = obj.GetType();
Type t = obj.GetType();
var methods = t.GetMethods()
.Where(m => !m.IsSpecialName)
.Select(p => new MethodNameParams(p));
Expand All @@ -179,7 +179,7 @@ public static string GetApiMethods(string deviceObjectPath)
return "{ \"error\":\"No Device\"}";

// Package up method names using helper objects
CType t = obj.GetType();
Type t = obj.GetType();
var methods = t.GetMethods()
.Where(m => !m.IsSpecialName)
.Where(m => m.GetCustomAttributes(typeof(ApiAttribute), true).Any())
Expand Down Expand Up @@ -226,7 +226,7 @@ public static object FindObjectOnPath(string deviceObjectPath)
Debug.LogMessage(LogEventLevel.Information, dev, " Checking for collection '{0}', index '{1}'", objName, indexStr);
}

CType oType = obj.GetType();
Type oType = obj.GetType();
var prop = oType.GetProperty(objName);
if (prop == null)
{
Expand Down Expand Up @@ -256,7 +256,7 @@ public static object FindObjectOnPath(string deviceObjectPath)
obj = indexedPropInfo.GetValue(collection, new object[] { properParam });
}
// if the index is bad, catch it here.
catch (Crestron.SimplSharp.Reflection.TargetInvocationException e)
catch (TargetInvocationException e)
{
if (e.InnerException is ArgumentOutOfRangeException)
Debug.LogMessage(LogEventLevel.Information, " Index Out of range");
Expand Down Expand Up @@ -287,7 +287,7 @@ public static string SetProperty(string deviceObjectPath)
//if (obj == null)
// return "{\"error\":\"No object found\"}";

//CType t = obj.GetType();
//Type t = obj.GetType();


//// get the properties and set them into a new collection of NameType wrappers
Expand Down Expand Up @@ -365,7 +365,7 @@ public class NameType
}

[AttributeUsage(AttributeTargets.All)]
public class ApiAttribute : CAttribute
public class ApiAttribute : Attribute
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/PepperDash.Essentials.Core/Devices/DeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static void DeactivateAll()
// var dev = GetDeviceForKey(devKey);
// if(dev != null)
// {
// var type = dev.GetType().GetCType();
// var type = dev.GetType().GetType();
// var methods = type.GetMethods(BindingFlags.Public|BindingFlags.Instance);
// var sb = new StringBuilder();
// sb.AppendLine(string.Format("{2} methods on [{0}] ({1}):", dev.Key, type.Name, methods.Length));
Expand Down
2 changes: 1 addition & 1 deletion src/PepperDash.Essentials.Core/Devices/EssentialsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Reflection;
using System.Reflection;

using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
Expand Down
6 changes: 2 additions & 4 deletions src/PepperDash.Essentials.Core/Devices/IHasFeedbacks.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Collections.Generic;
using System;
using System.Linq;
using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharp.Reflection;

using PepperDash.Core;
using Serilog.Events;
Expand All @@ -23,7 +21,7 @@ public static class IHasFeedbackExtensions
{
public static void DumpFeedbacksToConsole(this IHasFeedback source, bool getCurrentStates)
{
CType t = source.GetType();
Type t = source.GetType();
// get the properties and set them into a new collection of NameType wrappers
var props = t.GetProperties().Select(p => new PropertyNameType(p, t));

Expand Down
22 changes: 11 additions & 11 deletions src/PepperDash.Essentials.Core/Factory/DeviceFactory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


using Crestron.SimplSharp;
using Crestron.SimplSharp.Reflection;
using System.Reflection;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
Expand All @@ -14,13 +14,13 @@ namespace PepperDash.Essentials.Core
{
public class DeviceFactoryWrapper
{
public CType CType { get; set; }
public Type Type { get; set; }
public string Description { get; set; }
public Func<DeviceConfig, IKeyed> FactoryMethod { get; set; }

public DeviceFactoryWrapper()
{
CType = null;
Type = null;
Description = "Not Available";
}
}
Expand All @@ -40,7 +40,7 @@ public DeviceFactory()
{
try
{
var factory = (IDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type);
var factory = (IDeviceFactory)Activator.CreateInstance(type);
factory.LoadTypeFactories();
}
catch (Exception e)
Expand Down Expand Up @@ -69,7 +69,7 @@ public static void AddFactoryForType(string typeName, Func<DeviceConfig, IKeyed>
DeviceFactory.FactoryMethods.Add(typeName, new DeviceFactoryWrapper() { FactoryMethod = method});
}

public static void AddFactoryForType(string typeName, string description, CType cType, Func<DeviceConfig, IKeyed> method)
public static void AddFactoryForType(string typeName, string description, Type Type, Func<DeviceConfig, IKeyed> method)
{
//Debug.LogMessage(LogEventLevel.Debug, "Adding factory method for type '{0}'", typeName);

Expand All @@ -79,7 +79,7 @@ public static void AddFactoryForType(string typeName, string description, CType
return;
}

var wrapper = new DeviceFactoryWrapper() { CType = cType, Description = description, FactoryMethod = method };
var wrapper = new DeviceFactoryWrapper() { Type = Type, Description = description, FactoryMethod = method };
DeviceFactory.FactoryMethods.Add(typeName, wrapper);
}

Expand Down Expand Up @@ -180,17 +180,17 @@ public static void GetDeviceFactoryTypes(string filter)
foreach (var type in types.OrderBy(t => t.Key))
{
var description = type.Value.Description;
var cType = "Not Specified by Plugin";
var Type = "Not Specified by Plugin";

if (type.Value.CType != null)
if (type.Value.Type != null)
{
cType = type.Value.CType.FullName;
Type = type.Value.Type.FullName;
}

CrestronConsole.ConsoleCommandResponse(
@"Type: '{0}'
CType: '{1}'
Description: {2}{3}", type.Key, cType, description, CrestronEnvironment.NewLine);
Type: '{1}'
Description: {2}{3}", type.Key, Type, description, CrestronEnvironment.NewLine);
}
}

Expand Down
12 changes: 1 addition & 11 deletions src/PepperDash.Essentials.Core/Factory/IDeviceFactory.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Reflection;

using PepperDash.Core;
using PepperDash.Essentials.Core.Config;

namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Defines a class that is capable of loading device types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

using Crestron.SimplSharp.Reflection;
using System.Reflection;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
using Serilog.Events;
Expand All @@ -25,7 +25,7 @@ public ProcessorExtensionDeviceFactory() {
{
try
{
var factory = (IProcessorExtensionDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(extension);
var factory = (IProcessorExtensionDeviceFactory)Activator.CreateInstance(extension);
factory.LoadFactories();
}
catch( Exception e )
Expand Down Expand Up @@ -55,7 +55,7 @@ public static void AddFactoryForType(string extensionName, Func<DeviceConfig, IK
ProcessorExtensionDeviceFactory.ProcessorExtensionFactoryMethods.Add(extensionName, new DeviceFactoryWrapper() { FactoryMethod = method });
}

public static void AddFactoryForType(string extensionName, string description, CType cType, Func<DeviceConfig, IKeyed> method)
public static void AddFactoryForType(string extensionName, string description, Type Type, Func<DeviceConfig, IKeyed> method)
{
//Debug.LogMessage(LogEventLevel.Debug, "Adding factory method for type '{0}'", typeName);

Expand All @@ -65,7 +65,7 @@ public static void AddFactoryForType(string extensionName, string description, C
return;
}

var wrapper = new DeviceFactoryWrapper() { CType = cType, Description = description, FactoryMethod = method };
var wrapper = new DeviceFactoryWrapper() { Type = Type, Description = description, FactoryMethod = method };
ProcessorExtensionDeviceFactory.ProcessorExtensionFactoryMethods.Add(extensionName, wrapper);
}

Expand Down
1 change: 1 addition & 0 deletions src/PepperDash.Essentials.Core/Global/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public static char DirectorySeparator
public static void SetFilePathPrefix(string prefix)
{
FilePathPrefix = prefix;
Debug.LogMessage(LogEventLevel.Information, "File Path Prefix set to '{0}'", FilePathPrefix);
}

static string _AssemblyVersion;
Expand Down
8 changes: 4 additions & 4 deletions src/PepperDash.Essentials.Core/JoinMaps/JoinMapBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Globalization;
using System.Linq;
using System.Text;
using Crestron.SimplSharp.Reflection;
using System.Reflection;
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp;

Expand Down Expand Up @@ -109,7 +109,7 @@ protected JoinMapBaseAdvanced(uint joinStart, Type type):this(joinStart)
protected void AddJoins(Type type)
{
var fields =
type.GetCType()
type.GetType()
.GetFields(BindingFlags.Public | BindingFlags.Instance)
.Where(f => f.IsDefined(typeof (JoinNameAttribute), true));

Expand Down Expand Up @@ -501,7 +501,7 @@ public void SetCustomJoinData(JoinData customJoinData)
public string GetNameAttribute(MemberInfo memberInfo)
{
var name = string.Empty;
var attribute = (JoinNameAttribute)CAttribute.GetCustomAttribute(memberInfo, typeof(JoinNameAttribute));
var attribute = (JoinNameAttribute)Attribute.GetCustomAttribute(memberInfo, typeof(JoinNameAttribute));

if (attribute == null) return name;

Expand All @@ -514,7 +514,7 @@ public string GetNameAttribute(MemberInfo memberInfo)


[AttributeUsage(AttributeTargets.All)]
public class JoinNameAttribute : CAttribute
public class JoinNameAttribute : Attribute
{
private string _Name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<RootNamespace>PepperDash.Essentials.Core</RootNamespace>
<Title>PepperDash Essentials Core</Title>
<PackageId>PepperDash.Essentials.Core</PackageId>
<InformationalVersion>$(Version)</InformationalVersion>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<Version>2.0.0-local</Version>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
Expand All @@ -23,7 +26,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Crestron.SimplSharp.SDK.ProgramLibrary" Version="2.20.42" />
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-419" />
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-420" />
</ItemGroup>
<ItemGroup>
<None Include="Crestron\CrestronGenericBaseDevice.cs.orig" />
Expand Down
Loading

0 comments on commit 0a2aaa6

Please sign in to comment.