using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using XKRS.Common.Interface;
using XKRS.Common.Model.Helper;

namespace XKRS.Common.Factory
{
    public class UIFactory
    {
        public static IRunCtrl GetRunCtrl(IDevice device)
        {
            var attr = device.GetType().GetCustomAttribute<DeviceAttribute>();
            if (attr == null)
                return null;
            var type = FactoryHelper.GetTypeByAttributeTypeName(attr.TypeCode, EnumHelper.DeviceAttributeType.RunCtrl);
            if (type == null)
                return null;
            IRunCtrl runCtrl = Activator.CreateInstance(type, new object[] { device }) as IRunCtrl;
            return runCtrl;
        }
        public static bool IsDeviceCtrlExisted(string typeName,EnumHelper.DeviceAttributeType ctrlType)
        {
            var type = FactoryHelper.GetTypeByAttributeTypeName(typeName, ctrlType);
            return type != null;
        }
    }
}
