Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
fix: favicon route throws exception on some versions of IIS
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenRedd committed Aug 16, 2013
1 parent 234bcd6 commit 0a0b106
Showing 1 changed file with 177 additions and 177 deletions.
354 changes: 177 additions & 177 deletions TicketDesk-2/TicketDesk.Web.Client/Global.asax.cs
Original file line number Diff line number Diff line change
@@ -1,178 +1,178 @@
// TicketDesk - Attribution notice
// Contributor(s):
//
// Stephen Redd ([email protected], http://www.reddnet.net)
//
// This file is distributed under the terms of the Microsoft Public
// License (Ms-PL). See http://ticketdesk.codeplex.com/license
// for the complete terms of use.
//
// For any distribution that contains code from this file, this notice of
// attribution must remain intact, and a copy of the license must be
// provided to the recipient.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Compilation;
using System.Reflection;
using System.ComponentModel.Composition.Hosting;
using TicketDesk.Web.Client.Controllers;
using System.IO;
using System.Web.Security;
using System.Configuration;
using TicketDesk.Domain.Repositories;
using TicketDesk.Domain.Services;

namespace TicketDesk.Web.Client
{


// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801

public class MvcApplication : MefHttpApplication
{
private System.Timers.Timer DerelictAttachmentsTimer;
private System.Timers.Timer EmaiNotificationsTimer;


public static CompositionContainer RootContainer;
public static void RegisterRoutes(RouteCollection routes, bool hideHome)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*)?favicon.ico" });
//routes.IgnoreRoute("{*crossdomain}", new { crossdomain = @"(.*)?crossdomain.xml" });
//routes.IgnoreRoute("{*robots}", new { crossdomain = @"(.*)?robots.txt" });
//routes.IgnoreRoute("{*css}", new { css = @"(.*)?.css"});
routes.IgnoreRoute("{file}.txt");
routes.IgnoreRoute("{file}.htm");
routes.IgnoreRoute("{file}.html");
routes.IgnoreRoute("{file}.xml");
routes.IgnoreRoute("{*script}", new { script = @"Scripts/(.*)" });
routes.IgnoreRoute("{*content}", new { content = @"Content/(.*)" });

routes.MapRoute("Attachments", "Attachment/{action}/{fileId}", new { Controller = "Attachment" });

routes.MapRoute(
"MarkdownPreview",
"MarkdownPreview",
new { controller = "Markdown", action = "MarkdownPreview" });

routes.MapRoute(
"TicketCreate",
"NewTicket",
new { controller = "NewTicket", action = "Create" });

routes.MapRoute(
"TicketViewer",
"Ticket/{id}/{action}/{activity}",
new { controller = "TicketEditor", action = "Display", activity = string.Empty });

routes.MapRoute(
"TicketCenterPaging", // Route name
"TicketCenter/{action}/{listName}/{page}", // URL with parameters
new { controller = "TicketCenter", action = "List", listName = "unassigned", page = "1" }, // Parameter defaults
new { controller = "TicketCenter", page = @"\d+" }
);

if (hideHome)
{
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "TicketCenter", action = "List", id = UrlParameter.Optional } // Parameter defaults
);
}
else
{
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}

routes.MapRoute(
"404-PageNotFound",
"{*url}",
new { controller = "StaticContent", action = "PageNotFound" }
);
}

private static System.Timers.Timer SecurityRefreshTimer { get; set; }

private IApplicationSettingsService AppSettings;

protected override void Application_Start()
{

base.Application_Start();
AppSettings = MefHttpApplication.ApplicationContainer.GetExportedValue<IApplicationSettingsService>();

AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes, AppSettings.HideHomePage);

var databaseSchemaManager = MefHttpApplication.ApplicationContainer.GetExportedValue<IDatabaseSchemaManagerService>();
var searchService = MefHttpApplication.ApplicationContainer.GetExportedValue<TicketSearchService>();
var ticketService = MefHttpApplication.ApplicationContainer.GetExportedValue<ITicketService>();

databaseSchemaManager.EnsureSchemaVersion();

