Example #1
0
        private async Task ApplyChangeAsync(
            object key,
            object entity,
            EntityState entityState)
        {
            var targetPath = Path.AppendFile(key.ToString());

            switch (entityState)
            {
            case EntityState.Deleted:
                await AsyncFileSystem.DeleteAsync(targetPath);

                break;

            case EntityState.Added:
                var metadata = EntityMetadata(key, entity, EntityState.Added, null);
                using (var stream = await AsyncFileSystem.CreateFileAsync(targetPath))
                    Serialize(stream, metadata);
                break;

            case EntityState.Updated:
                var updatedMetadata = EntityMetadata(key, entity, EntityState.Updated,
                                                     await FindByIdInternalAsync(key));
                using (var stream = await AsyncFileSystem.CreateFileAsync(targetPath))
                    Serialize(stream, updatedMetadata);
                break;
            }
        }
Example #2
0
 private async Task FlushAsync(List <MetadataEntity> raw)
 {
     using (var stream = await AsyncFileSystem.CreateFileAsync(Path))
         using (var outstream = new StreamWriter(stream))
         {
             var writer = new JsonTextWriter(outstream);
             _listSerializer.WriteJson(writer, raw, _serializer);
         }
 }