Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            var version = FileVersionInfo.GetVersionInfo(typeof(Program).Assembly.Location).ProductVersion;

            Console.WriteLine($"Anysee Transcode {version}");
            Console.WriteLine("https://github.com/bluewalk/AnyseeTranscode\n");

            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
                         .WriteTo.Console(EnvironmentExtensions.GetEnvironmentVariable("LOG_LEVEL", LogEventLevel.Information),
                                          "{Timestamp:yyyy-MM-dd HH:mm:ss zzz} [{Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}",
                                          theme: AnsiConsoleTheme.Code
                                          ).CreateLogger();

            AppDomain.CurrentDomain.DomainUnload += (sender, eventArgs) => Log.CloseAndFlush();

            var builder = new HostBuilder()
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddOptions();

                services.AddSingleton <IHostedService, Logic>();
            })
                          .UseSerilog();

            await builder.RunConsoleAsync();
        }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            var version = FileVersionInfo.GetVersionInfo(typeof(Program).Assembly.Location).ProductVersion;

            Console.WriteLine($"RBL DNS Aggregator {version}");
            Console.WriteLine("https://github.com/bluewalk/rbldns-aggregator\n");

            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .MinimumLevel.Debug()
                         .WriteTo.ColoredConsole(
                EnvironmentExtensions.GetEnvironmentVariable <LogEventLevel>("LOG_LEVEL", LogEventLevel.Information)
                ).CreateLogger();

            AppDomain.CurrentDomain.DomainUnload += (sender, eventArgs) => Log.CloseAndFlush();

            var builder = new HostBuilder()
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddOptions();

                services.AddSingleton <IHostedService, Logic>();
            })
                          .UseSerilog();

            await builder.RunConsoleAsync();
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            EnvironmentExtensions.CheckVariables(
                EnvVars.PG_CONNECTION_STRING_READ,
                EnvVars.PG_CONNECTION_STRING_WRITE,
                EnvVars.REDIS_CONNECTION,
                EnvVars.ANALYZER_SUSPECT_IP_COUNT,
                EnvVars.NOTIFICATION_EMAIL_FROM
                );

            var serviceCollection = new ServiceCollection();

            ConfigureServices(serviceCollection);
            var services = serviceCollection.BuildServiceProvider();

            ApplyMigrations(services);

            var bootstrapper = services.GetService <Bootstrapper>();

            Task.Run(async() =>
            {
                await bootstrapper.StartAnalyzer();
            });

            resetEventSlim.Wait();
        }
Ejemplo n.º 4
0
 protected EntityBase()
 {
     CreatedOn     = DateTime.Now;
     EntityId      = Guid.NewGuid();
     LatestVersion = true;
     CreatedBy     = EnvironmentExtensions.GetCurrentUserName();
 }
Ejemplo n.º 5
0
 public void ConfigureServices(IServiceCollection services)
 {
     services
     .AddScoped <DbSeeder>()
     .AddDbContext <ApplicationDbContext>((provider, builder) =>
                                          builder.UseNpgsql(EnvironmentExtensions.GetValueOrThrow <string>("CONNECTION_STRING"))
                                          .UseLoggerFactory(LoggerFactory.Create(loggingBuilder =>
     {
         if (provider.GetRequiredService <IWebHostEnvironment>().IsDevelopment())
         {
             loggingBuilder.AddConsole();
         }
     })))
     .AddScoped <IAuthService, AuthService>()
     .AddSingleton <IEmailService, EmailService>()
     .AddSingleton <IResetPasswordTokenProvider, ResetPasswordTokenProvider>()
     .AddJwtBearerAuth(_configuration)
     .AddIdentity()
     .Configure <EmailOptions>(_configuration.GetSection(nameof(EmailOptions)))
     .AddSwagger()
     .AddLocalization(options => options.ResourcesPath = "Resources")
     .AddControllers(options =>
     {
         options.Filters.Add <ErrorableResultFilterAttribute>();
         options.Filters.Add(new ProducesAttribute(MediaTypeNames.Application.Json));
     })
     .AddDataAnnotationsLocalization(options => options.DataAnnotationLocalizerProvider = (_, factory) => factory.Create(typeof(SharedResource)))
     .AddJsonOptions(options => options
                     .JsonSerializerOptions
                     .Converters
                     .Add(new JsonStringEnumConverter()));
 }
        public void MapPath_RootedPathIsEqualToRelative()
        {
            var rootedPath   = EnvironmentExtensions.MapPath("~/my/test");
            var relativePath = EnvironmentExtensions.MapPath("my/test");

            Assert.AreEqual(Path.GetFullPath(rootedPath), Path.GetFullPath(relativePath));
        }