searchService.InitializeSearch(ticketService);

var securityService = MefHttpApplication.ApplicationContainer.GetExportedValue<ISecurityService>();

//timer is initialized by the service, but we have to hold a reference to it here or it will be garbage collected
// in SQL Security Environments, this will just return null; there is no timer
SecurityRefreshTimer = securityService.InitializeSecurityCacheRefreshTimer();

DerelictAttachmentsTimer = new System.Timers.Timer();
int derelictInterval = 300000;
DerelictAttachmentsTimer.Elapsed += new System.Timers.ElapsedEventHandler(DerelictAttachmentsTimer_Elapsed);
DerelictAttachmentsTimer.Interval = derelictInterval;
DerelictAttachmentsTimer.AutoReset = true;
DerelictAttachmentsTimer.Start();

if (AppSettings.EmailNotificationsEnabled())
{

EmaiNotificationsTimer = new System.Timers.Timer();

int emailInterval = AppSettings.EmailDeliveryTimerIntervalMinutes * 60000;

EmaiNotificationsTimer.Elapsed += new System.Timers.ElapsedEventHandler(EmaiNotificationsTimer_Elapsed);
EmaiNotificationsTimer.Interval = emailInterval;
EmaiNotificationsTimer.AutoReset = true;
EmaiNotificationsTimer.Start();

}
}
private static Object emaiNotificationsTimerIsRunningLock = new Object();
private void EmaiNotificationsTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
lock (emaiNotificationsTimerIsRunningLock)
{
var noteSender = MefHttpApplication.ApplicationContainer.GetExportedValue<INotificationSendingService>();
noteSender.ProcessWaitingTicketEventNotifications();
}
}

private static Object derelictAttachmentsTimerIsRunningLock = new Object();
private void DerelictAttachmentsTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
lock (derelictAttachmentsTimerIsRunningLock)
{
//clean up pending attachments that are now derelict
int hoursOld = AppSettings.CleanupPendingAttachmentsAfterHours;

var tsvc = MefHttpApplication.ApplicationContainer.GetExportedValue<ITicketService>();
tsvc.CleanUpDerelictAttachments(hoursOld);
}
}

}
// TicketDesk - Attribution notice
// Contributor(s):
//
// Stephen Redd ([email protected], http://www.reddnet.net)
//
// This file is distributed under the terms of the Microsoft Public
// License (Ms-PL). See http://ticketdesk.codeplex.com/license
// for the complete terms of use.
//
// For any distribution that contains code from this file, this notice of
// attribution must remain intact, and a copy of the license must be
// provided to the recipient.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Compilation;
using System.Reflection;
using System.ComponentModel.Composition.Hosting;
using TicketDesk.Web.Client.Controllers;
using System.IO;
using System.Web.Security;
using System.Configuration;
using TicketDesk.Domain.Repositories;
using TicketDesk.Domain.Services;

namespace TicketDesk.Web.Client
{


// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801

public class MvcApplication : MefHttpApplication
{
private System.Timers.Timer DerelictAttachmentsTimer;
private System.Timers.Timer EmaiNotificationsTimer;


public static CompositionContainer RootContainer;
public static void RegisterRoutes(RouteCollection routes, bool hideHome)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*)?favicon.ico" });
//routes.IgnoreRoute("{*crossdomain}", new { crossdomain = @"(.*)?crossdomain.xml" });
//routes.IgnoreRoute("{*robots}", new { crossdomain = @"(.*)?robots.txt" });
//routes.IgnoreRoute("{*css}", new { css = @"(.*)?.css"});
routes.IgnoreRoute("{file}.txt");
routes.IgnoreRoute("{file}.htm");
routes.IgnoreRoute("{file}.html");
routes.IgnoreRoute("{file}.xml");
routes.IgnoreRoute("{*script}", new { script = @"Scripts/(.*)" });
routes.IgnoreRoute("{*content}", new { content = @"Content/(.*)" });

routes.MapRoute("Attachments", "Attachment/{action}/{fileId}", new { Controller = "Attachment" });

routes.MapRoute(
"MarkdownPreview",
"MarkdownPreview",
new { controller = "Markdown", action = "MarkdownPreview" });

routes.MapRoute(
"TicketCreate",
"NewTicket",
new { controller = "NewTicket", action = "Create" });

routes.MapRoute(
"TicketViewer",
"Ticket/{id}/{action}/{activity}",
new { controller = "TicketEditor", action = "Display", activity = string.Empty });

routes.MapRoute(
"TicketCenterPaging", // Route name
"TicketCenter/{action}/{listName}/{page}", // URL with parameters
new { controller = "TicketCenter", action = "List", listName = "unassigned", page = "1" }, // Parameter defaults
new { controller = "TicketCenter", page = @"\d+" }
);

if (hideHome)
{
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "TicketCenter", action = "List", id = UrlParameter.Optional } // Parameter defaults
);
}
else
{
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}

