Ejemplo n.º 1
1
        private static void UseSmtpEmailer(Container container)
        {
            var appSettings = new AppSettings();

            //Use 'SmtpConfig' appSetting in Web.config if it exists otherwise use default config below:
            container.Register(appSettings.Get("SmtpConfig",
                new SmtpConfig {
                    Host = "smtphost",
                    Port = 587,
                    UserName = "******",
                    Password = "******"
                }));

            container.RegisterAs<SmtpEmailer, IEmailer>().ReusedWithin(ReuseScope.Request);
        }
Ejemplo n.º 2
0
        public override void Configure(Container container)
        {
            var appSettings = new AppSettings();

            var clientsManager = new RedisManagerPool(appSettings.Get("RedisConnectionString", "redis://localhost:6379"));
            container.Register<IRedisClientsManager>(c => clientsManager);

            container.Register<IPasswordGenerator>(
                new RngPasswordGenerator()
                {
                    PasswordLength = appSettings.Exists("PasswordLength") ? appSettings.Get<uint>("PasswordLength") : 16
                });

            container.Register<IOneTimePasswordRepository>(c => new RedisOneTimePasswordRepository()
            {
                ClientsManager = clientsManager,
                PasswordExpiryInSeconds = appSettings.Get<uint>("PasswordExpiryInSeconds", 30)
            });
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            string archivoPorProcesar = null;

            if (args.Length > 0) {
                archivoPorProcesar = args [0];
                Console.WriteLine (archivoPorProcesar);
            }

            var appSettings = new AppSettings();

            var fechaRadicacionInicial = appSettings.Get<DateTime>("FechaRadicacionInicial", new DateTime(2015, 1, 7));
            var fechaRadicacionFinal = appSettings.Get<DateTime>("FechaRadicacionFinal", DateTime.Today);
            var urlBaseVivanto = appSettings.Get<string>("UrlBaseVivanto", "http://190.60.70.149:82");
            var varConexionBD = appSettings.Get<string>("ConexionBD", "APP_CONEXION_IRD");
            var varUsuarioVivanto = appSettings.Get<string>("UsuarioVivanto", "APP_USUARIO_VIVANTO");
            var varClaveVivanto = appSettings.Get<string>("ClaveVivanto", "APP_CLAVE_VIVANTO");

            var conexionBD = Environment.GetEnvironmentVariable(varConexionBD);
            var usuarioVivanto = Environment.GetEnvironmentVariable(varUsuarioVivanto);
            var claveVivanto = Environment.GetEnvironmentVariable(varClaveVivanto);

            Console.WriteLine(fechaRadicacionInicial);
            Console.WriteLine(fechaRadicacionFinal);
            Console.WriteLine(urlBaseVivanto);
            Console.WriteLine(varConexionBD);
            Console.WriteLine(varUsuarioVivanto);
            Console.WriteLine(varClaveVivanto);
            Console.WriteLine(conexionBD);
            Console.WriteLine(usuarioVivanto);
            Console.WriteLine(claveVivanto);

            var login = new LoginVivanto { Usuario = usuarioVivanto, Clave = claveVivanto };

            var par = new ParametrosServicio() { UrlBase = urlBaseVivanto };
            var parProcesamiento = new ParametrosProcesamiento()
            {
                FechaRadicacionInicial = fechaRadicacionInicial,
                FechaRadicacionFinal = fechaRadicacionFinal
            };

            using (IConexionVivanto cliente = new ConexionVivanto (par, login)) {

                var dbfactory = new OrmLiteConnectionFactory (conexionBD, SqlServerDialect.Provider);
                var dbcliente = new ConexionIRDCOL (dbfactory);
                cliente.IniciarSesion ();
                var proc = new Procesamiento (cliente, dbcliente, parProcesamiento);
                var np = proc.Iniciar (archivoPorProcesar);
                Console.WriteLine ("Listo primera fase");
                Console.WriteLine ("esperando 5 segundos para iniciar con los no procesados");
                System.Threading.Thread.Sleep (5 * 1000);
                Console.WriteLine ("Iniciando ahora con los no procesados...");
                //proc = new Procesamiento (cliente, dbcliente, parProcesamiento);
                proc.Iniciar (np);
                cliente.CerrarSession ();
            }

            return;
        }
        public override void Configure(Container container)
        {
            container.RegisterAutoWired<EmailProvider>();
            container.RegisterAutoWired<FacebookGateway>();
            container.RegisterAutoWired<TwitterGateway>();
            
            Plugins.Add(new RazorFormat());
            Plugins.Add(new RequestLogsFeature());

            var appSettings = new AppSettings();
            Plugins.Add(new AuthFeature(() => new CustomSession(), 
                new IAuthProvider[] {
                    new CredentialsAuthProvider(appSettings), 
                    new TwitterAuthProvider(appSettings),
                    new FacebookAuthProvider(appSettings), 
                }));

            container.Register<IRedisClientsManager>(new PooledRedisClientManager("localhost:6379"));
            container.Register(c => c.Resolve<IRedisClientsManager>().GetCacheClient());

            container.Register<IDbConnectionFactory>(
                new OrmLiteConnectionFactory("~/App_Data/db.sqlite".MapHostAbsolutePath(), 
                    SqliteDialect.Provider) {
                        ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
                    });

            //Store User Data into above OrmLite database
            container.Register<IAuthRepository>(c => 
                new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));

            //If using and RDBMS to persist UserAuth, we must create required tables
            var authRepo = container.Resolve<IAuthRepository>();
            authRepo.InitSchema();

            //Register MQ Service
            var mqService = new RedisMqServer(container.Resolve<IRedisClientsManager>());
            container.Register<IMessageService>(mqService);
            container.Register(mqService.MessageFactory);

            mqService.RegisterHandler<SMessage>(ServiceController.ExecuteMessage);
            mqService.RegisterHandler<CallFacebook>(ServiceController.ExecuteMessage);
            mqService.RegisterHandler<EmailMessage>(ServiceController.ExecuteMessage);
            mqService.RegisterHandler<PostStatusTwitter>(ServiceController.ExecuteMessage);

            mqService.Start();

            if (appSettings.Get("ResetAllOnStartUp", false))
            {
                ResetAll(container, (OrmLiteAuthRepository)authRepo);
            }
        }