Ejemplo n.º 7
0
        public static void SetupAgentPath(ConfigurationSettings settings)
        {
            string variableValue = Environment.GetEnvironmentVariable(Constants.EnvironmentVariablesNames.Path);
            string chronosPath   = Assembly.GetExecutingAssembly().GetAssemblyPath();

            variableValue = EnvironmentExtensions.AppendEnvironmentPath(variableValue, chronosPath);
            settings.ProfilingTargetSettings.EnvironmentVariables[Constants.EnvironmentVariablesNames.Path] = variableValue;
        }
Ejemplo n.º 8
0
        public IActionResult GetRepoDirs()
        {
            List <string> repoDirs = new List <string>();
            var           repoRoot = EnvironmentExtensions.GetRepoPath();

            GetRepoDirs(repoRoot, repoRoot, repoDirs);

            return(Ok(repoDirs));
        }
        public void MapPath_EmptyOrBlankIsBasePath()
        {
            var emptyMap = EnvironmentExtensions.MapPath(String.Empty);
            var blankMap = EnvironmentExtensions.MapPath("   ");
            var baseMap  = EnvironmentExtensions.MapPath("~");

            Assert.AreEqual(baseMap, emptyMap);
            Assert.AreEqual(baseMap, blankMap);
        }
        public void IsVMSS_RetrunsExpectedResult(string roleInstanceId, bool expected)
        {
            IEnvironment env = new TestEnvironment();

            if (roleInstanceId != null)
            {
                env.SetEnvironmentVariable(EnvironmentSettingNames.RoleInstanceId, roleInstanceId);
            }

            Assert.Equal(expected, EnvironmentExtensions.IsVMSS(env));
        }
        public void IsAzureMonitorEnabled_ReturnsExpectedResult(string value, bool expected)
        {
            IEnvironment env = new TestEnvironment();

            if (value != null)
            {
                env.SetEnvironmentVariable(EnvironmentSettingNames.AzureMonitorCategories, value);
            }

            Assert.Equal(expected, EnvironmentExtensions.IsAzureMonitorEnabled(env));
        }
Ejemplo n.º 12
0
        public static void Main(string[] args)
        {
            EnvironmentExtensions.CheckVariables(
                EnvVars.AUTH_SERVER_URL,
                EnvVars.NOTIFY_SERVICE_URL,
                EnvVars.VIGRUZKI_SERVICE_URL,
                EnvVars.REDIS_CONNECTION,
                EnvVars.PG_CONNECTION_STRING_READ,
                EnvVars.NOTIFICATION_EMAIL_FROM,
                EnvVars.PG_CONNECTION_STRING_WRITE);

            CreateHostBuilder(args).Build().Run();
        }
Ejemplo n.º 13
0
        private static void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.AddLogging(l => l.AddConsole());
            services.AddDbContext <DnsDbContext>(opt =>
                                                 opt.UseNpgsql(EnvironmentExtensions.GetVariable(EnvVars.PG_CONNECTION_STRING_WRITE), dbOpt => dbOpt.MigrationsAssembly("Dns.DAL")));
            services.AddDbContext <DnsReadOnlyDbContext>(opt =>
                                                         opt.UseNpgsql(EnvironmentExtensions.GetVariable(EnvVars.PG_CONNECTION_STRING_READ)));

            services.AddTransient <ResolveService>();
            services.AddSingleton <RedisService>();
            services.AddTransient <Bootstrapper>();
        }
