public RegionManagementController(IRegionManager regionManager, IWhitespacesManager whitespacesManager, IRegionSource regionSource)
        {
            Microsoft.WhiteSpaces.Common.Check.IsNotNull(regionManager, "User Manager");
            Microsoft.WhiteSpaces.Common.Check.IsNotNull(whitespacesManager, "Whitespaces Manager");
            Microsoft.WhiteSpaces.Common.Check.IsNotNull(regionSource, "Region Source");

            this.regionManager      = regionManager;
            this.whitespacesManager = whitespacesManager;
            this.regionSource       = regionSource;
        }
        public PublicDataController(IPublicDataManager dataManager, IRegionSource regionSource)
        {
            if (dataManager == null)
            {
                throw new ArgumentNullException("dataManager");
            }

            if (regionSource == null)
            {
                throw new ArgumentException("regionSource");
            }

            this.dataManager  = dataManager;
            this.regionSource = regionSource;
        }
        public WSFinderController(IWhitespacesManager whitespacesManager, IRegionSource regionSource)
        {
            if (whitespacesManager == null)
            {
                throw new ArgumentNullException("whitespacesManager");
            }

            if (regionSource == null)
            {
                throw new ArgumentNullException("regionSource");
            }

            this.whitespacesManager = whitespacesManager;
            this.regionSource       = regionSource;
        }
        public override void OnException(ExceptionContext filterContext)
        {
            if (new HttpException(null, filterContext.Exception).GetHttpCode() != 500)
            {
                return;
            }

            if (!ExceptionType.IsInstanceOfType(filterContext.Exception))
            {
                return;
            }

            // Audit Exceptions
            if (!(filterContext.Exception.GetType() == typeof(AccessDeniedException) || filterContext.Exception.GetType() == typeof(ResponseErrorException) || filterContext.Exception.GetType() == typeof(ValidationErrorException)))
            {
                if (filterContext.Exception.GetType() == typeof(DataAccessException))
                {
                    if (this.ExceptionAuditor != null)
                    {
                        this.ExceptionAuditor.TransactionId = this.ExceptionLogger.TransactionId;
                        this.ExceptionAuditor.Audit(AuditId.Exception, AuditStatus.Failure, default(int), "Back end services thrown exception");
                    }

                    if (this.ExceptionLogger != null)
                    {
                        this.ExceptionLogger.Log(TraceEventType.Error, LoggingMessageId.PortalException, "Back end services thrown exception");
                    }
                }

                if (filterContext.Exception.GetType() == typeof(AccessDeniedException))
                {
                    if (this.ExceptionAuditor != null)
                    {
                        this.ExceptionAuditor.TransactionId = this.ExceptionLogger.TransactionId;
                        this.ExceptionAuditor.Audit(AuditId.Exception, AuditStatus.Failure, default(int), "Access token is expired");
                    }

                    if (this.ExceptionLogger != null)
                    {
                        this.ExceptionLogger.Log(TraceEventType.Error, LoggingMessageId.PortalException, "Access token is expired");
                    }
                }

                if (filterContext.Exception.GetType() == typeof(ValidationErrorException))
                {
                    if (this.ExceptionAuditor != null)
                    {
                        this.ExceptionAuditor.TransactionId = this.ExceptionLogger.TransactionId;
                        this.ExceptionAuditor.Audit(AuditId.Exception, AuditStatus.Failure, default(int), "Validation exception is thrown");
                    }

                    if (this.ExceptionLogger != null)
                    {
                        this.ExceptionLogger.Log(TraceEventType.Error, LoggingMessageId.PortalException, "Validation exception is thrown");
                    }
                }
                else
                {
                    if (this.ExceptionAuditor != null)
                    {
                        this.ExceptionAuditor.TransactionId = this.ExceptionLogger.TransactionId;
                        this.ExceptionAuditor.Audit(AuditId.Exception, AuditStatus.Failure, default(int), "An unknown exception occured, Message: " + filterContext.Exception.Message + " ," + "and stack trace: " + filterContext.Exception.StackTrace);
                    }

                    if (this.ExceptionLogger != null)
                    {
                        this.ExceptionLogger.Log(TraceEventType.Error, LoggingMessageId.PortalException, "An unknown exception occured, Message: " + filterContext.Exception.Message + " ," + "and stack trace: " + filterContext.Exception.StackTrace);
                    }
                }
            }

            string referringUrl = "http://" + filterContext.HttpContext.Request.Url.Authority + "/" + (string)filterContext.RouteData.Values["controller"];

            // if the request is AJAX return JSON else view.
            if (filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
            {
                JsonResult errorResult = new JsonResult
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                };

                if (filterContext.Exception.GetType() == typeof(AccessDeniedException))
                {
                    errorResult.Data = new
                    {
                        error   = true,
                        message = filterContext.Exception.Message,
                        type    = "Access Denied",
                        url     = referringUrl
                    };
                }
                else if (filterContext.Exception.GetType() == typeof(ResponseErrorException))
                {
                    ResponseErrorException exception = (ResponseErrorException)filterContext.Exception;
                    errorResult.Data = new
                    {
                        error   = true,
                        message = exception.Data == string.Empty ? exception.Message : exception.Data,
                        type    = "Response Error"
                    };
                }
                else
                {
                    errorResult.Data = new
                    {
                        error   = true,
                        message = filterContext.Exception.Message,
                        type    = "Unknown"
                    };
                }

                filterContext.Result = errorResult;
            }
            else
            {
                if (filterContext.Exception.GetType() == typeof(AccessDeniedException))
                {
                    var routeData = new RouteData();
                    routeData.Values["controller"] = "Account";
                    routeData.Values["action"]     = "Login";
                    routeData.Values["ReturnUrl"]  = referringUrl;

                    IUserManager  userManager  = ConfigHelper.CurrentContainer.Resolve <IUserManager>();
                    IRegionSource regionSource = ConfigHelper.CurrentContainer.Resolve <IRegionSource>();

                    IController errorsController = new AccountController(userManager, regionSource);
                    var         requestContext   = new RequestContext(new HttpContextWrapper(HttpContext.Current), routeData);
                    errorsController.Execute(requestContext);
                }
                else
                {
                    filterContext.Result = new ViewResult
                    {
                        ViewName = "~/Views/Home/Error.cshtml"
                    };
                }

                base.OnException(filterContext);
            }

            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AccountController"/> class
 /// </summary>
 /// <param name="userManager">instance of <see cref="IUserManager"/></param>
 /// <param name="regionSource">instance of IRegionSource.</param>
 public AccountController(IUserManager userManager, IRegionSource regionSource)
 {
     this.userManager  = userManager;
     this.regionSource = regionSource;
 }