using System;
using System.Collections.Generic;
using System.Text;
namespace Bwg.Scsi
{
///
/// This class contains information about a burner device that is useful to have
/// even when the device it not open
///
public class DeviceInfo
{
#region private member variables
///
/// The device name for the device
///
private string m_device_name;
///
/// The device latter for the device
///
private string m_device_letter;
///
/// The result of an inquiry
///
private InquiryResult m_inqury_result;
#endregion
#region static private member variables
///
/// The list of devices found and created. For each device only a single DeviceInfo object
/// will ever be created and this list holds the objects created to date
///
private static IList m_devices = new List();
#endregion
#region constructor
///
/// Create a new device info object given the device name and drive letter for the device
///
/// the device name
/// the drive letter
private DeviceInfo(string name, string letter)
{
m_device_name = name;
m_device_letter = letter;
}
#endregion
#region public properties
///
/// This property returns the drive letter associated with the device
///
public string DeviceLetter
{
get { return m_device_letter; }
}
///
/// This property returns the NT device name associated with the device
///
public string DeviceName
{
get { return m_device_name; }
}
///
/// This property returns a short description of the drive including drive letter
/// and NT device name.
///
public string ShortDesc
{
get { return m_device_letter + " ( " + m_device_name + " )"; }
}
///
/// This property return a long description of the drive including the drive letter,
/// NT device name, vendor ID and product ID.
///
public string LongDesc
{
get
{
string result = m_device_letter + " ";
// result += " ( " + m_device_name + " ) ";
result += "[" + m_inqury_result.VendorIdentification + " " +
m_inqury_result.ProductIdentification + " " +
m_inqury_result.FirmwareVersion + "]";
return result;
}
}
///
/// This property returns the inquiry data from the inquiry request
///
public InquiryResult InquiryData
{
get { return m_inqury_result; }
}
#endregion
#region public methods
///
/// This method returns a string representation of this object
///
/// string representatation of the object
public override string ToString()
{
return m_device_letter + " (" + m_inqury_result.VendorIdentification.Trim() + " " + m_inqury_result.ProductIdentification.Trim() + ")";
}
///
/// Extract the information we want to keep around after we close the device.
///
/// the open device we are going to query
/// true if we got the info, false otherwise
public bool ExtractInfo(Device dev)
{
if (dev.Inquiry(out m_inqury_result) != Device.CommandStatus.Success)
return false;
if (!m_inqury_result.Valid)
return false;
if (m_inqury_result.PeripheralQualifier != 0)
return false;
if (m_inqury_result.PeripheralDeviceType != Device.MMCDeviceType)
return false;
return true;
}
#endregion
#region public static methods
///
/// This method returns or creates a unique device info structure based on the name and the
/// drive letter for a given drive.
///
/// the NT name of the drive
/// the drive letter for the drive
/// the single DeviceInfo object that represents this drive
public static DeviceInfo CreateDevice(string name, string letter)
{
foreach (DeviceInfo info in m_devices)
{
if (info.DeviceName == name && info.DeviceLetter == letter)
return info;
}
DeviceInfo newdev = new DeviceInfo(name, letter);
m_devices.Add(newdev);
return newdev;
}
///
/// This method returns or creates a unique device info structure based on the
/// drive letter for a given drive.
///
/// the drive letter for the drive
/// the single DeviceInfo object that represents this drive
public static DeviceInfo CreateDevice(string letter)
{
return CreateDevice(DeviceManager.GetNtDeviceNameForDrive(letter),letter);
}
#endregion
}
}