Esempio n. 1
0
        /// <summary>
        /// Registers the device drivers.
        /// </summary>
        /// <param name="assemblyInfo">The assembly info.</param>
        public void RegisterDeviceDrivers(Assembly assemblyInfo)
        {
            var types = assemblyInfo.DefinedTypes;

            foreach (var type in types)
            {
                var attributes = type.CustomAttributes;

                foreach (var attributeData in attributes)
                {
                    if (attributeData.AttributeType != typeof(ISADeviceDriverAttribute) &&
                        attributeData.AttributeType != typeof(PCIDeviceDriverAttribute))
                    {
                        continue;
                    }

                    IDeviceDriver attribute = GetIDeviceDriver(attributeData);

                    if ((attribute.Platforms & platformArchitecture) != 0)
                    {
                        DeviceDriver deviceDriver = new DeviceDriver(attribute, type.AsType());

                        foreach (var memAttributeData in attributes)
                        {
                            if (memAttributeData.AttributeType != typeof(DeviceDriverPhysicalMemoryAttribute))
                            {
                                continue;
                            }

                            var memAttribute = GetDeviceDriverPhysicalMemoryAttribute(memAttributeData);

                            deviceDriver.Add(memAttribute);
                        }

                        AddDeviceDriver(deviceDriver);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 初始化驱动
        /// </summary>
        private void LoadDrivers()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;

            var files = Directory.GetFiles(path, "Sys.DataCollection.Drivers.*.dll", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var assembly    = Assembly.Load(File.ReadAllBytes(file));
                var driverTypes = assembly.GetTypes().Where(type => type.GetInterface("IDeviceDriver") != null).ToList();
                if (driverTypes == null || driverTypes.Count <= 0)
                {
                    continue;
                }

                IDeviceDriver deviceDriver = Activator.CreateInstance(driverTypes[0]) as IDeviceDriver;
                if (deviceDriver == null)
                {
                    //todo write log
                    continue;
                }
                else
                {
                    string deviceCode = deviceDriver.DriverCode;
                    if (_driverCache.ContainsKey(deviceCode))
                    {
                        _driverCache[deviceCode] = deviceDriver;
                        //todo 待确认驱动编码重复的处理
                    }
                    else
                    {
                        _driverCache.Add(deviceCode, deviceDriver);
                    }
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceDriver"/> class.
 /// </summary>
 /// <param name="deviceDriverAttribute">The device driver attribute.</param>
 /// <param name="driverType">Type of the driver.</param>
 public DeviceDriver(IDeviceDriver deviceDriverAttribute, Type driverType)
 {
     this.deviceDriverAttribute = deviceDriverAttribute;
     this.driverType            = driverType;
     this.memoryAttributes      = new LinkedList <DeviceDriverPhysicalMemoryAttribute>();
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceDriver"/> class.
 /// </summary>
 /// <param name="deviceDriverAttribute">The device driver attribute.</param>
 /// <param name="driverType">Type of the driver.</param>
 public DeviceDriver(IDeviceDriver deviceDriverAttribute, System.Type driverType)
 {
     this.deviceDriverAttribute = deviceDriverAttribute;
     this.driverType = driverType;
     this.memoryAttributes = new LinkedList<DeviceDriverPhysicalMemoryAttribute>();
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceDriver"/> class.
 /// </summary>
 /// <param name="deviceDriverAttribute">The device driver attribute.</param>
 /// <param name="driverType">Type of the driver.</param>
 public DeviceDriver(IDeviceDriver deviceDriverAttribute, Type driverType)
 {
     Attribute = deviceDriverAttribute;
     DriverType = driverType;
     MemoryAttributes = new LinkedList<DeviceDriverPhysicalMemoryAttribute>();
 }