Franc Stratton's .NET (TM) Web Application, OOP, and SOA Architecture & Programming Site

A site devoted to ASP.NET (TM), SilverLight (TM) and Browser-Based WPF (TM) Applications, IIS Services, and OOP Architectures

Home     .NET Security     Standards     Data Store     Windows Form Apps     WF/WCF/WPF     jQuery     C# Developer Corner     Java Development     Site Map      
Architecture Overview
N-Tier Architecture
Service Oriented Architecture
SOA Virtualization
Base Classes
BLL
DAL
Base Page
DALFactory
IDAL
Email
Application
Contact Us
Business Entities
Application and AppDataContract Classes
 
The Application class is a application business object whose encrypted database connection string properties are set in the global.asax file on application startup. The client page domain BLL has the ability to utilize this application object to access the SQL Server database either synchronously or asynchronously. The AppDataContract.cs file below the Application.cs file is normally utilized with a WCF service, but the example shown here is strictly OOP. The global.asax file is below the AppDataContract.cs file. The global.asax file utilizes the AppDataBLL.cs and The AppDataDAL.cs classes below also to access the SQL Server Stored procedure and table containing the encrypted connection strings. Finally shown are the web.config file entries to identify the environment (Developement, Quality Assurance, User Acceptance/Training, and Production database servers and the subsequent connection strings to access the application table and environment database connections.

  

namespace Sample.Entities

{

#region Class Using References

using System;

#endregion

///---------------------------------------------------------------------------

/// Namespace: Application

/// Base fm:

/// Author: Your Team

/// Date: 9/4/2009

/// Updated:

/// <summary>

/// Purpose: An application class that contains the fields and properties

/// stored in the Application Object in the Global Application

/// variable.

///

/// </summary>

///---------------------------------------------------------------------------

public class Application

{

public string SyncConnectionString { get; set; }

public string AsyncConnectionString { get; set; }

#region Class Constructors

public Application()

{

}

#endregion

}

}

 
 
 

namespace Sample.Entities

{

 

#region Class Using References

 

#endregion

///---------------------------------------------------------------------------

/// Namespace: DHS.CAM.Services.ApplicationData

/// Derived Class:

/// Filename: AppDataContract.cs

/// Author: Your Team

/// Date: 04/14/2008

/// Updated:

/// <summary>

/// Purpose: To hold the complex class types that the service will use to

/// send or receive application data from the ApplicationData service.

/// </summary>

///---------------------------------------------------------------------------

public class AppDataContract //set up as an interface for an applicaation WCF service

{

#region Private and Public Fields and Properties

//Add complete application data class here

public string SyncConnectionString { get; set; }

public string ASyncConnectionString { get; set; }

#endregion Private and Public Fields and Properties

 

#region Class Constructors

//Constructor is uncommented if used as an interface contract for a WCF

//public AppDataContract(string syncConnection, string asyncConnection)

//{

// this.SyncConnectionString = syncConnection;

// this.ASyncConnectionString = asyncConnection;

//}

#endregion

 

}

}

 

 

using System;

using System.Collections;

using System.Collections.Generic;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.Security;

using System.Web.SessionState;

using System.Xml.Linq;

using DHS.ARTS.BLL;

using DHS.ARTS.Entities;

//---------------------------------------------------------------------------

/// Namespace:

/// Base Class: System.Web.HttpApplication

/// Filename: Global.asax.cs

/// Author: Your Team

/// Date: 12/3/2008

/// Updated:

/// <summary>

/// Purpose: Initialize and set all Session and Application variables.

/// </summary>

//---------------------------------------------------------------------------

public class Global : System.Web.HttpApplication

{

#region Private Fields and Public Properties

private AppDataBLL svc = new AppDataBLL();

#endregion

//---------------------------------------------------------------------------

/// <summary>

/// Method Name: Application_Start

/// Description: Triggers when the application begins.

/// </summary>

///

/// <param name="sender">object</param>

/// <param name="e">event argument</param>

///

//---------------------------------------------------------------------------

protected void Application_Start(object sender, EventArgs e)

{

string environmentID = string.Empty;

string connectionString = string.Empty;

AppDataContract appData = new AppDataContract();

Application appInfo = new Application();

try

{

//Get Web.config info for app environment and connection string

environmentID = System.Configuration.ConfigurationManager.AppSettings["AppEnvironment"];

connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];

//assign the returning object

//to the data contract object instantiated above

appData = svc.GetAppDataByEnvironmentID(environmentID, connectionString);

appInfo.AsyncConnectionString = appData.ASyncConnectionString.ToString();

appInfo.SyncConnectionString = appData.SyncConnectionString.ToString();

//Store the Application Object in an application variable

Context.Application["AppInfo"] = appInfo;

}

catch (Exception ex)

{

string exception = ex.Message.ToString();

}

finally

{

//Get rid of the objects instantiated above

environmentID = null;

connectionString = null;

appData = null;

appInfo = null;

}

}

void Application_End(object sender, EventArgs e)

{

// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)

{

// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)

{

// Code that runs when a new session is started

}

void Session_End(object sender, EventArgs e)

{

// Code that runs when a session ends.

// Note: The Session_End event is raised only when the session state mode

// is set to InProc in the Web.config file. If session mode is set to StateServer

// or SQLServer, the event is not raised.

}

}

 

namespace Sample.BLL

{

#region Class Using References

using System;

using System.Collections.Generic;

using AppBase;

using Sample.Entities;

using Sample.DAL;

#endregion

///---------------------------------------------------------------------------

/// Namespace: Sample.BLL

/// Derived Class:

/// Filename: AppDataBLL.cs

/// Author: DHS ARTS Team/FS

/// Date: 9/3/2009

/// Updated:

/// <summary>

/// Purpose: A Business Logic Layer class that contains properties and methods

/// to validate Service or OOP input and retrieve application data through the

/// data access layer.

/// </summary>

///---------------------------------------------------------------------------

public class AppDataBLL : BLL

{

#region Private and Public Fields and Properties

 

#endregion Private and Public Fields and Properties

#region Class Constructors

public AppDataBLL()

{

}

#endregion Class Constructors

#region Static Methods

#endregion Static Methods

#region Instance Methods

 

 

public AppDataContract GetAppDataByEnvironmentID(string environmentID, string connectionString)

{

///---------------------------------------------------------------------------

/// <summary>

/// Method Name: BLL.GetAppDataByAppID

/// Description: Retreives an app row from the ARTS database

/// </summary>

///

/// <returns>an object of type, "AppDataContract"</returns>

///---------------------------------------------------------------------------

string connectString = Decrypt3DES(connectionString, true);

AppDataDAL aDAL = new AppDataDAL();

return aDAL.GetAppRowByEnvironmentID(connectString, environmentID);

}

}

}

 

namespace Sample.DAL

{

#region Class Using References

using System;

using System.Collections.Generic;

using Sample.Entities;

using System.Data.SqlClient;

using System.Data;

#endregion

///---------------------------------------------------------------------------

/// Namespace: DHS.ARTS.DAL

/// Derived fm: DHS.AppBase.DAL

/// Author: DHS Team/FCS

/// Date: 04/13/2008

/// Updated: 9/4/2009/FS

/// <summary>

/// Purpose: An application data access layer used to connect to the ARTS database

/// and retrieve app information for the AppInfo Global variable

///

/// </summary>

///---------------------------------------------------------------------------

public class AppDataDAL : AppBase.DAL

{

#region Private and Public Variables

/** Stored Procedures Used **/

private const string SP_GETAPPINFOBYENVIRONMENTID = "usp_GetAppInfoByEnvironmentID";

#endregion

#region Class Constructors

public AppDataDAL()

{

}

#endregion

#region Static Methods

#endregion Static Methods

#region Instance Methods and Functions

 

//---------------------------------------------------------------------------

/// <summary>

/// Method Name: DAL.GetAppRowByEnvironmentID

/// Description: Retreives an item from the ServiceTemplate database by its ID field

/// </summary>

///

/// <param name="environmentID">the id the environment - e.g., "Dev", "QA"</param>

/// <returns>AppDataContract</returns>

//---------------------------------------------------------------------------

public AppDataContract GetAppRowByEnvironmentID(string connectionString, string environmentID)

{

var appData = new AppDataContract();

SqlDataReader rd = null;

this.ConnectionString = connectionString;

this.ProviderType = AppBase.DataProvider.SqlServer;

this.CreateParameters(1);

this.AddParameters(0, "@EnvironmentID", environmentID); //user ID

this.Open();

rd = (SqlDataReader)this.ExecuteReader(CommandType.StoredProcedure, SP_GETAPPINFOBYENVIRONMENTID);

while (rd.Read())

{

appData.SyncConnectionString = rd[0].ToString();

appData.ASyncConnectionString = rd[1].ToString();

}

//int size = userList.Count;

rd.Close();

this.Close();

this.Dispose();

rd = null;

return appData;

}

#endregion

 

}

}

 

Finally, the web.config entries for the environment and the encrypted SQL Server connection string needed on Application_Start in the global.asax.cs file:

 

<!-- Uncomment out for each environment prior to deployment -->

<add key="AppEnvironment" value="Dev"/>

<!--

<add key="AppEnvironment" value="QA"/>-->

<!--<add key="AppEnvironment" value="UAT"/>-->

<!--<add key="AppEnvironment" value="Prod"/>-->

<!-- Uncomment out for each environment prior to deployment -->

<!--Dev Connection String-->

<add key="ConnectionString" value="blahvLI+y4jwKGp91bFo31PsWEuGOLuKBH2ZYXv7yAmWDiwshRe7TqymfBlahQ6fnBhdFbcUVuFUS9+MrWRPhd7nsOhSbqP/VwBodAXGByWkXI9pWfrN8/49n8lTblah"/>

<!--Connection to ART_QA-->

<!--<add key="ConnectionString" value="blahvLI+y4jwKGp91bFo31PsWEuGOLuKBH2ZYXv7yAmWDiwshRe7Tblah0PPdQ6f4OLgYMiGG1VD3u8Fr3AmEmFxcwkpqXDMOeh5fa2F+s9NqGULArM3c3t6mCvGblah"/>-->

<!--QA Connection String-->

<!--<add key="ConnectionString" value ="blahvLI+y4i2xex63kXidncnPwG/xMviBH2ZYXv7yAmWDiwshRe7Tqymf0PPdQ6fnBhdFbcUVuFUS9+blahPhd7nsOhSbqP/VwBodAXGByWkXI9pWfrN8/49n8lTblah"/>-->

<!--UAT Connection String-->

<!--<add key="ConnectionString" connectionString="encryptedblah"/>-->

<!--Prod Connection String-->

<!--<add key="ConnectionString" connectionString="encryptedblah"/>-->