Ejemplo n.º 14
0
        public Task AuthorizeAsync(string login, string pass)
        {
            var authServer = EnvironmentExtensions.GetVariable(EnvVars.AUTH_SERVER_URL);
            var loginUrl   = authServer.TrimEnd('/') + "/api/Auth/Login";
            var loginModel = new LoginModel
            {
                Login    = login,
                Password = pass
            };
            var body = new StringContent(loginModel.ToJson(), Encoding.Default, MediaTypeHeaderValue.Parse("application/json").MediaType);

            return(_httpClient.PostAsync(new Uri(loginUrl, UriKind.Absolute), body));
        }
Ejemplo n.º 15
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            });

            var connectionString = Configuration["Connections:urdb"];

            services.AddDbContext <ApplicationDbContext>(options =>
            {
                if (EnvironmentExtensions.IsDevelopment())
                {
                    options.EnableDetailedErrors();
                    options.EnableSensitiveDataLogging();
                }
                options.UseNpgsql(connectionString);
            });

            // configure jwt authentication
            var key = Encoding.ASCII.GetBytes(Configuration["AppSecret"]);

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });


            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddScoped <TranslationService>();
            services.AddScoped <MessageService>();
            services.AddScoped <LoginService>();
            services.AddScoped <RegistrationService>();
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] string data,
                                                           [Table("transactions", "AzureWebJobsStorage")] CloudTable table, HttpRequestMessage req, TraceWriter log)
        {
            if (string.IsNullOrWhiteSpace(data))
            {
                log.Error("Webhook content empty.");
                return(req.CreateResponse(HttpStatusCode.OK));
            }

// #if !DEBUG
            req.Headers.TryGetValues("X-Hook-Signature", out var headers);
            var sign = headers?.FirstOrDefault();

            var secret = EnvironmentExtensions.GetEnvString("STARLING_WEBHOOK_SECRET");

            var(_, valid) = WebhookPayloadValidator.Validate(sign, secret, data);

            if (!valid)
            {
                log.Error("Webhook signature mismatch. Rejected.");
                return(req.CreateResponse(HttpStatusCode.OK));
            }
// #endif

            var payload = StarlingDeserialiser.WebhookPayload(data);

            var existing = await table.GetExistingTransaction(payload.AccountHolderUid, payload.Content.TransactionUid);

            if (existing != null)
            {
                log.Warning($"Transaction {existing.RowKey} already processed on {existing.Timestamp}.");
                return(req.CreateResponse(HttpStatusCode.OK));
            }

            var goalId     = EnvironmentExtensions.GetEnvString("STARLING_GOAL_ID");
            var remainder  = (long)(Math.Abs(payload.Content.Amount) * 100 % 100);
            var difference = 100 - remainder;

            var threshold = EnvironmentExtensions.GetEnvInt("ROUND_UP_THRESHOLD");

            if (remainder >= threshold)
            {
                await _httpClient.SavingsGoalsAddMoney(goalId, difference);
            }

            await table.SaveTransaction(payload.AccountHolderUid, payload.Content.TransactionUid, difference);

            return(req.CreateResponse(HttpStatusCode.OK));
        }
        public void GetEffectiveCoresCount_RetrunsExpectedResult()
        {
            TestEnvironment env = new TestEnvironment();

            Assert.Equal(Environment.ProcessorCount, EnvironmentExtensions.GetEffectiveCoresCount(env));

            env.Clear();
            env.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteSku, ScriptConstants.DynamicSku);
            Assert.Equal(1, EnvironmentExtensions.GetEffectiveCoresCount(env));

            env.Clear();
            env.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteSku, ScriptConstants.DynamicSku);
            env.SetEnvironmentVariable(EnvironmentSettingNames.RoleInstanceId, "dw0SmallDedicatedWebWorkerRole_hr0HostRole-0-VM-1");
            Assert.Equal(Environment.ProcessorCount, EnvironmentExtensions.GetEffectiveCoresCount(env));
        }
        public void IsV2CompatMode(string extensionVersion, string compatMode, bool expected)
        {
            IEnvironment env = new TestEnvironment();

            if (extensionVersion != null)
            {
                env.SetEnvironmentVariable(EnvironmentSettingNames.FunctionsExtensionVersion, extensionVersion);
            }

            if (compatMode != null)
            {
                env.SetEnvironmentVariable(EnvironmentSettingNames.FunctionsV2CompatibilityModeKey, compatMode);
            }

            Assert.Equal(expected, EnvironmentExtensions.IsV2CompatibilityMode(env));
        }
