예제 #1
0
        public HelperCommand(string connectionString, CommandType commandType)
        {
            connectionString = ISConfiguration.GetDbConfig(connectionString);

            _connection = new SqlConnection(connectionString);
            _command    = new SqlCommand {
                CommandType = commandType, Connection = _connection
            };
        }
예제 #2
0
        /// <summary>
        /// Inicializa el helper de acceso a datos.
        /// </summary>
        /// <param name="connectionString">Cadena o nombre constante de conexión para la fuente de datos.</param>
        public HelperCommand(string connectionString)
        {
            connectionString = ISConfiguration.GetDbConfig(connectionString);

            _connection = new SqlConnection(connectionString);
            _command    = new SqlCommand {
                CommandType = CommandType.StoredProcedure, Connection = _connection
            };
        }
예제 #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
                                                                              sqlServerOptionsAction: sqlOptions =>
            {
                sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
                sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
            }));

            services.AddIdentity <ApplicationUser, ApplicationRole>(options =>
            {
                options.Password.RequiredLength         = 5;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireDigit           = false;
            })
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.AddHealthChecks()
            .AddCheck("self", () => HealthCheckResult.Healthy())
            .AddSqlServer(Configuration["ConnectionString"],
                          name: "IdentityDB-check",
                          tags: new string[] { "IdentityDB" });

            var config = new ISConfiguration(Configuration);

            services.AddIdentityServer()
            .AddAspNetIdentity <ApplicationUser>()
            .AddProfileService <ProfileService>()
            .AddInMemoryApiResources(config.Resourses)
            .AddInMemoryApiScopes(config.Scopes)
            .AddInMemoryClients(config.Clients)
            .AddDeveloperSigningCredential();

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc(ApiRoutes.V1.Version, new OpenApiInfo
                {
                    Title       = "App - Identity HTTP API",
                    Version     = ApiRoutes.V1.Version,
                    Description = "The Identity Service HTTP API"
                });
            });

            services.AddControllers();
        }
예제 #4
0
        private void ConfigureIdentityServer(IServiceCollection services)
        {
            services.AddIdentityServer()
            .AddInMemoryApiResources(ISConfiguration.GetApiResources())
            .AddInMemoryIdentityResources(ISConfiguration.GetIdentityResources())
            .AddInMemoryClients(ISConfiguration.GetClients())
            .AddExtensionGrantValidator <GoogleGrantValidator>()
            .AddDeveloperSigningCredential()
            .AddAspNetIdentity <AuthUser>();

            services.Configure <IdentityOptions>(options =>
            {
                options.Password.RequiredLength         = 1;
                options.Password.RequireDigit           = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
            });
        }
예제 #5
0
 public ISCrypto()
 {
     algorithm = cryptoProvider.Rijndael;
     _key      = ISConfiguration.GetConfigurationParameter("Security", "_appSecu_pkey");
     _IV       = ISConfiguration.GetConfigurationParameter("Security", "_appSecu_pIV");
 }
