Skip to content
Browse files

Initial PreApplicationStart sample commit

  • Loading branch information...
1 parent e0822af commit 2e2ddfbd382c674d9ffdbba8dbf96496a2a99b29 @grendello committed
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
View
0 PreApplicationStart/ChangeLog
No changes.
View
38 PreApplicationStart/PreApplicationStart.sln
@@ -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
View
BIN PreApplicationStart/PreApplicationStart.suo
Binary file not shown.
View
0 PreApplicationStart/PreApplicationStart/App_Data/.placeholder
No changes.
View
92 PreApplicationStart/PreApplicationStart/Application/Init.cs
@@ -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);
+ }
+ }
+ }
+ }
+}
View
106 PreApplicationStart/PreApplicationStart/PreApplicationStart.csproj
@@ -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>
View
35 PreApplicationStart/PreApplicationStart/Properties/AssemblyInfo.cs
@@ -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")]
View
30 PreApplicationStart/PreApplicationStart/Web.Debug.config
@@ -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>
View
31 PreApplicationStart/PreApplicationStart/Web.Release.config
@@ -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>
View
18 PreApplicationStart/PreApplicationStart/Web.config
@@ -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>
View
0 PreApplicationStart/PreApplicationStart/bin/.placeholder
No changes.
View
30 PreApplicationStart/PreApplicationStart/default.aspx
@@ -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>
View
20 PreApplicationStart/PreApplicationStart/default.aspx.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+
+using PreApplicationStartSupport.Core;
+
+namespace PreApplicationStart
+{
+ public partial class _default : System.Web.UI.Page
+ {
+ protected void Page_Load (object sender, EventArgs e)
+ {
+ EventLog.DataSource = MessageContainer.Instance.Messages;
+ EventLog.DataBind ();
+ }
+ }
+}
View
42 PreApplicationStart/PreApplicationStart/default.aspx.designer.cs
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace PreApplicationStart {
+
+
+ public partial class _default {
+
+ /// <summary>
+ /// form1 control.
+ /// </summary>
+ /// <remarks>
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ /// </remarks>
+ protected global::System.Web.UI.HtmlControls.HtmlForm form1;
+
+ /// <summary>
+ /// Label1 control.
+ /// </summary>
+ /// <remarks>
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ /// </remarks>
+ protected global::System.Web.UI.WebControls.Label Label1;
+
+ /// <summary>
+ /// EventLog control.
+ /// </summary>
+ /// <remarks>
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ /// </remarks>
+ protected global::System.Web.UI.WebControls.ListView EventLog;
+ }
+}
View
12 PreApplicationStart/PreApplicationStartSupport/Core/IPlugin.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace PreApplicationStartSupport.Core
+{
+ public interface IPlugin
+ {
+ string Name { get; }
+ Version Version { get; }
+
+ void Initialize ();
+ }
+}
View
12 PreApplicationStart/PreApplicationStartSupport/Core/ISetupPlugin.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace PreApplicationStartSupport.Core
+{
+ public interface ISetupPlugin : IPlugin
+ {
+ bool PerformSetupSteps (string rootDir);
+ }
+}
View
66 PreApplicationStart/PreApplicationStartSupport/Core/MessageContainer.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Text;
+
+namespace PreApplicationStartSupport.Core
+{
+ public class MessageContainer
+ {
+ List <string> messages;
+
+ public static MessageContainer Instance { get; private set; }
+
+ public ReadOnlyCollection<string> Messages
+ {
+ get { return messages.AsReadOnly (); }
+ }
+
+ static MessageContainer ()
+ {
+ Instance = new MessageContainer ();
+ }
+
+ MessageContainer ()
+ {
+ messages = new List<string> ();
+ }
+
+ public void Clear ()
+ {
+ messages.Clear ();
+ }
+
+ public void Add (string message, uint indent = 0, bool timeStamp = true)
+ {
+ var sb = new StringBuilder ();
+ if (indent > 0)
+ sb.Append ('\t', (int)indent);
+ if (timeStamp)
+ sb.AppendFormat ("[{0}] ", DateTime.Now);
+ sb.Append (message);
+
+ messages.Add (sb.ToString ());
+ }
+
+ public void Add (string format, params object [] args)
+ {
+ Add (0, true, format, args);
+ }
+
+ public void Add (uint indent, string format, params object [] args)
+ {
+ Add (indent, true, format, args);
+ }
+
+ public void Add (uint indent, bool timeStamp, string format, params object [] args)
+ {
+ if (args == null || args.Length == 0) {
+ Add (format, indent);
+ return;
+ }
+
+ Add (String.Format (format, args), indent, timeStamp);
+ }
+ }
+}
View
56 PreApplicationStart/PreApplicationStartSupport/Core/PluginLoader.cs
@@ -0,0 +1,56 @@
+using System;
+using System.IO;
+using System.Reflection;
+using System.Web;
+using System.Web.Configuration;
+
+namespace PreApplicationStartSupport.Core
+{
+ public static class PluginLoader
+ {
+ public static Assembly LoadPlugin (string baseName)
+ {
+ if (String.IsNullOrEmpty (baseName))
+ throw new ArgumentException ("Value must not be null or empty.", "baseName");
+
+ string pluginsRelDir = WebConfigurationManager.AppSettings ["pluginsDir"];
+ if (String.IsNullOrEmpty (pluginsRelDir))
+ pluginsRelDir = "plugins/";
+
+ string appPhysicalDir = HttpRuntime.AppDomainAppPath;
+ string pluginsDir = Path.Combine (appPhysicalDir, pluginsRelDir);
+ if (String.Compare (pluginsDir, appPhysicalDir, StringComparison.OrdinalIgnoreCase) == 0) {
+ MessageContainer.Instance.Add ("Plugins directory must not be the same as application root.");
+ return null;
+ }
+
+ if (!pluginsDir.StartsWith (appPhysicalDir, StringComparison.OrdinalIgnoreCase)) {
+ MessageContainer.Instance.Add ("Plugins directory '{0}' is not a subdirectory of application root.", pluginsDir);
+ return null;
+ }
+
+ if (!Directory.Exists (pluginsDir)) {
+ MessageContainer.Instance.Add ("Plugins directory '{0}' does not exist.", pluginsDir);
+ return null;
+ }
+
+ string assemblyPath = Path.Combine (pluginsDir, baseName + ".dll");
+ if (!File.Exists (assemblyPath)) {
+ MessageContainer.Instance.Add ("Plugin '{0}' not found.", baseName);
+ return null;
+ }
+
+ Assembly ret;
+ try {
+ ret = Assembly.LoadFrom (assemblyPath);
+ } catch (Exception ex) {
+ MessageContainer.Instance.Add ("Attempt to load plugin '{0}' failed because of exception '{1}' with message: {2}",
+ baseName, ex.GetType (), ex.Message);
+ return null;
+ }
+
+ MessageContainer.Instance.Add ("Plugin '{0}' loaded successfully.", baseName);
+ return ret;
+ }
+ }
+}
View
53 PreApplicationStart/PreApplicationStartSupport/PreApplicationStartSupport.csproj
@@ -0,0 +1,53 @@
+<?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>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{41F5BB8F-4D69-41E1-8E15-45F6494C22BE}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>PreApplicationStartSupport</RootNamespace>
+ <AssemblyName>PreApplicationStartSupport</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\PreApplicationStart\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\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Web" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Core\IPlugin.cs" />
+ <Compile Include="Core\ISetupPlugin.cs" />
+ <Compile Include="Core\MessageContainer.cs" />
+ <Compile Include="Core\PluginLoader.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- 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>
View
36 PreApplicationStart/PreApplicationStartSupport/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+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 ("PreApplicationStartSupport")]
+[assembly: AssemblyDescription ("")]
+[assembly: AssemblyConfiguration ("")]
+[assembly: AssemblyCompany ("")]
+[assembly: AssemblyProduct ("PreApplicationStartSupport")]
+[assembly: AssemblyCopyright ("Copyright © 2010")]
+[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 ("470e58cd-3ca1-4241-8dd5-20b2dd6807fc")]
+
+// 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 Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion ("1.0.0.0")]
+[assembly: AssemblyFileVersion ("1.0.0.0")]
View
36 PreApplicationStart/SamplePlugin/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+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 ("SamplePlugin")]
+[assembly: AssemblyDescription ("")]
+[assembly: AssemblyConfiguration ("")]
+[assembly: AssemblyCompany ("")]
+[assembly: AssemblyProduct ("SamplePlugin")]
+[assembly: AssemblyCopyright ("Copyright © 2010")]
+[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 ("eead7da5-0b17-4f67-8a00-0f1bc6245a84")]
+
+// 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 Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion ("1.0.0.0")]
+[assembly: AssemblyFileVersion ("1.0.0.0")]
View
34 PreApplicationStart/SamplePlugin/Sample.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+using PreApplicationStartSupport.Core;
+
+namespace SamplePlugin
+{
+ public class Sample : IPlugin
+ {
+ #region IPlugin Members
+
+ public string Name {
+ get { return "Sample Plugin"; }
+ }
+
+ public Version Version { get; private set; }
+
+ public void Initialize ()
+ {
+ Assembly asm = Assembly.GetExecutingAssembly ();
+ object [] attributes = asm.GetCustomAttributes (typeof (AssemblyVersionAttribute), false);
+ if (attributes == null || attributes.Length == 0) {
+ Version = new Version (0, 0, 0, 0);
+ return;
+ }
+
+ var asmVersion = attributes [0] as AssemblyVersionAttribute;
+ Version = new Version (asmVersion.Version);
+ }
+
+ #endregion
+ }
+}
View
56 PreApplicationStart/SamplePlugin/SamplePlugin.csproj
@@ -0,0 +1,56 @@
+<?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>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{29B84372-AFBB-4120-8213-CC23B6843594}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>SamplePlugin</RootNamespace>
+ <AssemblyName>SamplePlugin</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\PreApplicationStart\plugins\</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\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Sample.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\PreApplicationStartSupport\PreApplicationStartSupport.csproj">
+ <Project>{41F5BB8F-4D69-41E1-8E15-45F6494C22BE}</Project>
+ <Name>PreApplicationStartSupport</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- 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>
View
36 PreApplicationStart/SetupPlugin/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+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 ("SetupPlugin")]
+[assembly: AssemblyDescription ("")]
+[assembly: AssemblyConfiguration ("")]
+[assembly: AssemblyCompany ("")]
+[assembly: AssemblyProduct ("SetupPlugin")]
+[assembly: AssemblyCopyright ("Copyright © 2010")]
+[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 ("b1ffcc8d-53fa-40e1-90cd-76ff3354b9b7")]
+
+// 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 Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion ("1.0.0.0")]
+[assembly: AssemblyFileVersion ("1.0.0.0")]
View
80 PreApplicationStart/SetupPlugin/Setup.cs
@@ -0,0 +1,80 @@
+using System;
+using System.IO;
+using System.Reflection;
+using PreApplicationStartSupport.Core;
+
+namespace SetupPlugin
+{
+ public class Setup : ISetupPlugin
+ {
+ public Setup ()
+ {
+ }
+
+ #region ISetupPlugin Members
+
+ void CreateDirectory (string name, string dataDir, MessageContainer messages)
+ {
+ string newDir = Path.Combine (dataDir, name);
+ if (!Directory.Exists (newDir)) {
+ Directory.CreateDirectory (newDir);
+ messages.Add (1, false, "* directory {0} created", newDir);
+ }
+ }
+
+ public bool PerformSetupSteps (string rootDir)
+ {
+ MessageContainer messages = MessageContainer.Instance;
+ if (!Directory.Exists (rootDir)) {
+ messages.Add ("Setup: root directory '{0}' does not exist.", rootDir);
+ return false;
+ }
+
+ string dataDir = Path.Combine (rootDir, "App_Data");
+ if (!Directory.Exists (dataDir)) {
+ messages.Add ("Setup: application data directory '{0}' does not exist.", dataDir);
+ return false;
+ }
+
+ try {
+ messages.Add ("Setup: creating directories");
+ CreateDirectory ("directory1", dataDir, messages);
+ CreateDirectory ("logs", dataDir, messages);
+ CreateDirectory ("backups", dataDir, messages);
+
+ File.WriteAllText (Path.Combine (dataDir, ".setup_done"), DateTime.Now.ToString ());
+ } catch (Exception ex) {
+ messages.Add ("Setup: creating directories failed with exception '{0}': {1}", ex.GetType (), ex.Message);
+ return false;
+ }
+
+ return true;
+ }
+
+ #endregion
+
+ #region IPlugin Members
+
+ public string Name
+ {
+ get { return "Setup Plugin"; }
+ }
+
+ public Version Version { get; private set; }
+
+ public void Initialize ()
+ {
+ Assembly asm = GetType ().Assembly;
+ object[] attributes = asm.GetCustomAttributes (typeof (AssemblyVersionAttribute), false);
+ if (attributes == null || attributes.Length == 0) {
+ Version = new Version (0, 0, 0, 0);
+ return;
+ }
+
+ var asmVersion = attributes [0] as AssemblyVersionAttribute;
+ Version = new Version (asmVersion.Version);
+ }
+
+ #endregion
+ }
+}
View
56 PreApplicationStart/SetupPlugin/SetupPlugin.csproj
@@ -0,0 +1,56 @@
+<?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>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{61CD8A45-50EC-4593-8724-DCDD959E4B04}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>SetupPlugin</RootNamespace>
+ <AssemblyName>SetupPlugin</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\PreApplicationStart\plugins\</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\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Setup.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\PreApplicationStartSupport\PreApplicationStartSupport.csproj">
+ <Project>{41F5BB8F-4D69-41E1-8E15-45F6494C22BE}</Project>
+ <Name>PreApplicationStartSupport</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- 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 comments on commit 2e2ddfb

Please sign in to comment.
Something went wrong with that request. Please try again.