Example #1
0
            public void CheckOnStayAfterDuration(Object stateInfo)
            {
                GeoFence geoFence = (GeoFence)stateInfo;

                timer.Dispose();
                GeoFenceMonitoring.Instance.ExecuteOnStayCallback(this, geoFence);
            }
Example #2
0
        public void AddGeoFence(GeoFence geoFence, ICallback callback)
        {
            if (fencesToCallback.ContainsKey(geoFence))
            {
                if (!fencesToCallback[geoFence].EqualCallbackParameter(callback))
                {
                    throw new BackendlessException(String.Format(ExceptionMessage.GEOFENCE_ALREADY_MONITORING, geoFence.GeofenceName));
                }

                return;
            }

            if (!IsDefiniteRect(geoFence.NWPoint, geoFence.SEPoint))
            {
                DefiniteRect(geoFence);
            }

            this.fencesToCallback.Add(geoFence, callback);

            if (location != null && IsPointInFence(new GeoPoint(location.Latitude, location.Longitude), geoFence))
            {
                pointFences.Add(geoFence);
                callback.CallOnEnter(geoFence, location);
                AddOnStay(geoFence);
            }
        }
Example #3
0
        private void DefiniteRect(GeoFence geoFence)
        {
            switch (geoFence.Type)
            {
            case FenceType.RECT:
            {
                GeoPoint nwPoint = geoFence.Nodes[0];
                GeoPoint sePoint = geoFence.Nodes[1];
                geoFence.NWPoint = nwPoint;
                geoFence.SEPoint = sePoint;
                break;
            }

            case FenceType.CIRCLE:
            {
                double[] outRect = GeoMath.GetOutRectangle(geoFence.Nodes[0], geoFence.Nodes[0]);
                geoFence.NWPoint = new GeoPoint(outRect[0], outRect[1]);
                geoFence.SEPoint = new GeoPoint(outRect[2], outRect[3]);
                break;
            }

            case FenceType.SHAPE:
            {
                double[] outRect = GeoMath.GetOutRectangle(geoFence.Nodes);
                geoFence.NWPoint = new GeoPoint(outRect[0], outRect[1]);
                geoFence.SEPoint = new GeoPoint(outRect[2], outRect[3]);
                break;
            }

            default:
                break;
            }
        }
Example #4
0
        private void AddOnStay(GeoFence geoFence)
        {
            onStaySet.Add(geoFence);
            DurationStayTask task = new DurationStayTask();

            task.geoFence = geoFence;
            task.Schedule();
            tasks.Add(task);
        }
Example #5
0
        internal void ExecuteOnStayCallback(DurationStayTask task, GeoFence geoFence)
        {
            tasks.Remove(task);

            if (onStaySet.Contains(geoFence))
            {
                fencesToCallback[geoFence].CallOnStay(geoFence, location);
                CancelOnStay(geoFence);
            }
        }
Example #6
0
        public void removeGeoFence(String geoFenceName)
        {
            GeoFence removed = new GeoFence(geoFenceName);

            if (fencesToCallback.ContainsKey(removed))
            {
                fencesToCallback.Remove(removed);
                CancelOnStay(removed);
                pointFences.Remove(removed);
            }
        }
Example #7
0
        private bool IsPointInFence(GeoPoint geoPoint, GeoFence geoFence)
        {
            if (!GeoMath.IsPointInRectangular(geoPoint, geoFence.NWPoint, geoFence.SEPoint))
            {
                return(false);
            }

            if (geoFence.Type == FenceType.CIRCLE && !GeoMath.IsPointInCircle(geoPoint, geoFence.Nodes[0], GeoMath.Distance(geoFence.Nodes[0].Latitude, geoFence.Nodes[0].Longitude, geoFence.Nodes[1].Latitude, geoFence.Nodes[1].Longitude)))
            {
                return(false);
            }

            if (geoFence.Type == FenceType.SHAPE && !GeoMath.IsPointInShape(geoPoint, geoFence.Nodes))
            {
                return(false);
            }

            return(true);
        }
Example #8
0
 public void CallOnExit(GeoFence geoFence, GeoPoint location)
 {
     geoPoint = location;
     OnGeofenceServerCallback("onExitGeofence", geoFence.ObjectId, geoPoint);
 }
Example #9
0
 private void CancelOnStay(GeoFence geoFence)
 {
     onStaySet.Remove(geoFence);
 }
Example #10
0
    private void AddFenceMonitoring( ICallback callback, GeoFence[] geoFences )
    {
      if( geoFences.Length == 0 )
        return;

      if( geoFences.Length == 1 )
        GeoFenceMonitoring.Instance.AddGeoFence( geoFences[ 0 ], callback );
      else
        GeoFenceMonitoring.Instance.AddGeoFences( new HashSet<GeoFence>( geoFences ), callback );

      if( !LocationTracker.Instance.ContainsListener( GeoFenceMonitoring.NAME ) )
        LocationTracker.Instance.AddListener( GeoFenceMonitoring.NAME, GeoFenceMonitoring.Instance );
    }