Ejemplo n.º 19
0
        public static void Main(string[] args)
        {
            EnvironmentExtensions.CheckVariables(
                EnvVars.HYPERLOCAL_SERVER,
                EnvVars.PG_CONNECTION_STRING_READ,
                EnvVars.PG_CONNECTION_STRING_WRITE,
                EnvVars.REDIS_CONNECTION,
                EnvVars.RESOLVER_BUFFER_BLOCK_SIZE,
                EnvVars.RESOLVER_MAX_DEGREE_OF_PARALLELISM
                );

            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            ServicePointManager.DefaultConnectionLimit = int.MaxValue;

            var serviceCollection = new ServiceCollection();

            ConfigureServices(serviceCollection);
            var services = serviceCollection.BuildServiceProvider();

            ApplyMigrations(services);

            var bootstrapper = services.GetService <Bootstrapper>();
            var logger       = services.GetService <ILoggerFactory>().CreateLogger <Program>();

            Task.Run(async() =>
            {
                try
                {
                    while (true)
                    {
                        await bootstrapper.ResolveDomains();
                        await bootstrapper.NotifyCompletion();
                    }
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, ex.Message);
                    throw;
                }
            });
            resetEventSlim.Wait();
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            var program = new ConsoleProgram();

            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
                         .MinimumLevel.Debug()
                         .WriteTo.Debug()
                         .WriteTo.Console(
                EnvironmentExtensions.GetEnvironmentVariable("LOG_LEVEL", LogEventLevel.Information),
                "{Timestamp:yyyy-MM-dd HH:mm:ss zzz} [{Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}",
                theme: AnsiConsoleTheme.Code
                ).CreateLogger();

            var version = FileVersionInfo.GetVersionInfo(typeof(Program).Assembly.Location).ProductVersion;

            System.Console.WriteLine($"NukiBridge2Mqtt version {version}");
            System.Console.WriteLine("https://github.com/bluewalk/NukiBridge2Mqtt/\n");

            // Fire and forget
            Task.Run(() =>
            {
                program.Start(args.FirstOrDefault()?.Equals("docker") == true);
                waitHandle.WaitOne();
            });

            // Handle Control+C or Control+Break
            System.Console.CancelKeyPress += (o, e) =>
            {
                System.Console.WriteLine("Exit");

                program.Stop();

                // Allow the manin thread to continue and exit...
                waitHandle.Set();
            };

            // Wait
            waitHandle.WaitOne();
        }
        private static HttpClient InitHttpClient()
        {
            var baseAddress = EnvironmentExtensions.GetEnvString("STARLING_BASE_URL");
            var accessToken = EnvironmentExtensions.GetEnvString("STARLING_ACCESS_TOKEN");

            Guard.AgainstNullOrWhitespaceArgument(nameof(baseAddress), baseAddress);
            Guard.AgainstNullOrWhitespaceArgument(nameof(accessToken), accessToken);

            return(new HttpClient
            {
                BaseAddress = new Uri($"{baseAddress}"),
                DefaultRequestHeaders =
                {
                    Authorization = new AuthenticationHeaderValue("Bearer", $"{accessToken}"),
                    Accept        =
                    {
                        new MediaTypeWithQualityHeaderValue("application/json")
                    }
                }
            });
        }
