public ElectionGuardController(ILogger <ElectionGuardController> logger, IElectionMapper <Election, Ballot, VoteTally> electionMapper, IConfigFileService configService) { _config = configService; _logger = logger; _electionMapper = electionMapper; _exportPath = Path.Combine(_config.GetDataDirectory(), "election_results"); logger.LogInformation($"DATA: resolved at: {_config.GetDataDirectory()}"); // try to load the election config files from the file system var election = _config.GetElection(); if (election != null) { logger.LogInformation("ElectionController: Found Election"); _election = election; _electionMap = _electionMapper.GetElectionMap(_election); } else { logger.LogInformation("ElectionController: Could not find election.json"); } var electionguardConfig = _config.getElectionGuardConfig(); if (electionguardConfig != null) { logger.LogInformation("ElectionController: Found ElectionGuard Config"); _electionGuardConfig = electionguardConfig; } else { logger.LogInformation("ElectionController: Could not find election.config.json"); } var now = DateTime.Now; _encryptedBallotsExportFileName = $"encrypted-ballots_{now.Year}_{now.Month}_{now.Day}"; _registeredBallotsExportFileNamePrefix = $"registered-ballots"; _tallyExportFileNamePrefix = "tally-results"; }
public async Task <ActionResult <InitializeEncryptionResponse> > InitializeEncryption( [FromQuery] string exportPath, [FromQuery] string exportFileName, [FromQuery] string electionFilePath, [FromQuery] string electionGuardConfigFilePath) { try { _exportPath = exportPath; _encryptedBallotsExportFileName = exportFileName; var election = _config.GetElection(electionFilePath); var electionGuardConfig = _config.getElectionGuardConfig(electionGuardConfigFilePath); return(await InitializeEncryption(new InitializeEncryptionRequest { Election = election, ElectionGuardConfig = electionGuardConfig })); } catch (Exception ex) { _logger.LogError("InitializeEncryption: ", ex); return(BadRequest(FileLoadErrorMessage)); } }