void LoadRegionsFromDisk( ) { // first lock to make this synchronous lock ( locker ) { try { FileStream fileStream = new FileStream(CachedRegionsFileName, FileMode.Open); BinaryReader binaryReader = new BinaryReader(fileStream); // reset our region list Regions = new List <TrackedRegion>( ); // read the number of cached regions int regionCount = binaryReader.ReadInt32( ); for (int i = 0; i < regionCount; i++) { // read the region properties string regionId = binaryReader.ReadString( ); double regionLatitude = binaryReader.ReadDouble( ); double regionLongitude = binaryReader.ReadDouble( ); float regionRadius = binaryReader.ReadSingle( ); // create the region TrackedRegion region = new TrackedRegion(regionLatitude, regionLongitude, regionRadius, regionId, this); // read the landmarks for this region int landmarkCount = binaryReader.ReadInt32( ); for (int c = 0; c < landmarkCount; c++) { // read the landmark properties string provider = binaryReader.ReadString( ); double latitude = binaryReader.ReadDouble( ); double longitude = binaryReader.ReadDouble( ); // add the landmark region.AddLandmark(provider, latitude, longitude); } // add the region Regions.Add(region); } // done binaryReader.Close( ); fileStream.Close( ); } catch { Rock.Mobile.Util.Debug.WriteToLog(string.Format("Failed to load regions from disk. Until the activity runs and feeds us some, we can't scan for anything.")); } } }
public bool AddRegionForTrack(string description, double latitude, double longitude, float radius) { // make sure the user called 'BeginAddRegionsForTrack' if (CommitState == RegionCommitState.QueuingRegions) { Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::Adding Region For Tracking: {0}", description)); TrackedRegion newRegion = new TrackedRegion(latitude, longitude, radius, description, this); PendingRegionsForAdd.Add(newRegion); return(true); } return(false); }
public bool AddLandmarkToRegion(string regionDescription, string description, double latitude, double longitude) { // make sure the user called 'BeginAddRegionsForTrack' if (CommitState == RegionCommitState.QueuingRegions) { Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::Adding Landmark {0} for Region {1}", description, regionDescription)); TrackedRegion region = PendingRegionsForAdd.Where(tr => tr.Region.RequestId == regionDescription).Single( ); if (region != null) { region.AddLandmark(description, latitude, longitude); return(true); } } return(false); }
protected void HandleGeofencingEvent(GeofencingEvent geoEvent) { Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::Received Geofence event: {0}", geoEvent.GeofenceTransition)); Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::Num Geofences event: {0}", geoEvent.TriggeringGeofences.Count)); // find the region TrackedRegion trackedRegion = Regions.Where(gf => gf.Region.RequestId == geoEvent.TriggeringGeofences[0].RequestId).Single( ); if (trackedRegion != null) { Rock.Mobile.Util.Debug.WriteToLog(string.Format("Starting timer for region {0}", trackedRegion.Region.RequestId)); // don't process this geoevent NOW. instead, queue it, and we'll wait 10 seconds. // that way, if it's a false positive (like a quit exit-enter) we won't process it. trackedRegion.GeofenceEventTimer.Stop( ); trackedRegion.PendingGeofenceEvent = geoEvent; trackedRegion.GeofenceEventTimer.Start( ); } else { Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::Received geofence event for unknown region: {0}", geoEvent.TriggeringGeofences[0].RequestId)); } }
internal void HandlePendingGeofencingEvent(GeofencingEvent geoEvent, TrackedRegion trackedRegion) { Rock.Mobile.Util.Debug.WriteToLog(string.Format("Handling event for region {0}", trackedRegion.Region.RequestId)); // if we're entering, turn on intense scanning if (geoEvent.GeofenceTransition == Geofence.GeofenceTransitionEnter) { // make sure we're not IN the region yet (we could be if this is the result of a false positive, // like, we're in a region, and suddently get an 'exit-entered') if (trackedRegion.InRegion == false) { trackedRegion.InRegion = true; // start intense scanning right away StartIntenseLocationScanning( ); // notify the handler if they're interested and there is one SendLocationUpdateIntent(LocationEvent_EnteredRegion, trackedRegion.Region.RequestId, ""); } else { Rock.Mobile.Util.Debug.WriteToLog(string.Format("Ignoring ENTER for region {0} because we're already in it.", trackedRegion.Region.RequestId)); } } // else we're leaving... else { // make sure we're not OUT of the region yet (we could be if this is the result of a false positive, // like, we're outside a region, and suddently get an 'entered-exit') if (trackedRegion.InRegion == true) { trackedRegion.InRegion = false; // if this region owned our current landmark, reset that as well. if (trackedRegion.LandmarkInRegion(CurrentLandmark)) { CurrentLandmark = null; } // and turn off intensive scanning IF we're not in anymore regions at all bool outsideAllRegions = true; foreach (TrackedRegion region in Regions) { // if we find at least one region still being tracked, don't stop scanning. if (region.InRegion == true) { outsideAllRegions = false; break; } } if (outsideAllRegions) { Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::OUTSIDE ALL REGIONS. STOPPING INTENSE SCANNING")); StopIntenseLocationScanning( ); } // notify the handler if they're interested and there is one SendLocationUpdateIntent(LocationEvent_ExitedRegion, trackedRegion.Region.RequestId, outsideAllRegions.ToString( )); } else { Rock.Mobile.Util.Debug.WriteToLog(string.Format("Ignoring EXIT for region {0} because we're already in it.", trackedRegion.Region.RequestId)); } } }