コード例 #1
0
ファイル: Program.cs プロジェクト: mam/WidgenAir
        /// <summary>
        /// Program entry point for WidgenAir.Parser.
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            // Set database initializer to drop the database if it doesn't match our model.
            // Consider commenting the line out for release builds.
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<WidgenAirContext>());

            // Create and initialize new instance of NoaaMetarParser.
            IMetarParser metarParser = new NoaaMetarParser();

            using (WidgenAirContext dbContext = new WidgenAirContext())
            {
                foreach (Observation observation in metarParser.GetObservations())
                {
                    Console.WriteLine("{0}:\t{1}", observation.Icao, observation.Metar);

                    // Find existing record with matching ICAO code.
                    Observation existingObservationRecord = dbContext.Observations.FirstOrDefault(o => o.Icao == observation.Icao);

                    // Check if an existing record was found.
                    if (existingObservationRecord != null)
                    {
                        existingObservationRecord.Metar           = observation.Metar;
                        existingObservationRecord.ObservationTime = observation.ObservationTime;
                        existingObservationRecord.ColourState     = observation.ColourState;
                    }
                    // Create new database record if an existing record was not found.
                    else
                    {
                        Observation testObservation     = new Observation();
                        testObservation.Icao            = observation.Icao;
                        testObservation.Metar           = observation.Metar;
                        testObservation.ObservationTime = observation.ObservationTime;
                        testObservation.ColourState     = observation.ColourState;

                        // Add the newly created Observation record to database context.
                        dbContext.Observations.Add(testObservation);
                    }
                }
                // Save all changes made to the database context to the underlying database.
                dbContext.SaveChanges();

                Console.WriteLine("Run finished.");
            }
        }
コード例 #2
0
ファイル: MetarService.svc.cs プロジェクト: mam/WidgenAir
        public Observation GetObservation(string ICAO)
        {
            //Initializes a new instance of WidgenAirContext.
            using (WidgenAirContext dbContext = new WidgenAirContext())
            {
                Observation obs = new Observation();

                //Select dataset from database from an icao code.
                var observation = (from o in dbContext.Observations
                                   where o.Icao == ICAO
                                   select o).First();

                //Variables containing dataset from database.
                obs.ObservationId = obs.ObservationId;
                obs.Icao = observation.Icao;
                obs.Metar = observation.Metar;
                obs.ObservationTime = observation.ObservationTime;
                obs.ColourState = observation.ColourState;

                return obs;
            }
        }