Ejemplo n.º 1
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();
            var appSettings = new TextFileSettings("~/../../apps/chat/web.settings".MapProjectPath());

            app.UseServiceStack(new AppHost(appSettings));
        }
Ejemplo n.º 2
0
        public void TestFixtureSetUp()
        {
            var settings = new TextFileSettings("~/azureconfig.txt".MapProjectPath());

            Host             = settings.GetString("Host");
            Port             = settings.Get("Port", 6379);
            Password         = settings.GetString("Password");
            connectionString = "{0}@{1}".Fmt(Password, Host);
        }
Ejemplo n.º 3
0
    public AppHost() : base("Web", typeof(MyServices).Assembly)
    {
        var customSettings = new FileInfo("appsettings.txt");

        if (customSettings.Exists)
        {
            AppSettings = new TextFileSettings(customSettings.FullName);
        }
    }
        private void SeedAppSettings()
        {
            var customSettings = new FileInfo(@"~/../appsettings.txt".MapHostAbsolutePath());
            var appSettings    = new TextFileSettings(customSettings.FullName);

            foreach (var key in appSettings.GetAllKeys())
            {
                appHost.AppSettings.Set(key, appSettings.Get(key));
            }
        }
        public override IMessageService CreateMqServer(IAppHost host, int retryCount = 1)
        {
            var assembly   = typeof(AzureServiceBusMqServerPostMessageTests).Assembly;
            var path       = new Uri(assembly.CodeBase).LocalPath;
            var configFile = Path.Combine(Path.GetDirectoryName(path), "settings.config");

            var connectionString = new TextFileSettings(configFile).Get("ConnectionString");

            return(new ServiceBusMqServer(connectionString)
            {
                ResponseFilter = r => { host.OnEndRequest(null); return r; }
            });
        }
Ejemplo n.º 6
0
        public void Import_AppSettings_into_DynamoDb()
        {
            var fileSettings   = new TextFileSettings("~/../../deploy/appsettings.txt".MapHostAbsolutePath());
            var dynamoSettings = new DynamoDbAppSettings(AwsConfig.CreatePocoDynamo());

            dynamoSettings.InitSchema();

            //dynamoSettings.Set("SmtpConfig", "{Username:REPLACE_USER,Password:REPLACE_PASS,Host:email-smtp.us-east-1.amazonaws.com,Port:587}");
            foreach (var config in fileSettings.GetAll())
            {
                dynamoSettings.Set(config.Key, config.Value);
            }
        }
        public void IterableDataSettingsPluginAddedToPipelineContext()
        {
            var builder = new StringBuilder();

            builder.AppendLine("a-b-c");
            builder.AppendLine("1-2-3");
            var fileName = Path.GetTempFileName();

            File.WriteAllText(fileName, builder.ToString());
            var textFileSettings = new TextFileSettings
            {
                Path = fileName,
                ColumnHeadersInFirstLine = false,
                ColumnSeparator          = "-"
            };
            var endpointFrom = new Endpoint();

            endpointFrom.AddPlugin(textFileSettings);
            var pipelineStep = new PipelineStep {
                Enabled = true
            };

            pipelineStep.AddPlugin(new EndpointSettings {
                EndpointFrom = endpointFrom
            });
            var pipelineContext = new PipelineContext(new PipelineBatchContext());
            var logger          = Substitute.For <ILogger>();
            var processor       = new ReadTextFileStepProcessor();

            processor.StartProcessing(pipelineStep, pipelineContext, logger);
            var dataSettings = pipelineContext.GetPlugin <IterableDataSettings>();

            Assert.NotNull(dataSettings);
            Assert.NotNull(dataSettings.Data);
            var count = 0;

            foreach (var data in dataSettings.Data)
            {
                Assert.NotNull(data);
                Assert.IsType <string[]>(data);
                var dataAsArray = data as string[];
                Assert.NotNull(dataAsArray);
                Assert.Equal(3, dataAsArray.Length);
                count++;
            }
            Assert.Equal(2, count);
            File.Delete(fileName);
        }
        public override void Configure(Container container)
        {
            AppSettings = new TextFileSettings("~/appsettings.txt".MapHostAbsolutePath());

            var pgProvider       = ServiceStack.OrmLite.PostgreSQL.PostgreSqlDialectProvider.Instance;
            var connectionString = AppSettings.GetString("DatabaseConnectionString");
            var dbFactory        = new OrmLiteConnectionFactory(connectionString, PostgreSqlDialect.Provider, setGlobalDialectProvider: true);
            var dates            = OrmLiteConfig.DialectProvider.GetDateTimeConverter();

            dates.DateStyle = DateTimeKind.Utc;
            container.Register <IDbConnectionFactory>(dbFactory);

            using (var db = dbFactory.Open())
            {
                db.CreateTable <MyEntity>();
            }
        }
