Class Store<T>
A store that will be incrementally saved on the HDD. Thread-safe and process-safe.
public abstract class Store<T> : IDisposable where T : new()
Type Parameters
T
The type of elements in the store.
- Inheritance
-
Store<T>
- Implements
- Derived
- Extension Methods
Constructors
Store(Stream)
protected Store(Stream stream)
Parameters
stream
Stream
Fields
lockObject
protected object lockObject
Field Value
stream
protected Stream stream
Field Value
transaction
protected int transaction
Field Value
Properties
AutoLoadNewValues
Gets or sets a flag specifying if a Save should also load new values that happened in between.
public bool AutoLoadNewValues { get; set; }
Property Value
UseTransaction
Gets or sets a flag specifying if the index map changes should be kept aside instead of being committed immediately.
public bool UseTransaction { get; set; }
Property Value
Methods
AddLoaded(T)
Adds a value that has already been saved in the store (saved state).
protected abstract void AddLoaded(T item)
Parameters
item
TThe item.
AddUnsaved(T, int)
Adds a value that has not yet been saved in the store (pending state).
protected abstract void AddUnsaved(T item, int transaction)
Parameters
item
TThe item.
transaction
intThe transaction index.
AddValue(T)
Adds a value to the store.
public void AddValue(T item)
Parameters
item
TThe item.
AddValues(IEnumerable<T>)
Adds multiple values to the store
public void AddValues(IEnumerable<T> values)
Parameters
values
IEnumerable<T>The values.
BuildContext(Stream)
protected virtual object BuildContext(Stream stream)
Parameters
stream
Stream
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. Waits for pending operation to finish, if any. Note that it does not write pending transaction if Save() has not been called before.
public void Dispose()
GetPendingItems(int)
Gets the list of pending items for a given transaction index.
protected abstract IEnumerable<T> GetPendingItems(int transaction)
Parameters
transaction
intThe transaction index.
Returns
- IEnumerable<T>
LoadNewValues()
Refreshes URL to ObjectId mapping from the latest results in the index file.
public bool LoadNewValues()
Returns
- bool
True on success.
ReadEntries(Stream)
protected virtual List<T> ReadEntries(Stream localStream)
Parameters
localStream
Stream
Returns
- List<T>
RemoveUnsaved(IEnumerable<T>, int)
Removes values that have not yet been saved (pending state).
protected virtual void RemoveUnsaved(IEnumerable<T> items, int transaction)
Parameters
items
IEnumerable<T>The items.
transaction
intThe transaction index.
RemoveUnsaved(T, int)
Removes a value that has not yet been saved (pending state).
protected abstract void RemoveUnsaved(T item, int transaction)
Parameters
item
TThe item.
transaction
intThe transaction index.
Reset()
Resets the store to an empty state.
public void Reset()
ResetInternal()
Resets the store to an empty state, to be implemented by subclasses if necessary.
protected virtual void ResetInternal()
Save()
Saves the newly added mapping (only necessary when UseTransaction is set to true).
public void Save()
WriteEntry(Stream, T)
protected virtual void WriteEntry(Stream stream, T value)
Parameters
stream
Streamvalue
T