Пример #1
0
        public void UpdatePokemonSpawn(SpawnedPokemon spawnedPokemon)
        {
            if (spawnedPokemon.Despawn < DateTime.MinValue)
            {
                return;
            }

            try
            {
                lock (dbLock)
                {
                    using (var context = new PogoDBContext())
                    {
                        var pokemonSpawn = context.PokemonSpawns.FirstOrDefault(ps => ps.EncounterID == spawnedPokemon.EncounterID);
                        if (pokemonSpawn == null)
                        {
                            return;
                        }

                        pokemonSpawn.Despawn = pokemonSpawn.Despawn;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Failed to update pokemon spawn in database.");
            }
        }
Пример #2
0
 public static void AddPokemonSpawn(SpawnedPokemon spawnedPokemon)
 {
     try
     {
         lock (addLock)
         {
             using (var context = new PogoDBContext())
             {
                 context.PokemonSpawns.Add(spawnedPokemon);
                 context.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, "Failed to add pokemon spawn to database.");
     }
 }
Пример #3
0
 public void AddNearbyPokemon(NearbyPokemon nearbyPokemon)
 {
     try
     {
         lock (dbLock)
         {
             using (var context = new PogoDBContext())
             {
                 context.NearbyPokemons.Add(nearbyPokemon);
                 context.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, "Failed to add nearby pokemon to database.");
     }
 }
Пример #4
0
 public void AddGymDetails(GymDetails gymDetails)
 {
     try
     {
         lock (dbLock)
         {
             using (var context = new PogoDBContext())
             {
                 context.GymDetails.Add(gymDetails);
                 context.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, "Failed to add gym details to database.");
     }
 }
Пример #5
0
 public Dictionary <string, GymDetails> GetLatestGymDetails()
 {
     try
     {
         lock (dbLock)
         {
             using (var context = new PogoDBContext())
             {
                 return(context
                        .GymDetails
                        .Where(p => p.InstanceName == instanceName)
                        .ToDictionary(k => k.GymID, v => v));
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, "Failed to get latest spawn data.");
         return(new Dictionary <string, GymDetails>());
     }
 }
Пример #6
0
 public Dictionary <string, SpawnedPokemon> GetLatestSpawnData()
 {
     try
     {
         lock (dbLock)
         {
             using (var context = new PogoDBContext())
             {
                 return(context
                        .PokemonSpawns
                        .Where(p => p.InstanceName == instanceName)
                        .GroupBy(p => p.SpawnPointID)
                        .ToDictionary(k => k.Key, v => v.OrderByDescending(p => p.Encountered).FirstOrDefault()));
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, "Failed to get latest spawn data.");
         return(new Dictionary <string, SpawnedPokemon>());
     }
 }
Пример #7
0
        public void UpdateGymDetails(GymDetails gymDetails)
        {
            try
            {
                lock (dbLock)
                {
                    using (var context = new PogoDBContext())
                    {
                        var oldGymDetails = context.GymDetails.FirstOrDefault(g => g.GymID == gymDetails.GymID && g.InstanceName == gymDetails.InstanceName);
                        oldGymDetails.IsInBattle       = gymDetails.IsInBattle;
                        oldGymDetails.Owner            = gymDetails.Owner;
                        oldGymDetails.StrongestPokemon = gymDetails.StrongestPokemon;
                        oldGymDetails.LastUpdate       = gymDetails.LastUpdate;

                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Failed to update gym details in database.");
            }
        }
Пример #8
0
        public Dictionary <string, DateTime> GetLatestNearbyData()
        {
            try
            {
                lock (dbLock)
                {
                    DateTime fourHoursAgo = DateTime.Now.AddHours(-Handlers.PokemonHandler.KEEP_NEARBY_HOURS);

                    using (var context = new PogoDBContext())
                    {
                        return(context
                               .NearbyPokemons
                               .Where(p => p.InstanceName == instanceName)
                               .Where(p => p.Encountered > fourHoursAgo)
                               .ToDictionary(k => k.EncounterID, v => v.Encountered));
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Failed to get latest nearby data.");
                return(new Dictionary <string, DateTime>());
            }
        }