protected override async void ViewIsAppearing(object sender, EventArgs e) { AppCenterHelper.Track("DeviceTwinPageModel - ViewIsAppearing"); await OutputDeviceTwin(); base.ViewIsAppearing(sender, e); }
private void MonitorProximityBeacons() { _monitoringV2ManagerImmediate.StartMonitoring(BeaconsImmediate.Select(x => x.Key).ToArray()); _monitoringV2ManagerImmediate.EnterdDesiredRange += (object sender, MonitoringV2ManagerEnterdDesiredRangeEventArgs e) => { switch (BeaconsImmediate[e.Identifier]) { case "Bedroom": _settings.AtBedroom = true; break; } AppCenterHelper.Track($"LocationBeacon EnterdDesiredRange: {BeaconsImmediate[e.Identifier]}"); }; _monitoringV2ManagerImmediate.ExitedDesiredRange += (object sender, MonitoringV2ManagerExitedDesiredRangeEventArgs e) => { switch (BeaconsImmediate[e.Identifier]) { case "Bedroom": _settings.AtBedroom = false; break; } AppCenterHelper.Track($"LocationBeacon ExitedDesiredRange: {BeaconsImmediate[e.Identifier]}"); }; }
protected override async void ViewIsAppearing(object sender, EventArgs e) { await _azureIoTHub.GetDeviceTwin(); AppCenterHelper.Track("SecurityPageModel - ViewIsAppearing"); base.ViewIsAppearing(sender, e); }
private async Task OccupantStateUpdated() { var occupantState = GetOccupantState(); _settings.OccupantState = occupantState; await _azureIoTHub.UpdateOccupantState(occupantState); AppCenterHelper.Track(nameof(OccupantStateUpdated)); }
public async Task GetDeviceTwin() { var twin = await _registryManager.GetTwinAsync(DeviceId); AppCenterHelper.Track(nameof(GetDeviceTwin)); // Update DeviceTwin _deviceTwin.ApplianceConnected = twin.ConnectionState == DeviceConnectionState.Connected; try { var reportedPropertyForRelayState = twin.Properties.Reported["RelayState"]; RelayState relayState = JsonConvert.DeserializeObject <RelayState>(reportedPropertyForRelayState.ToJson()); _deviceTwin.LightsGarden = relayState.LightsGarden; _deviceTwin.AlarmStrobe = relayState.AlarmStrobe; _deviceTwin.AlarmSiren = relayState.AlarmSiren; } catch (Exception ex) { AppCenterHelper.Error("Error updating RelayState", ex); } try { var reportedPropertyOccupantState = twin.Properties.Reported[nameof(_deviceTwin.Occupant)]; var occupant = JsonConvert.DeserializeObject <OccupantState>(reportedPropertyOccupantState.ToJson()); _deviceTwin.Occupant = occupant; } catch (Exception ex) { AppCenterHelper.Error("Error updating Occupant", ex); } try { var reportedPropertyArmedState = twin.Properties.Reported[nameof(ArmedState)]; var armedState = JsonConvert.DeserializeObject <ArmedState>(reportedPropertyArmedState.ToJson()); _deviceTwin.ArmedState = armedState; } catch (Exception ex) { AppCenterHelper.Error("Error updating ArmedState", ex); } try { _deviceTwin.GarageDoorOpen = (bool)twin.Properties.Reported["GarageDoorOpen"]; } catch (Exception ex) { AppCenterHelper.Error("Error updating GarageDoorOpen", ex); } }
public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { // Do something with the notification AppCenterHelper.Track("DidReceiveRemoteNotification - Active Notification"); // Will also call '// App Active' in AppDelegate // Tell system to display the notification anyway or use // `None` to say we have handled the display locally. completionHandler(UNNotificationPresentationOptions.Alert); }
private void MonitorSecureBeacons() { _secureBeaconManager.AuthorizationStatusChanged += (object sender, SecureBeaconManagerAuthorizationStatusChangedEventArgs e) => { StartMonitorinBeacons(); }; _secureBeaconManager.EnteredRegion += (object sender, SecureBeaconManagerEnteredRegionEventArgs e) => { switch (e.Region.Identifier) { case nameof(MySecureBeacon): // Do stuff break; } AppCenterHelper.Track($"SecureBeacon EnteredRegion: {e.Region.Identifier}"); }; _secureBeaconManager.ExitedRegion += (object sender, SecureBeaconManagerExitedRegionEventArgs e) => { switch (e.Region.Identifier) { case nameof(MySecureBeacon): // Do stuff break; } AppCenterHelper.Track($"SecureBeacon ExitedRegion: {e.Region.Identifier}"); }; _secureBeaconManager.DeterminedState += (object sender, SecureBeaconManagerDeterminedStateEventArgs e) => { switch (e.Region.Identifier) { case nameof(MySecureBeacon): // Do stuff break; } AppCenterHelper.Track($"SecureBeacon DeterminedState: {e.Region.Identifier}"); }; try { StartMonitorinBeacons(); } catch (Exception ex) { AppCenterHelper.Error(nameof(MonitorSecureBeacons), ex); } }
public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { // User Tapped if (response.IsDefaultAction) { var userInfo = response.Notification.Request.Content?.UserInfo; if (userInfo != null) { AppCenterHelper.Track("DidReceiveNotificationResponse - User Tapped"); } } completionHandler(); }
public void MonitorHomeGeolocation() { LocationService.Instance.AuthorizationChanged += (s, e) => { if (e.Status == CLAuthorizationStatus.AuthorizedAlways) { LocationService.Instance.StartMonitoring(HomeRegion); } }; // https://medium.com/@mizutori/tracking-highly-accurate-location-in-ios-vol-3-7cd827a84e4d LocationService.Instance.RequestAlwaysAuthorization(); LocationService.Instance.AllowsBackgroundLocationUpdates = true; LocationService.Instance.PausesLocationUpdatesAutomatically = false; LocationService.Instance.DesiredAccuracy = CLLocation.AccurracyBestForNavigation; LocationService.Instance.DistanceFilter = CLLocationDistance.FilterNone; LocationService.Instance.RegionEntered += async(object sender, CLRegionEventArgs e) => { if (e.Region is CLCircularRegion && e.Region.Identifier == "Microsoft Melbourne") { _settings.AtHome = true; AppCenterHelper.Track("Microsoft Melbourne Entered"); } }; LocationService.Instance.RegionLeft += async(object sender, CLRegionEventArgs e) => { if (e.Region is CLCircularRegion && e.Region.Identifier == "Microsoft Melbourne") { _settings.AtHome = false; AppCenterHelper.Track("Microsoft Melbourne Left"); } }; LocationService.Instance.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => { if (e.Region is CLCircularRegion && e.Region.Identifier == "Microsoft Melbourne") { _settings.AtHome = e.State == CLRegionState.Inside; AppCenterHelper.Track("Microsoft Melbourne Determine State"); } }; try { LocationService.Instance.StartMonitoring(HomeRegion); } catch (Exception ex) { AppCenterHelper.Error(nameof(MonitorHomeGeolocation), ex); } }
public async Task UpdateOccupantState(OccupantState occupantState) { using (await Lock.LockAsync()) { switch (Config.Person) { case "Occupant": if (_deviceTwin.Occupant.GetHashCode() == occupantState.GetHashCode()) { AppCenterHelper.Track("UpdateOccupantState passed"); return; } break; } dynamic desiredState; switch (Config.Person) { case "Occupant": default: desiredState = new { Occupant = occupantState }; break; } var patch = new { properties = new { desired = desiredState } }; // TODO: This can fail, add in resiliency var updatedTwin = await _registryManager.UpdateTwinAsync(DeviceId, JsonConvert.SerializeObject(patch), "*"); await GetDeviceTwin(); AppCenterHelper.Track("Updated Occupant State"); } }
private async Task <bool> InvokeMethodWithResponseState(string method, bool currentState) { AppCenterHelper.Track($"SecurityPageModel - {method}"); var response = await ResilientCall.ExecuteWithRetry( () => _azureIoTHub.InvokeMethod(method)); if (response.Outcome == OutcomeType.Successful && response.Result.Status == 200) { var stateResponse = JsonConvert.DeserializeObject <StateResponse>(response.Result.ResponsePayload); return(stateResponse.State); } // Error ShowError(); AppCenterHelper.Error(method, response.FinalException); return(currentState); }
public void RequestBeaconStates() { var monitoredBeacons = new Dictionary <string, MonitoringState>(); foreach (var id in BeaconsImmediate.Keys) { var state = _monitoringV2ManagerImmediate.StateForBeacon(id); monitoredBeacons.Add(BeaconsImmediate[id], state); } foreach (var monitoredBeacon in monitoredBeacons) { switch (monitoredBeacon.Key) { case "Bedroom": _settings.AtBedroom = monitoredBeacon.Value == MonitoringState.InsideZone; break; } } _secureBeaconManager.RequestState(MySecureBeacon); AppCenterHelper.Track(nameof(RequestBeaconStates)); }