private void AlljoynServiceJoined(IProvider sender, ServiceJoinedEventArgs args) { Utils.LogLine("Podłączono urządzenie AllJoyn: " + args.Service.AboutData.DeviceName); LightbulbDevice joinedDevice = new LightbulbDevice(args.Service); Lightbulbs.Add(joinedDevice); NotifyServiceUp("IsAllJoynEnabled"); }
private async void ServiceJoined(IProvider sender, ServiceJoinedEventArgs args) { var name = args.Service.AboutData?.DeviceName; var id = args.Service.AboutData?.DeviceId; var appName = args.Service.AboutData?.AppName; if (appName == "Guybrush Station") { var obj = args.Service.Objects.FirstOrDefault(x => x.Path == "/Guybrush"); if (obj != null) { var readInterface = obj.Interfaces.FirstOrDefault(x => x.Name == "com.guybrush.devices.reader"); var deviceInterface = obj.Interfaces.FirstOrDefault(x => x.Name == "com.guybrush.devices.onoffcontrol"); var conditionInterface = obj.Interfaces.FirstOrDefault(x => x.Name == "com.guybrush.station.conditions"); if (readInterface != null) { lock (Context.Current.Locks["Readings"]) { //if (Context.Current.Readings.All(x => x.Title != name)) { var reading = new Reading(readInterface, name); Context.Current.Readings.Add(reading); } } } else if (deviceInterface != null) { lock (Context.Current.Locks["Devices"]) { //if (Context.Current.Devices.All(x => x.Title != name)) { var device = new Device(deviceInterface, name); Context.Current.Devices.Add(device); } } } else if (conditionInterface != null) { var getCondition = conditionInterface.Methods.FirstOrDefault(x => x.Name == "GetConditions"); if (getCondition != null) { Context.Current.ConditionManager.Configure(conditionInterface, name); } } } } System.Diagnostics.Debug.WriteLine($"Found device '{name}' : ID = {id}"); }
private void Config_ServiceJoined(IProvider sender, ServiceJoinedEventArgs args) { ServiceJoined(args.Service); }
private void ServiceJoined(IProvider sender, ServiceJoinedEventArgs args) { /// Try to create and keep own object (MyService) and release AllJoyn service ComObjects (args.Service) /// --> No effect though. /// Some interfaces are still null. /// To be precise: Only one AllJoyn device offers its interfaces, for all other devices interfaces is null. /// This behavior is deterministic. Given the same set of AllJoyn devices always the same device can be used. /// Order of detection does not matter. Maybe it is the alphabetic order of some property which matters? /// d /// Note: While using these dummy objects does not allow invoking AllJoyn actions, it seems to be good /// to dispose the ComObjects. OpenAlljoynExplorer hangs/freezes less often than with the ComObjects. /// Most important, the warning below about "AllJoyn device simulator" does not apply when using /// own objects. (The disposing of the ComObjects is not mandatory!) /// //var asyncOkay10 = Dispatcher.Dispatch(() => //{ // try // { // var service = new AllJoynService(new MyService(args.Service)); // VM.AllJoynServices.Add(service); // } // catch (Exception ex) // { // System.Diagnostics.Debug.WriteLine(ex); // } //}); //ReleaseServiceComObject(args.Service); //return; // Warning! If there are too many devices or a bad device, OpenAlljoynExplorer will freeze on refreshing. // MainThread hangs in external code. Probably DeviceProvider is misbehaving. Not sure though. // This always happens when "AllJoyn device simulator" is mocking a device. Task mytask = Task.Run(() => { AllJoynService service = null; try { service = new AllJoynService(args.Service); var asyncOkay1 = Favorite.SetAvailableFavorite(VM.Favorites, service); var asyncOkay2 = service.ReadIconAsync(); //service.ReadAll(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); return; } var asyncOkay3 = Dispatcher.Dispatch(() => { try { VM.AllJoynServices.Add(service); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } }); }); }