예제 #6
0
        /// <summary>
        /// Envio de email con varios adjuntos.
        /// </summary>
        /// <param name="to"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="isHtmlBody"></param>
        /// <param name="attachments"></param>
        /// <param name="resultMessage"></param>
        /// <returns></returns>
        public static bool SendMailWithAttachment(string to, string subject,
                                                  string body,
                                                  bool isHtmlBody,
                                                  IList <Adjunto> attachments,
                                                  out string resultMessage)
        {
            //SE VALIDA CONFIGURACION DE CORREO
            if (string.IsNullOrEmpty(ISConfiguration.GetConfigurationParameter("Email", "_appMail_FromAddress")))
            {
                resultMessage = "Invalid configuration value: FromAddress";
                ISException.RegisterExcepcion(resultMessage);
                return(false);
            }

            try
            {
                using (var mailMessage = new MailMessage
                {
                    From = new MailAddress(ISConfiguration.GetConfigurationParameter("Email", "_appMail_FromAddress")),
                    Subject = subject,
                    Body = body,
                    IsBodyHtml = isHtmlBody,
                })
                {
                    mailMessage.To.Add(to);
                    //SE AGREGAN LOS ADJUNTOS
                    if (attachments != null && attachments.Count > 0)
                    {
                        for (int i = 0; i < attachments.Count; i++)
                        {
                            if (!string.IsNullOrEmpty(attachments[i].Contenido) && !string.IsNullOrEmpty(attachments[i].Nombre))
                            {
                                //SE CARGA EL ADJUNTO AL MENSAJE
                                byte[] filebytes = Convert.FromBase64String(attachments[i].Contenido);
                                Stream stream    = new MemoryStream(filebytes);
                                mailMessage.Attachments.Add(new Attachment(stream, attachments[i].Nombre));
                            }
                        }
                    }

                    //SE CREA EL CLIENTE SMTP
                    var smtpClient = new SmtpClient
                    {
                        Host =
                            ISConfiguration.GetConfigurationParameter("Email", "_appMail_SmtpServer"),
                        Port =
                            ISConvert.ToInteger(ISConfiguration.GetConfigurationParameter("Email",
                                                                                          "_appMail_SmtpPort")),
                        Credentials =
                            new NetworkCredential(
                                ISConfiguration.GetConfigurationParameter("Email", "_appMail_User"),
                                ISConfiguration.GetConfigurationParameter("Email", "_appMail_Password"),
                                ISConfiguration.GetConfigurationParameter("Email", "_appMail_Domain")),
                        EnableSsl =
                            ISConvert.ToBoolean(ISConfiguration.GetConfigurationParameter("Email",
                                                                                          "_appMail_AuthenticationRequired"))
                    };

                    //SE ENVIA EL MAIL
                    //smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtpClient.Send(mailMessage);
                }
                resultMessage = string.Empty;
                return(true);
            }
            catch (FormatException ex)
            {
                resultMessage = ex.Message;
                ISException.RegisterExcepcion(ex);
                return(false);
            }
            catch (SmtpException ex)
            {
                resultMessage = ex.Message;
                ISException.RegisterExcepcion(ex);
                return(false);
            }
            catch (Exception ex)
            {
                resultMessage = ex.Message;
                ISException.RegisterExcepcion(ex);
                return(false);
            }
        }
예제 #7
0
        public bool SendMail(string[] strListTo, string[] strListCc, string strSubject, string strBody,
                             bool blnIsBodyHtml, bool blnAsyncMethod, object objState, out string _strResultMessage)
        {
            if (string.IsNullOrEmpty(ISConfiguration.GetConfigurationParameter("Email", "_appMail_FromAddress")))
            {
                _strResultMessage = "Invalid configuration value: FromAddress";
                ISException.RegisterExcepcion(_strResultMessage);
                return(false);
            }

            try
            {
                var objMailMessage = new MailMessage();

                objMailMessage.From =
                    new MailAddress(ISConfiguration.GetConfigurationParameter("Email", "_appMail_FromAddress"));

                for (int index = 0; index < strListTo.Length; index++)
                {
                    objMailMessage.To.Add(strListTo[index]);
                }

                for (int index = 0; index < strListCc.Length; index++)
                {
                    objMailMessage.CC.Add(strListCc[index]);
                }

                objMailMessage.Subject    = strSubject;
                objMailMessage.Body       = strBody;
                objMailMessage.IsBodyHtml = blnIsBodyHtml;

                var objSmtpClient = new SmtpClient();
                objSmtpClient.Host = ISConfiguration.GetConfigurationParameter("Email", "_appMail_SmtpServer");
                objSmtpClient.Port =
                    ISConvert.ToInteger(ISConfiguration.GetConfigurationParameter("Email", "_appMail_SmtpPort"));
                ;
                objSmtpClient.Credentials =
                    new NetworkCredential(ISConfiguration.GetConfigurationParameter("Email", "_appMail_User"),
                                          ISConfiguration.GetConfigurationParameter("Email", "_appMail_Password"),
                                          ISConfiguration.GetConfigurationParameter("Email", "_appMail_Domain"));
                objSmtpClient.EnableSsl =
                    ISConvert.ToBoolean(ISConfiguration.GetConfigurationParameter("Email",
                                                                                  "_appMail_AuthenticationRequired"));

                if (blnAsyncMethod)
                {
                    objSmtpClient.SendCompleted += objSmtpClient_SendCompleted;
                    objSmtpClient.SendAsync(objMailMessage, objState);

                    _strResultMessage = string.Empty;
                    return(true);
                }

                objSmtpClient.Send(objMailMessage);
                _strResultMessage = string.Empty;
                return(true);
            }
            catch (FormatException ex)
            {
                _strResultMessage = ex.Message;
                ISException.RegisterExcepcion(ex);
                return(false);
            }
            catch (SmtpException ex)
            {
                _strResultMessage = ex.Message;
                ISException.RegisterExcepcion(ex);
                return(false);
            }
            catch (Exception ex)
            {
                _strResultMessage = ex.Message;
                ISException.RegisterExcepcion(ex);
                return(false);
            }
        }