Exemplo n.º 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;
        }
Exemplo n.º 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);
        }