Ejemplo n.º 22
0
        private async Task <string> GetAccessToken(string login, string password)
        {
            using (var client = new HttpClient())
            {
                var dict = new Dictionary <string, string>();
                dict.Add("client_id", "gamecenter.mail.ru");
                dict.Add("grant_type", "password");
                dict.Add("username", login);
                dict.Add("password", password.Decrypt(EnvironmentExtensions.GetSecret()));

                var content = new FormUrlEncodedContent(dict);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                client.DefaultRequestHeaders.Add("User-Agent", _userAgent);

                var response = client.PostAsync(
                    "https://o2.mail.ru/token",
                    content).Result;
                response.EnsureSuccessStatusCode();
                var token = await response.Content.ReadAsAsync <AuthModel>();

                return(token.AccessToken);
            }
        }
Ejemplo n.º 23
0
        public async Task ResolveDomains()
        {
            var whiteDomains = await GetWhiteDomains();

            var blackDomains = await GetBlackDomains();

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var resolvedWhiteDomains = await _resolve.ResolveDomainsWithRetry(whiteDomains, 3);

            stopWatch.Stop();
            _logger.LogWarning($"[RESOLVING, PARALLELISM - {EnvironmentExtensions.GetVariable(EnvVars.RESOLVER_MAX_DEGREE_OF_PARALLELISM)}, BUFFER - {EnvironmentExtensions.GetVariable(EnvVars.RESOLVER_BUFFER_BLOCK_SIZE)}] {resolvedWhiteDomains.Count()} domains took {stopWatch.Elapsed}");
            stopWatch.Restart();
            var resolvedBlackDomains = await _resolve.ResolveDomainsWithRetry(blackDomains, 3);

            _logger.LogWarning($"[RESOLVING, PARALLELISM - {EnvironmentExtensions.GetVariable(EnvVars.RESOLVER_MAX_DEGREE_OF_PARALLELISM)}, BUFFER - {EnvironmentExtensions.GetVariable(EnvVars.RESOLVER_BUFFER_BLOCK_SIZE)}] {resolvedBlackDomains.Count()} domains took {stopWatch.Elapsed}");
            stopWatch.Stop();

            await _redis.SaveResolvedDomains(RedisKeys.WHITE_DOMAINS_RESOLVED, resolvedWhiteDomains);

            await _redis.SaveResolvedDomains(RedisKeys.BLACK_DOMAINS_RESOLVED, resolvedBlackDomains);
        }
Ejemplo n.º 24
0
        private NotificationEmail BuildGroupEmailMessage(IEnumerable <AttackGroups> attacks)
        {
            var emailBody = File.ReadAllText(Path.Combine(EmailPath, EMAIL_GROUP_TEMPLATE));
            var row       = File.ReadAllText(Path.Combine(EmailPath, EMAIL_GROUP_TEMPLATE_ADDITION));

            var htmlBody = new HtmlDocument();

            htmlBody.LoadHtml(emailBody);

            var tableBody = htmlBody.DocumentNode.Descendants("tbody").First();

            foreach (var attack in attacks)
            {
                var blackDomain = attack.Attacks.FirstOrDefault().BlackDomain;
                var whiteDomain = attack.Attacks.FirstOrDefault().WhiteDomain;
                var lastChange  = attack.GroupHistories.OrderByDescending(x => x.Id).FirstOrDefault();
                var newStatus   = lastChange.CurrentEnum.GetDisplayName();
                var statusText  = newStatus;
                if (lastChange.PrevStatusEnum != AttackGroupStatusEnum.None)
                {
                    statusText = $"{lastChange.PrevStatusEnum.GetDisplayName()} -> {newStatus}";
                }

                var newRow = row
                             .Replace(EMAIL_BLACK_DOMAIN_KEY, blackDomain)
                             .Replace(EMAIL_WHITE_DOMAIN_KEY, whiteDomain)
                             .Replace(EMAIL_STATUS_KEY, statusText)
                             .Replace(EMAIL_URL_KEY, attack.Id.ToString());
                tableBody.AppendChild(HtmlNode.CreateNode(newRow));
            }
            return(new NotificationEmail
            {
                Body = htmlBody.DocumentNode.OuterHtml,
                From = EnvironmentExtensions.GetVariable(EnvVars.NOTIFICATION_EMAIL_FROM),
                Subject = EMAIL_SUBJECT
            });
        }
Ejemplo n.º 25
0
 public IActionResult GetVariables()
 {
     return(Ok(EnvironmentExtensions.GetVariables()));
 }
