Example #1
0
        public static Dictionary<string, int> GetPortDistancesLookup(DbConn dbConn)
        {
            var ret = new Dictionary<string, int>();
            int nPorts = (int)dbConn.ExecuteScalar("select count (*) from Port");

            List<int> ports = new List<int>();
            for (int i = 1; i != nPorts + 1; ++i)
                ports.Add(i);

            foreach (int port in ports)
            {
                var otherPorts = new List<int>(ports);
                string otherPortsStr = String.Join(",", otherPorts);

                var cmd = new SqlCommand(
            @"select p.ID, o.ID, p.Location.STDistance(o.Location)
            from Port p, Port o
            where p.ID = @PortID");
                cmd.Parameters.AddWithValue("@PortID", port);
                var reader = dbConn.ExecuteQuery(cmd);
                while (reader.Read())
                {
                    int pid = reader.GetInt32(0);
                    int oid = reader.GetInt32(1);
                    double distance = reader.GetDouble(2);
                    ret[pid + "," + oid] = (int)distance;
                }
                reader.Close();
            }

            return ret;
        }
Example #2
0
        public FXServer(string[] args)
        {
            Util.SetConsoleTitle("FXServer");

            DbConn dbConn = new DbConn();

            Console.WriteLine("Reading currencies from db");
            List<CurrencyMsgItem> tmpList = new List<CurrencyMsgItem>();
            SqlDataReader reader = dbConn.ExecuteQuery(new SqlCommand("SELECT ID, ShortName, USDValue FROM Currency ORDER BY ID ASC"));
            while (reader.Read()) {
                int id = reader.GetInt32(0);
                string shortName = reader.GetString(1);
                decimal USDValue = reader.GetDecimal(2);
                Console.WriteLine("{0}: {1}", id, USDValue);
                tmpList.Add(new CurrencyMsgItem(id, USDValue));

                //we don't make the price of USD fluctuate relative to USD...
                if (shortName == "USD")
                    USDID = id;
            }
            reader.Close();
            currencies.items = tmpList.ToArray();

            dbConn.Dispose();

            bankServer = new Server(ServerConfigs["FXServer-Bank"], AppSettings, true);
        }
Example #3
0
        public ShippingCompany(string[] args)
        {
            myID = SetID("ShippingCompany", args);

            int nTraders;
            try
            {
                nTraders = Int32.Parse(args[1]);
            }
            catch (Exception)
            {
                throw new ApplicationException("Requires 2 command line arguments: first is id, second is number of traders");
            }

            DbConn dbConn = new DbConn();
            portDistances = DBUtil.GetPortDistancesLookup(dbConn);
            dbConn.Dispose();

            bankClient = new Client(ServerConfigs["Bank-Shipping"], AppSettings, myID, false);

            var conf = ServerConfigs["Trader-Shipping"];
            for (int i = 0; i != nTraders; ++i)
            {
                traderClients[conf.port] = new Client(conf, AppSettings, myID, false);
                moveWishes[conf.port] = new List<MoveContractMsg>();
                conf.port += 1;
            }
        }
Example #4
0
        public BankDBLogic()
        {
            dbConn = new DbConn(false);

            //truncate some of the tables in the database which don't make sense if not cleared between
            //runs
            dbConn.ExecuteNonQuery("delete from CommodityTransport");
            dbConn.ExecuteNonQuery("delete from CommodityTransaction");
            dbConn.ExecuteNonQuery("delete from FuturesContract;");
        }
Example #5
0
 public TraderLogic()
 {
     dbConn = new DbConn();
 }