Ejemplo n.º 9
0
        public override IUserAuth CreateUserAuth(IUserAuth newUser, string password)
        {
            var user = base.CreateUserAuth(newUser, password);

            using (var db = dbFactory.OpenDbConnection())
            {
                var settings = new TextFileSettings("appsettings.txt");
                var provider = new ApiKeyAuthProvider();
                provider.KeySizeBytes = 32;
                var key = provider.GenerateApiKey(String.Empty, String.Empty, 32).Substring(0, 32);
                db.Save <APIKey>(new APIKey()
                {
                    UserId       = user.Id,
                    RequestLimit = 2500,
                    Key          = key
                });

                var mimeMessage = new MimeMessage();
                mimeMessage.From.Add(new MailboxAddress(settings.GetString("EmailFromName"), settings.GetString("EmailFrom")));
                mimeMessage.To.Add(new MailboxAddress(user.Email, user.Email));
                mimeMessage.Subject = "Your api key";
                var builder = new BodyBuilder();
                builder.TextBody =
                    "Your api key is: " + key +
                    "\n\n" +
                    "Support: " + settings.GetString("EmailFrom");
                builder.HtmlBody =
                    "Your api key is: " + key +
                    "<br /><br />" +
                    "Support: " + settings.GetString("EmailFrom");

                mimeMessage.Body = builder.ToMessageBody();
                using (var client = new SmtpClient())
                {
                    client.Connect(settings.GetString("SMTPHost"), 587, false);
                    // Note: only needed if the SMTP server requires authentication
                    // Error 5.5.1 Authentication
                    client.Authenticate(settings.GetString("SMTPUser"), settings.GetString("SMTPPass"));
                    client.Send(mimeMessage);
                    client.Disconnect(true);
                }
            }

            return(user);
        }
        public void NoIterableDataSettingsPluginAddedToPipelineContextWhenNoPathIsSetOnTheTextFileSettingsPluginSetOnTheEndpoint()
        {
            var textFileSettings = new TextFileSettings();
            var endpointFrom     = new Endpoint();

            endpointFrom.AddPlugin(textFileSettings);
            var pipelineStep = new PipelineStep {
                Enabled = true
            };

            pipelineStep.AddPlugin(new EndpointSettings {
                EndpointFrom = endpointFrom
            });
            var pipelineContext = new PipelineContext(new PipelineBatchContext());
            var logger          = Substitute.For <ILogger>();
            var processor       = new ReadTextFileStepProcessor();

            processor.StartProcessing(pipelineStep, pipelineContext, logger);
            Assert.Null(pipelineContext.GetPlugin <IterableDataSettings>());
        }
