///// <summary> ///// Task will query provided device for 'Drive geometry' function ///// </summary> ///// <param name="device"><see cref="SystemDevice"/> to query</param> ///// <param name="token">Cancellation token</param> ///// <returns>Task that result in Nullable <see cref="DISK_GEOMETRY_EX"/> structure</returns> //protected Task<Nullable<DISK_GEOMETRY_EX>> GetDriveGeometry(SystemDevice device, CancellationToken token) //{ // return Task.Factory.StartNew<Nullable<DISK_GEOMETRY_EX>>(() => // { // DISK_GEOMETRY_EX diskGeometry; // token.ThrowIfCancellationRequested(); // try // { // diskGeometry = base.GetDriveGeometry(device); // return diskGeometry; // } // catch (Exception) // { // return null; // } // } // , token); //} /// <summary> /// Sets the volume information. /// </summary> /// <param name="device"><see cref="SystemVolume"/> to query</param> /// <param name="token">Cancellation token</param> /// <returns>Task the will do the job</returns> protected Task SetVolumeInformation(SystemVolume device, CancellationToken token) { return(Task.Factory.StartNew(() => { token.ThrowIfCancellationRequested(); base.SetVolumeInformation(device); } , token)); }
public void Respond(TransactionController controller, object state) { MessageAdapter.CreateAnsHandler(new AnsData() { AnsType = CmdMsgHandler.CMD_VOLUME, AnsStatus = status, AnsValue = Convert.ToString((int)SystemVolume.GetMasterVolume()), AnsMsg = "音量调节成功", })?.Respond(controller, state); }
public static HttpVolumeControllerServer GetOrCreateServer(int minPort, SystemVolume sysVol) { if (minPort < 1024 || minPort > ushort.MaxValue) { throw new ArgumentOutOfRangeException(nameof(minPort)); } if (_server != null && !_server.disposedValue) { return(_server); } _server = new HttpVolumeControllerServer(GetAvailablePort(minPort), sysVol); return(_server); }
public void Handle(TransactionController controller, object state) { if (enable) { SystemVolume.SetMasterVolume(value); if (value == (int)SystemVolume.GetMasterVolume()) { status = true; } Respond(controller, state); } Logging.Info("Handle 音量调节"); }
private HttpVolumeControllerServer(int port, SystemVolume sysVol) { _listener = new HttpListener(); var serAddr = $"http://+:{port.ToString()}/volume/"; _cmdArgAddUrl = $"http add urlacl url={serAddr} user={WindowsIdentity.GetCurrent().Name}"; _cmdArgDelUrl = $"http delete urlacl url={serAddr}"; _listener.Prefixes.Add(serAddr); _sysVol = sysVol; ServerAddress = $"http://{Utilities.GetLocalIP()}:{port}/volume"; _port = port; }
/// <summary> /// Automute the system volume. /// Mute when one device is playng, Unmute when no one is playing. /// </summary> public void AutoMute(bool playing) { if (mainForm.GetAutoMute()) { if (playing) { SystemVolume.Mute(true, mainForm); isMuted = true; } else if (!playing && !IsAnyDevicePlaying() && isMuted) { SystemVolume.Mute(false, mainForm); isMuted = false; } } }
/// <summary> /// Task will query provided device for 'Volume extents' function /// </summary> /// <param name="device"><see cref="SystemVolume"/> to query</param> /// <param name="token">Cancellation token</param> /// <returns>Task that result in <c>Nullable</c> <see cref="VOLUME_DISK_EXTENTS"/> structure</returns> protected Task <Nullable <VOLUME_DISK_EXTENTS> > GetVolumeDiskExtents(SystemVolume device, CancellationToken token) { token.ThrowIfCancellationRequested(); return(Task.Factory.StartNew <Nullable <VOLUME_DISK_EXTENTS> >(() => { VOLUME_DISK_EXTENTS?diskExtents; try { diskExtents = base.GetDiskExtendsForVolume(device); return diskExtents; } catch (Exception) { return null; } } , token)); }
/// <summary> /// Sets the volume information. /// </summary> /// <param name="device"><see cref="SystemVolume"/> to query</param> /// <exception cref="System.ComponentModel.Win32Exception"> /// Could not acquire volume information /// </exception> internal virtual void SetVolumeInformation(SystemVolume device) { StringBuilder volumeName = new StringBuilder(UnsafeNativeMethods.MAX_PATH + 1); uint lpVolumeSerialNumber = 0; uint lpMaximumComponentLength = 0; //FileSystemFlags lpFileSystemFlags = 0; uint lpFileSystemFlags = 0; StringBuilder lpFileSystemNameBuffer = new StringBuilder(UnsafeNativeMethods.MAX_PATH + 1); bool functionResult = false; if (string.IsNullOrEmpty(device.DevicePath)) { return; } if (DeviceIoControl <int> .IsAccessible(device) == false) { // Device is not accessible return; } functionResult = UnsafeNativeMethods.GetVolumeInformation(device.DevicePath, volumeName, Convert.ToUInt32(volumeName.Capacity), out lpVolumeSerialNumber, out lpMaximumComponentLength, out lpFileSystemFlags, lpFileSystemNameBuffer, Convert.ToUInt32(lpFileSystemNameBuffer.Capacity)); if (functionResult == false) { throw new Win32Exception("Could not acquire volume information", new Win32Exception(Marshal.GetLastWin32Error())); } device.SerialNumber = lpVolumeSerialNumber; device.FileSystemName = lpFileSystemNameBuffer.ToString(); }
public static HttpVolumeControllerServer GetOrCreateServer(SystemVolume sysVol) => GetOrCreateServer(MIN_DYANMIC_PORT, sysVol);
/// <summary> /// Task will query provided device for 'Drive layout' function /// </summary> /// <param name="device"><see cref="SystemVolume"/> to query</param> /// <param name="token">Cancellation token</param> /// <returns>Task that result in Nullable <see cref="DRIVE_LAYOUT_INFORMATION_EX"/> structure</returns> protected Task <Tuple <DRIVE_LAYOUT_INFORMATION_EX, PARTITION_INFORMATION_EX[]> > GetDriveLayout(SystemVolume device, CancellationToken token) { return(Task.Factory.StartNew <Tuple <DRIVE_LAYOUT_INFORMATION_EX, PARTITION_INFORMATION_EX[]> >(() => { Tuple <DRIVE_LAYOUT_INFORMATION_EX, PARTITION_INFORMATION_EX[]> driveLayout; token.ThrowIfCancellationRequested(); try { driveLayout = base.GetDriveLayout(device); return driveLayout; } catch (Exception) { return null; } } , token)); }
/// <summary> /// Function will calculate/read 'Layout information' for provided <see cref="SystemVolume"/> /// </summary> /// <param name="device"><see cref="SystemVolume"/> to query</param> /// <returns>Tuple of <see cref="DRIVE_LAYOUT_INFORMATION_EX"/> and array of <see cref="PARTITION_INFORMATION_EX"/></returns> /// <remarks>MSDN: http://msdn.microsoft.com/en-us/library/aa365174(v=vs.85).aspx </remarks> internal virtual Tuple <DRIVE_LAYOUT_INFORMATION_EX, PARTITION_INFORMATION_EX[]> GetDriveLayout(SystemVolume device) { DeviceIoControl <DRIVE_LAYOUT_INFORMATION_EX> deviceControl = new DeviceIoControl <DRIVE_LAYOUT_INFORMATION_EX>(); return(deviceControl.GetDriveLayout(device)); }
/// <summary> /// Function will all physical disk that 'volume' is extended/spanned on it /// </summary> /// <remarks>MSDN: http://msdn.microsoft.com/en-us/library/aa365194(v=vs.85).aspx </remarks> /// <param name="device"><see cref="SystemVolume"/> to query</param> /// <returns><see cref="VOLUME_DISK_EXTENTS"/> structure that volume extends on</returns> internal virtual Nullable <VOLUME_DISK_EXTENTS> GetDiskExtendsForVolume(SystemVolume device) { DeviceIoControl <VOLUME_DISK_EXTENTS> deviceControl = new DeviceIoControl <VOLUME_DISK_EXTENTS>(); return(deviceControl.GetDataForDevice(device, IoControlCode.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS)); }