示例#1
0
        // Remember the information for an airport
        public static Airport RecordAirport(Dictionary<string, object> row)
        {
            lock (cache)
            {
                string code = (string) row["code"];

                // look in the cache
                Airport airport;
                if (cache.TryGetValue(code, out airport))
                    return airport;

                // Add it to the cache
                airport = new Airport(code, (string)row["title"], (string)row["country"]);
                cache[code] = airport;

                return airport;
            }
        }
示例#2
0
        // Get an airport, either from the cache or the database
        public static Airport GetAirport(string code, DbFace dbface)
        {
            lock (cache)
            {
                // look in the cache
                Airport airport;
                if (cache.TryGetValue(code, out airport))
                    return airport;

                // look in the database
                List<Dictionary<string, object>> rows = dbface.AssocEnumerate(string.Format("select * from airports where code = '{0}' limit 1", code));
                if (rows == null || rows.Count != 1)
                    return new Airport(code, "Unknown", "Unknown");

                Dictionary<string, object> row = rows[0];

                airport = new Airport((string)row["code"], (string)row["title"], (string)row["country"]);
                cache[code] = airport;

                return airport;
            }
        }