Esempio n. 1
0
        /// <summary> Add a new myDriveInfo to this collection. </summary>
        /// <param name="myDriveInfo"> myDriveInfo object for this new myDriveInfo </param>
        /// <returns> The index for this new Divsion </returns>
        public int Add(myDriveInfo myDriveInfo)
        {
            // Add hit myDriveInfo to the list and keep the index
            int returnVal = List.Add(myDriveInfo);

            // Return the index
            return(returnVal);
        }
Esempio n. 2
0
        /// <summary> Remove an existing myDriveInfo from this collection. </summary>
        /// <param name="myDriveInfo"> myDriveInfo to remove from this collection. </param>
        /// <exception cref="Exception"> Throws a <see cref="Exception"/> if the specified
        /// <see cref="myDriveInfo"/> object to remove is not in this collection. </exception>
        internal void Remove(myDriveInfo myDriveInfo)
        {
            // Check to see if this myDriveInfo exists in this collection
            if (!Contains(myDriveInfo))
            {
                throw new Exception("The specified myDriveInfo does not exist in this collection.");
            }

            // Remove the myDriveInfo which does exist
            List.Remove(myDriveInfo);
        }
Esempio n. 3
0
        /// <summary> Insert a new myDriveInfo into a specified index in this collection.  </summary>
        /// <param name="Index"> Index specifying location to insert new myDriveInfo </param>
        /// <param name="myDriveInfo"> myDriveInfo object for this new myDriveInfo </param>
        /// <exception cref="Exception"> Throws an <see cref="Exception"/> if there is
        /// an index out of bounds error. </exception>
        internal void Insert(int Index, myDriveInfo myDriveInfo)
        {
            // Check that this is a valid index
            if (Index >= List.Count)
            {
                throw new Exception("Index out of bounds during insert of new myDriveInfo in a myDriveInfo_Collection.");
            }

            // Complete the insert
            List.Insert(Index, myDriveInfo);
        }
Esempio n. 4
0
        private static void populate_drive_collection()
        {
            // Clear the drive collection
            driveCollection.Clear();

            // Get collection of drives attached to this machine
            ManagementObjectSearcher   query           = new ManagementObjectSearcher("SELECT Name, VolumeName, VolumeSerialNumber, DriveType From Win32_LogicalDisk");
            ManagementObjectCollection queryCollection = query.Get();

            // Step through each drive connected to this computer
            myDriveInfo localDrive;
            string      name, drive, serial;

            foreach (ManagementObject mo in queryCollection)
            {
                // Get the volume name
                if ((mo["VolumeName"] == null) || (mo["VolumeName"].ToString().Length == 0))
                {
                    name = "UNLABELED";
                }
                else
                {
                    name = mo["VolumeName"].ToString();
                }

                // Get the drive name
                drive = mo["Name"].ToString();

                // Get the serial number
                if ((mo["VolumeSerialNumber"] == null) || (mo["VolumeSerialNumber"].ToString().Length == 0))
                {
                    serial = "NO SERIAL";
                }
                else
                {
                    serial = mo["VolumeSerialNumber"].ToString();
                }

                // Add this as a new drive
                localDrive = new myDriveInfo(drive, name, serial, Convert.ToInt32(mo["DriveType"]));
                driveCollection.Add(localDrive);
            }
        }
Esempio n. 5
0
 /// <summary> Check to see if a myDriveInfo currently exists in this collection.  </summary>
 /// <param name="myDriveInfo"> myDriveInfo to check for existence in this collection. </param>
 /// <returns>TRUE if the provided myDriveInfo is already part of this myDriveInfo Collection </returns>
 internal bool Contains(myDriveInfo myDriveInfo)
 {
     return(List.Contains(myDriveInfo));
 }