Example #11
0
 public void CallOnExit( GeoFence geoFence, GeoPoint location )
 {
   LocationInfo locationInfo = new LocationInfo( geoFence.GeofenceName, geoFence.ObjectId, location.Latitude, location.Longitude );
   geofenceCallback.OnExitHandler( locationInfo );
 }
    internal void ExecuteOnStayCallback( DurationStayTask task, GeoFence geoFence )
    {
      tasks.Remove( task );

      if( onStaySet.Contains( geoFence ) )
      {
          fencesToCallback[ geoFence ].CallOnStay( geoFence, location );
          CancelOnStay( geoFence );
      }
    }
    public void AddGeoFence( GeoFence geoFence, ICallback callback )
    {
      if( fencesToCallback.ContainsKey( geoFence ) )
      {
        if( !fencesToCallback[ geoFence ].EqualCallbackParameter( callback ) )
          throw new BackendlessException( String.Format( ExceptionMessage.GEOFENCE_ALREADY_MONITORING, geoFence.GeofenceName ) );

        return;
      }

      if( !IsDefiniteRect( geoFence.NWPoint, geoFence.SEPoint ) )
        DefiniteRect( geoFence );

      this.fencesToCallback.Add( geoFence, callback );

      if( location != null && IsPointInFence( new GeoPoint( location.Latitude, location.Longitude ), geoFence ) )
      {
        pointFences.Add( geoFence );
        callback.CallOnEnter( geoFence, location );
        AddOnStay( geoFence );
      }
    }
 private void CancelOnStay( GeoFence geoFence )
 {
   onStaySet.Remove( geoFence );
 }
 private void AddOnStay( GeoFence geoFence )
 {
   onStaySet.Add( geoFence );
   DurationStayTask task = new DurationStayTask();
   task.geoFence = geoFence;
   task.Schedule();
   tasks.Add( task );
 }
 private void DefiniteRect( GeoFence geoFence )
 {
   switch( geoFence.Type )
   {
     case FenceType.RECT:
       {
         GeoPoint nwPoint = geoFence.Nodes[ 0 ];
         GeoPoint sePoint = geoFence.Nodes[ 1 ];
         geoFence.NWPoint = nwPoint;
         geoFence.SEPoint = sePoint;
         break;
       }
     case FenceType.CIRCLE:
       {
         double[] outRect = GeoMath.GetOutRectangle( geoFence.Nodes[ 0 ], geoFence.Nodes[ 0 ] );
         geoFence.NWPoint = new GeoPoint( outRect[ 0 ], outRect[ 1 ] );
         geoFence.SEPoint = new GeoPoint( outRect[ 2 ], outRect[ 3 ] );
         break;
       }
     case FenceType.SHAPE:
       {
         double[] outRect = GeoMath.GetOutRectangle( geoFence.Nodes );
         geoFence.NWPoint = new GeoPoint( outRect[ 0 ], outRect[ 1 ] );
         geoFence.SEPoint = new GeoPoint( outRect[ 2 ], outRect[ 3 ] );
         break;
       }
     default:
       break;
   }
 }
    private bool IsPointInFence( GeoPoint geoPoint, GeoFence geoFence )
    {
      if( !GeoMath.IsPointInRectangular( geoPoint, geoFence.NWPoint, geoFence.SEPoint ) )
      {
        return false;
      }

      if( geoFence.Type == FenceType.CIRCLE && !GeoMath.IsPointInCircle( geoPoint, geoFence.Nodes[ 0 ], GeoMath.Distance( geoFence.Nodes[ 0 ].Latitude, geoFence.Nodes[ 0 ].Longitude, geoFence.Nodes[ 1 ].Latitude, geoFence.Nodes[ 1 ].Longitude ) ) )
      {
        return false;
      }

      if( geoFence.Type == FenceType.SHAPE && !GeoMath.IsPointInShape( geoPoint, geoFence.Nodes ) )
      {
        return false;
      }

      return true;
    }
    public void removeGeoFence( String geoFenceName )
    {
      GeoFence removed = new GeoFence( geoFenceName );

      if( fencesToCallback.ContainsKey( removed ) )
      {
        fencesToCallback.Remove( removed );
        CancelOnStay( removed );
        pointFences.Remove( removed );
      }
    }
Example #19
0
 public void CallOnExit( GeoFence geoFence, GeoPoint location )
 {
     geoPoint = location;
     OnGeofenceServerCallback( "onExitGeofence", geoFence.ObjectId, geoPoint );
 }
Example #20
0
        public void CallOnExit(GeoFence geoFence, GeoPoint location)
        {
            LocationInfo locationInfo = new LocationInfo(geoFence.GeofenceName, geoFence.ObjectId, location.Latitude, location.Longitude);

            geofenceCallback.OnExitHandler(locationInfo);
        }