Exemple #1
0
        private static bool VisitedThisPlaceWithinLastNMinutes(Position pos, double minutesThreshold)
        {
            if (pos.IsValid())
            {
                LocationEntry lastVisit = LocationHelper.GetLastVisit(pos);
                if (lastVisit != null)
                {
                    var minutesSinceVisited = DateTime.Now.Subtract(lastVisit.VisitedOn).TotalMinutes;
                    return(minutesSinceVisited <= minutesThreshold);
                }
            }

            return(false);
        }
Exemple #2
0
        public static void ExecuteLocationRecipes()
        {
            try
            {
                //execute buy-milk recipe
                var buyMilkRecipe = Repository.Instance.GetRecipe("Buy Milk");
                if (buyMilkRecipe != null && buyMilkRecipe.IsAvailable && buyMilkRecipe.IsEnabled)
                {
                    var work = KnownLocations.Get(KnownLocations.WORK);
                    if (VisitedThisPlaceWithinLastNMinutes(work, Constants.LEFT_FROM_DURATION_THRESHOLD))
                    {
                        var arguments = new Dictionary <string, object>()
                        {
                            { "HeaderText", "Isn't your wife waiting?" },
                            { "AlertText", "Hope you have bought milk before going home." },
                            { "Persistent", true },
                            { "Delay", 500 }
                        };

                        buyMilkRecipe.ScopeHours = TimeSpan.FromMinutes(Constants.LEFT_FROM_DURATION_THRESHOLD).TotalHours + 1;
                        SendNotification(buyMilkRecipe, arguments);
                    }
                }

                //execute car-service recipe
                var carServiceRecipe = Repository.Instance.GetRecipe("Car Service");
                if (carServiceRecipe != null && carServiceRecipe.IsAvailable && carServiceRecipe.IsEnabled)
                {
                    var carShowroom = KnownLocations.Get(KnownLocations.CAR_SHOWROOM);
                    if (carShowroom.IsValid())
                    {
                        LocationEntry lastVisit = LocationHelper.GetLastVisit(carShowroom);
                        if (lastVisit != null)
                        {
                            var daysSinceVisited = DateTime.Now.Subtract(lastVisit.VisitedOn).TotalDays;
                            if (daysSinceVisited >= Constants.CAR_SERVICE_INTERVAL)
                            {
                                var arguments = new Dictionary <string, object>()
                                {
                                    { "HeaderText", "Your car is doing good?" },
                                    { "AlertText", "It's " + daysSinceVisited + " days since you visited the Car Showroom." },
                                    { "Persistent", true },
                                    { "Delay", 500 }
                                };
                                SendNotification(carServiceRecipe, arguments);
                            }
                        }
                    }
                }

                //execute gym recipe
                var gymRecipe = Repository.Instance.GetRecipe("Gym");
                if (gymRecipe != null && gymRecipe.IsAvailable && gymRecipe.IsEnabled)
                {
                    var gym = KnownLocations.Get(KnownLocations.GYM);
                    if (gym.IsValid())
                    {
                        LocationEntry lastVisit = LocationHelper.GetLastVisit(gym);
                        if (lastVisit != null)
                        {
                            var daysSinceVisited = DateTime.Now.Subtract(lastVisit.VisitedOn).TotalDays;
                            if (daysSinceVisited >= Constants.MAX_GYM_VACATION)
                            {
                                var arguments = new Dictionary <string, object>()
                                {
                                    { "HeaderText", "Aren't you health conscious?" },
                                    { "AlertText", "It's " + daysSinceVisited + " days since you visited the Gym." },
                                    { "Persistent", true },
                                    { "Delay", 500 }
                                };
                                SendNotification(gymRecipe, arguments);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }