Initial commit
This commit is contained in:
59
SIG.Web/AppCode/Configuration/AppServices.cs
Normal file
59
SIG.Web/AppCode/Configuration/AppServices.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using SIG.Web.AppCode.Contracts.Database;
|
||||
using SIG.Web.AppCode.Contracts.Search;
|
||||
using SIG.Web.AppCode.Contracts.Security;
|
||||
using SIG.Web.AppCode.Notifications.Contracts;
|
||||
using SIG.Web.AppCode.Notifications.Services;
|
||||
using SIG.Web.AppCode.Repositories.Security;
|
||||
using SIG.Web.AppCode.Services.Database;
|
||||
using SIG.Web.AppCode.Services.Menu;
|
||||
using SIG.Web.AppCode.Services.Search;
|
||||
using SIG.Web.AppCode.Services.Security;
|
||||
using SIG.Web.AppCode.Session;
|
||||
|
||||
namespace SIG.Web.AppCode.Configuration
|
||||
{
|
||||
public static class AppServices
|
||||
{
|
||||
public static IDbConnectionFactory DbConnectionFactory { get; private set; }
|
||||
public static IDbExecutor DbExecutor { get; private set; }
|
||||
public static IPasswordHasher PasswordHasher { get; private set; }
|
||||
public static IUserRepository UserRepository { get; private set; }
|
||||
public static IUserAdministrationRepository UserAdministrationRepository { get; private set; }
|
||||
public static IPublicRegistrationService PublicRegistrationService { get; private set; }
|
||||
public static ILoginAttemptRepository LoginAttemptRepository { get; private set; } public static IUserSessionRepository UserSessionRepository { get; private set; }
|
||||
public static ILoginService LoginService { get; private set; }
|
||||
public static IUserContextProvider UserContext { get; private set; }
|
||||
public static IPermissionService PermissionService { get; private set; }
|
||||
public static IMenuProvider MenuProvider { get; private set; }
|
||||
public static INotificationCenter NotificationCenter { get; private set; }
|
||||
public static IBuscadorCatalogoDataProvider SearchProvider { get; private set; }
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
DbConnectionFactory = new DbConnectionFactory();
|
||||
DbExecutor = new DbExecutor(DbConnectionFactory);
|
||||
|
||||
PasswordHasher = new PasswordHasher();
|
||||
|
||||
UserRepository = new UserRepository(DbExecutor);
|
||||
UserAdministrationRepository = new UserAdministrationRepository(DbExecutor);
|
||||
LoginAttemptRepository = new LoginAttemptRepository(DbExecutor); UserSessionRepository = new UserSessionRepository(DbExecutor);
|
||||
|
||||
UserContext = new WebFormsUserContextProvider();
|
||||
PermissionService = new PermissionService(DbExecutor);
|
||||
MenuProvider = new MenuProvider(DbExecutor);
|
||||
NotificationCenter = new DummyNotificationCenter();
|
||||
SearchProvider = new DummyBuscadorCatalogoDataProvider();
|
||||
|
||||
LoginService = new LoginService(
|
||||
UserRepository,
|
||||
PasswordHasher,
|
||||
LoginAttemptRepository,
|
||||
UserSessionRepository);
|
||||
|
||||
PublicRegistrationService = new PublicRegistrationService(
|
||||
UserAdministrationRepository,
|
||||
PasswordHasher,
|
||||
new SmtpEmailSender());
|
||||
} }
|
||||
}
|
||||
127
SIG.Web/AppCode/Configuration/BundleConfig.cs
Normal file
127
SIG.Web/AppCode/Configuration/BundleConfig.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using System.Web.Optimization;
|
||||
using System.Web.UI;
|
||||
|
||||
namespace SIG.Web.AppCode.Configuration
|
||||
{
|
||||
public static class BundleConfig
|
||||
{
|
||||
public static void RegisterBundles(BundleCollection bundles)
|
||||
{
|
||||
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
|
||||
"~/Metronic/assets/global/plugins/jquery.min.js"
|
||||
));
|
||||
|
||||
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", null, new ScriptResourceDefinition
|
||||
{
|
||||
Path = "~/bundles/jquery"
|
||||
});
|
||||
|
||||
bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
|
||||
"~/Metronic/assets/global/plugins/jquery-ui/jquery-ui.min.js",
|
||||
"~/Metronic/assets/global/plugins/jquery-migrate.min.js",
|
||||
"~/Scripts/funciones.js",
|
||||
"~/Scripts/FixFocus.js",
|
||||
"~/Scripts/jquery.number.js",
|
||||
"~/Scripts/jquery.maskMoney.js",
|
||||
"~/Scripts/jquery.thickbox.js",
|
||||
"~/Scripts/jquery.fancybox-1.3.4.js",
|
||||
"~/Scripts/jquery.maskedinput-1.2.2.min.js",
|
||||
"~/Scripts/raphael.2.1.0.min.js",
|
||||
"~/Scripts/justgage.1.0.1.min.js",
|
||||
"~/Scripts/multiselect.js",
|
||||
"~/Scripts/jquery.mask.min.js",
|
||||
"~/Scripts/gridviewScroll.js",
|
||||
"~/Metronic/Carusel/slick.min.js"
|
||||
));
|
||||
|
||||
bundles.Add(new ScriptBundle("~/Metronic/assets/global/scripts/JSV1").Include(
|
||||
"~/Metronic/assets/global/plugins/bootstrap/js/bootstrap.min.js",
|
||||
"~/Metronic/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js",
|
||||
"~/Metronic/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js",
|
||||
"~/Metronic/assets/global/plugins/jquery.blockui.min.js",
|
||||
"~/Metronic/assets/global/plugins/jquery.cokie.min.js",
|
||||
"~/Metronic/assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js",
|
||||
"~/Metronic/assets/global/plugins/select2/select2.full.min.js",
|
||||
"~/Metronic/assets/global/plugins/select2/i18n/es.js",
|
||||
"~/Metronic/assets/global/plugins/bootstrap-confirmation/bootstrap-confirmation.min.js",
|
||||
"~/Metronic/assets/global/plugins/bootbox/bootbox.min.js",
|
||||
"~/Metronic/assets/global/plugins/bootstrap-toastr/toastr.min.js",
|
||||
"~/Metronic/assets/global/scripts/metronic.js",
|
||||
"~/Metronic/assets/admin/layout/scripts/layout.js",
|
||||
"~/Metronic/assets/admin/layout/scripts/quick-sidebar.js",
|
||||
"~/Metronic/assets/admin/layout/scripts/demo.js",
|
||||
"~/Scripts/porcentaje-box.js",
|
||||
"~/Scripts/DropdownGrid.js",
|
||||
"~/Scripts/UcBuscadorCatalogo.js",
|
||||
"~/Scripts/SigPdfViewer.js",
|
||||
"~/Scripts/SigPdfDrawer.js",
|
||||
"~/Scripts/custom.js"
|
||||
));
|
||||
|
||||
bundles.Add(new ScriptBundle("~/bundles/WebFormsJs").Include(
|
||||
"~/Scripts/WebForms/WebForms.js",
|
||||
"~/Scripts/WebForms/WebUIValidation.js",
|
||||
"~/Scripts/WebForms/MenuStandards.js",
|
||||
"~/Scripts/WebForms/Focus.js",
|
||||
"~/Scripts/WebForms/GridView.js",
|
||||
"~/Scripts/WebForms/DetailsView.js",
|
||||
"~/Scripts/WebForms/TreeView.js",
|
||||
"~/Scripts/WebForms/WebParts.js"
|
||||
));
|
||||
|
||||
ScriptManager.ScriptResourceMapping.AddDefinition("WebFormsBundle", new ScriptResourceDefinition
|
||||
{
|
||||
Path = "~/bundles/WebFormsJs"
|
||||
});
|
||||
|
||||
bundles.Add(new ScriptBundle("~/bundles/MsAjaxJs").Include(
|
||||
"~/Scripts/WebForms/MsAjax/MicrosoftAjax.js",
|
||||
"~/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js",
|
||||
"~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
|
||||
"~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"
|
||||
));
|
||||
|
||||
ScriptManager.ScriptResourceMapping.AddDefinition("MsAjaxBundle", new ScriptResourceDefinition
|
||||
{
|
||||
Path = "~/bundles/MsAjaxJs"
|
||||
});
|
||||
|
||||
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include("~/Scripts/modernizr-*"));
|
||||
|
||||
ScriptManager.ScriptResourceMapping.AddDefinition("respond", new ScriptResourceDefinition
|
||||
{
|
||||
Path = "~/Scripts/respond.min.js",
|
||||
DebugPath = "~/Scripts/respond.js"
|
||||
});
|
||||
|
||||
bundles.Add(new StyleBundle("~/Content/AjaxControlToolkit/Styles/Bundle").Include(
|
||||
"~/Content/AjaxControlToolkit/Styles/AjaxFileUpload.min.css",
|
||||
"~/Content/AjaxControlToolkit/Styles/Calendar.min.css",
|
||||
"~/Content/AjaxControlToolkit/Styles/Tabs.min.css",
|
||||
"~/Content/AjaxControlToolkit/Styles/ValidatorCallout.min.css",
|
||||
"~/Content/AjaxControlToolkit/Styles/HtmlEditorExtender.min.css"
|
||||
));
|
||||
|
||||
bundles.Add(new StyleBundle("~/Metronic/assets/global/css/cssV1")
|
||||
.Include("~/Metronic/assets/global/plugins/font-awesome/css/font-awesome.min.css", new CssRewriteUrlTransform())
|
||||
.Include("~/Metronic/assets/global/plugins/bootstrap/css/bootstrap.min.css", new CssRewriteUrlTransform())
|
||||
.Include("~/Metronic/assets/global/plugins/simple-line-icons/simple-line-icons.min.css", new CssRewriteUrlTransform())
|
||||
.Include(
|
||||
"~/Styles/porcentaje-box.css",
|
||||
"~/Styles/DropdownGrid.css",
|
||||
"~/Styles/UcBuscadorCatalogo.css",
|
||||
"~/Styles/SigPdfViewer.css",
|
||||
"~/Styles/SigPdfDrawer.css",
|
||||
"~/Styles/Estilos2.css",
|
||||
"~/Metronic/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css",
|
||||
"~/Metronic/assets/global/plugins/bootstrap-toastr/toastr.min.css",
|
||||
"~/Metronic/assets/global/plugins/select2/select2.css",
|
||||
"~/Metronic/assets/global/css/components.css",
|
||||
"~/Metronic/assets/global/css/plugins.css",
|
||||
"~/Metronic/assets/admin/layout/css/layout.css",
|
||||
"~/Metronic/assets/admin/layout/css/custom.css")
|
||||
.Include("~/Metronic/Carusel/slick.css", new CssRewriteUrlTransform())
|
||||
.Include("~/Metronic/Carusel/slick-theme.css", new CssRewriteUrlTransform()));
|
||||
}
|
||||
}
|
||||
}
|
||||
294
SIG.Web/AppCode/Configuration/ErrorHandlerConfig.cs
Normal file
294
SIG.Web/AppCode/Configuration/ErrorHandlerConfig.cs
Normal file
@@ -0,0 +1,294 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using SIG.Web.AppCode.Services.Errors;
|
||||
using SIG.Web.AppCode.Session;
|
||||
|
||||
namespace SIG.Web.AppCode.Configuration
|
||||
{
|
||||
public static class ErrorHandlerConfig
|
||||
{
|
||||
public static void Register()
|
||||
{
|
||||
}
|
||||
|
||||
public static void HandleServerError(
|
||||
Exception exception,
|
||||
HttpContext context)
|
||||
{
|
||||
if (exception == null || context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
UserSessionModel usuario = ObtenerUsuarioActual();
|
||||
|
||||
string cveUsuario = usuario != null
|
||||
? usuario.CveUsuario.ToString()
|
||||
: string.Empty;
|
||||
|
||||
string nombreUsuario = usuario != null
|
||||
? usuario.Nombre
|
||||
: string.Empty;
|
||||
|
||||
int cveRole = usuario != null
|
||||
? usuario.CveRol
|
||||
: 0;
|
||||
|
||||
string codigo = SIGErrorManager.Registrar(
|
||||
exception,
|
||||
context,
|
||||
"Application_Error",
|
||||
cveUsuario,
|
||||
nombreUsuario
|
||||
);
|
||||
|
||||
bool esPeticionAsincrona =
|
||||
SIGErrorManager.EsPeticionAsincrona(context);
|
||||
|
||||
/*
|
||||
* El detalle t<>cnico completo siempre se guarda en log.
|
||||
* Solo el administrador puede verlo en la respuesta.
|
||||
*/
|
||||
bool mostrarDetalle = cveRole == 1;
|
||||
|
||||
context.Server.ClearError();
|
||||
|
||||
if (esPeticionAsincrona)
|
||||
{
|
||||
EscribirErrorAsincrono(
|
||||
context,
|
||||
codigo,
|
||||
exception,
|
||||
mostrarDetalle
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
EscribirPaginaError(
|
||||
context,
|
||||
codigo,
|
||||
exception,
|
||||
mostrarDetalle,
|
||||
cveUsuario,
|
||||
nombreUsuario,
|
||||
cveRole
|
||||
);
|
||||
}
|
||||
catch (Exception handlerException)
|
||||
{
|
||||
try
|
||||
{
|
||||
SIGErrorManager.Registrar(
|
||||
handlerException,
|
||||
context,
|
||||
"ErrorHandlerConfig.HandleServerError",
|
||||
string.Empty,
|
||||
string.Empty
|
||||
);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// El manejador global nunca debe provocar otro error.
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
context.Server.ClearError();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetFriendlyMessage(
|
||||
Exception exception)
|
||||
{
|
||||
if (exception == null)
|
||||
{
|
||||
return "Ocurri<72> un error inesperado.";
|
||||
}
|
||||
|
||||
Exception baseException =
|
||||
exception.GetBaseException();
|
||||
|
||||
SqlException sqlException =
|
||||
baseException as SqlException;
|
||||
|
||||
if (sqlException != null)
|
||||
{
|
||||
switch (sqlException.Number)
|
||||
{
|
||||
case 207:
|
||||
return "No fue posible completar la operaci<63>n porque falta una columna requerida en la base de datos.";
|
||||
|
||||
case 208:
|
||||
return "No fue posible completar la operaci<63>n porque falta una tabla o vista requerida en la base de datos.";
|
||||
|
||||
case 4060:
|
||||
return "No fue posible abrir la base de datos configurada.";
|
||||
|
||||
case 18456:
|
||||
return "No fue posible iniciar sesi<73>n en la base de datos.";
|
||||
|
||||
case -2:
|
||||
return "La base de datos tard<72> demasiado en responder.";
|
||||
|
||||
case 1205:
|
||||
return "La operaci<63>n no pudo completarse porque ocurri<72> un bloqueo en la base de datos. Intente nuevamente.";
|
||||
|
||||
case 547:
|
||||
return "No fue posible completar la operaci<63>n porque existen registros relacionados.";
|
||||
|
||||
case 2627:
|
||||
case 2601:
|
||||
return "Ya existe un registro con la misma informaci<63>n.";
|
||||
|
||||
default:
|
||||
return "Ocurri<72> un error al consultar la base de datos.";
|
||||
}
|
||||
}
|
||||
|
||||
if (baseException is TimeoutException)
|
||||
{
|
||||
return "La solicitud tard<72> demasiado en responder. Intente nuevamente.";
|
||||
}
|
||||
|
||||
if (baseException is OperationCanceledException)
|
||||
{
|
||||
return "La operaci<63>n fue cancelada antes de completarse.";
|
||||
}
|
||||
|
||||
HttpException httpException =
|
||||
baseException as HttpException;
|
||||
|
||||
if (httpException != null)
|
||||
{
|
||||
int statusCode =
|
||||
httpException.GetHttpCode();
|
||||
|
||||
switch (statusCode)
|
||||
{
|
||||
case 400:
|
||||
return "La solicitud enviada no es v<>lida.";
|
||||
|
||||
case 401:
|
||||
return "Su sesi<73>n no tiene autorizaci<63>n para realizar esta operaci<63>n.";
|
||||
|
||||
case 403:
|
||||
return "No tiene permisos para realizar esta operaci<63>n.";
|
||||
|
||||
case 404:
|
||||
return "No se encontr<74> el recurso solicitado.";
|
||||
|
||||
case 408:
|
||||
return "La solicitud tard<72> demasiado en responder.";
|
||||
|
||||
case 413:
|
||||
return "El archivo o contenido enviado supera el tama<6D>o permitido.";
|
||||
|
||||
default:
|
||||
return "Ocurri<72> un error al procesar la solicitud.";
|
||||
}
|
||||
}
|
||||
|
||||
return "Ocurri<72> un error inesperado. Intente nuevamente.";
|
||||
}
|
||||
|
||||
private static void EscribirErrorAsincrono(
|
||||
HttpContext context,
|
||||
string codigo,
|
||||
Exception exception,
|
||||
bool mostrarDetalle)
|
||||
{
|
||||
string respuesta =
|
||||
"SIG_ERROR|" + codigo;
|
||||
|
||||
if (mostrarDetalle)
|
||||
{
|
||||
string detalle =
|
||||
SIGErrorManager.ObtenerDetalleTecnico(
|
||||
exception
|
||||
);
|
||||
|
||||
string detalleBase64 =
|
||||
Convert.ToBase64String(
|
||||
Encoding.UTF8.GetBytes(detalle)
|
||||
);
|
||||
|
||||
respuesta += "|" + detalleBase64;
|
||||
}
|
||||
|
||||
context.Response.Clear();
|
||||
context.Response.ClearHeaders();
|
||||
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.TrySkipIisCustomErrors = true;
|
||||
context.Response.ContentType =
|
||||
"text/plain; charset=utf-8";
|
||||
|
||||
context.Response.AddHeader(
|
||||
"X-SIG-Error-Code",
|
||||
codigo
|
||||
);
|
||||
|
||||
context.Response.Write(respuesta);
|
||||
|
||||
context.ApplicationInstance.CompleteRequest();
|
||||
}
|
||||
|
||||
private static void EscribirPaginaError(
|
||||
HttpContext context,
|
||||
string codigo,
|
||||
Exception exception,
|
||||
bool mostrarDetalle,
|
||||
string cveUsuario,
|
||||
string nombreUsuario,
|
||||
int cveRole)
|
||||
{
|
||||
string html =
|
||||
SIGErrorManager.CrearHtmlError(
|
||||
codigo,
|
||||
exception,
|
||||
mostrarDetalle,
|
||||
cveUsuario,
|
||||
nombreUsuario,
|
||||
cveRole
|
||||
);
|
||||
|
||||
context.Response.Clear();
|
||||
context.Response.ClearHeaders();
|
||||
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.TrySkipIisCustomErrors = true;
|
||||
context.Response.ContentType =
|
||||
"text/html; charset=utf-8";
|
||||
|
||||
context.Response.Write(html);
|
||||
|
||||
context.ApplicationInstance.CompleteRequest();
|
||||
}
|
||||
|
||||
private static UserSessionModel ObtenerUsuarioActual()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (AppServices.UserContext == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return AppServices.UserContext.GetCurrentUser();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user