Beispiel #1
0
        private TemporaryExposureKeyArgs[] GetRandomKeys(int WorkflowCount, int seed)
        {
            var random = new Random(seed);
            var WorkflowKeyValidatorConfig = new HardCodedAgTemporaryExposureKeyValidatorConfig();
            var WorkflowValidatorConfig    = new HardCodedAgWorkflowValidatorConfig();

            var result    = new List <TemporaryExposureKeyArgs>(WorkflowCount * WorkflowValidatorConfig.WorkflowKeyCountMax);
            var keyBuffer = new byte[WorkflowKeyValidatorConfig.DailyKeyByteCount];

            for (var i = 0; i < WorkflowCount; i++)
            {
                var keyCount = 1 + random.Next(WorkflowValidatorConfig.WorkflowKeyCountMax - 1);
                var keys     = new List <TemporaryExposureKeyArgs>(keyCount);
                for (var j = 0; j < keyCount; j++)
                {
                    random.NextBytes(keyBuffer);
                    keys.Add(new TemporaryExposureKeyArgs
                    {
                        KeyData               = keyBuffer,
                        RollingStartNumber    = WorkflowKeyValidatorConfig.RollingPeriodMin + j,
                        RollingPeriod         = 11,
                        TransmissionRiskLevel = 2
                    });
                }
                result.AddRange(keys);
            }
            return(result.ToArray());
        }
        public void Execute(int WorkflowCount, Func <int, int> randomInt, Action <byte[]> randomBytes)
        {
            var luhnModNConfig             = new LuhnModNConfig();
            var WorkflowKeyGenerator       = new GenerateWorkflowKeys(luhnModNConfig);
            var WorkflowValidatorConfig    = new HardCodedAgWorkflowValidatorConfig();
            var WorkflowKeyValidatorConfig = new HardCodedAgTemporaryExposureKeyValidatorConfig();
            var writer = new WorkflowInsertDbCommand(_DbContextProvider, new StandardUtcDateTimeProvider());
            var c      = new HttpPostWorkflowCommand(
                writer,
                new WorkflowValidator(
                    WorkflowValidatorConfig,
                    new WorkflowAuthorisationTokenLuhnModNValidator(luhnModNConfig),
                    new TemporaryExposureKeyValidator(WorkflowKeyValidatorConfig)),
                _DbContextProvider);

            var keyBuffer = new byte[WorkflowKeyValidatorConfig.DailyKeyByteCount];

            for (var i = 0; i < WorkflowCount; i++)
            {
                var Workflow = new WorkflowArgs
                {
                    Token = WorkflowKeyGenerator.Next(randomInt)
                };

                var keyCount = 1 + randomInt(WorkflowValidatorConfig.WorkflowKeyCountMax - 1);
                var keys     = new List <WorkflowKeyArgs>(keyCount);
                for (var j = 0; j < keyCount; j++)
                {
                    randomBytes(keyBuffer);
                    keys.Add(new WorkflowKeyArgs
                    {
                        KeyData               = Convert.ToBase64String(keyBuffer),
                        RollingStartNumber    = WorkflowKeyValidatorConfig.RollingPeriodMin + j,
                        RollingPeriod         = 11,
                        TransmissionRiskLevel = 2
                    });
                }
                Workflow.Items = keys.ToArray();

                c.Execute(Workflow);

                if (i > 0 && i % 100 == 0)
                {
                    Console.WriteLine($"Workflow count {i}...");
                }
            }
            Console.WriteLine("Generating Workflows finished.");
        }