Ejemplo n.º 5
0
        public static void ConfigureAuth(List<IPlugin> Plugins, Funq.Container container)
        {
            //Enable and register existing services you want this host to make use of.
            //Look in Web.config for examples on how to configure your oauth proviers, e.g. oauth.facebook.AppId, etc.
            var appSettings = new AppSettings();

            //Register all Authentication methods you want to enable for this web app.
            Plugins.Add(new AuthFeature(
                () => new AuthUserSession(), //Use your own typed Custom UserSession type
                new IAuthProvider[] {
                    new CredentialsAuthProvider()
                }));

            //Provide service for new users to register so they can login with supplied credentials.
            Plugins.Add(new RegistrationFeature());

            //Create a DB Factory configured to access the UserAuth SQL Server DB
            var connStr = appSettings.Get("MYSQL_CONNECTION_STRING", //AppHarbor or Local connection string
                ConfigUtils.GetConnectionString("UserAuth"));
            container.Register<IDbConnectionFactory>(
                new OrmLiteConnectionFactory(connStr, //ConnectionString in Web.Config
                    ServiceStack.OrmLite.MySql.MySqlDialectProvider.Instance)
                {
                    ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
                });

            //Store User Data into the referenced SqlServer database
            container.Register<IUserAuthRepository>(c =>
                new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>())); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info

            var authRepo = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>(); //If using and RDBMS to persist UserAuth, we must create required tables
            if (appSettings.Get("RecreateAuthTables", false))
                authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
            else
                authRepo.CreateMissingTables();   //Create only the missing tables
        }
Ejemplo n.º 6
0
            private static IDbConnectionFactory GetDataFactory()
            {
                var appSettings = new AppSettings();

                var connStringName = appSettings.Get<string>("ConnectionString", null);
                if (connStringName == null)
                {
                    // TODO
                    return null;
                }

                var connString = ConfigurationManager.ConnectionStrings[connStringName];
                var provider = GetDialectProvider(connString.ProviderName);

                return new OrmLiteConnectionFactory(connString.ConnectionString, provider);
            }
        public void Ready()
        {
            //Invoke on DOM ready
            var appSettings = new AppSettings();
            var checkForUpdates = appSettings.Get<bool>("EnableAutoUpdate");
            if (!checkForUpdates)
                return;

            var releaseFolderUrl = appSettings.GetString("UpdateManagerUrl");
            try
            {
                var updatesAvailableTask = AppUpdater.CheckForUpdates(releaseFolderUrl);
                updatesAvailableTask.ContinueWith(isAvailable =>
                {
                    isAvailable.Wait(TimeSpan.FromMinutes(1));
                    bool updatesAvailable = isAvailable.Result;
                    //Only check once one launch then release UpdateManager.
                    if (!updatesAvailable)
                    {
                        AppUpdater.Dispose();
                        return;
                    }
                    if (formMain == null)
                    {
                        return;
                    }
                    // Notify web client updates are available.
                    formMain.InvokeOnUiThreadIfRequired(() =>
                    {
                        formMain.ChromiumBrowser.GetMainFrame().ExecuteJavaScriptAsync("window.updateAvailable();");
                    });
                });
            }
            catch (Exception e)
            {
                // Error reaching update server
            }
        }
