using Bro.Common.Helper;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Configuration;
|
using System.IO;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace Bro.Common.Factory
|
{
|
public static class FactoryHelper
|
{
|
private static List<Type> types = new List<Type>();
|
public static List<Type> TYPES
|
{
|
get
|
{
|
if (types.Count <= 0)
|
{
|
var dllFiles = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).GetFiles("*.dll").Select(u => u.FullName).ToList();
|
|
dllFiles.ForEach(f =>
|
{
|
try
|
{
|
Assembly assm = Assembly.LoadFrom(f);
|
if (assm != null)
|
{
|
assm.GetTypes().ToList().ForEach(t =>
|
{
|
DeviceAttribute attr = t.GetCustomAttribute<DeviceAttribute>();
|
|
if (attr != null)
|
{
|
types.Add(t);
|
|
//if (attr.AttrType == EnumHelper.DeviceAttributeType.Device)
|
//{
|
// DEVICE_TYPE_NAMES.Add(attr.TypeCode);
|
// DEVICE_DICT[attr.TypeCode] = t;
|
//}
|
}
|
});
|
}
|
}
|
catch (Exception)
|
{
|
}
|
});
|
}
|
|
return types;
|
}
|
}
|
|
//private static Dictionary<string, Type> device_dict = new Dictionary<string, Type>();
|
//public static Dictionary<string, Type> DEVICE_DICT
|
//{
|
// get
|
// {
|
// if (device_dict.Count < 0)
|
// {
|
|
// }
|
|
// return device_dict;
|
// }
|
//}
|
|
//private static List<string> device_type_names = new List<string>();
|
//public static List<string> DEVICE_TYPE_NAMES
|
//{
|
// get
|
// {
|
// if (device_type_names.Count < 0)
|
// {
|
|
// }
|
|
// return device_type_names;
|
// }
|
//}
|
|
public static Type GetTypeByAtrributeTypeName(string attrTypeName, EnumHelper.DeviceAttributeType attrType)
|
{
|
Type type = TYPES.FirstOrDefault(t =>
|
{
|
DeviceAttribute attr = t.GetCustomAttribute<DeviceAttribute>();
|
return attr != null && attr.TypeCode == attrTypeName && attr.AttrType == attrType;
|
});
|
|
return type;
|
}
|
}
|
}
|