public void AlphaFS_Host_EnumerateNetworkConnections_Local_Success() { UnitTestConstants.PrintUnitTestHeader(false); var networkConnectionCount = 0; foreach (var networkConnection in Host.EnumerateNetworkConnections().OrderBy(networkConnection => networkConnection.NetworkInfo.Name)) { Console.WriteLine("#{0:000}\tNetwork: [{1}]", ++networkConnectionCount, networkConnection.NetworkInfo.Name); UnitTestConstants.Dump(networkConnection, -21); UnitTestConstants.Dump(networkConnection.NetworkInfo, -21, true); UnitTestConstants.Dump(networkConnection.NetworkInterface, -20, true); Console.WriteLine(); } if (networkConnectionCount == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
public void AlphaFS_Host_EnumerateSessions_Local_Success() { UnitTestConstants.PrintUnitTestHeader(false); var host = Environment.MachineName; Console.WriteLine("Input Host: [{0}]", host); var sessionCount = 0; foreach (var sessionsInfo in Alphaleonis.Win32.Network.Host.EnumerateSessions(host)) { //Console.WriteLine("\n\t#{0:000}\tShare: [{1}]", ++cnt, shareInfo); if (UnitTestConstants.Dump(sessionsInfo, -16)) { sessionCount++; } Console.WriteLine(); } if (sessionCount == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
public void AlphaFS_Host_EnumerateOpenResources_Local_Success() { UnitTestAssert.IsElevatedProcess(); UnitTestConstants.PrintUnitTestHeader(false); var host = Environment.MachineName; Console.WriteLine("Connected to Host: [{0}]", host); var count = 0; foreach (var openResourceInfo in Alphaleonis.Win32.Network.Host.EnumerateOpenResources(host, null, null, false)) { UnitTestConstants.Dump(openResourceInfo); Assert.IsNotNull(openResourceInfo); count++; Console.WriteLine(); } if (count == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
private void EnumerateOpenConnections(string host, string share) { //UnitTestAssert.IsElevatedProcess(); // In User mode nothing is enumerated. UnitTestConstants.PrintUnitTestHeader(false); Console.WriteLine("Connected to Share: [{0}\\{1}]", host, share); var count = 0; foreach (var openConnectionInfo in Alphaleonis.Win32.Network.Host.EnumerateOpenConnections(host, share, true)) { UnitTestConstants.Dump(openConnectionInfo); Assert.IsNotNull(openConnectionInfo); count++; Console.WriteLine(); } if (count == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
public void AlphaFS_Volume_EnumerateVolumes_Local_Success() { UnitTestConstants.PrintUnitTestHeader(false); Console.WriteLine("Should give the same (or more) enumeration as \"mountvol.exe\"\n"); var volumeCount = 0; foreach (var volume in Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumes()) { Console.WriteLine("#{0:000}\tVolume: [{1}]", ++volumeCount, volume); Console.WriteLine(); foreach (var displayName in Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumePathNames(volume)) { Console.WriteLine("\t\tVolume points to logcal drive: [{0}]", displayName); Console.WriteLine(); } Console.WriteLine(); } if (volumeCount == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
public void AlphaFS_Host_EnumerateShares_Local_Success() { UnitTestConstants.PrintUnitTestHeader(false); var host = Environment.MachineName; Console.WriteLine("Input Host: [{0}]", host); var count = 0; foreach (var shareInfo in Alphaleonis.Win32.Network.Host.EnumerateShares(host, true)) { if (UnitTestConstants.Dump(shareInfo, -18)) { count++; } Console.WriteLine(); } if (count == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
public void AlphaFS_Host_EnumerateDfsLinks_Network_Success() { UnitTestConstants.PrintUnitTestHeader(true); var cnt = 0; var noDomainConnection = true; try { foreach (var dfsNamespace in Alphaleonis.Win32.Network.Host.EnumerateDomainDfsRoot()) { noDomainConnection = false; Console.Write("#{0:000}\tDFS Root: [{1}]\n", ++cnt, dfsNamespace); var cnt2 = 0; try { foreach (var dfsInfo in Alphaleonis.Win32.Network.Host.EnumerateDfsLinks(dfsNamespace).OrderBy(d => d.EntryPath)) { Console.Write("\n\t#{0:000}\tDFS Link: [{1}]", ++cnt2, dfsInfo.EntryPath); } } catch (NetworkInformationException ex) { Console.WriteLine("NetworkInformationException #1: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\nCaught (UNEXPECTED #1) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine(); } } catch (NetworkInformationException ex) { Console.WriteLine("NetworkInformationException #2: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\nCaught (UNEXPECTED #2) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } if (noDomainConnection) { UnitTestAssert.Inconclusive("Test ignored because the computer is either not connected to a domain or no DFS root exists."); } else if (cnt == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } Console.WriteLine(); }
public void AlphaFS_Volume_GetUniqueVolumeNameForPath_Local_Success() { UnitTestConstants.PrintUnitTestHeader(false); var logicalDriveCount = 0; foreach (var drive in System.IO.DriveInfo.GetDrives()) { // Skip mapped drives and network drives. if (drive.DriveType == System.IO.DriveType.NoRootDirectory || drive.DriveType == System.IO.DriveType.Network) { continue; } var driveName = drive.Name; var deviceGuid = Alphaleonis.Win32.Filesystem.Volume.GetVolumeGuid(driveName); Console.WriteLine("#{0:000}\tInput Path: [{1}]", ++logicalDriveCount, driveName); var volumeNameResult = Alphaleonis.Win32.Filesystem.Volume.GetUniqueVolumeNameForPath(driveName); Console.WriteLine("\n\tGetUniqueVolumeNameForPath: [{0}]", volumeNameResult ?? "null"); // Typically, only one mount point exists so the Volume GUIDs will match. Assert.AreEqual(deviceGuid, volumeNameResult); var pathNames = Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumePathNames(volumeNameResult).ToArray(); foreach (var displayName in pathNames) { Console.WriteLine("\n\t(Input Volume GUID Path) EnumerateVolumePathNames: Volume points to logcal drive: [{0}]\n", displayName); // Volumes don't always have drive letters. if (!string.IsNullOrWhiteSpace(displayName)) { Assert.AreEqual(driveName, displayName); } } } if (logicalDriveCount == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
private void AlphaFS_Directory_EncryptDecrypt(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var folder = tempRoot.CreateTree(); Console.WriteLine("Input Directory Path: [{0}]", folder.FullName); // Encrypt root folder only. Alphaleonis.Win32.Filesystem.Directory.Encrypt(folder.FullName); // Verify that the contents of the folder are still decrypted. var cnt = 0; foreach (var fsei in Alphaleonis.Win32.Filesystem.Directory.EnumerateFileSystemEntryInfos <Alphaleonis.Win32.Filesystem.FileSystemEntryInfo>(folder.FullName, Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.Recursive)) { cnt++; Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.Encrypted) == 0, "It is expected that the file system object is decrypted, but it is not."); } if (cnt == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } // Encrypt entire folder for decrypt test. Alphaleonis.Win32.Filesystem.Directory.Encrypt(folder.FullName, true); // Decrypt root folder only. Alphaleonis.Win32.Filesystem.Directory.Decrypt(folder.FullName); // Verify that the contents of the folder are still encrypted. cnt = 0; foreach (var fsei in Alphaleonis.Win32.Filesystem.Directory.EnumerateFileSystemEntryInfos <Alphaleonis.Win32.Filesystem.FileSystemEntryInfo>(folder.FullName, Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.Recursive)) { cnt++; Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.Encrypted) != 0, "It is expected that the file system object is encrypted, but it is not."); } if (cnt == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } } Console.WriteLine(); }
public void AlphaFS_Volume_GetDriveNameForNtDeviceName_And_GetVolumeGuidForNtDeviceName_Local_Success() { UnitTestConstants.PrintUnitTestHeader(false); var logicalDriveCount = 0; foreach (var drive in System.IO.DriveInfo.GetDrives()) { // Skip mapped drives and network drives. if (drive.DriveType == System.IO.DriveType.NoRootDirectory || drive.DriveType == System.IO.DriveType.Network) { continue; } var driveName = drive.Name; var dosDeviceName = Alphaleonis.Win32.Filesystem.Volume.GetVolumeDeviceName(driveName); var deviceGuid = Alphaleonis.Win32.Filesystem.Volume.GetVolumeGuid(driveName); Console.WriteLine("#{0:000}\tInput Path: [{1}]", ++logicalDriveCount, dosDeviceName); var driveNameResult = Alphaleonis.Win32.Filesystem.Volume.GetDriveNameForNtDeviceName(dosDeviceName); Console.WriteLine("\n\tGetDriveNameForNtDeviceName() : [{0}]", driveNameResult ?? "null"); Assert.AreEqual(driveName, driveNameResult); var driveGuidResult = Alphaleonis.Win32.Filesystem.Volume.GetVolumeGuidForNtDeviceName(dosDeviceName); Console.WriteLine("\n\tGetVolumeGuidForNtDeviceName(): [{0}]\n", driveGuidResult ?? "null"); Assert.AreEqual(deviceGuid, driveGuidResult); } if (logicalDriveCount == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
public void AlphaFS_Volume_EnumerateVolumeMountPoints_Local_Success() { UnitTestAssert.IsElevatedProcess(); UnitTestConstants.PrintUnitTestHeader(false); var cnt = 0; Console.WriteLine("Logical Drives\n"); // Get Logical Drives from UnitTestConstants.Local Host, .IsReady Drives only. foreach (var drive in Alphaleonis.Win32.Filesystem.Directory.GetLogicalDrives(false, true)) { try { // Logical Drives --> Volumes --> Volume Mount Points. var uniqueVolName = Alphaleonis.Win32.Filesystem.Volume.GetUniqueVolumeNameForPath(drive); if (!Alphaleonis.Utils.IsNullOrWhiteSpace(uniqueVolName) && !uniqueVolName.Equals(drive, StringComparison.OrdinalIgnoreCase)) { foreach (var mountPoint in Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumeMountPoints(uniqueVolName).Where(mp => !Alphaleonis.Utils.IsNullOrWhiteSpace(mp))) { string guid = null; try { guid = Alphaleonis.Win32.Filesystem.Volume.GetVolumeGuid(System.IO.Path.Combine(drive, mountPoint)); } catch (Exception ex) { Console.WriteLine("\n\tCaught (UNEXPECTED #1) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\t#{0:000}\tLogical Drive: [{1}]\tGUID: [{2}]\n\t\tDestination : [{3}]\n", ++cnt, drive, guid ?? "null", mountPoint); } } } catch (Exception ex) { Console.WriteLine("\n\tCaught (UNEXPECTED #2) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } } if (cnt == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
private void AlphaFS_Device_EnumerateDevices() { UnitTestConstants.PrintUnitTestHeader(false); var tempPath = Environment.MachineName; var classCnt = 0; foreach (var deviceClass in EnumMemberToList <Alphaleonis.Win32.Filesystem.DeviceGuid>()) { Console.WriteLine("#{0:000}\tClass: [{1}]", ++classCnt, deviceClass); foreach (var device in Alphaleonis.Win32.Filesystem.Device.EnumerateDevices(tempPath, deviceClass)) { UnitTestConstants.Dump(device); } Console.WriteLine(); } if (classCnt == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
public void AlphaFS_Volume_GetXxx_Local_Success() { UnitTestConstants.PrintUnitTestHeader(false); var deviceNamePrefix = Alphaleonis.Win32.Filesystem.Path.DevicePrefix + "HarddiskVolume"; var volumePrefix = Alphaleonis.Win32.Filesystem.Path.VolumePrefix + "{"; var logicalDriveCount = 0; foreach (var logicalDrive in System.IO.DriveInfo.GetDrives()) { Console.WriteLine("#{0:000}\tInput Logical Drive Path: [{1}]\n", ++logicalDriveCount, logicalDrive.Name); if (logicalDrive.DriveType == System.IO.DriveType.CDRom) { Console.WriteLine(); continue; } // GetVolumeDeviceName: "C:\" --> "\Device\HarddiskVolume4" var deviceNameFromLogicalDrive = Alphaleonis.Win32.Filesystem.Volume.GetVolumeDeviceName(logicalDrive.Name); Console.WriteLine("\tGetVolumeDeviceName\t\t\t: [{0}]", deviceNameFromLogicalDrive); Assert.IsNotNull(deviceNameFromLogicalDrive); // Skip mapped drives and network drives. if (logicalDrive.DriveType != System.IO.DriveType.NoRootDirectory && logicalDrive.DriveType != System.IO.DriveType.Network) { Assert.IsTrue(deviceNameFromLogicalDrive.StartsWith(deviceNamePrefix)); // GetVolumeGuid: "C:\" --> "\\?\Volume{db5044f9-bd1f-4243-ab97-4b985eb29e80}\" var volumeGuidFromLogicalDrive = Alphaleonis.Win32.Filesystem.Volume.GetVolumeGuid(logicalDrive.Name); Console.WriteLine("\tGetVolumeGuid\t\t\t\t: [{0}]", volumeGuidFromLogicalDrive); Assert.IsNotNull(volumeGuidFromLogicalDrive); Assert.IsTrue(volumeGuidFromLogicalDrive.StartsWith(volumePrefix)); // GetUniqueVolumeNameForPath: "C:\" --> "\\?\Volume{db5044f9-bd1f-4243-ab97-4b985eb29e80}\" var uniqueVolumeNameFromlDriveInputPath = Alphaleonis.Win32.Filesystem.Volume.GetUniqueVolumeNameForPath(logicalDrive.Name); Console.WriteLine("\tGetUniqueVolumeNameForPath\t: [{0}]", uniqueVolumeNameFromlDriveInputPath); Assert.IsNotNull(uniqueVolumeNameFromlDriveInputPath); Assert.IsTrue(uniqueVolumeNameFromlDriveInputPath.StartsWith(volumePrefix)); } // GetVolumePathName: "C:\" or "C:\Windows" --> "C:\" var volumePathNameFromLogicalDrive = Alphaleonis.Win32.Filesystem.Volume.GetVolumePathName(logicalDrive.Name); Console.WriteLine("\tGetVolumePathName\t\t\t: [{0}]\n", volumePathNameFromLogicalDrive); Assert.IsNotNull(volumePathNameFromLogicalDrive); Assert.AreEqual(logicalDrive.Name, volumePathNameFromLogicalDrive); } if (logicalDriveCount == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }
public void AlphaFS_DfsInfo() { var cnt = 0; var noDomainConnection = true; try { foreach (var dfsNamespace in Host.EnumerateDomainDfsRoot()) { noDomainConnection = false; try { Console.Write("\n#{0:000}\tDFS Root: [{1}]\n", ++cnt, dfsNamespace); var dfsInfo = Host.GetDfsInfo(dfsNamespace); UnitTestConstants.Dump(dfsInfo); Console.Write("\n\tNumber of Storages: [{0}]\n", dfsInfo.StorageInfoCollection.Count()); foreach (var store in dfsInfo.StorageInfoCollection) { UnitTestConstants.Dump(store); } Console.WriteLine(); } catch (NetworkInformationException ex) { Console.WriteLine("\n\tNetworkInformationException #1: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\n\t(1) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } } if (cnt == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } } catch (NetworkInformationException ex) { Console.WriteLine("\n\tNetworkInformationException #2: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\n\t(2) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } if (noDomainConnection) { UnitTestAssert.Inconclusive("Test ignored because the computer is either not connected to a domain or no DFS root exists."); } if (cnt == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } Console.WriteLine(); }
public void AlphaFS_Host_EnumerateDfsRoot_Network_Success() { UnitTestConstants.PrintUnitTestHeader(true); var cnt = 0; var noDomainConnection = true; // Drill down to get servers from the first namespace retrieved. try { foreach (var dfsName in Alphaleonis.Win32.Network.Host.EnumerateDomainDfsRoot()) { noDomainConnection = false; Console.Write("#{0:000}\tDFS Root: [{1}]\n", ++cnt, dfsName); try { var dfsInfo = Alphaleonis.Win32.Network.Host.GetDfsInfo(dfsName); foreach (var storage in dfsInfo.StorageInfoCollection) { var cnt2 = 0; Console.Write("\n\tEnumerating DFS Namespaces from host: [{0}]\n", storage.ServerName); foreach (var dfsNamespace in Alphaleonis.Win32.Network.Host.EnumerateDfsRoot(storage.ServerName, true)) { Console.Write("\t#{0:000}\tDFS Root: [{1}]\n", ++cnt2, dfsNamespace); } } } catch (NetworkInformationException ex) { Console.WriteLine("NetworkInformationException #1: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\n\tCaught (UNEXPECTED #1) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine(); } if (cnt == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } } catch (NetworkInformationException ex) { Console.WriteLine("NetworkInformationException #2: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("Caught (UNEXPECTED #2) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } if (noDomainConnection) { UnitTestAssert.Inconclusive("Test ignored because the computer is either not connected to a domain or no DFS root exists."); } else if (cnt == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } Console.WriteLine(); }
public void AlphaFS_Volume_GetUniqueVolumeNameForPath_Local_Success() { UnitTestConstants.PrintUnitTestHeader(false); var logicalDriveCount = 0; foreach (var driveInfo in System.IO.DriveInfo.GetDrives()) { // Skip mapped drives and network drives. if (driveInfo.DriveType == System.IO.DriveType.NoRootDirectory || driveInfo.DriveType == System.IO.DriveType.Network) { continue; } var driveName = driveInfo.Name; var deviceGuid = Alphaleonis.Win32.Filesystem.Volume.GetVolumeGuid(driveName); Console.WriteLine("#{0:000}\tInput Path: [{1}]", ++logicalDriveCount, driveName); var volumeNameResult = Alphaleonis.Win32.Filesystem.Volume.GetUniqueVolumeNameForPath(driveName); Console.WriteLine("\n\tGetUniqueVolumeNameForPath: [{0}]", volumeNameResult ?? "null"); // Typically, only one mount point exists so the Volume GUIDs will match. Assert.AreEqual(deviceGuid, volumeNameResult); var pathNames = Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumePathNames(volumeNameResult).ToArray(); foreach (var uniqueName in pathNames) { Console.WriteLine("\n\tUnique name: [{0}]", uniqueName); try { var targetInfo = Alphaleonis.Win32.Filesystem.Directory.GetLinkTargetInfo(uniqueName); UnitTestConstants.Dump(targetInfo); Assert.AreEqual(deviceGuid, Alphaleonis.Win32.Filesystem.Path.LongPathPrefix + targetInfo.SubstituteName.Replace(Alphaleonis.Win32.Filesystem.Path.NonInterpretedPathPrefix, string.Empty)); } catch { if (!string.IsNullOrWhiteSpace(uniqueName)) { Assert.AreEqual(driveName, uniqueName); } } } Console.WriteLine(); } if (logicalDriveCount == 0) { UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty(); } }