public DeviceController(IDeviceDiscovery deviceDiscovery, IDevicePairing devicePairing, IPlayerNotificationProvider notificationProvider, IDeviceSettingProvider settingProvider) { if (deviceDiscovery == null) { Console.WriteLine("deviceDiscovery null."); throw new ArgumentNullException("deviceDiscovery"); } if (devicePairing == null) { Console.WriteLine("devicePairing null."); throw new ArgumentNullException("devicePairing"); } if (settingProvider == null) { Console.WriteLine("settingProvider null."); throw new ArgumentNullException("settingProvider"); } if (notificationProvider == null) { Console.WriteLine("notificationProvider null"); throw new ArgumentNullException("notificationProvider"); } this.deviceDiscovery = deviceDiscovery; this.deviceDiscovery.DeviceConnected += new EventHandler <DeviceInfoEventArgs>(this.deviceDiscovery_DeviceConnected); this.deviceDiscovery.DeviceUpdated += new EventHandler <DeviceInfoEventArgs>(this.deviceDiscovery_DeviceUpdated); this.deviceDiscovery.DeviceDisconnected += new EventHandler <DeviceInfoEventArgs>(this.deviceDiscovery_DeviceDisconnected); this.devicePairing = devicePairing; this.notificationProvider = notificationProvider; this.settingProvider = settingProvider; this.Devices = new ObservableCollection <DeviceInfo>(); this.tokenSource = new CancellationTokenSource(); }
public EntryViewModel() { //this.server = (CMAuthServer)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("D27678AB-DDCC-4470-A637-2DE030023E0E"))); //string test = string.Concat(Directory.GetCurrentDirectory(), "\\data\\"); //this.server.StartServer(test); Guid deviceId = Settings.Default.DeviceId; if (deviceId == Guid.Empty) { Settings @default = Settings.Default; Guid guid = Guid.NewGuid(); deviceId = guid; @default.DeviceId = guid; Settings.Default.Save(); } this.transportFactory = new TransportFactory(); this.devicePairing = new DevicePairing(deviceId, this.transportFactory, new SpcApiWrapper()); }
static async void loadController() { Guid deviceId = Settings.Default.DeviceId; if (deviceId == Guid.Empty) { Console.WriteLine("No saved device ID found"); Settings @default = Settings.Default; Guid guid = Guid.NewGuid(); deviceId = guid; @default.DeviceId = guid; Settings.Default.Save(); } else { //Console.WriteLine("Previously saved device ID found"); } transportFactory = new TransportFactory(); devicePairing = new DevicePairing(deviceId, transportFactory, new SpcApiWrapper()); IPlayerNotificationProvider playerNotificationProvider = new PlayerNotificationProvider(); IDeviceListener uPnPDeviceListener = new UPnPDeviceListener(new NetworkInfoProvider(), transportFactory); IDeviceDiscovery uPnPDeviceDiscovery = new UPnPDeviceDiscovery(transportFactory, uPnPDeviceListener); IDeviceDiscovery tvDiscovery = new TvDiscovery(uPnPDeviceDiscovery, new TcpWebTransport(TimeSpan.FromSeconds(5))); deviceController = new DeviceController(tvDiscovery, devicePairing, playerNotificationProvider, new DeviceSettingProvider()); //Console.WriteLine("Device discovery starting"); deviceController.StartDiscovery(); bool previousDeviceAsync = await deviceController.ConnectToPreviousDeviceAsync(); if (!previousDeviceAsync) { Console.WriteLine("No previously paired TV found."); loadDevice(deviceController); checkNetwork(deviceController); } else { Console.WriteLine("Previously paired TV found."); verifyNetwork(); } }