Skip to content

Commit

Permalink
Init logger on first request
Browse files Browse the repository at this point in the history
Rebuild sample web app from scratch in VS2013
  • Loading branch information
mausch committed Jun 28, 2015
1 parent 6ede367 commit 0346078
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 255 deletions.
19 changes: 9 additions & 10 deletions QuartzNetWebConsole.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{CAD78976-5F87-4988-BC1D-E3E70398F7CD}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
Expand All @@ -10,15 +12,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{CAD789
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuartzNetWebConsole", "QuartzNetWebConsole\QuartzNetWebConsole.csproj", "{72A7A322-38DD-47DD-8948-6ED6E2F9DC5D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleApp", "SampleApp\SampleApp.csproj", "{F2832947-64D9-4B0A-A0BD-DDE7E90AC968}"
ProjectSection(ProjectDependencies) = postProject
{72A7A322-38DD-47DD-8948-6ED6E2F9DC5D} = {72A7A322-38DD-47DD-8948-6ED6E2F9DC5D}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuartzNetWebConsole.Tests", "QuartzNetWebConsole.Tests\QuartzNetWebConsole.Tests.csproj", "{05021F00-C4D1-45C3-92EC-92C467B74F67}"
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "QuartzNetWebConsole.Views", "QuartzNetWebConsole.Views\QuartzNetWebConsole.Views.vbproj", "{7961AB01-1549-4340-8D3D-F0DA43B8C84F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleApp", "SampleApp\SampleApp.csproj", "{AA2D041C-4CDC-4055-8FC5-C0ECD4D8AE48}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -29,10 +28,6 @@ Global
{72A7A322-38DD-47DD-8948-6ED6E2F9DC5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72A7A322-38DD-47DD-8948-6ED6E2F9DC5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72A7A322-38DD-47DD-8948-6ED6E2F9DC5D}.Release|Any CPU.Build.0 = Release|Any CPU
{F2832947-64D9-4B0A-A0BD-DDE7E90AC968}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2832947-64D9-4B0A-A0BD-DDE7E90AC968}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2832947-64D9-4B0A-A0BD-DDE7E90AC968}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2832947-64D9-4B0A-A0BD-DDE7E90AC968}.Release|Any CPU.Build.0 = Release|Any CPU
{05021F00-C4D1-45C3-92EC-92C467B74F67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05021F00-C4D1-45C3-92EC-92C467B74F67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05021F00-C4D1-45C3-92EC-92C467B74F67}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -41,6 +36,10 @@ Global
{7961AB01-1549-4340-8D3D-F0DA43B8C84F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7961AB01-1549-4340-8D3D-F0DA43B8C84F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7961AB01-1549-4340-8D3D-F0DA43B8C84F}.Release|Any CPU.Build.0 = Release|Any CPU
{AA2D041C-4CDC-4055-8FC5-C0ECD4D8AE48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA2D041C-4CDC-4055-8FC5-C0ECD4D8AE48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA2D041C-4CDC-4055-8FC5-C0ECD4D8AE48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA2D041C-4CDC-4055-8FC5-C0ECD4D8AE48}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 0 additions & 16 deletions SampleApp/Default.aspx

This file was deleted.

17 changes: 0 additions & 17 deletions SampleApp/Default.aspx.cs

This file was deleted.

27 changes: 0 additions & 27 deletions SampleApp/Default.aspx.designer.cs

This file was deleted.

2 changes: 1 addition & 1 deletion SampleApp/Global.asax
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%@ Application Codebehind="Global.asax.cs" Inherits="SampleApp.Global" Language="C#" %>
<%@ Application Codebehind="Global.asax.cs" Inherits="SampleApp.MvcApplication" Language="C#" %>
54 changes: 27 additions & 27 deletions SampleApp/Global.asax.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
using System;
using System.Web;
using System.Web.Routing;
using Quartz;
using Quartz.Impl;
using QuartzNetWebConsole;

