Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config abstract class introduced #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions TestLibrary/MyStartupCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public static class MyStartupCode
public static bool CallMeAfterAppStartCalled { get; set; }
public static bool CallMeWhenAppEndsCalled { get; set; }

public static string ConfigExecutedOrder = "";
public static bool ConfigStartCalled { get; set; }
public static bool ConfigStart2Called { get; set; }
public static bool ConfigCallMeAfterAppStartCalled { get; set; }
public static bool ConfigCallMeWhenAppEndsCalled { get; set; }

internal static void Start()
{
if (StartCalled)
Expand Down
29 changes: 29 additions & 0 deletions TestWebApp/App_Start/CallMeAfterAppStartConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using TestLibrary;
using WebActivator;

namespace TestWebApp.App_Start
{
public class CallMeAfterAppStartConfig : Config
{
/// <summary>
/// This method is going to be execute after Application_Start():
/// </summary>
public override void Setup()
{
Debug.WriteLine("CallMeAfterAppStartConfig::Setup() method called.");

if (MyStartupCode.ConfigCallMeAfterAppStartCalled)
{
throw new Exception("Unexpected second call to CallMeAfterAppStart");
}

MyStartupCode.ConfigCallMeAfterAppStartCalled = true;
MyStartupCode.ConfigExecutedOrder += "CallMeAfterAppStart";
}
}
}
29 changes: 29 additions & 0 deletions TestWebApp/App_Start/CallMeWhenAppEndsConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using TestLibrary;
using WebActivator;

namespace TestWebApp.App_Start
{
public class CallMeWhenAppEndsConfig : Config
{
/// <summary>
/// This method is going to be execute at the end of application
/// </summary>
public override void Shutdown()
{
Debug.WriteLine("CallMeWhenAppEndsConfig::Shutdown() method called.");

if (MyStartupCode.ConfigCallMeWhenAppEndsCalled)
{
throw new Exception("Unexpected second call to CallMeWhenAppEndsConfig");
}

MyStartupCode.ConfigCallMeWhenAppEndsCalled = true;
MyStartupCode.ConfigExecutedOrder += "CallMeWhenAppEnds";
}
}
}
67 changes: 67 additions & 0 deletions TestWebApp/App_Start/Start2Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using TestLibrary;
using WebActivator;

namespace TestWebApp.App_Start
{
public class Start2Config : Config
{
public override EPriority Priority
{
get
{
//Setting priority to very low level, so all code will be executed AFTER config tasks with higher priority
return EPriority.VeryLow;
}
}

/// <summary>
/// This method is going to be executed before Application_Start():
/// </summary>
public override void PreSetup()
{
if (MyStartupCode.ConfigStart2Called)
{
throw new Exception("Unexpected second call to Start2");
}

MyStartupCode.ConfigStart2Called = true;
MyStartupCode.ConfigExecutedOrder += "Start2";
}

/// <summary>
/// This method is going to be execute after Application_Start():
/// </summary>
public override void Setup()
{
Debug.WriteLine("Start2Config::Setup() method called.");
}

/// <summary>
/// This method allows to attach event handlers for an HttpApplication
/// </summary>
/// <param name="context"></param>
public override void AttachEventHandlers(HttpApplication context)
{
context.EndRequest += context_EndRequest;
Debug.WriteLine("Start2Config::AttachEventHandlers() called.");
}

void context_EndRequest(object sender, EventArgs e)
{
Debug.WriteLine("Start2Config::context_EndRequest() called.");
}

/// <summary>
/// This method is going to be execute at the end of application
/// </summary>
public override void Shutdown()
{
Debug.WriteLine("Start2Config::Shutdown() method called.");
}
}
}
62 changes: 62 additions & 0 deletions TestWebApp/App_Start/Start3Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using TestLibrary;
using WebActivator;

namespace TestWebApp.App_Start
{
public class Start3Config : Config
{
public override EPriority Priority
{
get
{
//Setting priority to very low level, so all code will be executed AFTER config tasks with higher priority
return EPriority.Low;
}
}

/// <summary>
/// This method is going to be executed before Application_Start():
/// </summary>
public override void PreSetup()
{
MyStartupCode.ConfigStartCalled = true;
MyStartupCode.ConfigExecutedOrder += "Start3";
}

/// <summary>
/// This method is going to be execute after Application_Start():
/// </summary>
public override void Setup()
{
Debug.WriteLine("Start3Config::Setup() method called.");
}

/// <summary>
/// This method allows to attach event handlers for an HttpApplication
/// </summary>
/// <param name="context"></param>
public override void AttachEventHandlers(HttpApplication context)
{
context.EndRequest += context_EndRequest;
Debug.WriteLine("Start3Config::AttachEventHandlers() called.");
}

void context_EndRequest(object sender, EventArgs e)
{
Debug.WriteLine("Start3Config::context_EndRequest() called.");
}

/// <summary>
/// This method is going to be execute at the end of application
/// </summary>
public override void Shutdown()
{
Debug.WriteLine("Start3Config::Shutdown() method called.");
}
}
}
58 changes: 58 additions & 0 deletions TestWebApp/App_Start/StartConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using TestLibrary;
using WebActivator;

namespace TestWebApp.App_Start
{
public class StartConfig : Config
{
/// <summary>
/// This method is going to be executed before Application_Start():
/// </summary>
public override void PreSetup()
{
if (MyStartupCode.ConfigStartCalled)
{
throw new Exception("Unexpected second call to Start");
}

MyStartupCode.ConfigStartCalled = true;
MyStartupCode.ConfigExecutedOrder += "Start";
}

/// <summary>
/// This method is going to be execute after Application_Start():
/// </summary>
public override void Setup()
{
Debug.WriteLine("StartConfig::Setup() method called.");
}

/// <summary>
/// This method allows to attach event handlers for an HttpApplication
/// </summary>
/// <param name="context"></param>
public override void AttachEventHandlers(HttpApplication context)
{
context.EndRequest += context_EndRequest;
Debug.WriteLine("StartConfig::AttachEventHandlers() called.");
}

void context_EndRequest(object sender, EventArgs e)
{
Debug.WriteLine("StartConfig::context_EndRequest() called.");
}

/// <summary>
/// This method is going to be execute at the end of application
/// </summary>
public override void Shutdown()
{
Debug.WriteLine("StartConfig::Shutdown() method called.");
}
}
}
3 changes: 3 additions & 0 deletions TestWebApp/Global.asax.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;
Expand Down Expand Up @@ -35,6 +36,8 @@ protected void Application_Start()

RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);

Debug.WriteLine("MvcApplication::Application_Start() method called.");
}
}
}
9 changes: 9 additions & 0 deletions TestWebApp/TestWebApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -65,6 +69,11 @@
</ItemGroup>
<ItemGroup>
<Content Include="App_Code\AppCodeStartupCode.cs" />
<Compile Include="App_Start\CallMeAfterAppStartConfig.cs" />
<Compile Include="App_Start\CallMeWhenAppEndsConfig.cs" />
<Compile Include="App_Start\Start3Config.cs" />
<Compile Include="App_Start\StartConfig.cs" />
<Compile Include="App_Start\Start2Config.cs" />
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Global.asax.cs">
Expand Down
Loading