コード例 #1
0
        private void SeedClients(ApplicationDbContext context, string name, string city)
        {
            var client = new Client()
            {
                Name            = name,
                City            = city,
                Country         = "Canada",
                Province        = "AB",
                CreatedByUserId = admin1User.Id,
                CreatedDate     = DateTime.UtcNow,
                Status          = Status.Active,
            };

            var clientHistory = new ClientHistory()
            {
                Name             = name,
                City             = city,
                Country          = "Canada",
                Province         = "AB",
                ModifiedByUserId = admin1User.Id,
                ModifiedDate     = client.CreatedDate,
                Status           = Status.Active,
            };

            //if (!context.Clients.Any(c => c.Id == 1))
            context.Clients.AddOrUpdate(client);
            context.ClientsHistory.AddOrUpdate(clientHistory);
            context.SaveChanges();
        }
コード例 #2
0
    public GameClient()
    {
        playerState = new PlayerState();
        pers        = new GameClientPersistant();
        sess        = new GameClientSession();
        history     = new ClientHistory[CConstVar.NUM_CLIENT_HISTORY];
        for (int i = 0; i < CConstVar.NUM_CLIENT_HISTORY; i++)
        {
            history[i] = new ClientHistory();
        }
        saved = new ClientHistory();

        agent = new BaseEntity();
        // agent.Init();
    }
コード例 #3
0
ファイル: DBConnection.cs プロジェクト: emrood/promoBank
    // Methode retournant l'historique de transaction d'un compte en banque | utilisation de jointure entre 5 tables differents
    public static bool loadAccountHistory(int compte)
    {
        histories     = new List <ClientHistory>();
        historyResult = new List <string>();
        query         = "SELECT client.nom, client.prenom, client.nif, transaction.libele_transaction, historique.montant, historique.date_transaction" +
                        " FROM client, compte_client, historique, transaction, compte" +
                        " WHERE (compte_client.no_compte = " + compte + ") AND (historique.no_compte = " + compte +
                        ") AND (transaction.type_transaction = historique.type_transaction) " +
                        " AND (client.nif = compte_client.nif)";
        try
        {
            connection = new MySqlConnection(@"Data Source=localhost;port=3309;Initial Catalog=mybank;User Id=root;password=''");
            connection.Open();
            command = new MySqlCommand(query, connection);
            reader  = command.ExecuteReader();
            while (reader.HasRows && reader.Read())
            {
                ClientHistory ch = new ClientHistory();
                ch.Nom     = reader.GetString(reader.GetOrdinal("nom"));
                ch.Prenom  = reader.GetString(reader.GetOrdinal("prenom"));
                ch.Montant = reader.GetFloat(reader.GetOrdinal("montant"));
                ch.Nif     = reader.GetInt32(reader.GetOrdinal("nif"));
                ch.Libele  = reader.GetString(reader.GetOrdinal("libele_transaction"));
                ch.Date    = reader.GetDateTime(reader.GetOrdinal("date_transaction"));
                histories.Add(ch);
            }

            connection.Close();
            return(true);
        }
        catch (MySqlException e)
        {
            string error2 = e.Message;
            connection.Close();
            return(false);
        }
    }