routes.MapRoute(
"404-PageNotFound",
"{*url}",
new { controller = "StaticContent", action = "PageNotFound" }
);
}

private static System.Timers.Timer SecurityRefreshTimer { get; set; }

private IApplicationSettingsService AppSettings;

protected override void Application_Start()
{

base.Application_Start();
AppSettings = MefHttpApplication.ApplicationContainer.GetExportedValue<IApplicationSettingsService>();

AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes, AppSettings.HideHomePage);

var databaseSchemaManager = MefHttpApplication.ApplicationContainer.GetExportedValue<IDatabaseSchemaManagerService>();
var searchService = MefHttpApplication.ApplicationContainer.GetExportedValue<TicketSearchService>();
var ticketService = MefHttpApplication.ApplicationContainer.GetExportedValue<ITicketService>();

databaseSchemaManager.EnsureSchemaVersion();

searchService.InitializeSearch(ticketService);

var securityService = MefHttpApplication.ApplicationContainer.GetExportedValue<ISecurityService>();

//timer is initialized by the service, but we have to hold a reference to it here or it will be garbage collected
// in SQL Security Environments, this will just return null; there is no timer
SecurityRefreshTimer = securityService.InitializeSecurityCacheRefreshTimer();

DerelictAttachmentsTimer = new System.Timers.Timer();
int derelictInterval = 300000;
DerelictAttachmentsTimer.Elapsed += new System.Timers.ElapsedEventHandler(DerelictAttachmentsTimer_Elapsed);
DerelictAttachmentsTimer.Interval = derelictInterval;
DerelictAttachmentsTimer.AutoReset = true;
DerelictAttachmentsTimer.Start();

if (AppSettings.EmailNotificationsEnabled())
{

EmaiNotificationsTimer = new System.Timers.Timer();

int emailInterval = AppSettings.EmailDeliveryTimerIntervalMinutes * 60000;

EmaiNotificationsTimer.Elapsed += new System.Timers.ElapsedEventHandler(EmaiNotificationsTimer_Elapsed);
EmaiNotificationsTimer.Interval = emailInterval;
EmaiNotificationsTimer.AutoReset = true;
EmaiNotificationsTimer.Start();

}
}
private static Object emaiNotificationsTimerIsRunningLock = new Object();
private void EmaiNotificationsTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
lock (emaiNotificationsTimerIsRunningLock)
{
var noteSender = MefHttpApplication.ApplicationContainer.GetExportedValue<INotificationSendingService>();
noteSender.ProcessWaitingTicketEventNotifications();
}
}

private static Object derelictAttachmentsTimerIsRunningLock = new Object();
private void DerelictAttachmentsTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
lock (derelictAttachmentsTimerIsRunningLock)
{
//clean up pending attachments that are now derelict
int hoursOld = AppSettings.CleanupPendingAttachmentsAfterHours;

var tsvc = MefHttpApplication.ApplicationContainer.GetExportedValue<ITicketService>();
tsvc.CleanUpDerelictAttachments(hoursOld);
}
}

}
}

0 comments on commit 0a0b106

Please sign in to comment.