Permalink
Browse files

Initial PreApplicationStart sample commit

  • Loading branch information...
grendello committed May 13, 2010
1 parent e0822af commit 2e2ddfbd382c674d9ffdbba8dbf96496a2a99b29
Showing with 975 additions and 0 deletions.
  1. 0 PreApplicationStart/ChangeLog
  2. +38 −0 PreApplicationStart/PreApplicationStart.sln
  3. BIN PreApplicationStart/PreApplicationStart.suo
  4. 0 PreApplicationStart/PreApplicationStart/App_Data/.placeholder
  5. +92 −0 PreApplicationStart/PreApplicationStart/Application/Init.cs
  6. +106 −0 PreApplicationStart/PreApplicationStart/PreApplicationStart.csproj
  7. +35 −0 PreApplicationStart/PreApplicationStart/Properties/AssemblyInfo.cs
  8. +30 −0 PreApplicationStart/PreApplicationStart/Web.Debug.config
  9. +31 −0 PreApplicationStart/PreApplicationStart/Web.Release.config
  10. +18 −0 PreApplicationStart/PreApplicationStart/Web.config
  11. 0 PreApplicationStart/PreApplicationStart/bin/.placeholder
  12. +30 −0 PreApplicationStart/PreApplicationStart/default.aspx
  13. +20 −0 PreApplicationStart/PreApplicationStart/default.aspx.cs
  14. +42 −0 PreApplicationStart/PreApplicationStart/default.aspx.designer.cs
  15. +12 −0 PreApplicationStart/PreApplicationStartSupport/Core/IPlugin.cs
  16. +12 −0 PreApplicationStart/PreApplicationStartSupport/Core/ISetupPlugin.cs
  17. +66 −0 PreApplicationStart/PreApplicationStartSupport/Core/MessageContainer.cs
  18. +56 −0 PreApplicationStart/PreApplicationStartSupport/Core/PluginLoader.cs
  19. +53 −0 PreApplicationStart/PreApplicationStartSupport/PreApplicationStartSupport.csproj
  20. +36 −0 PreApplicationStart/PreApplicationStartSupport/Properties/AssemblyInfo.cs
  21. +36 −0 PreApplicationStart/SamplePlugin/Properties/AssemblyInfo.cs
  22. +34 −0 PreApplicationStart/SamplePlugin/Sample.cs
  23. +56 −0 PreApplicationStart/SamplePlugin/SamplePlugin.csproj
  24. +36 −0 PreApplicationStart/SetupPlugin/Properties/AssemblyInfo.cs
  25. +80 −0 PreApplicationStart/SetupPlugin/Setup.cs
  26. +56 −0 PreApplicationStart/SetupPlugin/SetupPlugin.csproj