Ejemplo n.º 8
0
            public override void Configure(Funq.Container container)
            {
                //register any dependencies your services use, e.g:
                //container.Register<ICacheClient>(new MemoryCacheClient());

                Plugins.Add (new SwaggerFeature ());

                Routes.Add<LocationRequest> ("/Location/Update/", "POST");

                SetConfig (new EndpointHostConfig {
                    DebugMode = true
                });

                this.PreRequestFilters.Add ((req, resp) => {

                });

                this.RequestFilters.Add ((IHttpRequest httpReq, IHttpResponse httpResp, object requestDto) => {
                    var appSettings = new AppSettings ();

                    if (httpReq.Headers ["Authorization-API"] == null) {
                        throw HttpError.Unauthorized ("No Authorization Header provided");
                    }

                    string storedAPIKey = appSettings.Get ("GeoAPIKey", "");
                    string passedAPIKey = httpReq.Headers ["Authorization-API"];

                    if (String.IsNullOrEmpty (storedAPIKey)) {
                        throw HttpError.Unauthorized ("API Key not configured");
                    } else if (storedAPIKey != passedAPIKey) {
                        throw HttpError.Unauthorized ("API Key passed from the client was not found");
                    }

                });
            }
Ejemplo n.º 9
0
 public QuoteMeConfig(string arg0, string arg1)
 {
     Settings = new AppSettings();
     this.ServiceUrl = arg0 ?? Settings.Get("ServiceUrl", "http://*:1337/");
     this.DataFilePath = arg1 ?? Settings.Get("DataFilePath", "Quotes.json");
 }
Ejemplo n.º 10
0
        private void ConfigureAuth(Container container)
        {
            //Enable and register existing services you want this host to make use of.
            //Look in Web.config for examples on how to configure your oauth providers, e.g. oauth.facebook.AppId, etc.
            var appSettings = new AppSettings();

            //Register all Authentication methods you want to enable for this web app.            
            Plugins.Add(new AuthFeature(
                () => new CustomUserSession(), //Use your own typed Custom UserSession type
                new IAuthProvider[] {
                    new CredentialsAuthProvider(),              //HTML Form post of UserName/Password credentials
                    new TwitterAuthProvider(appSettings),       //Sign-in with Twitter
                    new FacebookAuthProvider(appSettings),      //Sign-in with Facebook
                    new DigestAuthProvider(appSettings),        //Sign-in with Digest Auth
                    new BasicAuthProvider(),                    //Sign-in with Basic Auth
                    new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Google OpenId
                    new YahooOpenIdOAuthProvider(appSettings),  //Sign-in with Yahoo OpenId
                    new OpenIdOAuthProvider(appSettings),       //Sign-in with Custom OpenId
                    new GoogleOAuth2Provider(appSettings),      //Sign-in with Google OAuth2 Provider
                    new LinkedInOAuth2Provider(appSettings),    //Sign-in with LinkedIn OAuth2 Provider
                }));

#if HTTP_LISTENER
            //Required for DotNetOpenAuth in HttpListener 
            OpenIdOAuthProvider.OpenIdApplicationStore = new InMemoryOpenIdApplicationStore();
#endif

            //Provide service for new users to register so they can login with supplied credentials.
            Plugins.Add(new RegistrationFeature());

            //override the default registration validation with your own custom implementation
            container.RegisterAs<CustomRegistrationValidator, IValidator<Register>>();

            //Store User Data into the referenced SqlServer database
            container.Register<IAuthRepository>(c =>
                new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>())); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info

            var authRepo = (OrmLiteAuthRepository)container.Resolve<IAuthRepository>(); //If using and RDBMS to persist UserAuth, we must create required tables
            if (appSettings.Get("RecreateAuthTables", false))
                authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
            else
                authRepo.CreateMissingTables();   //Create only the missing tables

            Plugins.Add(new RequestLogsFeature());
        }
Ejemplo n.º 11
0
            /* Uncomment to enable ServiceStack Authentication and CustomUserSession */
            private void ConfigureAuth(Funq.Container container)
            {
                var appSettings = new AppSettings();
                //Register all Authentication methods you want to enable for this web app.
                Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                    new IAuthProvider[] {
                   }
                ));
                Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                new IAuthProvider[] {
                new ShibbolethAuthProvider(),
                new TwitterAuthProvider(appSettings),
                new FacebookAuthProvider(appSettings),
                new GoogleOAuth2Provider(appSettings),
                })
                {
                    HtmlRedirect = "~/",
                    IncludeRegistrationService = true,
                    MaxLoginAttempts = appSettings.Get("MaxLoginAttempts", 5),
                });
                Plugins.Add(new RegistrationFeature());

                container.Register<ICacheClient>(new MemoryCacheClient());
                var userRep = new InMemoryAuthRepository();
                container.Register<IUserAuthRepository>(userRep);
                //Default route: /auth/{provider}
            }
