/// <summary> /// Constructs a new instance of the device information. Device and useragent are provided /// uses indexes in the providers strings collection. /// </summary> /// <param name="provider">The provider the device will be assigned to.</param> /// <param name="uniqueDeviceID">The unique device name.</param> /// <param name="parent">The parent device, or null if no parent.</param> internal DeviceInfo(BaseProvider provider, string uniqueDeviceID, DeviceInfo parent) : base(provider, uniqueDeviceID, String.Empty, parent) { }
/// <summary> /// Constructs a new instance of the device information. Device and useragent are provided /// uses indexes in the providers strings collection. /// </summary> /// <param name="provider">The provider the device will be assigned to.</param> /// <param name="uniqueDeviceID">The unique device name.</param> /// <param name="userAgentStringIndex">The string index of the user agent string.</param> /// <param name="parent">The parent device, or null if no parent.</param> internal DeviceInfo(BaseProvider provider, string uniqueDeviceID, int userAgentStringIndex, DeviceInfo parent) : base(provider, uniqueDeviceID, userAgentStringIndex >= 0 ? provider.Strings.Get(userAgentStringIndex) : String.Empty, parent) { }
/// <summary> /// Reads the devices and any children. /// </summary> /// <param name="reader">BinaryReader of the input stream.</param> /// <param name="provider">The provider the device will be added to.</param> /// <param name="parent">The parent of the device, or null if a root device.</param> private static void ReadDevices(BinaryReader reader, Provider provider, DeviceInfo parent) { short count = reader.ReadInt16(); for (short i = 0; i < count; i++) { // Get the device id string. int uniqueDeviceIDStringIndex = reader.ReadInt32(); string uniqueDeviceID = uniqueDeviceIDStringIndex >= 0 ? provider.Strings.Get(uniqueDeviceIDStringIndex) : String.Empty; // Create the new device. var device = new DeviceInfo( provider, uniqueDeviceID, parent); // Read the number of useragents to associate with this // device. short userAgentCount = reader.ReadInt16(); for (int u = 0; u < userAgentCount; u++) { // Get the user agent string index and create a new // device. int userAgentStringIndex = reader.ReadInt32(); var uaDevice = new DeviceInfo( provider, uniqueDeviceID, userAgentStringIndex, device); // Add the device to the handlers. foreach (short index in ReadDeviceHandlers(reader)) provider.Handlers[index].Set(uaDevice); } // Add the device to the list of all devices. int hashCode = device.DeviceId.GetHashCode(); if (provider.AllDevices.ContainsKey(hashCode)) { // Yes. Add this device to the list. provider.AllDevices[hashCode].Add(device); } else { // No. So add the new device. provider.AllDevices.Add(hashCode, new List<BaseDeviceInfo>(new[] { device })); } // Get the remaining properties and values to the device. ReadCollection(reader, device.Properties); // Read the child devices. ReadDevices(reader, provider, device); } }