namespace SampleApp {
public class Global : HttpApplication {

static readonly HttpRequest InitialRequest;

static Global() {
// Workaround to fix error "Request is not available in this context" with IIS7 or IIS Express
// http://sammyageil.com/post/Request-is-not-available-in-this-context-exception-in-Globalasaxs-Application_Start-IIS-7-Integrated-mode
InitialRequest = HttpContext.Current.Request;
}

protected void Application_Start(object sender, EventArgs e) {
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication {
void Application_Start() {
// First, initialize Quartz.NET as usual. In this sample app I'll configure Quartz.NET by code.
var schedulerFactory = new StdSchedulerFactory();
var scheduler = schedulerFactory.GetScheduler();
Expand All @@ -24,9 +18,6 @@ protected void Application_Start(object sender, EventArgs e) {
// This tells the QuartzNetWebConsole what scheduler to use
Setup.Scheduler = () => scheduler;

// This adds an logger to the QuartzNetWebConsole. It's optional.
var partialQuartzConsoleUrl = string.Format("http://{0}:{1}/quartz/", InitialRequest.Url.Host, InitialRequest.Url.Port);
Setup.Logger = new MemoryLogger(1000, partialQuartzConsoleUrl);

// I'll add some global listeners
scheduler.ListenerManager.AddJobListener(new GlobalJobListener());
Expand All @@ -39,7 +30,7 @@ protected void Application_Start(object sender, EventArgs e) {
.WithIntervalInSeconds(6))
.StartNow()
.Build();
var job = new JobDetailImpl("myJob", null, typeof (HelloJob));
var job = new JobDetailImpl("myJob", null, typeof(HelloJob));
scheduler.ScheduleJob(job, trigger);

// A cron trigger and job
Expand All @@ -52,19 +43,28 @@ protected void Application_Start(object sender, EventArgs e) {
scheduler.ScheduleJob(cron);

// A dummy calendar
scheduler.AddCalendar("myCalendar", new DummyCalendar {Description = "dummy calendar"}, false, false);
scheduler.AddCalendar("myCalendar", new DummyCalendar { Description = "dummy calendar" }, false, false);
RouteTable.Routes.Add(new R());
}

protected void Session_Start(object sender, EventArgs e) {}

protected void Application_BeginRequest(object sender, EventArgs e) {}

protected void Application_AuthenticateRequest(object sender, EventArgs e) {}

protected void Application_Error(object sender, EventArgs e) {}

protected void Session_End(object sender, EventArgs e) {}

protected void Application_End(object sender, EventArgs e) {}
private class R : RouteBase {
private static readonly Lazy<object> initLogger = new Lazy<object>(() => {
// This adds an logger to the QuartzNetWebConsole. It's optional.
var partialQuartzConsoleUrl = string.Format("http://{0}:{1}/quartz/", HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port);
Setup.Logger = new MemoryLogger(1000, partialQuartzConsoleUrl);
return null;
});

public override RouteData GetRouteData(HttpContextBase httpContext) {
var _ = initLogger.Value;
if (httpContext.Request.Url.PathAndQuery == "/")
httpContext.Response.Redirect("/quartz/index.ashx", endResponse: true);
return null;
}

public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) {
throw new NotImplementedException();
}
}
}
}
6 changes: 3 additions & 3 deletions SampleApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
[assembly: AssemblyTitle("SampleApp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SampleApp")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -20,7 +20,7 @@
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3d5900ae-111a-45be-96b3-d9e4606ca793")]
[assembly: Guid("b13b6624-5506-4db3-8661-88816e5e3f7c")]

// Version information for an assembly consists of the following four values:
//
Expand Down
100 changes: 52 additions & 48 deletions SampleApp/SampleApp.csproj
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F2832947-64D9-4B0A-A0BD-DDE7E90AC968}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<ProjectGuid>{AA2D041C-4CDC-4055-8FC5-C0ECD4D8AE48}</ProjectGuid>
<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SampleApp</RootNamespace>
<AssemblyName>SampleApp</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
<UseIISExpress>false</UseIISExpress>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>true</UseIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -46,39 +43,26 @@
<ItemGroup>
<Reference Include="Common.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Common.Logging.3.0.0\lib\net35\Common.Logging.dll</HintPath>
<HintPath>..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="Common.Logging.Core">
<HintPath>..\packages\Common.Logging.Core.3.0.0\lib\net35\Common.Logging.Core.dll</HintPath>
</Reference>
<Reference Include="Quartz, Version=2.3.2.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
<Reference Include="Common.Logging.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Quartz.2.3.2\lib\net35\Quartz.dll</HintPath>
<HintPath>..\packages\Common.Logging.Core.3.0.0\lib\net40\Common.Logging.Core.dll</HintPath>
</Reference>
<Reference Include="QuartzNetWebConsole, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Quartz, Version=2.3.2.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\QuartzNetWebConsole\Build\QuartzNetWebConsole.dll</HintPath>
<HintPath>..\packages\Quartz.2.3.2\lib\net40\Quartz.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
</ItemGroup>
<ItemGroup>
<Content Include="Default.aspx" />
<Content Include="Global.asax" />
<Content Include="Web.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="Default.aspx.cs">
<SubType>ASPXCodeBehind</SubType>
<DependentUpon>Default.aspx</DependentUpon>
</Compile>
<Compile Include="Default.aspx.designer.cs">
<DependentUpon>Default.aspx</DependentUpon>
</Compile>
<Compile Include="DummyCalendar.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
Expand All @@ -89,11 +73,24 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
<Content Include="Global.asax" />
<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>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\QuartzNetWebConsole\QuartzNetWebConsole.csproj">
<Project>{72a7a322-38dd-47dd-8948-6ed6e2f9dc5d}</Project>
<Name>QuartzNetWebConsole</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="job_scheduling_data_2_0.xsd">
<SubType>Designer</SubType>
Expand All @@ -106,23 +103,18 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<!-- 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 Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
-->
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>39255</DevelopmentServerPort>
<DevelopmentServerPort>61402</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>
</IISUrl>
<IISUrl>http://localhost:39255/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
Expand All @@ -132,5 +124,17 @@
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- 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>
Loading

0 comments on commit 0346078

Please sign in to comment.