示例#1
0
        public async Task Handle(UnderlyingChangedEvent e)
        {
            switch (e.ChangeType)
            {
            case ChangeType.Creation:
                _underlyingsCache.AddOrUpdateByMdsCode(
                    _convertService.Convert <UnderlyingContract, UnderlyingsCacheModel>(e.NewValue));
                break;

            case ChangeType.Edition:

                var model = _convertService.Convert <UnderlyingContract, UnderlyingsCacheModel>(e.NewValue);

                await UpdateUnderlyingsCache(e, model);
                await HandleMdsCodeChanged(e);

                await _legacyAssetsCacheUpdater.HandleUnderlyingUpdated(e.OldValue.MdsCode, model, e.Timestamp);

                break;

            case ChangeType.Deletion:
                _underlyingsCache.Remove(
                    _convertService.Convert <UnderlyingContract, UnderlyingsCacheModel>(e.OldValue));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private async Task ProcessMessageAsync(UnderlyingChangedEvent message)
        {
            await _handler.Handle(message);

            _log.WriteInfo(nameof(UnderlyingChangedSubscriber), nameof(ProcessMessageAsync),
                           $"Handled event {nameof(UnderlyingChangedEvent)}. Event created at: {message.Timestamp.ToShortTimeString()}");
        }
示例#3
0
 private async Task UpdateUnderlyingsCache(UnderlyingChangedEvent e, UnderlyingsCacheModel model)
 {
     if (e.OldValue.MdsCode != e.NewValue.MdsCode)
     {
         _underlyingsCache.AddOrUpdateByChangedMdsCode(e.OldValue.MdsCode, model);
     }
     else
     {
         _underlyingsCache.AddOrUpdateByMdsCode(model);
     }
 }
示例#4
0
 private async Task HandleMdsCodeChanged(UnderlyingChangedEvent e)
 {
     if (e.OldValue.MdsCode != e.NewValue.MdsCode)
     {
         try
         {
             await _productsService.ChangeUnderlyingMdsCodeAsync(e.OldValue.MdsCode,
                                                                 e.NewValue.MdsCode,
                                                                 e.Username,
                                                                 e.CorrelationId);
         }
         catch (Exception exception)
         {
             throw new Exception(
                       $"Cannot update products with underlying mds code {e.OldValue.MdsCode}: {exception.Message}",
                       exception);
         }
     }
 }