public static FileIndexKeyValueStorage <TKey, TValue> CreateOrOpen( IEnumerable <KeyValuePair <TKey, TValue> > values, string filename, long initialSize, long count, ISerializer <TValue> serializer = null, AccessStrategy strategy = AccessStrategy.MemoryMapped, IIndexSerializer <TKey> indexSerializer = null, IEnumerable <KeyValuePair <string, object> > additionalMetadata = null) { var fi = new FileInfo(filename); IRandomAccessStore reader = GetCreateReaderForStrategy(initialSize, strategy, fi); if (fi.Exists) { try { return(new FileIndexKeyValueStorage <TKey, TValue>(fi, reader, serializer, indexSerializer)); } catch (NoMagicException) { // no magic almost certainly means the file was partially written as the header is written last return(new FileIndexKeyValueStorage <TKey, TValue>(values, fi, initialSize, serializer, count, reader, indexSerializer, additionalData: additionalMetadata)); } } else { return(new FileIndexKeyValueStorage <TKey, TValue>(values, fi, initialSize, serializer, count, reader, indexSerializer, additionalData: additionalMetadata)); } }
public List <IUser> FetchData() { string[] productData = AccessStrategy.FetchData(); List <IUser> parsedData = ParserStrategy.Parse(productData, ParseSingle); return(parsedData); }
public void UpdateData(IUser newUser) { List <IUser> usersInFile = FetchData(); int userIndex = usersInFile.FindIndex(x => x.ID == newUser.ID); usersInFile[userIndex] = newUser; string unparsedData = ParserStrategy.Unparse(usersInFile.ToArray()); AccessStrategy.OverwriteAllData(unparsedData); }
public FieldConfiguration(string propertyName, Type type, bool isComplexType = false, ICollection <FieldConfiguration> fieldConfigurations = null, IPropertyConverter propertyConverter = null, AccessStrategy accessStrategy = AccessStrategy.Default) { Type = type; PropertyName = propertyName; IsComplexType = isComplexType; FieldConfigurations = fieldConfigurations ?? new List <FieldConfiguration>(); PropertyConverter = propertyConverter; AccessStrategy = accessStrategy; }
public static FileIndexKeyValueStorage <TKey, TValue> Create( IEnumerable <KeyValuePair <TKey, TValue> > values, string filename, long initialSize, ISerializer <TValue> serializer, long count, AccessStrategy strategy = AccessStrategy.MemoryMapped, IIndexSerializer <TKey> indexFactory = null, IEnumerable <KeyValuePair <string, object> > additionalMetadata = null, JsonSerializerSettings additionalDataSerializerSettings = null ) { var fi = new FileInfo(filename); var reader = GetCreateReaderForStrategy(initialSize, strategy, fi); return(new FileIndexKeyValueStorage <TKey, TValue>(values, fi, initialSize, serializer, count, reader, indexFactory, additionalMetadata, additionalDataSerializerSettings)); }
public static FileIndexKeyValueStorage <TKey, TValue> Open( string filename, AccessStrategy strategy = AccessStrategy.MemoryMapped, ISerializer <TValue> serializer = null, IIndexSerializer <TKey> indexFactory = null, Policy policy = null) { var fi = new FileInfo(filename); var reader = GetReaderForStrategy(strategy, fi); if (policy != null) { reader = new PolicyStore(reader, policy); } return(new FileIndexKeyValueStorage <TKey, TValue>(fi, reader, serializer, indexFactory)); }
public override Func <Target, Equinox.Core.IStream <TEvent, TState> > Resolve <TEvent, TState>( FsCodec.IUnionEncoder <TEvent, byte[], object> codec, Func <TState, IEnumerable <TEvent>, TState> fold, TState initial, Func <TEvent, bool> isOrigin = null, Func <TState, TEvent> compact = null) { var accessStrategy = isOrigin == null && compact == null ? null : AccessStrategy <TEvent, TState> .NewSnapshot(FuncConvert.FromFunc(isOrigin), FuncConvert.FromFunc(compact)); var cacheStrategy = _cache == null ? null : CachingStrategy.NewSlidingWindow(_cache, TimeSpan.FromMinutes(20)); var resolver = new Resolver <TEvent, TState, object>(_store, codec, FuncConvert.FromFunc(fold), initial, cacheStrategy, accessStrategy); return(t => resolver.Resolve(t)); }
public override Func <string, IStream <TEvent, TState> > Resolve <TEvent, TState>( FsCodec.IEventCodec <TEvent, byte[], object> codec, Func <TState, IEnumerable <TEvent>, TState> fold, TState initial, Func <TEvent, bool> isOrigin = null, Func <TState, TEvent> toSnapshot = null) { var accessStrategy = isOrigin == null && toSnapshot == null ? null : AccessStrategy <TEvent, TState> .NewRollingSnapshots(FuncConvert.FromFunc(isOrigin), FuncConvert.FromFunc(toSnapshot)); var cacheStrategy = _cache == null ? null : CachingStrategy.NewSlidingWindow(_cache, TimeSpan.FromMinutes(20)); var cat = new EventStoreCategory <TEvent, TState, object>(_connection, codec, FuncConvert.FromFunc(fold), initial, cacheStrategy, accessStrategy); return(t => cat.Resolve(t)); }
private static IRandomAccessStore GetReaderForStrategy(AccessStrategy strategy, FileInfo fi) { IRandomAccessStore reader; switch (strategy) { case AccessStrategy.MemoryMapped: reader = new MemoryMappedStore(fi); break; case AccessStrategy.Streams: reader = new StreamStore(fi); break; default: throw new Exception("Unexpected access strategy: " + strategy); } return(reader); }
public override Func <Target, IStream <TEvent, TState> > Resolve <TEvent, TState>( IUnionEncoder <TEvent, byte[]> codec, Func <TState, IEnumerable <TEvent>, TState> fold, TState initial, Func <TEvent, bool> isOrigin = null, Func <TState, TEvent> compact = null) { var accessStrategy = isOrigin == null && compact == null ? null : AccessStrategy <TEvent, TState> .NewRollingSnapshots(FuncConvert.FromFunc(isOrigin), FuncConvert.FromFunc(compact)); var cacheStrategy = _cache == null ? null : CachingStrategy.NewSlidingWindow(_cache, TimeSpan.FromMinutes(20)); var resolver = new GesResolver <TEvent, TState>(_gateway, codec, FuncConvert.FromFunc(fold), initial, accessStrategy, cacheStrategy); return(t => resolver.Resolve.Invoke(t)); }
public FieldConfiguration And(AccessStrategy accessStrategy) { return(With(accessStrategy)); }
public FieldConfiguration With(AccessStrategy accessStrategy) { this.AccessStrategy = accessStrategy; return(this); }