-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make Drive and ZipService use a consistent interface * Rename file to match class name * Add constants for filenames * Allow for multiple writes * update constants and IStorageService * implicit conversion for records to string * export encryption * Storage extract * Update Election * Bump actions/setup-node from 2 to 3 (#226) * Moved to the CiphertextBallot and removed the deprecated one (#228) Fixed the order of the number of guardians and quorum for creating a new key ceremony * remove uneeded files * export election package * resolve Linter issues * Cleanup * UtcNow not now * Unneeded using * Linter updates * constructor update * mark step 1 complete * AddBallots Button enabling * set DateTime on export * Mark election as exported * naming --------- Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Steve Maier <82616727+SteveMaier-IRT@users.noreply.github.com>
- Loading branch information
1 parent
d632cbb
commit 3b75787
Showing
23 changed files
with
463 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 47 additions & 21 deletions
68
src/electionguard-ui/ElectionGuard.UI.Lib/Services/FileSystem/DriveService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,56 @@ | ||
namespace ElectionGuard.UI.Lib.Services; | ||
using System.IO.Compression; | ||
using ElectionGuard.UI.Lib.Models; | ||
|
||
namespace ElectionGuard.UI.Lib.Services; | ||
|
||
/// <summary> | ||
/// Class to read and write file to the hard drive | ||
/// </summary> | ||
public class DriveService : IStorageService | ||
{ | ||
/// <summary> | ||
/// Read in the contents of a file | ||
/// </summary> | ||
/// <param name="filename">filename including path</param> | ||
/// <returns>the string data from the file</returns> | ||
public string FromFile(string filename) | ||
private string _rootDirectoryPath; | ||
|
||
public DriveService(string rootDirectoryPath) | ||
{ | ||
_rootDirectoryPath = rootDirectoryPath; | ||
} | ||
|
||
public DriveService() : this(Path.GetTempPath()) | ||
{ | ||
} | ||
|
||
public void ToFile(string fileName, string content) | ||
{ | ||
var filePath = Path.Combine(_rootDirectoryPath, fileName); | ||
File.WriteAllText(filePath, content); | ||
} | ||
|
||
public void ToFiles(List<FileContents> fileContents) | ||
{ | ||
return File.ReadAllText(filename); | ||
Parallel.ForEach(fileContents, fileContent => | ||
{ | ||
ToFile(fileContent.FileName, fileContent.Contents); | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Write a string to a file on a drive | ||
/// </summary> | ||
/// <param name="path">folder where the file will be created</param> | ||
/// <param name="filename">name of the file</param> | ||
/// <param name="data">data to save into file</param> | ||
public void ToFile(string path, string filename, string data) | ||
public string FromFile(string fileName) | ||
{ | ||
Directory.CreateDirectory(path); | ||
var name = Path.Combine(path, filename); | ||
File.WriteAllText(name, data); | ||
if (string.IsNullOrEmpty(fileName)) throw new ArgumentNullException(nameof(fileName)); | ||
|
||
var filePath = Path.Combine(_rootDirectoryPath, fileName); | ||
|
||
if (!File.Exists(filePath)) throw new FileNotFoundException(nameof(filePath)); | ||
|
||
return File.ReadAllText(filePath); | ||
} | ||
|
||
public void UpdatePath(string path) | ||
{ | ||
if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path)); | ||
|
||
if (! Directory.Exists(path)) | ||
{ | ||
// create directory | ||
Directory.CreateDirectory(path); | ||
|
||
_rootDirectoryPath = path; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.