private async Task <bool> DeserializeAsync <TState>(ILog log, IHaveState <TState> stateHolder, ISnapshotRepository <TState> repository)
        {
            await log.WriteInfoAsync(nameof(DeserializeAsync), "", "Loading state...");

            var state = await repository.TryGetAsync();

            if (state == null)
            {
                await log.WriteWarningAsync("SnapshotSerializer", nameof(DeserializeAsync),
                                            stateHolder.GetType().Name, "No snapshot found to deserialize");

                return(false);
            }

            string stateDescription;

            try
            {
                stateDescription = stateHolder.DescribeState(state);
            }
            catch (NotSupportedException)
            {
                await log.WriteWarningAsync(nameof(DeserializeAsync), "", "Not supported, skipping");

                return(false);
            }

            await log.WriteInfoAsync(nameof(DeserializeAsync), stateDescription, "Settings state...");

            try
            {
                stateHolder.SetState(state);
            }
            catch (NotSupportedException)
            {
                await log.WriteWarningAsync(nameof(DeserializeAsync), "", "Not supported, skipping");

                return(false);
            }

            await log.WriteInfoAsync(nameof(DeserializeAsync), "", "State was set");

            return(true);
        }
コード例 #2
0
        public async Task DeserializeAsync()
        {
            await _log.WriteInfoAsync(nameof(DeserializeAsync), "", "Loading state...");

            var state = await _repository.TryGetAsync();

            if (state == null)
            {
                await _log.WriteWarningAsync("SnapshotSerializer", nameof(DeserializeAsync),
                                             _stateHolder.GetType().Name, "No snapshot found to deserialize");

                return;
            }

            await _log.WriteInfoAsync(nameof(DeserializeAsync), _stateHolder.DescribeState(state), "Settings state...");

            _stateHolder.SetState(state);

            await _log.WriteInfoAsync(nameof(DeserializeAsync), "", "State was set");
        }
 public async Task <bool> DeserializeAsync <TState>(IHaveState <TState> stateHolder, ISnapshotRepository <TState> repository)
 {
     return(await DeserializeAsync(_log.CreateComponentScope($"{nameof(SnapshotSerializer)}[{stateHolder.GetType().Name}]"), stateHolder, repository));
 }
コード例 #4
0
 public async Task SerializeAsync <TState>(IHaveState <TState> stateHolder, ISnapshotRepository <TState> repository)
 {
     await SerializeAsync(_logFactory.CreateLog($"{nameof(SnapshotSerializer)}[{stateHolder.GetType().Name}]"), stateHolder, repository);
 }
コード例 #5
0
 public SnapshotSerializer(
     IHaveState <TState> stateHolder,
     ISnapshotRepository <TState> repository,
     ILog log)
 {
     _stateHolder = stateHolder;
     _repository  = repository;
     _log         = log.CreateComponentScope($"{nameof(SnapshotSerializer<TState>)}[{_stateHolder.GetType().Name}]");
 }