コード例 #4
0
ファイル: IW4MServer.cs プロジェクト: mldYM/IW4M-Admin
        override public async Task <bool> ProcessUpdatesAsync(CancellationToken cts)
        {
            try
            {
                #region SHUTDOWN
                if (Manager.ShutdownRequested())
                {
                    foreach (var client in GetClientsAsList())
                    {
                        var e = new GameEvent()
                        {
                            Type   = GameEvent.EventType.PreDisconnect,
                            Origin = client,
                            Owner  = this,
                        };

                        Manager.GetEventHandler().AddEvent(e);
                        await e.WaitAsync();
                    }

                    foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
                    {
                        await plugin.OnUnloadAsync();
                    }

                    return(true);
                }
                #endregion

                try
                {
                    var polledClients = await PollPlayersAsync();

                    var waiterList = new List <GameEvent>();

                    foreach (var disconnectingClient in polledClients[1])
                    {
                        if (disconnectingClient.State == ClientState.Disconnecting)
                        {
                            continue;
                        }

                        var e = new GameEvent()
                        {
                            Type   = GameEvent.EventType.PreDisconnect,
                            Origin = disconnectingClient,
                            Owner  = this
                        };

                        Manager.GetEventHandler().AddEvent(e);
                        // wait until the disconnect event is complete
                        // because we don't want to try to fill up a slot that's not empty yet
                        waiterList.Add(e);
                    }
                    // wait for all the disconnect tasks to finish
                    await Task.WhenAll(waiterList.Select(e => e.WaitAsync(10 * 1000)));

                    waiterList.Clear();
                    // this are our new connecting clients
                    foreach (var client in polledClients[0])
                    {
                        // note: this prevents players in ZMBI state from being registered with no name
                        if (string.IsNullOrEmpty(client.Name))
                        {
                            continue;
                        }

                        var e = new GameEvent()
                        {
                            Type   = GameEvent.EventType.PreConnect,
                            Origin = client,
                            Owner  = this
                        };

                        Manager.GetEventHandler().AddEvent(e);
                        waiterList.Add(e);
                    }

                    // wait for all the connect tasks to finish
                    await Task.WhenAll(waiterList.Select(e => e.WaitAsync(10 * 1000)));

                    waiterList.Clear();
                    // these are the clients that have updated
                    foreach (var client in polledClients[2])
                    {
                        var e = new GameEvent()
                        {
                            Type   = GameEvent.EventType.Update,
                            Origin = client,
                            Owner  = this
                        };

                        Manager.GetEventHandler().AddEvent(e);
                        waiterList.Add(e);
                    }

                    await Task.WhenAll(waiterList.Select(e => e.WaitAsync(10 * 1000)));

                    if (ConnectionErrors > 0)
                    {
                        var _event = new GameEvent()
                        {
                            Type   = GameEvent.EventType.ConnectionRestored,
                            Owner  = this,
                            Origin = Utilities.IW4MAdminClient(this),
                            Target = Utilities.IW4MAdminClient(this)
                        };

                        Manager.GetEventHandler().AddEvent(_event);
                    }

                    ConnectionErrors = 0;
                    LastPoll         = DateTime.Now;
                }

                catch (NetworkException e)
                {
                    ConnectionErrors++;
                    if (ConnectionErrors == 3)
                    {
                        var _event = new GameEvent()
                        {
                            Type   = GameEvent.EventType.ConnectionLost,
                            Owner  = this,
                            Origin = Utilities.IW4MAdminClient(this),
                            Target = Utilities.IW4MAdminClient(this),
                            Extra  = e,
                            Data   = ConnectionErrors.ToString()
                        };

                        Manager.GetEventHandler().AddEvent(_event);
                    }
                    return(true);
                }

                LastMessage = DateTime.Now - start;
                lastCount   = DateTime.Now;

                // update the player history
                if ((lastCount - playerCountStart).TotalMinutes >= SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval)
                {
                    while (ClientHistory.Count > ((60 / SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval) * 12)) // 12 times a hour for 12 hours
                    {
                        ClientHistory.Dequeue();
                    }

                    ClientHistory.Enqueue(new SharedLibraryCore.Helpers.PlayerHistory(ClientNum));
                    playerCountStart = DateTime.Now;
                }

                // send out broadcast messages
                if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().Configuration().AutoMessagePeriod &&
                    BroadcastMessages.Count > 0 &&
                    ClientNum > 0)
                {
                    string[] messages = (await this.ProcessMessageToken(Manager.GetMessageTokens(), BroadcastMessages[NextMessage])).Split(Environment.NewLine);

                    foreach (string message in messages)
                    {
                        Broadcast(message);
                    }

                    NextMessage = NextMessage == (BroadcastMessages.Count - 1) ? 0 : NextMessage + 1;
                    start       = DateTime.Now;
                }

                return(true);
            }

            // this one is ok
            catch (ServerException e)
            {
                if (e is NetworkException && !Throttled)
                {
                    Logger.WriteError(loc["SERVER_ERROR_COMMUNICATION"].FormatExt($"{IP}:{Port}"));
                    Logger.WriteDebug(e.GetExceptionInfo());
                }

                return(false);
            }

            catch (Exception E)
            {
                Logger.WriteError(loc["SERVER_ERROR_EXCEPTION"].FormatExt($"[{IP}:{Port}]"));
                Logger.WriteDebug(E.GetExceptionInfo());
                return(false);
            }
        }