Ejemplo n.º 12
0
        private static IUserAuthRepository CreateOrmLiteAuthRepo(Container container, AppSettings appSettings)
        {
            //Store User Data into the referenced SqlServer database
            container.Register<IAuthRepository>(c => new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));

            //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info
            var authRepo = (OrmLiteAuthRepository)container.Resolve<IAuthRepository>();
            //If using and RDBMS to persist UserAuth, we must create required tables
            if (appSettings.Get("RecreateAuthTables", false))
                authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
            else
                authRepo.InitSchema(); //Create only the missing tables

            return authRepo;
        }
Ejemplo n.º 13
0
        private EmailServiceModels BuildEmailMessage(string email)
        {
            var appSettings = new AppSettings();
            var mail = new EmailServiceModels();

            mail.IsBodyHtml = true;
            mail.Subject = "Cocaine-books Password Recovery";

            var data = "{0}".Fmt(email);// , DateTime.Now.AddHours(2).ToString("hh-mm-ss"));

            string encrypted = data.Encrypt("hash");

            mail.Body = @"Hello, <br/><br/>

                        Please use the link below to reset your password:<br/>
                        {0}<br/><br/>

                        Thank you,<br/>
                        Cocaine Books".Fmt(appSettings.Get("Site.ResetUrl", "") + "?" + encrypted);

            mail.To.Add(email);

            return mail;
        }
Ejemplo n.º 14
0
 public TsonServiceConfig(string arg0, string arg1)
 {
     Settings = new AppSettings();
     this.ServiceUrl = arg0 ?? Settings.Get("ServiceUrl", "http://*:1337/");
     this.CorsAllowedOrigins = Settings.GetList("CorsAllowedOrigins");
 }
Ejemplo n.º 15
0
            private void ConfigureCors(Container container)
            {
                var appSettings = new AppSettings();

                if (!appSettings.Get("CorsEnabled", false)) return;

                var origins = appSettings.Get("CorsOrigins", "*");
                var methods = appSettings.Get("CorsMethods", "GET, POST, PUT, DELETE, OPTIONS");
                var headers = appSettings.Get("CorsHeaders", "Content-Type");
                var credentials = appSettings.Get("CorsCreds", false);

                if (!string.IsNullOrEmpty(origins))
                    Config.GlobalResponseHeaders.Add(HttpHeaders.AllowOrigin, origins);
                if (!string.IsNullOrEmpty(methods))
                    Config.GlobalResponseHeaders.Add(HttpHeaders.AllowMethods, methods);
                if (!string.IsNullOrEmpty(headers))
                    Config.GlobalResponseHeaders.Add(HttpHeaders.AllowHeaders, headers);
                if (credentials)
                    Config.GlobalResponseHeaders.Add(HttpHeaders.AllowCredentials, "true");

                PreRequestFilters.Add((httpReq, httpRes) =>
                {
                    if (httpReq.HttpMethod == "OPTIONS")
                    {
                        httpRes.ApplyGlobalResponseHeaders();
                        httpRes.End();
                    }
                });
            }
Ejemplo n.º 16
0
            private void ConfigureAuth(Container container)
            {
                var appSettings = new AppSettings();

                Plugins.Add(new AuthFeature(
                    () => new AuthUserSession(),
                    new IAuthProvider[] {
                        new CredentialsAuthProvider(),              // HTML Form post of UserName/Password credentials
                        new TwitterAuthProvider(appSettings),       // Sign-in with Twitter
                        new FacebookAuthProvider(appSettings),      // Sign-in with Facebook
                        new DigestAuthProvider(appSettings),        // Sign-in with Digest Auth
                        new BasicAuthProvider()                     // Sign-in with Basic Auth
                        // TODO Custom auth provider for AD integration
                }));

                container.Register<IUserAuthRepository>(c => new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));

                var authRepo = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>();
                if (appSettings.Get("RecreateAuthTables", false))
                {
                    authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
                }
                else
                {
                    authRepo.CreateMissingTables();   //Create only the missing tables
                }

                var defaultUsername = appSettings.Get("DefaultAdminUsername", "admin");
                if (authRepo.GetUserAuthByUserName(defaultUsername) == null)
                {
                    authRepo.CreateUserAuth(new UserAuth
                    {
                        UserName = defaultUsername,
                        FirstName = "Default",
                        LastName = "Administrator",
                        Roles = { Constants.EmployeeRoleName }
                    }, appSettings.Get("DefaultAdminPassword", "password"));
                }

                RequestFilters.Add((request, response, dto) =>
                                       {
                                           const string key = ServiceExtensions.RequestItemsSessionKey;
                                           HttpContext.Current.Items[key] = request.Items[key];
                                       });
            }