-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
4,483 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
A new HTTP handler has been configured in your application for consulting the | ||
error log and its feeds. It is reachable at elmah.axd under your application | ||
root. If, for example, your application is deployed at http://www.example.com, | ||
the URL for ELMAH would be http://www.example.com/elmah.axd. You can, of | ||
course, change this path in your application's configuration file. | ||
|
||
ELMAH is also set up to be secure such that it can only be accessed locally. | ||
You can enable remote access but then it is paramount that you secure access | ||
to authorized users or/and roles only. This can be done using standard | ||
authorization rules and configuration already built into ASP.NET. For more | ||
information, see http://code.google.com/p/elmah/wiki/SecuringErrorLogPages on | ||
the project site. | ||
|
||
Please review the commented out authorization section under | ||
<location path="elmah.axd"> and make the appropriate changes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Web.Mvc; | ||
|
||
namespace PlayR.Areas.Admin | ||
{ | ||
public class AdminAreaRegistration : AreaRegistration | ||
{ | ||
public override string AreaName | ||
{ | ||
get | ||
{ | ||
return "Admin"; | ||
} | ||
} | ||
|
||
public override void RegisterArea(AreaRegistrationContext context) | ||
{ | ||
context.MapRoute( | ||
"Admin_default", | ||
"Admin/{controller}/{action}/{id}", | ||
new { action = "Index", id = UrlParameter.Optional } ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
using Elmah; | ||
|
||
namespace PlayR.Areas.Admin.Controllers | ||
{ | ||
//[Authorize(Roles = "Admin")] | ||
public class ElmahController : Controller | ||
{ | ||
public ActionResult Index() | ||
{ | ||
return new ElmahResult(); | ||
} | ||
|
||
public ActionResult Stylesheet() | ||
{ | ||
return new ElmahResult("stylesheet"); | ||
} | ||
|
||
public ActionResult Rss() | ||
{ | ||
return new ElmahResult("rss"); | ||
} | ||
|
||
public ActionResult DigestRss() | ||
{ | ||
return new ElmahResult("digestrss"); | ||
} | ||
|
||
public ActionResult About() | ||
{ | ||
return new ElmahResult("about"); | ||
} | ||
|
||
public ActionResult Detail() | ||
{ | ||
return new ElmahResult("detail"); | ||
} | ||
|
||
public ActionResult Download() | ||
{ | ||
return new ElmahResult("download"); | ||
} | ||
|
||
public ActionResult Json() | ||
{ | ||
return new ElmahResult("json"); | ||
} | ||
|
||
public ActionResult Xml() | ||
{ | ||
return new ElmahResult("xml"); | ||
} | ||
} | ||
|
||
internal class ElmahResult : ActionResult | ||
{ | ||
private readonly string _resouceType; | ||
|
||
public ElmahResult() | ||
: this(null) | ||
{ | ||
} | ||
|
||
public ElmahResult(string resouceType) | ||
{ | ||
_resouceType = resouceType; | ||
} | ||
|
||
public override void ExecuteResult(ControllerContext context) | ||
{ | ||
var factory = new ErrorLogPageFactory(); | ||
|
||
if (!string.IsNullOrEmpty(_resouceType)) | ||
{ | ||
string pathInfo = "/" + _resouceType; | ||
context.HttpContext.RewritePath(FilePath(context), pathInfo, | ||
context.HttpContext.Request.QueryString.ToString()); | ||
} | ||
|
||
var currentContext = GetCurrentContextAsHttpContext(context); | ||
|
||
var httpHandler = factory.GetHandler(currentContext, null, null, null); | ||
var httpAsyncHandler = httpHandler as IHttpAsyncHandler; | ||
|
||
if (httpAsyncHandler != null) | ||
{ | ||
httpAsyncHandler.BeginProcessRequest(currentContext, r => { }, null); | ||
return; | ||
} | ||
|
||
httpHandler.ProcessRequest(currentContext); | ||
} | ||
|
||
private static HttpContext GetCurrentContextAsHttpContext(ControllerContext context) | ||
{ | ||
return context.HttpContext.ApplicationInstance.Context; | ||
} | ||
|
||
private string FilePath(ControllerContext context) | ||
{ | ||
return _resouceType != "stylesheet" | ||
? context.HttpContext.Request.Path.Replace(String.Format("/{0}", _resouceType), string.Empty) | ||
: context.HttpContext.Request.Path; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Data.SqlClient; | ||
|
||
namespace PlayR.Core | ||
{ | ||
public class DatabaseMessageLogger : IMessageLogger, IDisposable | ||
{ | ||
SqlConnection connection; | ||
|
||
public DatabaseMessageLogger() | ||
{ | ||
connection = GetConnection(); | ||
} | ||
|
||
public void LogMessage(string message, string user) | ||
{ | ||
using(var command = new SqlCommand("insert into Messages values (@user, @message)", connection)) | ||
{ | ||
command.Parameters.AddWithValue("user", user); | ||
command.Parameters.AddWithValue("message", message); | ||
|
||
connection.Open(); | ||
command.ExecuteNonQuery(); | ||
} | ||
} | ||
|
||
SqlConnection GetConnection() | ||
{ | ||
return new SqlConnection(GetConnectionString()); | ||
} | ||
|
||
string GetConnectionString() | ||
{ | ||
System.Configuration.Configuration rootWebConfig = | ||
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/"); | ||
System.Configuration.ConnectionStringSettings connString; | ||
if(rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0) | ||
{ | ||
connString = | ||
rootWebConfig.ConnectionStrings.ConnectionStrings["playr"]; | ||
if(connString != null) | ||
return connString.ConnectionString; | ||
} | ||
return null; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
connection.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace PlayR.Core | ||
{ | ||
public interface IMessageLogger | ||
{ | ||
void LogMessage(string message, string user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
using SignalR.Hubs; | ||
using PlayR.Core; | ||
using SignalR.Hubs; | ||
|
||
namespace PlayR.Hubs | ||
{ | ||
public class Chat : Hub | ||
{ | ||
readonly IMessageLogger _messageLogger; | ||
|
||
public Chat() | ||
: this(new DatabaseMessageLogger()) | ||
{ | ||
} | ||
|
||
public Chat(IMessageLogger messageLogger) | ||
{ | ||
_messageLogger = messageLogger; | ||
} | ||
|
||
public void Send(string message, string user) | ||
{ | ||
// Call the addMessage method on all clients | ||
Clients.addMessage(message, user); | ||
_messageLogger.LogMessage(message, user); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using SignalR; | ||
using StructureMap; | ||
|
||
namespace PlayR.Infrastructure | ||
{ | ||
public class StructureMapResolver : DefaultDependencyResolver | ||
{ | ||
private IContainer _container; | ||
|
||
public StructureMapResolver(IContainer container) | ||
{ | ||
_container = container; | ||
} | ||
|
||
public override object GetService(Type serviceType) | ||
{ | ||
object service = null; | ||
if(!serviceType.IsAbstract && !serviceType.IsInterface && serviceType.IsClass) | ||
{ | ||
// Concrete type resolution | ||
service = _container.GetInstance(serviceType); | ||
} | ||
else | ||
{ | ||
// Other type resolution with base fallback | ||
service = _container.TryGetInstance(serviceType) ?? base.GetService(serviceType); | ||
} | ||
return service; | ||
} | ||
|
||
public override IEnumerable<object> GetServices(Type serviceType) | ||
{ | ||
var objects = _container.GetAllInstances(serviceType).Cast<object>(); | ||
objects.Concat(base.GetServices(serviceType)); | ||
return objects; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.