Exemplo n.º 1
0
        public void InsertOrUpdateServer(Domains.Server server)
        {
            if (server == null)
            {
                throw new NullReferenceException();
            }
            if (server.Endpoint == null)
            {
                throw new ArgumentException($"Не указан {Domains.Server.Properties.Endpoint}");
            }

            using (var connection = new SQLiteConnection(connectionString))
            {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    var query   = $@"
INSERT OR REPLACE INTO {Tables.Server} (
{Domains.Server.Properties.Endpoint},
{ServerInfo.Properties.Name},
{ServerInfo.Properties.GameModes}
) VALUES (
'{server.Endpoint}',
'{server.Info.Name}',
'{JsonConvert.SerializeObject(server.Info.GameModes)}'
);";
                    var command = new SQLiteCommand(query, connection, transaction);
                    command.ExecuteNonQuery();

                    transaction.Commit();
                }
                connection.Close();
            }
        }
Exemplo n.º 2
0
        private async Task <Response> InsertServer(string requestBody, GroupCollection splitUrl)
        {
            var serverInfo = GetValueFromRequestBody <ServerInfo>(requestBody);
            var endpoint   = splitUrl[1].ToString();
            var server     = new Domains.Server(endpoint, serverInfo);

            await database.InsertOrUpdateServerAsync(server);

            return(new Response(HttpStatusCode.OK, null));
        }
Exemplo n.º 3
0
        public static string InsertServer(Domains.Server server) => $@"
INSERT OR REPLACE INTO {Tables.Server} (
{Domains.Server.Properties.Endpoint},
{ServerInfo.Properties.Name},
{ServerInfo.Properties.GameModes}
) VALUES (
'{server.Endpoint}',
'{server.Info.Name}',
'{JsonConvert.SerializeObject(server.Info.GameModes)}'
);";
Exemplo n.º 4
0
 public Match GetRandomMatchForServer(Domains.Server server, DateTime dateTime)
 {
     return
         (new Match(server.Endpoint, dateTime.AddMilliseconds(-dateTime.Millisecond),
                    new MatchResult(GetRandomFromList(maps),
                                    GetRandomFromList(gameModes),
                                    rnd.Next(50),
                                    rnd.Next(50),
                                    Math.Round((decimal)rnd.NextDouble() * 15, 6),
                                    GetUniqueRandomEnumerable(players, GetRandomScoreboard, 100).ToList())));
 }
Exemplo n.º 5
0
        public List <Match> GetUniqueRandomMatchesForServer(Domains.Server server, int count, int deltaDays = 1)
        {
            var secondsInDay = 60 * 60 * 24;
            var list         = new List <Match>();

            while (list.Count != count)
            {
                var match = GetRandomMatchForServer(server,
                                                    DateTime.Parse($"{DateTime.UtcNow:s}").ToUniversalTime().AddSeconds(
                                                        rnd.Next(deltaDays * secondsInDay) - deltaDays * secondsInDay / 2));
                if (list.All(i => i.Timestamp != match.Timestamp))
                {
                    list.Add(match);
                }
            }

            return(list);
        }
Exemplo n.º 6
0
 public virtual async Task InsertOrUpdateServerAsync(Domains.Server server)
 {
     await ExecuteNonQueryAsync(Queries.InsertServer(server));
 }