private async void OnDeviceAdded(DeviceWatcher deviceWatcher, DeviceInformation deviceInfo) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { DiscoveredDevices.Add(new DiscoveredDevice(deviceInfo)); }); }
/// <summary> /// Updates view. /// </summary> public override void UpdateView() { DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); if (devices != null) { View.DeviceManagementUrl = devices.ServiceAddress; View.IP = devices.DeviceAddress != null?devices.DeviceAddress.ToString() : string.Empty; if (_client != null && _client.Address != devices.ServiceAddress) { View.Clear(); } } else { View.DeviceManagementUrl = string.Empty; View.IP = string.Empty; View.Clear(); } DeviceEnvironment environment = ContextController.GetDeviceEnvironment(); if (_client != null) { _client.Timeout = environment.Timeouts.Message; } }
/// <summary> /// Checks if device address is not empty. /// </summary> /// <returns>True if device is selected and address is not empty.</returns> public bool DeviceNotEmpty() { DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); bool bHasAddress = devices != null && !string.IsNullOrEmpty(devices.ServiceAddress); return(bHasAddress); }
/// <summary> /// Collects parameters for launching current test/current test group/all selected tests /// </summary> /// <returns></returns> public TestSuiteParameters GetParameters() { TestSuiteParameters parameters = new TestSuiteParameters(); DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); parameters.Address = devices.ServiceAddress; parameters.CameraIP = devices.DeviceAddress; parameters.NetworkInterfaceController = devices.NIC; if ((devices.Current != null) && (devices.Current.ByDiscovery != null)) { parameters.CameraUUID = devices.Current.ByDiscovery.UUID; } DeviceEnvironment env = ContextController.GetDeviceEnvironment(); parameters.UserName = env.Credentials.UserName; parameters.Password = env.Credentials.Password; parameters.UseUTCTimestamp = env.Credentials.UseUTCTimeStamp; DeviceEnvironment environment = ContextController.GetDeviceEnvironment(); parameters.MessageTimeout = environment.Timeouts.Message; parameters.RebootTimeout = environment.Timeouts.Reboot; parameters.TimeBetweenTests = environment.Timeouts.InterTests; parameters.PTZNodeToken = environment.TestSettings.PTZNodeToken; parameters.EnvironmentSettings = new Tests.Common.TestEngine.EnvironmentSettings() { DnsIpv4 = env.EnvironmentSettings.DnsIpv4, NtpIpv4 = env.EnvironmentSettings.NtpIpv4, DnsIpv6 = env.EnvironmentSettings.DnsIpv6, NtpIpv6 = env.EnvironmentSettings.NtpIpv6, DefaultGateway = env.EnvironmentSettings.GatewayIpv4, DefaultGatewayIpv6 = env.EnvironmentSettings.GatewayIpv6 }; parameters.UseEmbeddedPassword = environment.TestSettings.UseEmbeddedPassword; parameters.Password1 = environment.TestSettings.Password1; parameters.Password2 = environment.TestSettings.Password2; parameters.SecureMethod = environment.TestSettings.SecureMethod; parameters.VideoSourceToken = environment.TestSettings.VideoSourceToken; parameters.OperationDelay = environment.TestSettings.OperationDelay; parameters.RecoveryDelay = environment.TestSettings.RecoveryDelay; parameters.EventTopic = environment.TestSettings.EventTopic; parameters.SubscriptionTimeout = environment.TestSettings.SubscriptionTimeout; parameters.TopicNamespaces = environment.TestSettings.TopicNamespaces; parameters.RelayOutputDelayTimeMonostable = environment.TestSettings.RelayOutputDelayTimeMonostable; Dictionary <string, object> advanced = new Dictionary <string, object>(); foreach (object o in environment.TestSettings.AdvancedSettings) { advanced.Add(o.GetType().GUID.ToString(), o); } parameters.AdvancedPrameters = advanced; return(parameters); }
protected override Task StartScanningForDevicesNativeAsync(Guid[] serviceUuids, bool allowDuplicatesKey, CancellationToken scanCancellationToken) { var hasFilter = serviceUuids?.Any() ?? false; DiscoveredDevices.Clear(); _BleWatcher = new BluetoothLEAdvertisementWatcher(); _BleWatcher.ScanningMode = BluetoothLEScanningMode.Active; _prevScannedDevices = new List <ulong>(); Trace.Message("Starting a scan for devices."); if (hasFilter) { //adds filter to native scanner if serviceUuids are specified foreach (var uuid in serviceUuids) { _BleWatcher.AdvertisementFilter.Advertisement.ServiceUuids.Add(uuid); } Trace.Message($"ScanFilters: {string.Join(", ", serviceUuids)}"); } //don't allow duplicates except for testing, results in multiple versions //of the same device being found if (allowDuplicatesKey) { _BleWatcher.Received += DeviceFoundAsyncDuplicate; } else { _BleWatcher.Received += DeviceFoundAsync; } _BleWatcher.Start(); return(Task.FromResult(true)); }
private void OnServiceAdded(object sender, ServiceAnnouncementEventArgs e) { ServiceAddedSemaphoreSlim.Wait(); try { var txtValues = e.Announcement.Txt .Select(i => i.Split('=')) .ToDictionary(y => y[0], y => y[1]); if (!txtValues.ContainsKey("fn")) { return; } var ip = e.Announcement.Addresses[0]; Uri.TryCreate("https://" + ip, UriKind.Absolute, out Uri myUri); var chromecast = new ChromecastReceiver { DeviceUri = myUri, Name = txtValues["fn"], Model = txtValues["md"], Version = txtValues["ve"], ExtraInformation = txtValues, Status = txtValues["rs"], Port = e.Announcement.Port }; ChromecastReceivedFound?.Invoke(this, chromecast); DiscoveredDevices.Add(chromecast); } finally { ServiceAddedSemaphoreSlim.Release(); } }
public List <IDevice> GetSystemConnectedOrPairedDevices(Guid[] services = null) { if (services != null) { return(DiscoveredDevices.Where(d => services.Contains(d.Id)).ToList()); } return(DiscoveredDevices.ToList()); }
/// <summary> /// Start GetDeviceInformation operation /// </summary> public void GetDeviceInformation() { DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); string url = devices.ServiceAddress; _requestPending = true; ReportOperationStarted(); InitializeClient(url); _client.GetDeviceInformation(); }
/// <summary> /// Updates setup tab control /// </summary> public override void UpdateView() { base.UpdateView(); if (CurrentState == Enums.ApplicationState.Idle) { DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); bool enable = (devices != null) && !string.IsNullOrEmpty(devices.ServiceAddress); View.EnableGetFromDevice(enable); } }
/// <summary> /// Returns service addresses /// </summary> public void GetAddress(Onvif.CapabilityCategory[] categories) { DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); _deviceClientWorking = true; string address = devices != null ? devices.ServiceAddress : string.Empty; InitializeDeviceClient(address); _deviceClient.GetCapabilities(categories); }
/// <summary> /// Returns media service address /// </summary> public void GetMediaAddress() { DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); _deviceClientWorking = true; string address = devices != null ? devices.ServiceAddress : string.Empty; InitializeDeviceClient(address); _deviceClient.GetCapabilities(new Device.CapabilityCategory[] { Device.CapabilityCategory.Media }); }
private void DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { var deviceId = Device.DeviceIdentifierToGuid(e.Peripheral.Identifier); if (DiscoveredDevices.All(x => x.Id != deviceId)) { var device = new Device(e.Peripheral); DiscoveredDevices.Add(device); DeviceDiscovered(this, new DeviceDiscoveredEventArgs(device)); } }
/// <summary> /// Raises the le scan event. /// </summary> /// <param name="bleDevice">The BLE device that was discovered.</param> /// <param name="rssi">Rssi.</param> /// <param name="scanRecord">Scan record.</param> public void OnLeScan(BluetoothDevice bleDevice, int rssi, byte[] scanRecord) { var deviceId = Device.DeviceIdFromAddress(bleDevice.Address); if (DiscoveredDevices.All(x => x.Id != deviceId)) { var device = new Device(bleDevice, null, null, rssi, scanRecord); DiscoveredDevices.Add(device); DeviceDiscovered(this, new DeviceDiscoveredEventArgs(device)); } }
private async void OnDeviceRemoved(DeviceWatcher deviceWatcher, DeviceInformationUpdate deviceInfoUpdate) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { foreach (DiscoveredDevice discoveredDevice in DiscoveredDevices) { if (discoveredDevice.DeviceInfo.Id == deviceInfoUpdate.Id) { DiscoveredDevices.Remove(discoveredDevice); break; } } }); }
/// <summary> /// Returns service addresses /// </summary> public void GetAddress(CapabilityCategory[] categories) { DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); _deviceClientWorking = true; string address = devices != null ? devices.ServiceAddress : string.Empty; InitializeDeviceClient(address); DebugInfo info = ContextController.GetDebugInfo(); bool capabilitiesStyle = (info.CapabilitiesExchange == CapabilitiesExchangeStyle.GetCapabilities); _deviceClient.GetServiceAddresses(capabilitiesStyle, categories); }
public void EnableControls(bool enable) { Invoke(new Action(() => { DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); string address = devices != null ? devices.ServiceAddress : string.Empty; bool testProfileSelected = false; if (cmbMediaProfile.SelectedItem != null) { testProfileSelected = IsTestProfile(((MediaProfileWrapper)cmbMediaProfile.SelectedItem).Profile); } btnGetMediaUrl.Enabled = enable && !string.IsNullOrEmpty(address); btnGetMediaUrl.Refresh(); btnGetProfiles.Enabled = enable && !string.IsNullOrEmpty(MediaAddress); btnGetProfiles.Refresh(); btnDeleteProfile.Enabled = enable && testProfileSelected; btnDeleteProfile.Refresh(); buttonGetVideoSources.Enabled = testProfileSelected && enable && !string.IsNullOrEmpty(MediaAddress); buttonGetVideoSources.Refresh(); buttonGetVideoEncoders.Enabled = testProfileSelected && enable && !string.IsNullOrEmpty(MediaAddress); buttonGetVideoEncoders.Refresh(); buttonGetVideoCodecs.Enabled = buttonGetVideoEncoders.Enabled && (cmbVideoEncoder.SelectedItem != null); buttonGetVideoCodecs.Refresh(); buttonGetAudioSources.Enabled = testProfileSelected && enable && !string.IsNullOrEmpty(MediaAddress); buttonGetAudioSources.Refresh(); buttonGetAudioEncoders.Enabled = testProfileSelected && enable && !string.IsNullOrEmpty(MediaAddress); buttonGetAudioEncoders.Refresh(); buttonGetAudioCodecs.Enabled = buttonGetAudioEncoders.Enabled && (cmbAudioEncoder.SelectedItem != null); buttonGetAudioCodecs.Refresh(); btnGetStreams.Enabled = (enable && cmbVideoResolution.SelectedItem != null) || (_videoWindow != null); cmbMediaProfile.Enabled = enable; cmbAudioCodec.Enabled = testProfileSelected && enable; cmbAudioEncoder.Enabled = testProfileSelected && enable; cmbAudioSource.Enabled = testProfileSelected && enable; cmbVideoCodec.Enabled = testProfileSelected && enable; cmbVideoEncoder.Enabled = testProfileSelected && enable; cmbVideoResolution.Enabled = testProfileSelected && enable; txtVideoBitrate.Enabled = testProfileSelected && enable && (cmbVideoCodec.SelectedItem != null); txtVideoFramerate.Enabled = testProfileSelected && enable && (cmbVideoCodec.SelectedItem != null); cmbVideoSource.Enabled = testProfileSelected && enable; cmbAudioBitrate.Enabled = testProfileSelected && enable; cmbTransport.Enabled = testProfileSelected && enable; btnGetStreams.Refresh(); })); }
private void btnWatcher_Click(object sender, RoutedEventArgs e) { if (_fWatcherStarted == false) { _publisher.Start(); if (_publisher.Status != WiFiDirectAdvertisementPublisherStatus.Started) { rootPage.NotifyUser("Failed to start advertisement.", NotifyType.ErrorMessage); return; } DiscoveredDevices.Clear(); rootPage.NotifyUser("Finding Devices...", NotifyType.StatusMessage); String deviceSelector = WiFiDirectDevice.GetDeviceSelector( Utils.GetSelectedItemTag <WiFiDirectDeviceSelectorType>(cmbDeviceSelector)); _deviceWatcher = DeviceInformation.CreateWatcher(deviceSelector, new string[] { "System.Devices.WiFiDirect.InformationElements" }); _deviceWatcher.Added += OnDeviceAdded; _deviceWatcher.Removed += OnDeviceRemoved; _deviceWatcher.Updated += OnDeviceUpdated; _deviceWatcher.EnumerationCompleted += OnEnumerationCompleted; _deviceWatcher.Stopped += OnStopped; _deviceWatcher.Start(); btnWatcher.Content = "Stop Watcher"; _fWatcherStarted = true; } else { _publisher.Stop(); btnWatcher.Content = "Start Watcher"; _fWatcherStarted = false; _deviceWatcher.Added -= OnDeviceAdded; _deviceWatcher.Removed -= OnDeviceRemoved; _deviceWatcher.Updated -= OnDeviceUpdated; _deviceWatcher.EnumerationCompleted -= OnEnumerationCompleted; _deviceWatcher.Stopped -= OnStopped; _deviceWatcher.Stop(); rootPage.NotifyUser("Device watcher stopped.", NotifyType.StatusMessage); } }
protected override async Task StartScanningForDevicesNativeAsync(Guid[] serviceUuids, CancellationToken scanCancellationToken) { // Wait for the PoweredOn state await WaitForState(CBCentralManagerState.PoweredOn, scanCancellationToken).ConfigureAwait(false); Trace.Message("Adapter: Starting a scan for devices."); CBUUID[] serviceCbuuids = null; if (serviceUuids != null && serviceUuids.Any()) { serviceCbuuids = serviceUuids.Select(u => CBUUID.FromString(u.ToString())).ToArray(); Trace.Message("Adapter: Scanning for " + serviceCbuuids.First()); } DiscoveredDevices.Clear(); _centralManager.ScanForPeripherals(serviceCbuuids); }
protected BluetoothLEManager() { CentralManager = new CBCentralManager(DispatchQueue.CurrentQueue); CentralManager.DiscoveredPeripheral += (object sender, CBDiscoveredPeripheralEventArgs e) => { Console.WriteLine("DiscoveredPeripheral: " + e.Peripheral.Name); DiscoveredDevices.Add(e.Peripheral); DeviceDiscovered(this, e); }; CentralManager.UpdatedState += (object sender, EventArgs e) => { Console.WriteLine("UpdatedState: " + CentralManager.State); }; CentralManager.ConnectedPeripheral += (object sender, CBPeripheralEventArgs e) => { Console.WriteLine("ConnectedPeripheral: " + e.Peripheral.Name); // When a peripheral gets connected, add that peripheral to our running list of // connected peripherals if (!ConnectedDevices.Contains(e.Peripheral)) { ConnectedDevices.Add(e.Peripheral); } // raise our connected event DeviceConnected(sender, e); }; CentralManager.DisconnectedPeripheral += (object sender, CBPeripheralErrorEventArgs e) => { Console.WriteLine("DisconnectedPeripheral: " + e.Peripheral.Name); // When a peripheral disconnects, remove it from our running list. if (ConnectedDevices.Contains(e.Peripheral)) { ConnectedDevices.Remove(e.Peripheral); } // Raise our disconnected event DeviceDisconnected(sender, e); }; }
/// <summary> /// Queries PTZ nodes /// </summary> public void GetPTZNodes() { DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); string address = devices != null ? devices.ServiceAddress : string.Empty; DeviceEnvironment env = ContextController.GetDeviceEnvironment(); ManagementServiceProvider deviceClient = new ManagementServiceProvider(address, env.Timeouts.Message); ReportOperationStarted(); Thread thread = new Thread(new ThreadStart(new Action(() => { try { Device.Capabilities capabilities = deviceClient.GetCapabilitiesSync(new Device.CapabilityCategory[] { Device.CapabilityCategory.PTZ }); if (capabilities.PTZ != null) { string ptzAddress = capabilities.PTZ.XAddr; PTZServiceProvider ptzClient = new PTZServiceProvider(ptzAddress, env.Timeouts.Message); PTZ.PTZNode[] nodes = ptzClient.GetNodes(); if ((nodes != null) && (nodes.Length > 0)) { View.SetPTZNodes(nodes); } else { throw new Exception("No PTZ nodes returned by device"); } } else { throw new Exception("Device does not support PTZ service"); } } catch (System.Exception ex) { View.ShowError(ex); } finally { ReportOperationCompleted(); } }))); thread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture; thread.Start(); }
/////////////////////////////////////////////////////////////////////////// //! @author Ivan Vagunin //// /// <summary> /// Saves context data. /// </summary> public void SaveContextData() { IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.Machine | IsolatedStorageScope.Application, new System.Security.Policy.Url("www.onvif.org/OnvifTestTool")); IsolatedStorageFileStream isoFile = new IsolatedStorageFileStream(_dataFileName, FileMode.Create, isoStore); // Create a StreamWriter using the isolated storage file StreamWriter writer = new StreamWriter(isoFile); XmlSerializer serializer = new XmlSerializer(typeof(SavedContext)); SavedContext context = new SavedContext(); _conformanceTestController.UpdateContext(); context.SetupInfo = ContextController.GetSetupInfo(); _discoveryController.UpdateContext(); DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); if (devices != null) { context.DiscoveryContext = new SavedDiscoveryContext(); context.DiscoveryContext.ServiceAddress = devices.ServiceAddress; context.DiscoveryContext.DeviceAddress = (devices.DeviceAddress != null) ? devices.DeviceAddress.ToString() : string.Empty; context.DiscoveryContext.SearchScopes = devices.SearchScopes.Replace(System.Environment.NewLine, " "); context.DiscoveryContext.ShowSearchOptions = devices.ShowSearchOptions; if ((devices.NIC != null) && (devices.NIC.IP != null)) { context.DiscoveryContext.InterfaceAddress = devices.NIC.IP.ToString(); } } _managementController.UpdateContext(); context.DeviceEnvironment = ContextController.GetDeviceEnvironment(); _deviceController.UpdateContext(); context.RequestsInfo = ContextController.GetRequestsInfo(); context.MediaInfo = ContextController.GetMediaInfo(); context.PTZInfo = ContextController.GetPTZInfo(); context.DebugInfo = ContextController.GetDebugInfo(); serializer.Serialize(writer, context); writer.Close(); }
/// <summary> /// Initializes service client, if it's possibly. /// </summary> /// <returns>True if client has been initialized successfully.</returns> bool InitializeClient() { string serviceAddress = string.Empty; DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); if (devices.Current != null) { serviceAddress = devices.ServiceAddress; } try { new Uri(serviceAddress); } catch (Exception) { View.ShowError("Device service address is invalid!"); return(false); } try { DeviceEnvironment env = ContextController.GetDeviceEnvironment(); _client = new ManagementServiceProvider(serviceAddress, env.Timeouts.Message); _client.ExceptionThrown += _client_ExceptionThrown; _client.OnDeviceInformationReceived += _client_OnDeviceInformationReceived; _client.OperationCompleted += _client_OperationCompleted; _client.OperationStarted += _client_OperationStarted; _client.ResponseReceived += _client_ResponseReceived; _client.Security = ContextController.GetDebugInfo().Security; return(true); } catch (Exception exc) { View.ShowError(string.Format("Error occurred: {0}", exc.Message)); return(false); } }
/// <summary> /// Handles button get device information click event /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event argument</param> private void btnGetDeviceInformation_Click(object sender, EventArgs e) { DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); string url = devices.ServiceAddress; if (!string.IsNullOrEmpty(url)) { try { Controller.GetDeviceInformation(); } catch (System.ServiceModel.EndpointNotFoundException) { MessageBox.Show(this, "Could not connect to " + url, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { ShowError(ex); } } }
/////////////////////////////////////////////////////////////////////////// //! @author Ivan Vagunin //// /// <summary> /// Saves context data. /// </summary> public void SaveContextData() { IsolatedStorageFile isoStore = IsolatedStorageFile.GetMachineStoreForAssembly(); IsolatedStorageFileStream isoFile = new IsolatedStorageFileStream(_dataFileName, FileMode.Create, isoStore); // Create a StreamWriter using the isolated storage file StreamWriter writer = new StreamWriter(isoFile); XmlSerializer serializer = new XmlSerializer(typeof(SavedContext)); SavedContext context = new SavedContext(); _setupController.UpdateContext(); context.SetupInfo = ContextController.GetSetupInfo(); _discoveryController.UpdateContext(); DiscoveredDevices devices = ContextController.GetDiscoveredDevices(); if (devices != null) { context.DiscoveryContext = new SavedDiscoveryContext(); context.DiscoveryContext.ServiceAddress = devices.ServiceAddress; context.DiscoveryContext.DeviceAddress = (devices.DeviceAddress != null) ? devices.DeviceAddress.ToString() : string.Empty; if ((devices.NIC != null) && (devices.NIC.IP != null)) { context.DiscoveryContext.InterfaceAddress = devices.NIC.IP.ToString(); } } _reportController.UpdateContext(); context.ReportInfo = ContextController.GetReportInfo(); _managementController.UpdateContext(); context.DeviceEnvironment = ContextController.GetDeviceEnvironment(); _requestsController.UpdateContext(); context.RequestsInfo = ContextController.GetRequestsInfo(); _deviceController.MediaController.UpdateContext(); context.MediaInfo = ContextController.GetMediaInfo(); _deviceController.PTZController.UpdateContext(); context.PTZInfo = ContextController.GetPTZInfo(); serializer.Serialize(writer, context); writer.Close(); }
/// <summary> /// Updates application context /// </summary> public override void UpdateContext() { DiscoveredDevices devices = new DiscoveredDevices(); devices.NIC = View.NIC; devices.Current = new DeviceInfoFull(); devices.Current.ByDiscovery = View.Current; devices.ServiceAddress = View.ServiceAddress; devices.DeviceAddress = View.DeviceAddress; foreach (DeviceDiscoveryData data in View.Devices) { DeviceInfoFull info = new DeviceInfoFull(); info.ByDiscovery = data; devices.Discovered.Add(info); } ContextController.UpdateDiscoveredDevices(devices); UpdateCredentials(); View.UpdateFormTitle(); }
public void OnLeScan(BluetoothDevice bleDevice, int rssi, byte[] scanRecord) { Console.WriteLine("Adapter.LeScanCallback: " + bleDevice.Name); // TODO: for some reason, this doesn't work, even though they have the same pointer, // it thinks that the item doesn't exist. so i had to write my own implementation // if(!_discoveredDevices.Contains(device) ) { // _discoveredDevices.Add (device ); // } Device device = new Device(bleDevice, null, null, rssi); if (!DeviceExistsInDiscoveredList(bleDevice)) { DiscoveredDevices.Add(device); // TODO: in the cross platform API, cache the RSSI // TODO: shouldn't i only raise this if it's not already in the list? DeviceDiscovered(this, new DeviceDiscoveredEventArgs { Device = device }); } }