Exemplo n.º 1
0
 /// <summary>
 /// Setup all the listeners for the database tables
 /// </summary>
 public static void SetupDatabaseListeners(OnChange_Player player, OnChange_ResourceOffers resourceOffer,
                                           OnChange_TradeOffers tradeOffer, OnChange_Chat chat)
 {
     DependencyInitialization();
     MonitorPlayers(player);
     MonitorResourceOffers(resourceOffer);
     MonitorTradeOffer(tradeOffer);
     MonitorChat(chat);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Setup listener for the player table
        /// </summary>
        /// <param name="player">The event handler methode which should be run when the event fires</param>
        public static void MonitorPlayers(OnChange_Player playerMethode)
        {
            try
            {
                string query = "SELECT Name, Wood, Clay, Wool, " +
                               "Stone, Iron, Straw, Food, Gold FROM dbo.Players";
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand(query, connection))
                    {
                        SqlDependency dependency = new SqlDependency(command);
                        dependency.OnChange += new OnChangeEventHandler(playerMethode);
                        command.ExecuteNonQuery();
                    }
                }
            }
#pragma warning disable CS0168 // Variable is declared but never used
            catch (SqlException ex)
#pragma warning restore CS0168 // Variable is declared but never used
            { }
        }