void RegionLeft(object sender, CLRegionEventArgs e) { if (!GeofenceResults.ContainsKey(e.Region.Identifier) || GeofenceResults[e.Region.Identifier].Transition != GeofenceTransition.Exited) { OnRegionLeft(e.Region); } }
void OnRegionEntered(CLRegion region) { if (GeofenceResults.ContainsKey(region.Identifier) && GeofenceResults[region.Identifier].Transition == GeofenceTransition.Entered) { return; } if (!mGeofenceResults.ContainsKey(region.Identifier)) { mGeofenceResults.Add(region.Identifier, new GeofenceResult() { RegionId = region.Identifier }); } if (LastKnownLocation != null) { mGeofenceResults[region.Identifier].Latitude = LastKnownLocation.Latitude; mGeofenceResults[region.Identifier].Longitude = LastKnownLocation.Longitude; mGeofenceResults[region.Identifier].Accuracy = LastKnownLocation.Accuracy; } else { mGeofenceResults[region.Identifier].Latitude = region.Center.Latitude; mGeofenceResults[region.Identifier].Longitude = region.Center.Longitude; mGeofenceResults[region.Identifier].Accuracy = region.Radius; } mGeofenceResults[region.Identifier].LastEnterTime = DateTime.Now; mGeofenceResults[region.Identifier].LastExitTime = null; mGeofenceResults[region.Identifier].Transition = GeofenceTransition.Entered; if (mRegions.ContainsKey(region.Identifier)) { region.NotifyOnEntry = mRegions[region.Identifier].NotifyOnEntry; } if (region.NotifyOnEntry) { CrossGeofence.GeofenceListener.OnRegionStateChanged(mGeofenceResults[region.Identifier]); if (Regions.ContainsKey(region.Identifier) && Regions[region.Identifier].ShowNotification && Regions[region.Identifier].ShowEntryNotification) { CreateNotification(ViewAction, string.IsNullOrEmpty(Regions[region.Identifier].NotificationEntryMessage) ? GeofenceResults[region.Identifier].ToString() : Regions[region.Identifier].NotificationEntryMessage); } } Task.Factory.StartNew(async() => { //Checks if device has stayed asynchronously await CheckIfStayed(region.Identifier); }); }
void OnRegionLeft(CLRegion region) { if (GeofenceResults.ContainsKey(region.Identifier) && GeofenceResults[region.Identifier].Transition == GeofenceTransition.Exited) { return; } if (!mGeofenceResults.ContainsKey(region.Identifier)) { mGeofenceResults.Add(region.Identifier, new GeofenceResult() { RegionId = region.Identifier }); } if (LastKnownLocation != null) { mGeofenceResults[region.Identifier].Latitude = LastKnownLocation.Latitude; mGeofenceResults[region.Identifier].Longitude = LastKnownLocation.Longitude; mGeofenceResults[region.Identifier].Accuracy = LastKnownLocation.Accuracy; } else { mGeofenceResults[region.Identifier].Latitude = region.Center.Latitude; mGeofenceResults[region.Identifier].Longitude = region.Center.Longitude; mGeofenceResults[region.Identifier].Accuracy = region.Radius; } mGeofenceResults[region.Identifier].LastExitTime = DateTime.Now; mGeofenceResults[region.Identifier].Transition = GeofenceTransition.Exited; CrossGeofence.GeofenceListener.OnRegionStateChanged(mGeofenceResults[region.Identifier]); if (Regions.ContainsKey(region.Identifier) && Regions[region.Identifier].ShowNotification && Regions[region.Identifier].ShowExitNotification) { CreateNotification(ViewAction, string.IsNullOrEmpty(Regions[region.Identifier].NotificationExitMessage) ? GeofenceResults[region.Identifier].ToString() : Regions[region.Identifier].NotificationExitMessage); } }
static void Main(string[] args) { while (true) { Console.WriteLine("Begin dataload or enter 'EXIT' to end?"); string userResponse = Console.ReadLine(); if (!string.IsNullOrEmpty(userResponse)) { if (string.Compare(userResponse, "y", true) == 0) { #region "ACCESS POINTS" string currentRestUrl = string.Format("{0}{1}", CloudConfigurationManager.GetSetting(Settings.APPKEY_RESTENDPOINT_URL), Settings.REST_ACCESSPOINT); string currentData = getJsonData(currentRestUrl); Access_point_results apData = JsonConvert.DeserializeObject <Access_point_results>(currentData); foreach (Access_point_result result in apData.Access_point_result) { //Write the data writeAPData(result); } #endregion #region "PRESENCE" currentRestUrl = string.Format("{0}{1}", CloudConfigurationManager.GetSetting(Settings.APPKEY_RESTENDPOINT_URL), Settings.REST_PRESENCE); currentData = getJsonData(currentRestUrl); PresenceResults presenceData = JsonConvert.DeserializeObject <PresenceResults>(currentData); foreach (PresenceResult result in presenceData.Presence_result) { //Write the data writePresenceData(result); } #endregion #region "CAMPUS" currentRestUrl = string.Format("{0}{1}", CloudConfigurationManager.GetSetting(Settings.APPKEY_RESTENDPOINT_URL), Settings.REST_CAMPUS); currentData = getJsonData(currentRestUrl); CampusResults campusData = JsonConvert.DeserializeObject <CampusResults>(currentData); foreach (CampusResult result in campusData.Campus_result) { //Write the data writeCampusData(result); } #endregion #region "BUILDING" currentRestUrl = string.Format("{0}{1}", CloudConfigurationManager.GetSetting(Settings.APPKEY_RESTENDPOINT_URL), Settings.REST_BUILIDNG); currentData = getJsonData(currentRestUrl); BuildingResults buildingData = JsonConvert.DeserializeObject <BuildingResults>(currentData); foreach (BuildingResult result in buildingData.Building_result) { //Write the data writeBuldingData(result); } #endregion #region "FLOOR" currentRestUrl = string.Format("{0}{1}", CloudConfigurationManager.GetSetting(Settings.APPKEY_RESTENDPOINT_URL), Settings.REST_FLOOR); currentData = getJsonData(currentRestUrl); FloorResults floorData = JsonConvert.DeserializeObject <FloorResults>(currentData); foreach (FloorResult result in floorData.Floor_result) { //Write the data writeFloorData(result); } #endregion #region "GEOFENCE" currentRestUrl = string.Format("{0}{1}", CloudConfigurationManager.GetSetting(Settings.APPKEY_RESTENDPOINT_URL), Settings.REST_GEOFENCE); currentData = getJsonData(currentRestUrl); GeofenceResults geofenceData = JsonConvert.DeserializeObject <GeofenceResults>(currentData); foreach (GeofenceResult result in geofenceData.Geofence_result) { //Write the data writeGeofenceData(result); } #endregion } else if (string.Compare(userResponse, "exit", true) == 0) { break; } } } }