Ejemplo n.º 11
0
        public PasswordResetRequest ResetPassword(PasswordResetRequest request, IUserAuth user)
        {
            request.Id = Guid.NewGuid().ToString().Replace("-", "");
            var    settings = new TextFileSettings("appsettings.txt");
            string subject  = "Password Reset Requested";
            string html     = String.Format(String.Concat(
                                                "Hello {0},",
                                                "<br /><br />",
                                                "You recently requested to change your password at <a href=\"{1}\">{1}</a>",
                                                "<br/><br/>",
                                                "You may use the following link to set your passowrd: {2}",
                                                "<br/><br/>",
                                                "This link will be valid for 1 hour"),
                                            user.UserName,
                                            settings.Get <string>("BaseUrl"),
                                            String.Format("<a href=\"{0}/reset/{1}\">{0}/reset/{1}</a>", settings.Get <string>("BaseUrl"), request.Id)
                                            );

            var mimeMessage = new MimeMessage();

            mimeMessage.From.Add(new MailboxAddress(settings.GetString("EmailFromName"), settings.GetString("EmailFrom")));
            mimeMessage.To.Add(new MailboxAddress(user.Email, user.Email));
            mimeMessage.Subject = subject;
            var builder = new BodyBuilder();

            builder.HtmlBody = html;
            mimeMessage.Body = builder.ToMessageBody();
            using (var client = new SmtpClient())
            {
                client.Connect(settings.GetString("SMTPHost"), 587, false);
                // Note: only needed if the SMTP server requires authentication
                // Error 5.5.1 Authentication
                client.Authenticate(settings.GetString("SMTPUser"), settings.GetString("SMTPPass"));
                client.Send(mimeMessage);
                client.Disconnect(true);
            }
            return(request);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            var appSettingsFile = Path.Combine(AppContext.BaseDirectory, "app.settings");
            var appSettings     = new TextFileSettings(appSettingsFile);
            var checkInterval   = appSettings.Get <TimeSpan>("CheckInterval");
            var definitions     = appSettings.Get <List <ProcessDefinition> >("Definitions");

            HostFactory.Run(windowsService =>
            {
                windowsService.Service <HungProcessMonitor>(s =>
                {
                    s.ConstructUsing(service => new HungProcessMonitor(checkInterval, definitions));
                    s.WhenStarted(service => service.Start());
                    s.WhenStopped(service => service.Stop());
                });

                windowsService.RunAsLocalSystem();
                windowsService.StartAutomatically();

                windowsService.SetServiceName("HungProcessKiller");
                windowsService.SetDisplayName("HungProcessKiller");
                windowsService.SetDescription("A Windows background service which monitors hung processes and kills them after a fixed time period");
            });
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
#if DEBUG
            LogManager.LogFactory = new ConsoleLogFactory();
#endif

            var help = new HashSet <string> {
                "-h", "--help", "/h", "/help"
            };
            if (args.Any(help.Contains))
            {
                "Usage: Chat.exe                          # Run using default appsettings.txt".Print();
                "Usage: Chat.exe /port=1337               # Run on port 1337".Print();
                "Usage: Chat.exe /redis=localhost:6379    # Run using RedisServerEvents".Print();
                "Usage: Chat.exe /background=/img/bg.jpg  # Run using background image".Print();
                return;
            }

            //default with settings defined in appsettings.txt
            var customSettings = new FileInfo("appsettings.txt");
            var appSettings    = new DictionarySettings();
            if (customSettings.Exists)
            {
                appSettings = new TextFileSettings(customSettings.FullName);
            }
            else
            {
                ExportFile(customSettings.Name);
            }

            var port       = appSettings.Get("port", 1337);
            var redisHost  = appSettings.GetString("redis");
            var background = appSettings.GetString("background");

            //override with command line args if any
            var portArg = args.FirstOrDefault(x => x.Contains("port"));
            if (portArg != null)
            {
                int.TryParse(portArg.SplitOnFirst('=').Last(), out port);
            }

            var redisArg = args.FirstOrDefault(x => x.Contains("redis"));
            var useRedis = redisArg != null;
            if (useRedis)
            {
                var parts = redisArg.SplitOnFirst('=');
                redisHost = parts.Length > 1 ? parts[1] : (redisHost ?? "localhost");
            }

            var backgroundArg = args.FirstOrDefault(x => x.Contains("background"));
            if (backgroundArg != null)
            {
                var parts = backgroundArg.SplitOnFirst('=');
                background = parts.Length > 1 ? parts[1] : background;
            }

            new AppHost {
                RedisHost  = redisHost,
                Background = background,
            }
            .Init()
            .Start("http://*:{0}/".Fmt(port));

            var url = "http://localhost:{0}/".Fmt(port);
            "Listening on {0} with {1} on {2}".Print(url, redisHost != null ? "RedisServerEvents on " + redisHost : "MemoryServerEvents", background);
            "Type Ctrl+C to quit..\n".Print();
            Process.Start(url);
            Thread.Sleep(Timeout.Infinite);
        }
Ejemplo n.º 14
0
        public void Configure(IApplicationBuilder app)
        {
            var appSettings = new TextFileSettings("~/../app.settings".MapProjectPath());

            app.UseServiceStack(new AppHost(appSettings));
        }