-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lets go back to the more simple design with snapshots for now.
- Loading branch information
Showing
3 changed files
with
27 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,26 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using DotJEM.Json.Index2.Util; | ||
|
||
namespace DotJEM.Json.Index2.Snapshots.Zip | ||
{ | ||
public class ZipFileSnapshot : Disposable, ISnapshot | ||
{ | ||
public long Generation { get; } | ||
public string FilePath { get; } | ||
|
||
private readonly Lazy<ISnapshotReader> snapshotReader; | ||
private readonly Lazy<ISnapshotWriter> snapshotWriter; | ||
|
||
public ISnapshotReader OpenReader() | ||
{ | ||
EnsureNotDisposed(); | ||
return snapshotReader.Value; | ||
} | ||
|
||
public ISnapshotWriter OpenWriter() | ||
{ | ||
EnsureNotDisposed(); | ||
return snapshotWriter.Value; | ||
} | ||
namespace DotJEM.Json.Index2.Snapshots.Zip; | ||
|
||
public ZipFileSnapshot(string path) | ||
: this(path, long.Parse(Path.GetFileNameWithoutExtension(path), NumberStyles.AllowHexSpecifier)) | ||
{ | ||
} | ||
|
||
public ZipFileSnapshot(string path, long generation, bool isReadonly = false) | ||
{ | ||
FilePath = path; | ||
Generation = generation; | ||
public class ZipFileSnapshot : ISnapshot | ||
{ | ||
public long Generation { get; } | ||
public string FilePath { get; } | ||
|
||
this.snapshotReader = new Lazy<ISnapshotReader>(() => new ZipSnapshotReader(this)); | ||
this.snapshotWriter = isReadonly | ||
? new Lazy<ISnapshotWriter>(() => throw new InvalidOperationException()) | ||
: new Lazy<ISnapshotWriter>(() => new ZipSnapshotWriter(this)); | ||
} | ||
public ISnapshotReader OpenReader() => new ZipSnapshotReader(this); | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (!disposing || disposed) | ||
return; | ||
base.Dispose(true); | ||
public ISnapshotWriter OpenWriter() => new ZipSnapshotWriter(this); | ||
|
||
if(snapshotReader.IsValueCreated) | ||
snapshotReader.Value.Dispose(); | ||
public ZipFileSnapshot(string path) | ||
: this(path, long.Parse(Path.GetFileNameWithoutExtension(path), NumberStyles.AllowHexSpecifier)) | ||
{ | ||
} | ||
|
||
if(snapshotWriter.IsValueCreated) | ||
snapshotWriter.Value.Dispose(); | ||
} | ||
public ZipFileSnapshot(string path, long generation) | ||
{ | ||
FilePath = path; | ||
Generation = generation; | ||
} | ||
} | ||
} |