No changes.
@@ -0,0 +1,38 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PreApplicationStart", "PreApplicationStart\PreApplicationStart.csproj", "{349F62FB-801D-4942-B400-131B4642A6EA}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PreApplicationStartSupport", "PreApplicationStartSupport\PreApplicationStartSupport.csproj", "{41F5BB8F-4D69-41E1-8E15-45F6494C22BE}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetupPlugin", "SetupPlugin\SetupPlugin.csproj", "{61CD8A45-50EC-4593-8724-DCDD959E4B04}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplePlugin", "SamplePlugin\SamplePlugin.csproj", "{29B84372-AFBB-4120-8213-CC23B6843594}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {349F62FB-801D-4942-B400-131B4642A6EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {349F62FB-801D-4942-B400-131B4642A6EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {349F62FB-801D-4942-B400-131B4642A6EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {349F62FB-801D-4942-B400-131B4642A6EA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {41F5BB8F-4D69-41E1-8E15-45F6494C22BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {41F5BB8F-4D69-41E1-8E15-45F6494C22BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {41F5BB8F-4D69-41E1-8E15-45F6494C22BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {41F5BB8F-4D69-41E1-8E15-45F6494C22BE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {61CD8A45-50EC-4593-8724-DCDD959E4B04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {61CD8A45-50EC-4593-8724-DCDD959E4B04}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {61CD8A45-50EC-4593-8724-DCDD959E4B04}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {61CD8A45-50EC-4593-8724-DCDD959E4B04}.Release|Any CPU.Build.0 = Release|Any CPU
+ {29B84372-AFBB-4120-8213-CC23B6843594}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {29B84372-AFBB-4120-8213-CC23B6843594}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {29B84372-AFBB-4120-8213-CC23B6843594}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {29B84372-AFBB-4120-8213-CC23B6843594}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Binary file not shown.
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using System.Web;
+
+using PreApplicationStartSupport.Core;
+
+// There can be only one such attribute instance per assembly.
+[assembly:PreApplicationStartMethod (typeof (PreApplicationStart.Application.Init), "InitializeApplication")]
+
+namespace PreApplicationStart.Application
+{
+ public class Init
+ {
+ public static void InitializeApplication ()
+ {
+ string appDir = HttpRuntime.AppDomainAppPath;
+ string stampFile = Path.Combine (appDir, "App_Data", ".setup_done");
+ MessageContainer messages = MessageContainer.Instance;
+
+ messages.Clear ();
+ if (!File.Exists (stampFile)) {
+ messages.Add ("First run - need to perform setup steps.");
+ RunSetup (messages, appDir);
+ }
+
+ Assembly pluginAssembly = PluginLoader.LoadPlugin ("SamplePlugin");
+ if (pluginAssembly == null)
+ messages.Add ("Init: failed to load plugin 'SamplePlugin'");
+ else
+ LoadPluginResources (pluginAssembly, messages);
+ }
+
+ static void LoadPluginResources (Assembly pluginAssembly, MessageContainer messages)
+ {
+ Type [] types = pluginAssembly.GetTypes ();
+ IPlugin plugin;
+
+ foreach (Type t in types) {
+ if (!typeof (IPlugin).IsAssignableFrom (t))
+ continue;
+
+ try {
+ plugin = Activator.CreateInstance (t) as IPlugin;
+ plugin.Initialize ();
+ messages.Add ("Init: plugin type '{0}' v{1} loaded", t.FullName, plugin.Version);
+ } catch (Exception ex) {
+ messages.Add ("Init: failed to create instance of type '{0}'. Exception '{1}' was caught, with message: {2}",
+ t.FullName, ex.GetType (), ex.Message);
+ continue;
+ }
+ }
+ }
+
+ static void RunSetup (MessageContainer messages, string appDir)
+ {
+ Assembly setupAssembly = PluginLoader.LoadPlugin ("SetupPlugin");
+ if (setupAssembly == null) {
+ messages.Add ("Init: failed to load setup plugin assembly.");
+ return;
+ }
+
+ Type[] types = setupAssembly.GetTypes ();
+ ISetupPlugin setupPlugin;
+ foreach (Type t in types) {
+ if (!typeof (ISetupPlugin).IsAssignableFrom (t))
+ continue;
+
+ try {
+ setupPlugin = Activator.CreateInstance (t) as ISetupPlugin;
+ setupPlugin.Initialize ();
+ messages.Add ("Init: setup type '{0}' v{1} loaded", t.FullName, setupPlugin.Version);
+ } catch (Exception ex) {
+ messages.Add ("Init: failed to create instance of type '{0}' - cannot perform setup with this type. Exception '{1}' was caught, with message: {2}",
+ t.FullName, ex.GetType (), ex.Message);
+ continue;
+ }
+
+ try {
+ if (!setupPlugin.PerformSetupSteps (appDir)) {
+ messages.Add ("Init: setup failed.");
+ continue;
+ }
+ messages.Add ("Init: setup successful.");
+ } catch (Exception ex) {
+ messages.Add ("Init: setup failed. Exception '{0}' caught: {1}", ex.GetType (), ex.Message);
+ }
+ }
+ }
+ }
+}
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>
+ </ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{349F62FB-801D-4942-B400-131B4642A6EA}</ProjectGuid>
+ <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>PreApplicationStart</RootNamespace>
+ <AssemblyName>PreApplicationStart</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Web.ApplicationServices" />
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="System.Web.Extensions" />
+ <Reference Include="System.Web" />
+ <Reference Include="System.Configuration" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="default.aspx" />
+ <Content Include="Web.config" />
+ <Content Include="Web.Debug.config">
+ <DependentUpon>Web.config</DependentUpon>
+ </Content>
+ <Content Include="Web.Release.config">
+ <DependentUpon>Web.config</DependentUpon>
+ </Content>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Application\Init.cs" />
+ <Compile Include="default.aspx.cs">
+ <DependentUpon>default.aspx</DependentUpon>
+ <SubType>ASPXCodeBehind</SubType>
+ </Compile>
+ <Compile Include="default.aspx.designer.cs">
+ <DependentUpon>default.aspx</DependentUpon>
+ </Compile>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\PreApplicationStartSupport\PreApplicationStartSupport.csproj">
+ <Project>{41F5BB8F-4D69-41E1-8E15-45F6494C22BE}</Project>
+ <Name>PreApplicationStartSupport</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="App_Data\" />
+ <Folder Include="plugins\" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
+ <WebProjectProperties>
+ <UseIIS>False</UseIIS>
+ <AutoAssignPort>True</AutoAssignPort>
+ <DevelopmentServerPort>49388</DevelopmentServerPort>
+ <DevelopmentServerVPath>/</DevelopmentServerVPath>
+ <IISUrl>
+ </IISUrl>
+ <NTLMAuthentication>False</NTLMAuthentication>
+ <UseCustomServer>False</UseCustomServer>
+ <CustomServerUrl>
+ </CustomServerUrl>
+ <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
+ </WebProjectProperties>
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle ("PreApplicationStart")]
+[assembly: AssemblyDescription ("pre-application start blog sample")]
+[assembly: AssemblyConfiguration ("")]
+[assembly: AssemblyCompany ("Marek Habersack")]
+[assembly: AssemblyProduct ("PreApplicationStart")]
+[assembly: AssemblyCopyright ("Copyright © 2010 Marek Habersack")]
+[assembly: AssemblyTrademark ("")]
+[assembly: AssemblyCulture ("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible (false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid ("6ccd039b-4a03-4bf5-8ae9-9e55d8c06481")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion ("1.0.0.0")]
+[assembly: AssemblyFileVersion ("1.0.0.0")]
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+
+<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
+
+<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
+ <!--
+ In the example below, the "SetAttributes" transform will change the value of
+ "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
+ finds an atrribute "name" that has a value of "MyDB".
+
+ <connectionStrings>
+ <add name="MyDB"
+ connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
+ xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
+ </connectionStrings>
+ -->
+ <system.web>
+ <!--
+ In the example below, the "Replace" transform will replace the entire
+ <customErrors> section of your web.config file.
+ Note that because there is only one customErrors section under the
+ <system.web> node, there is no need to use the "xdt:Locator" attribute.
+
+ <customErrors defaultRedirect="GenericError.htm"
+ mode="RemoteOnly" xdt:Transform="Replace">
+ <error statusCode="500" redirect="InternalError.htm"/>
+ </customErrors>
+ -->
+ </system.web>
+</configuration>
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+
+<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
+
+<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
+ <!--
+ In the example below, the "SetAttributes" transform will change the value of
+ "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
+ finds an atrribute "name" that has a value of "MyDB".
+
+ <connectionStrings>
+ <add name="MyDB"
+ connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
+ xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
+ </connectionStrings>
+ -->
+ <system.web>
+ <compilation xdt:Transform="RemoveAttributes(debug)" />
+ <!--
+ In the example below, the "Replace" transform will replace the entire
+ <customErrors> section of your web.config file.
+ Note that because there is only one customErrors section under the
+ <system.web> node, there is no need to use the "xdt:Locator" attribute.
+
+ <customErrors defaultRedirect="GenericError.htm"
+ mode="RemoteOnly" xdt:Transform="Replace">
+ <error statusCode="500" redirect="InternalError.htm"/>
+ </customErrors>
+ -->
+ </system.web>
+</configuration>
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+
+<!--
+ For more information on how to configure your ASP.NET application, please visit
+ http://go.microsoft.com/fwlink/?LinkId=169433
+ -->
+
+<configuration>
+ <appSettings>
+ <!-- a subdirectory of application's root -->
+ <add key="pluginsDir" value="plugins/"/>
+ </appSettings>
+
+ <system.web>
+ <compilation debug="true" targetFramework="4.0" />
+ </system.web>
+
+</configuration>
@@ -0,0 +1,30 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="PreApplicationStart._default" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head runat="server">
+ <title></title>
+</head>
+<body>
+ <form id="form1" runat="server">
+ <div>
+ <asp:Label ID="Label1" runat="server" Text="Event log:"></asp:Label>
+ </div>
+ <div>
+
+ <asp:ListView ID="EventLog" runat="server">
+ <EmptyDataTemplate>
+ <span>No data was returned.</span>
+ </EmptyDataTemplate>
+ <ItemTemplate><%# Container.DataItem %>'
+</ItemTemplate>
+ <LayoutTemplate>
+ <pre ID="itemPlaceholderContainer" runat="server"><span runat="server" id="itemPlaceholder" /></pre>
+ </LayoutTemplate>
+ </asp:ListView>
+
+ </div>
+ </form>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit 2e2ddfb

Please sign in to comment.