Ejemplo n.º 1
0
        public void GetWhenVariableExistsReturnsVariable()
        {
            string variableName = "variableName";
            string value        = "variable";

            A.CallTo(() => _environment.GetEnvironmentalVariable(variableName)).Returns(value);
            string variable = _environmentVariables.Get(variableName);

            Assert.That(variable, Is.EqualTo(value));
        }
Ejemplo n.º 2
0
 public static IHostBuilder CreateHostBuilder()
 {
     return(new HostBuilder()
            .ConfigureWebHostDefaults(webBuilder =>
     {
         webBuilder.UseStartup <Startup>();
         webBuilder.UseSentry(EnvironmentVariables.Get(EnvironmentVariables._SentryUrl));
     }));
 }
        public SqlServerDistributedAppLockProviderTests()
        {
            var env = new EnvironmentVariables();

            _connectionString = env.Get("SQL_SERVER_CONNECTION",
                                        "Server=localhost,1433; Trusted_Connection=False; User=sa; Password=sql-s3rv3r%");

            _connection = new SqlConnection(_connectionString);

            _connectionFactory = () =>
            {
                if (_connection.State != ConnectionState.Open)
                {
                    _connection.Open();
                }

                return(_connection);
            };
        }
        public void Get_ReturnsDefault_IfEnvHasNoValue()
        {
            var actual = envVariables.Get <string>("some_key_that_definitely_does_not_exist", "the glorious default");

            Assert.Equal("the glorious default", actual);
        }
Ejemplo n.º 5
0
        protected virtual string GetConnectionString()
        {
            var envVars = new EnvironmentVariables();

            return(envVars.Get("RAPIDCORE_DATASTORE_URL", "localhost:8081"));
        }
Ejemplo n.º 6
0
        protected virtual string GetProjectId()
        {
            var envVars = new EnvironmentVariables();

            return(envVars.Get("RAPIDCORE_DATASTORE_PROJECT_ID", "rapidcore-local"));
        }
Ejemplo n.º 7
0
 static ProxyCredentials()
 {
     _username = EnvironmentVariables.Get(EnvironmentVariables.ProxyUsername);
     _password = EnvironmentVariables.Get(EnvironmentVariables.ProxyPassword);
 }
Ejemplo n.º 8
0
        private async void DoWork()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledException);

            Debug.Log("Background task started.");
            Debug.Log($"Version: {Assembly.GetExecutingAssembly().GetName().Version}");

            var connStr = EnvironmentVariables.Get(EnvironmentVariables.SQLConnectionString);

            //Debug.Log($"{nameof(connStr)}: {connStr}");
            if (string.IsNullOrEmpty(connStr))
            {
                Debug.Log($"{nameof(connStr)} is null, quitting...");
                Environment.Exit(-1);
                return;
            }

            var pwEmail = EnvironmentVariables.Get(EnvironmentVariables.PerfectWardEmail);

            //Debug.Log($"{nameof(pwEmail)}: {pwEmail}");
            if (string.IsNullOrEmpty(pwEmail))
            {
                Debug.Log($"{nameof(pwEmail)} is null, quitting...");
                Environment.Exit(-1);
                return;
            }

            var pwToken = EnvironmentVariables.Get(EnvironmentVariables.PerfectWardToken);

            //Debug.Log($"{nameof(pwToken)}: {pwToken}");
            if (string.IsNullOrEmpty(pwToken))
            {
                Debug.Log($"{nameof(pwToken)} is null, quitting...");
                Environment.Exit(-1);
                return;
            }

            Environment.CurrentDirectory = new FileInfo(Assembly.GetExecutingAssembly().CodeBase.Substring(8)).DirectoryName;

            var driver = DbDriver.Create(connStr);

            if (driver == null)
            {
                Debug.Log("No DB driver found, quitting.");
                Environment.Exit(-1);
                return;
            }

            Debug.Log($"DB driver found: {driver.GetType()}");

            if (!driver.TestConnection())
            {
                Debug.Log("Failed to connect to the database.");
                Environment.Exit(-1);
                return;
            }

            var creds = new StringCredentials(pwEmail, pwToken);
            var pwc   = new PerfectWardClient(creds);

            if (!await pwc.TestApi())
            {
                Debug.Log("Failed to connect to the API.");
                Environment.Exit(-1);
                return;
            }

            driver.CreateTables();
            var existingIDs     = driver.ListReportIDs();
            var maxTimestamp    = driver.GetLatestStartDate().ToTimeStamp();
            var reportsResponse = await pwc.ListReportsSince(maxTimestamp);

            var reports = reportsResponse.Reports;

            if (reportsResponse.Meta != null)
            {
                int currentPage = reportsResponse.Meta.CurrentPage;
                int totalPages  = reportsResponse.Meta.TotalPages;
                while (currentPage < totalPages)
                {
                    if (AnnounceCancel())
                    {
                        break;
                    }
                    reportsResponse = await pwc.ListReportsSince(maxTimestamp, ++currentPage);

                    reports.AddRange(reportsResponse.Reports);
                }
            }
            reports = reports.Distinct(new ReportEqualityComparer()).Where(x => !existingIDs.Contains(x.Id)).OrderBy(x => x.Id).ToList();
            Debug.Log($"Query returned reports: {reports.Count}");

            var conn = driver.OpenConnection();

            var reportsStack = new Queue <Report>(reports);

            while (reportsStack.Any())
            {
                if (AnnounceCancel())
                {
                    break;
                }
                var report = reportsStack.Peek();
                var drr    = pwc.ReportDetails(report.Id).Result;
                driver.UploadReport(ref conn, drr);
                reportsStack.Dequeue();
            }

            Debug.Log($"Finished uploading reports, terminating...");

            conn.Close();
            conn.Dispose();

            TaskComplete.Set();
            if (!AnnounceCancel())
            {
                Stop();
            }
        }