Ejemplo n.º 26
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <DnsDbContext>(opt =>
                                                 opt.UseNpgsql(EnvironmentExtensions.GetVariable(EnvVars.PG_CONNECTION_STRING_WRITE), dbOpt => dbOpt.MigrationsAssembly("Dns.DAL")));
            services.AddDbContext <DnsReadOnlyDbContext>(opt =>
                                                         opt.UseNpgsql(EnvironmentExtensions.GetVariable(EnvVars.PG_CONNECTION_STRING_READ)));


            services.AddSwaggerGen(x =>
            {
                x.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version     = "v1",
                    Title       = "DNS API",
                    Description = "Service of analyze domains"
                });
                x.IncludeXmlComments("Dns.Site.xml");
                x.DescribeAllEnumsAsStrings();
            });


            services.AddCors(options =>
            {
                options.AddPolicy("AllowAll",
                                  builder =>
                {
                    builder
                    .AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader();
                });
            });

            services.AddStackExchangeRedisCache(opts =>
            {
                opts.Configuration = EnvironmentExtensions.GetVariable(EnvVars.REDIS_CONNECTION);
                opts.InstanceName  = "Dns_Redis_Cache";
            });

            services.AddControllersWithViews()
            .AddNewtonsoftJson();

            services.AddSignalR(opts => opts.EnableDetailedErrors = true)
            .AddStackExchangeRedis(EnvironmentExtensions.GetVariable(EnvVars.REDIS_CONNECTION), opt =>
                                   opt.Configuration.ChannelPrefix = "Dns_SignalR_");

            if (HostEnvironment.IsProduction())
            {
                services.ConfigureSharedCookieAuthentication();

                services.AddAuthorization(opts =>
                {
                    opts.AddPolicy("DnsPolicy", policy => policy.RequireAssertion(context => context.User.HasRole(UserRoles.DnsViewer)));
                });
            }

            //ADD SERVICES
            services.AddScoped <AttackService>();
            services.AddScoped <NotifyService>();
            services.AddScoped <ExcelService>();

            services.AddHttpClient <IUserService, AuthService.Client>((provider, client) =>
            {
                client.BaseAddress = new Uri(EnvironmentExtensions.GetVariable(EnvVars.AUTH_SERVER_URL));
            });

            services.AddHttpClient <INotifyApiService, NotificationService.Client>((provider, client) =>
            {
                client.BaseAddress = new Uri(EnvironmentExtensions.GetVariable(EnvVars.NOTIFY_SERVICE_URL));
            });
            services.AddHttpClient <IVigruzkiService, VigruzkiService.Client>((provider, client) =>
            {
                client.BaseAddress = new Uri(EnvironmentExtensions.GetVariable(EnvVars.VIGRUZKI_SERVICE_URL));
            });

            services.AddSingleton <RedisService>();
        }
Ejemplo n.º 27
0
 public RedisService(ILogger <RedisService> logger)
 {
     _logger = logger;
     _redis  = ConnectionMultiplexer.Connect(EnvironmentExtensions.GetVariable(EnvVars.REDIS_CONNECTION));
 }
Ejemplo n.º 28
0
 public void MapPath_NullString()
 {
     Assert.Throws <ArgumentNullException>(() => EnvironmentExtensions.MapPath(null));
 }
Ejemplo n.º 29
0
        public void MapPath_BasePathIsAppDomainDirectory()
        {
            var basePath = EnvironmentExtensions.MapPath("~");

            Assert.AreEqual(AppDomain.CurrentDomain.BaseDirectory, basePath);
        }
Ejemplo n.º 30
0
 public void MapPath_MappedPathIsAlwaysRooted()
 {
     Assert.IsTrue(Path.IsPathRooted(EnvironmentExtensions.MapPath("~/my/test")));
     Assert.IsTrue(Path.IsPathRooted(EnvironmentExtensions.MapPath("my/test")));
     Assert.IsTrue(Path.IsPathRooted(EnvironmentExtensions.MapPath("C:/my/test")));
 }