Exemple #1
0
        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."));
                }
            }
        }
Exemple #2
0
        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);
        }