Click here to Skip to main content
15,891,905 members
Articles / Database Development / SQL Server / SQL Server 2008

Event-Driven Architecture in the Clouds with Windows Azure

,
Rate me:
Please Sign up or sign in to vote.
4.95/5 (23 votes)
5 Feb 2010CPOL14 min read 71.1K   577   58  
To demonstrate Azure and EDA, this article will show you how to build a flight delay management system for all US airports in clouds with Windows Azure.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using Microsoft.Practices.EnterpriseLibrary.Data;
using FlightUpdates.Entities;
using System.Data.Common;
using FlightUpdates.Utility.Constants;
using System.Data;

namespace FlightUpdates.Business
{
    public class AirportManager : BaseManager
    {
        /// <summary>
        /// Get a list of all US airports
        /// </summary>
        public  List<AirportInfo> GetAirports()
        {
            List<AirportInfo> AirportList = new List<AirportInfo>();

            //Set StoredProc
            DbCommand dbCommand = FlightUpdateDB.GetStoredProcCommand("spAirportActive_Select");

            //Get data
            using (IDataReader reader = FlightUpdateDB.ExecuteReader(dbCommand))
            {
                while (reader.Read())
                {
                    AirportInfo airportItem = new AirportInfo()
                    {
                        AirportCode = DataAccessUtility.GetValue<string>(reader["AirportCode"]),
                        AirportName = DataAccessUtility.GetValue<string>(reader["AirportName"]),
                        LatitudeDegree = DataAccessUtility.GetValue<double>(reader["LatitudeDeg"]),
                        LongitudeDegree = DataAccessUtility.GetValue<double>(reader["LongitudeDeg"]),
                        DelayTime = DataAccessUtility.GetValue<int>(reader["DelayTime"])
                    };

                    AirportList.Add(airportItem);
                }
            }

            return AirportList;
        }

        /// <summary>
        /// Get flight delays for an airport 
        /// </summary> 
        /// <param name="Airport">airport code</param>
        public List<FlightDelayFeed> GetFlightDelayFeed(string Airport)
        {
            List<FlightDelayFeed> FlightDelayFeedList = new List<FlightDelayFeed>();

            //Set StoredProc with paramters
            DbCommand dbCommand = FlightUpdateDB.GetStoredProcCommand("spFlightDelayFeed_Select");
            FlightUpdateDB.AddInParameter(dbCommand, "flightCity", DbType.String, Airport);

            //Get data
            using (IDataReader reader = FlightUpdateDB.ExecuteReader(dbCommand))
            {
                while (reader.Read())
                {
                    FlightDelayFeed flightDelayFeedItem = new FlightDelayFeed()
                    {
                        DelayTime = DataAccessUtility.GetValue<int>(reader["DelayTime"]),
                        DelayExpiration = DataAccessUtility.GetValue<DateTime>(reader["DelayExpiration"]),
                        FlightCity = DataAccessUtility.GetValue<string>(reader["FlightCity"]),
                        FlightNumber = DataAccessUtility.GetValue<string>(reader["FlightNumber"]),
                        LastUpdateTime = DataAccessUtility.GetValue<DateTime>(reader["LastUpdateTime"])
                    };

                    FlightDelayFeedList.Add(flightDelayFeedItem);
                }
            }

            return FlightDelayFeedList;
        }
    }
    internal class DataAccessUtility
    {
        internal static T GetValue<T>(object obj)
        {
            if (obj != DBNull.Value)
            {
                return (T)obj;
            }
            return default(T);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Other
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions