public void When_network_setup_is_requested_it_must_send_operation() { // Arrange var deviceAddress = new WirelessNetworkAddress("AABBCC"); const bool setMembership = true; const DeviceRoles roles = DeviceRoles.Keypad; using var testRunner = new CirceUsbLoopbackTestRunner <NetworkSetupOperation>(); testRunner.RemoteSessionManager.ConnectionStateChanged += (_, e) => { if (e.State == ControllerConnectionState.Connected) { testRunner.RemoteSessionManager.NetworkSetupAsync(deviceAddress, setMembership, roles); } }; testRunner.OperationReceived += (_, e) => { if (e.Operation is NetworkSetupOperation networkSetupOperation) { testRunner.SignalSucceeded(networkSetupOperation); } }; // Act bool succeeded = testRunner.Start(); // Assert succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>"); testRunner.Result.ShouldNotBeNull(); testRunner.Result.DestinationAddress.Should().Be(deviceAddress); testRunner.Result.SetMembership.Should().Be(setMembership); testRunner.Result.Roles.Should().Be(roles); }
public Task NetworkSetupAsync([NotNull] WirelessNetworkAddress destinationAddress, bool joinNetwork, DeviceRoles roles, CancellationToken cancellationToken = default(CancellationToken)) { Guard.NotNull(destinationAddress, nameof(destinationAddress)); var operation = new NetworkSetupOperation(destinationAddress, joinNetwork, roles); return sessionGuard.SendAsync(operation, cancellationToken); }
public NetworkSetupEventArgs([NotNull] WirelessNetworkAddress destinationAddress, bool joinNetwork, DeviceRoles roles, CancellationToken cancelToken) { Guard.NotNull(destinationAddress, nameof(destinationAddress)); DestinationAddress = destinationAddress; JoinNetwork = joinNetwork; Roles = roles; CancelToken = cancelToken; }
public DeviceRolePageViewModel() { AddCmd = new AuthCommand(AddDeviceController); ModifyCmd = new AuthCommand(ModifyDeviceController); DeleteCmd = new AuthCommand(DeleteDeviceController); var viewmodels = DeviceRoles.Select(x => new DeviceRoleViewModel(x)); DeviceRoleViewModels = new ObservableCollection <DeviceRoleViewModel>(viewmodels); }
private DeviceRole InitDeviceRole() { var config = _sysConfigRepository.Query(new Hashtable()).FirstOrDefault(x => x.Name == ConstStrings.DataSyncDefaultRole); if (config != null && !string.IsNullOrWhiteSpace(config.Value)) { return(DeviceRoles.FirstOrDefault(x => x.DeviceRoleID == config.Value.ToInt32())); } else { return(DeviceRoles.First()); } }
public MMDevice GetDefaultRecordingDevice(DeviceRoles deviceRole) { switch (deviceRole) { case DeviceRoles.Multimedia: return(_mmDeviceCache.Find(x => x.IsMultimediaDefault && x.DataFlow == DataFlows.Capture)); case DeviceRoles.Communication: return(_mmDeviceCache.Find(x => x.IsCommunicationsDefault && x.DataFlow == DataFlows.Capture)); } return(null); }
public void When_notify_status_operation_is_received_it_must_raise_event_for_added_device() { // Arrange var deviceAddress = new WirelessNetworkAddress("AABBCC"); const bool getMembership = true; const DeviceCapabilities capabilities = DeviceCapabilities.ControlKeypad | DeviceCapabilities.NumericKeypad | DeviceCapabilities.StartSensor | DeviceCapabilities.FinishSensor | DeviceCapabilities.IntermediateSensor; const DeviceRoles roles = DeviceRoles.StartTimer | DeviceRoles.FinishTimer; const int signalStrength = 25; const int batteryStatus = 83; const bool isAligned = true; const ClockSynchronizationStatus clockSynchronization = ClockSynchronizationStatus.RequiresSync; const bool hasVersionMismatch = false; using var testRunner = new CirceUsbLoopbackTestRunner <DeviceStatus>(); testRunner.RemoteSessionManager.ConnectionStateChanged += (_, e) => { if (e.State == ControllerConnectionState.Connected) { testRunner.Connection.Send(new NotifyStatusOperation(deviceAddress, getMembership, capabilities, roles, signalStrength) { BatteryStatus = batteryStatus, IsAligned = isAligned, ClockSynchronization = clockSynchronization, HasVersionMismatch = false }); } }; testRunner.RemoteSessionManager.DeviceTracker.DeviceAdded += (_, e) => testRunner.SignalSucceeded(e.Argument); // Act bool succeeded = testRunner.Start(); // Assert succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>"); testRunner.Result.ShouldNotBeNull(); testRunner.Result.DeviceAddress.Should().Be(deviceAddress); testRunner.Result.IsInNetwork.Should().Be(getMembership); testRunner.Result.Capabilities.Should().Be(capabilities); testRunner.Result.Roles.Should().Be(roles); testRunner.Result.SignalStrength.Should().Be(signalStrength); testRunner.Result.BatteryStatus.Should().Be(batteryStatus); testRunner.Result.IsAligned.Should().Be(isAligned); testRunner.Result.ClockSynchronization.Should().Be(clockSynchronization); testRunner.Result.HasVersionMismatch.Should().Be(hasVersionMismatch); }
public void SetDefaultEndpoint(string devID, DeviceRoles eRole) { if (_PolicyConfig != null) { Marshal.ThrowExceptionForHR(_PolicyConfig.SetDefaultEndpoint(devID, eRole)); return; } if (_PolicyConfigVista != null) { Marshal.ThrowExceptionForHR(_PolicyConfigVista.SetDefaultEndpoint(devID, eRole)); return; } if (_PolicyConfig10 != null) { Marshal.ThrowExceptionForHR(_PolicyConfig10.SetDefaultEndpoint(devID, eRole)); } }
private static DeviceRoles ReduceRolesToComplyWith(DeviceCapabilities capabilities, DeviceRoles roles) { var allowed = DeviceRoles.None; if ((capabilities & DeviceCapabilities.ControlKeypad) != 0) { allowed |= DeviceRoles.Keypad; } if ((capabilities & DeviceCapabilities.StartSensor) != 0 || (capabilities & DeviceCapabilities.TimeSensor) != 0) { allowed |= DeviceRoles.StartTimer; } if ((capabilities & DeviceCapabilities.IntermediateSensor) != 0 || (capabilities & DeviceCapabilities.TimeSensor) != 0) { allowed |= IntermediateTimers; } if ((capabilities & DeviceCapabilities.FinishSensor) != 0 || (capabilities & DeviceCapabilities.TimeSensor) != 0) { allowed |= DeviceRoles.FinishTimer; } if ((capabilities & DeviceCapabilities.Display) != 0) { allowed |= DeviceRoles.Display; } return(roles & allowed); }
public DeviceStatus(WirelessNetworkAddress deviceAddress, bool isInNetwork, DeviceCapabilities capabilities, DeviceRoles roles, int signalStrength, int?batteryStatus, bool?isAligned, ClockSynchronizationStatus?clockSynchronization, bool?hasVersionMismatch) { Guard.NotNull(deviceAddress, nameof(deviceAddress)); DeviceAddress = deviceAddress; IsInNetwork = isInNetwork; Capabilities = capabilities; Roles = ReduceRolesToComplyWith(capabilities, roles); SignalStrength = signalStrength; BatteryStatus = batteryStatus; IsAligned = isAligned; ClockSynchronization = clockSynchronization; HasVersionMismatch = hasVersionMismatch; }
public DeviceStatus ChangeRoles(DeviceRoles roles) { return(new(DeviceAddress, IsInNetwork, Capabilities, roles, SignalStrength, BatteryStatus, IsAligned, ClockSynchronization, HasVersionMismatch)); }
public DeviceRolesWithCapabilities(DeviceCapabilities capabilities, DeviceRoles roles) { Capabilities = capabilities; Roles = roles; }
private static string GetDefaultDeviceId(IMMDeviceEnumerator deviceEnumerator, DataFlows dataFlow, DeviceRoles role) { IMMDevice _device = null; Marshal.ThrowExceptionForHR(deviceEnumerator.GetDefaultAudioEndpoint(dataFlow, role, out _device)); string ID; Marshal.ThrowExceptionForHR(_device.GetId(out ID)); return(ID); }
public NetworkCompositionBuilder WithDeviceInRoles(WirelessNetworkAddress deviceAddress, DeviceCapabilities capabilities, DeviceRoles roles) { composition = composition.ChangeRolesFor(deviceAddress, capabilities, roles); return(this); }
private static int DecodeNextBlock(System.IO.Stream buffer, ushort dcp_length, out KeyValuePair <BlockOptions, object> block) { int ret = 0; BlockOptions options; UInt16 dcp_block_length; UInt16 block_info = 0; UInt16 tmp, tmp2; string str; object content; ResponseStatus set_response; if (buffer.Position >= buffer.Length || dcp_length <= 0) { block = new KeyValuePair <BlockOptions, object>(0, null); return(ret); } ret += DecodeBlock(buffer, out options, out dcp_block_length); if (dcp_block_length >= 2) { ret += DecodeU16(buffer, out block_info); } dcp_block_length -= 2; switch (options) { case BlockOptions.DeviceProperties_NameOfStation: ret += DecodeString(buffer, dcp_block_length, out str); content = str; break; case BlockOptions.IP_IPParameter: byte[] ip, subnet, gateway; ret += DecodeOctets(buffer, 4, out ip); ret += DecodeOctets(buffer, 4, out subnet); ret += DecodeOctets(buffer, 4, out gateway); content = new IpInfo((BlockInfo)block_info, ip, subnet, gateway);; break; case BlockOptions.DeviceProperties_DeviceID: ret += DecodeU16(buffer, out tmp); ret += DecodeU16(buffer, out tmp2); content = new DeviceIdInfo(tmp, tmp2); break; case BlockOptions.DeviceProperties_DeviceOptions: BlockOptions[] option_list = new BlockOptions[dcp_block_length / 2]; for (int i = 0; i < option_list.Length; i++) { ret += DecodeU16(buffer, out tmp); option_list[i] = (BlockOptions)tmp; } content = option_list; break; case BlockOptions.DeviceProperties_DeviceRole: DeviceRoles roles = (DeviceRoles)buffer.ReadByte(); buffer.ReadByte(); //padding ret += 2; content = new DeviceRoleInfo(roles); break; case BlockOptions.DeviceProperties_DeviceVendor: ret += DecodeString(buffer, dcp_block_length, out str); content = str; break; case BlockOptions.Control_Response: set_response = new ResponseStatus(); set_response.Option = (BlockOptions)block_info; set_response.Error = (BlockErrors)buffer.ReadByte(); ret++; content = set_response; break; default: byte[] arr; ret += DecodeOctets(buffer, dcp_block_length, out arr); content = arr; break; } block = new KeyValuePair <BlockOptions, object>(options, content); //padding if ((dcp_block_length % 2) != 0) { buffer.ReadByte(); ret++; } return(ret); }
public DeviceRoleInfo(DeviceRoles device_role) { DeviceRole = device_role; }
/// <summary> /// Initializes a new instance of the <see cref="NotifyStatusOperation" /> class with required parameters. /// </summary> /// <param name="originatingAddress"> /// The originating address of the device in the wireless network. /// </param> /// <param name="getMembership"> /// Indicates whether the device is part of the logical network configuration. /// </param> /// <param name="capabilities"> /// The capabilities that the device can perform. /// </param> /// <param name="roles"> /// The subset of <paramref name="capabilities" /> that the device currently performs in the logical network. /// </param> /// <param name="signalStrength"> /// The wireless signal strength. Higher values indicate a better signal. /// </param> public NotifyStatusOperation([NotNull] WirelessNetworkAddress originatingAddress, bool getMembership, DeviceCapabilities capabilities, DeviceRoles roles, int signalStrength) : this() { Guard.NotNull(originatingAddress, nameof(originatingAddress)); OriginatingAddress = originatingAddress; GetMembership = getMembership; Capabilities = capabilities; Roles = roles; SignalStrength = signalStrength; }
private void SetDefault(MMDevice mmDevice, DeviceRoles deviceRole) { var client = new PolicyConfigClient(); client.SetDefaultEndpoint(mmDevice.Id, deviceRole); }
/// <summary> /// Initializes a new instance of the <see cref="NetworkSetupOperation" /> class with required parameters. /// </summary> /// <param name="destinationAddress"> /// The destination address of the device in the wireless network. /// </param> /// <param name="setMembership"> /// Instructs whether the destination device must be part of the logical network configuration or not. Set to <c>true</c> /// to join network or <c>false</c> to leave network. /// </param> /// <param name="roles"> /// The subset of capabilities that a device performs or is going to perform in the logical network. /// </param> public NetworkSetupOperation([NotNull] WirelessNetworkAddress destinationAddress, bool setMembership, DeviceRoles roles) : this() { Guard.NotNull(destinationAddress, nameof(destinationAddress)); DestinationAddress = destinationAddress; SetMembership = setMembership; Roles = roles; }