private void buttonSave_Click(object sender, EventArgs e) { string name = textBoxName.Text; int version = (int)numericUpDownVersion.Value; Driver.OS_Type osType = (Driver.OS_Type)comboBoxOSType.SelectedValue; Device.DeviceType deviceType = (Device.DeviceType)comboBoxDeviceType.SelectedValue; if (string.IsNullOrWhiteSpace(name)) { MessageBox.Show("The driver must have a name", "Error", MessageBoxButtons.OK); } else if (version <= 0) { MessageBox.Show("The version of driver must be greater than zero", "Error", MessageBoxButtons.OK); } else { driver.Name = name; driver.Version = version; driver.OSType = osType; driver.DeviceType = deviceType; Form1 main = this.Owner as Form1; main.update_drivers(); this.Hide(); } }
public void EditDevice(Device device, string name, string manufacturer, Device.DeviceType type, PortType portType) { device.Name = name; device.Manufacturer = manufacturer; device.Type = type; device.PortType = portType; }
/// <summary> /// Функция проверки добавляемого устройства /// </summary> /// <param name="deviceName">Имя устройства</param> /// <returns></returns> private bool ValidateDevice(string deviceName) { bool isValidType = false; Device.Device device = Device.DeviceManager.GetInstance(). GetDeviceByEplanName(deviceName); Device.DeviceType deviceType = device.DeviceType; Device.DeviceSubType deviceSubType = device.DeviceSubType; Device.DeviceType[] validTypes; Device.DeviceSubType[] validSubTypes; GetDevTypes(out validTypes, out validSubTypes); if (validTypes == null) { return(true); } else { foreach (Device.DeviceType type in validTypes) { if (type == deviceType) { isValidType = true; break; } else { isValidType = false; } } if (validSubTypes != null) { bool isValidSubType = false; foreach (Device.DeviceSubType subType in validSubTypes) { if ((subType == deviceSubType) && isValidType) { isValidSubType = true; } } if (isValidSubType && isValidSubType) { return(true); } else { return(false); } } } return(isValidType); }
public List <Device> GetNetworkDevice() { List <Device> netdevices = new List <Device>(); Device.DeviceType type = Device.DeviceType.NetworkDevice; foreach (var netdevice in Devices.Where(item => item.deviceType == type)) { netdevices.Add(netdevice); } return(netdevices); }
/// <summary> /// Функция проверки добавляемого устройства /// </summary> /// <param name="device">Устройство</param> /// <returns></returns> private bool ValidateDevice(Device.IDevice device) { bool isValidType = false; Device.DeviceType deviceType = device.DeviceType; Device.DeviceSubType deviceSubType = device.DeviceSubType; Action.GetDisplayObjects(out Device.DeviceType[] validTypes, out Device.DeviceSubType[] validSubTypes, out _); if (validTypes == null) { return(true); } else { foreach (Device.DeviceType type in validTypes) { if (type == deviceType) { isValidType = true; break; } else { isValidType = false; } } if (validSubTypes != null) { bool isValidSubType = false; foreach (Device.DeviceSubType subType in validSubTypes) { if ((subType == deviceSubType) && isValidType) { isValidSubType = true; } } if (isValidSubType && isValidSubType) { return(true); } else { return(false); } } } return(isValidType); }
private static Device.IDevice MakeMockedDevice(string objName, int objNum, Device.DeviceType devType, int devNumber, Device.DeviceSubType deviceSubType) { var devMock = new Mock <Device.IDevice>(); devMock.SetupGet(x => x.ObjectName).Returns(objName); devMock.SetupGet(x => x.ObjectNumber).Returns(objNum); devMock.SetupGet(x => x.DeviceType).Returns(devType); devMock.SetupGet(x => x.DeviceNumber).Returns(devNumber); devMock.SetupGet(x => x.DeviceSubType).Returns(deviceSubType); return(devMock.Object); }
public static Device SelectModule(IWin32Window owner, Device.DeviceType type) { FrmModuleSelector form = new FrmModuleSelector(type); form.ShowDialog(owner); if (form.DialogResult == DialogResult.OK) { return(form.SelectedModule); } return(null); }
public void download_drivers() { Random rand = new Random(); for (int i = 0; i < rand.Next(1, 10); i++) { string name = ($"{ Guid.NewGuid()}"); int version = rand.Next(1, 100); Driver.OS_Type os_type = (Driver.OS_Type)rand.Next(1, 4); Device.DeviceType dev_type = (Device.DeviceType)rand.Next(1, 14); Driver driver = new Driver(name, version, os_type, dev_type); this.Drivers.Add(driver.GetHashCode(), driver); } }
public FrmConnectionFinder(Device.DeviceType type, DeviceConnection connection) { InitializeComponent(); this.Type = type; switch (this.Type) { case Device.DeviceType.AccessoryDecoder: ShowOutputs(connection); break; case Device.DeviceType.SensorModule: ShowInputs(connection); break; } chkShowUnused.Checked = true; }
public FrmModuleSelector(Device.DeviceType type) { InitializeComponent(); this.SelectedModule = null; this.Type = type; switch (type) { case Device.DeviceType.SensorModule: this.CurrentGridView = grdSensorView; ListSensorModules(); break; default: this.CurrentGridView = grdAccessoryView; ListAccessoryModules(); break; } }
/// <summary> /// Настройка отображаемых объектов /// </summary> private void SetUpDisplayObjects() { deviceTypes = new Device.DeviceType[0]; displayParameters = false; foreach (var displayObject in DisplayObjects) { switch (displayObject) { case DisplayObject.Parameters: displayParameters = true; break; case DisplayObject.Signals: deviceTypes = new Device.DeviceType[] { Device.DeviceType.AI, Device.DeviceType.AO, Device.DeviceType.DI, Device.DeviceType.DO }; break; } } }
// Raw input message private void _ProcessInput(ref IntPtr lResult, IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam) { lResult = IntPtr.Zero; // Get data packet uint size = 0; if (0 > GetRawInputData(lParam, RID_INPUT, null, ref size, (uint)Marshal.SizeOf(typeof(RAWINPUTHEADER)))) { throw new Exception("Bad return value from Win32 function"); } if (size <= 0) { return; } var bytes = new byte[size]; if (0 >= GetRawInputData(lParam, RID_INPUT, bytes, ref size, (uint)Marshal.SizeOf(typeof(RAWINPUTHEADER)))) { throw new Exception("Bad return value from Win32 function"); } // Extract the header and raw data portions var header = ToStruct <RAWINPUTHEADER>(bytes); if (header.dwSize != size) { throw new Exception("Size field mismatch"); } int hdrSize = Marshal.SizeOf(typeof(RAWINPUTHEADER)); var data = new byte[size - hdrSize]; Array.Copy(bytes, hdrSize, data, 0, data.Length); // Parse data bytes object obj = null; if (header.dwType == RIM_TYPEMOUSE) { var raw = ToStruct <RAWMOUSE>(data); obj = new MouseData { flags = raw.usFlags, buttons = raw.ulButtons, rawButtons = raw.ulRawButtons, lastX = raw.lLastX, lastY = raw.lLastY, extraInformation = raw.ulExtraInformation }; } if (header.dwType == RIM_TYPEKEYBOARD) { var raw = ToStruct <RAWKEYBOARD>(data); obj = new KeyboardData { makecode = raw.usMakecode, flags = raw.usFlags, reserved = raw.usReserved, vKey = raw.usVKey, message = raw.dwMessage, extraInformation = raw.ulExtraInformation }; } if (header.dwType == RIM_TYPEHID) { // Hid data contains 2x DWORD header plus variable-length stream of bytes var raw = new RAWHID(); raw.dwSizeHid = BitConverter.ToUInt32(data, 0); raw.dwCount = BitConverter.ToUInt32(data, 4); int len = (int)(raw.dwSizeHid * raw.dwCount); if (len < data.Length - 8) { throw new Exception("RawData array length too small to fit requested elements count"); } raw.bRawData = new byte[len]; Array.Copy(data, 8, raw.bRawData, 0, raw.bRawData.Length); var arrays = new byte[raw.dwCount][]; for (int i = 0; i < arrays.Length; i++) { arrays[i] = new byte[raw.dwSizeHid]; Array.Copy(raw.bRawData, i * raw.dwSizeHid, arrays[i], 0, arrays[i].Length); } obj = new HidData { rawData = arrays }; } // IntPtr.Zero means there is no associated device if (header.hDevice == IntPtr.Zero) { // Trigger universal event & null device's event if (header.dwType >= 0 && header.dwType <= 2) { Device.DeviceType tp = 0; if (header.dwType == RIM_TYPEMOUSE) { tp = Device.DeviceType.Mouse; } if (header.dwType == RIM_TYPEKEYBOARD) { tp = Device.DeviceType.Keyboard; } if (header.dwType == RIM_TYPEHID) { tp = Device.DeviceType.Hid; } var dev = _nullDevices[tp]; InputReceived?.Invoke(this, new RawInputEventArgs(dev, obj)); dev.RaiseInputReceived(obj); } } // Data does have an associated device else { // Lookup device in dictionary if (_devices.ContainsKey(header.hDevice)) { // Trigger universal event & device object's event var dev = _devices[header.hDevice]; InputReceived?.Invoke(this, new RawInputEventArgs(dev, obj)); dev.RaiseInputReceived(obj); } } }
public void add_device(string name, Device.DeviceType type) { this.Devices.Add(new Device(name, type)); }
///// <summary> ///// Gets all connections for the specified element. ///// </summary> ///// <param name="element">Element.</param> ///// <returns>The requested list of <see cref="DeviceConnection"/> related to the specified element.</returns> //public DeviceConnection[] GetByElement(Element element) //{ // return this.GetByElement(element, Device.DeviceType.Undefined); //} /// <summary> /// Gets connections of the specified type for the specified element. /// </summary> /// <param name="element">Element.</param> /// <param name="type">Type of element.</param> /// <returns>The requested list of <see cref="DeviceConnection"/> related to the specified element.</returns> public DeviceConnection[] GetByElement(Element element, Device.DeviceType type) { string sql = string.Empty; DeviceConnection item = null; DeviceConnection[] items = null; Logger.LogDebug(this, "[CLASS].GetByElement([{0}], {1})", (element != null ? element.ID.ToString() : "null"), type); // Return an empty array if element is null or doesn't have outputs if (element == null) { return(new DeviceConnection[0]); } else if (type == Device.DeviceType.AccessoryDecoder && (element.Connections == null || element.Connections.Count <= 0)) { return(new DeviceConnection[0]); } else if (type == Device.DeviceType.FeedbackModule && (element.Connections == null || element.Connections.Count <= 0)) { return(new DeviceConnection[0]); } try { switch (type) { case Device.DeviceType.AccessoryDecoder: items = new DeviceConnection[element.Connections.Count]; break; case Device.DeviceType.FeedbackModule: items = new DeviceConnection[element.Connections.Count]; break; } Connect(); sql = @"SELECT " + DeviceConnectionDAO.SQL_FIELDS_SELECT + @" FROM " + DeviceConnectionDAO.SQL_TABLE + @" con WHERE elementid = @elementid And @type = (SELECT type FROM " + DeviceDAO.SQL_TABLE + @" deco WHERE con.deviceid = deco.id) ORDER BY [index] Asc, id Asc"; SetParameter("elementid", element.ID); SetParameter("type", (int)type); using (SQLiteDataReader reader = ExecuteReader(sql)) { while (reader.Read()) { item = this.ReadEntityRecord(reader); if (item != null && item.Index <= items.Length) { items[item.Index - 1] = item; } } } return(items); } catch (Exception ex) { Logger.LogError(this, ex); throw; } finally { Disconnect(); } }
public static Dictionary <int, Equip> getEquips(CommandReader cr, User user) { Dictionary <int, Equip> res = new Dictionary <int, Equip>(); int equipCount = cr.getInt(); for (int i = 0; i < equipCount; i++) { Equip eq = new Equip(); eq.id = cr.getInt(); int item_id = cr.getInt(); Item.ItemType iType = (Item.ItemType)cr.getInt(); int dType = cr.getInt(); eq.in_use = cr.getInt() == 0 ? false: true; eq.wear = cr.getInt(); int location = cr.getInt(); eq.location = location == 0 ? null : user.planets[location]; eq.num = cr.getInt(); eq.last_use = cr.getDbl(); switch (iType) { case Item.ItemType.consumable: { Consumable item = MainData.itemCollect.get <Consumable>(item_id); eq.item = item; break; } case Item.ItemType.device: { Device.DeviceType devT = (Device.DeviceType)dType; switch (devT) { case Device.DeviceType.Body: { Body item = MainData.itemCollect.get <Body>(item_id); eq.item = item; break; } case Device.DeviceType.Droid: { Droid item = MainData.itemCollect.get <Droid>(item_id); eq.item = item; break; } case Device.DeviceType.Engine: { Engine item = MainData.itemCollect.get <Engine>(item_id); eq.item = item; break; } case Device.DeviceType.Fuelbag: { Fuelbag item = MainData.itemCollect.get <Fuelbag>(item_id); eq.item = item; break; } case Device.DeviceType.Hyper: { Hyper item = MainData.itemCollect.get <Hyper>(item_id); eq.item = item; break; } case Device.DeviceType.Radar: { Radar item = MainData.itemCollect.get <Radar>(item_id); eq.item = item; break; } case Device.DeviceType.Shield: { Shield item = MainData.itemCollect.get <Shield>(item_id); eq.item = item; break; } case Device.DeviceType.Weapon: { Weapon item = MainData.itemCollect.get <Weapon>(item_id); eq.item = item; break; } } break; } } res.Add(eq.id, eq); } return(res); }
public static ItemCollection getItems(CommandReader cr, User user) { ItemCollection res = new ItemCollection(); int itemTypeCount = cr.getInt(); for (int i = 0; i < itemTypeCount; i++) { int itemCount = cr.getInt(); for (int j = 0; j < itemCount; j++) { int item_id = cr.getInt(); Item.ItemType item_itemType = (Item.ItemType)cr.getInt(); String item_description = cr.getStr(); int item_volume = cr.getInt(); int item_region_id = cr.getInt(); int item_use_only = cr.getInt(); int item_price = cr.getInt(); switch (item_itemType) { case Item.ItemType.consumable: { Consumable item = new Consumable(); item.id = item_id; item.itemType = item_itemType; item.description = item_description; item.volume = item_volume; item.region = item_region_id; res.consumables.Add(item.id, item); break; } case Item.ItemType.device: { String device_vendorStr = cr.getStr(); Device.DeviceType device_deviceType = (Device.DeviceType)cr.getInt(); int device_durability = cr.getInt(); switch (device_deviceType) { case Device.DeviceType.Body: { Body dev = new Body(); int body_slot_weapons = cr.getInt(); int body_slot_droids = cr.getInt(); int body_slot_shield = cr.getInt(); int body_slot_hyper = cr.getInt(); dev.id = item_id; dev.itemType = item_itemType; dev.description = item_description; dev.volume = item_volume; dev.region = item_region_id; dev.vendorStr = device_vendorStr; dev.deviceType = device_deviceType; dev.durability = device_durability; dev.use_only = item_use_only; dev.price = item_price; dev.slot_weapons = body_slot_weapons; dev.slot_droids = body_slot_droids; dev.slot_shield = body_slot_shield; dev.slot_hyper = body_slot_hyper; res.bodyes.Add(dev.id, dev); break; } case Device.DeviceType.Droid: { Droid dev = new Droid(); int droid_power = cr.getInt(); int droid_time_reload = cr.getInt(); int radius = cr.getInt(); dev.id = item_id; dev.itemType = item_itemType; dev.description = item_description; dev.volume = item_volume; dev.region = item_region_id; dev.vendorStr = device_vendorStr; dev.deviceType = device_deviceType; dev.durability = device_durability; dev.use_only = item_use_only; dev.price = item_price; dev.power = droid_power; dev.time_reload = droid_time_reload; res.droids.Add(dev.id, dev); break; } case Device.DeviceType.Engine: { Engine dev = new Engine(); int engine_power = cr.getInt(); int engine_economic = cr.getInt(); dev.id = item_id; dev.itemType = item_itemType; dev.description = item_description; dev.volume = item_volume; dev.region = item_region_id; dev.vendorStr = device_vendorStr; dev.deviceType = device_deviceType; dev.durability = device_durability; dev.use_only = item_use_only; dev.price = item_price; dev.power = engine_power; dev.economic = engine_economic; res.engines.Add(dev.id, dev); break; } case Device.DeviceType.Fuelbag: { Fuelbag dev = new Fuelbag(); int fuelbag_compress = cr.getInt(); dev.id = item_id; dev.itemType = item_itemType; dev.description = item_description; dev.volume = item_volume; dev.region = item_region_id; dev.vendorStr = device_vendorStr; dev.deviceType = device_deviceType; dev.durability = device_durability; dev.use_only = item_use_only; dev.price = item_price; dev.compress = fuelbag_compress; res.fuelbags.Add(dev.id, dev); break; } case Device.DeviceType.Hyper: { Hyper dev = new Hyper(); int hyper_radius = cr.getInt(); int hyper_time_start = cr.getInt(); int hyper_time_reload = cr.getInt(); dev.id = item_id; dev.itemType = item_itemType; dev.description = item_description; dev.volume = item_volume; dev.region = item_region_id; dev.vendorStr = device_vendorStr; dev.deviceType = device_deviceType; dev.durability = device_durability; dev.use_only = item_use_only; dev.price = item_price; dev.radius = hyper_radius; dev.time_start = hyper_time_start; dev.time_reload = hyper_time_reload; res.hypers.Add(dev.id, dev); break; } case Device.DeviceType.Radar: { Radar dev = new Radar(); int radar_radius = cr.getInt(); int radar_defense = cr.getInt(); int big_radius = cr.getInt(); dev.id = item_id; dev.itemType = item_itemType; dev.description = item_description; dev.volume = item_volume; dev.region = item_region_id; dev.vendorStr = device_vendorStr; dev.deviceType = device_deviceType; dev.durability = device_durability; dev.use_only = item_use_only; dev.price = item_price; dev.radius = radar_radius; dev.defense = radar_defense; dev.hyper = big_radius; res.radars.Add(dev.id, dev); break; } case Device.DeviceType.Shield: { Shield dev = new Shield(); int shield_power = cr.getInt(); dev.id = item_id; dev.itemType = item_itemType; dev.description = item_description; dev.volume = item_volume; dev.region = item_region_id; dev.vendorStr = device_vendorStr; dev.deviceType = device_deviceType; dev.durability = device_durability; dev.use_only = item_use_only; dev.price = item_price; dev.power = shield_power; res.shields.Add(dev.id, dev); break; } case Device.DeviceType.Weapon: { Weapon dev = new Weapon(); int weapon_weaponType = cr.getInt(); int weapon_radius = cr.getInt(); int weapon_power = cr.getInt(); int weapon_time_start = cr.getInt(); int weapon_time_reload = cr.getInt(); dev.id = item_id; dev.itemType = item_itemType; dev.description = item_description; dev.volume = item_volume; dev.region = item_region_id; dev.vendorStr = device_vendorStr; dev.deviceType = device_deviceType; dev.durability = device_durability; dev.use_only = item_use_only; dev.price = item_price; dev.weaponType = (Weapon.WeaponType)weapon_weaponType; dev.radius = weapon_radius; dev.power = weapon_power; dev.time_start = weapon_time_start; dev.time_reload = weapon_time_reload; res.weapons.Add(dev.id, dev); break; } } break; } } } } return(res); }
public Device GetLocalDevice() { Device.DeviceType type = Device.DeviceType.LocalDevice; return(Devices.Find(item => item.deviceType == type)); }
/// <summary> /// Gets connections of the specified type for the specified element. /// </summary> /// <param name="element">Element.</param> /// <param name="type">Type of element.</param> /// <returns>The requested list of <see cref="DeviceConnection"/> related to the specified element.</returns> public DeviceConnection[] GetDeviceConnections(ElementBase element, Device.DeviceType type) { return(OTCProject.LayoutManager.DeviceConnectionDAO.GetByElement(element, type)); }