public async Task <IAssetAttribute> AddAsync(string assetId, IAssetAttribute attribute)
        {
            await _assetAttributeRepository.AddAsync(assetId, attribute);

            await _myNoSqlWriter.TryInsertOrReplaceAsync(AssetAttributeNoSql.Create(assetId, attribute.Key, attribute.Value));

            return(attribute);
        }
Пример #2
0
        public async Task <IAssetCategory> AddAsync(IAssetCategory assetCategory)
        {
            await _assetCategoryRepository.AddAsync(assetCategory);

            await _myNoSqlWriter.TryInsertOrReplaceAsync(AssetCategoryNoSql.Create(assetCategory));

            return(assetCategory);
        }
        public async Task <IAssetExtendedInfo> AddAsync(IAssetExtendedInfo assetInfo)
        {
            await _assetExtendedInfoRepository.UpsertAsync(assetInfo);

            await _myNoSqlWriter.TryInsertOrReplaceAsync(AssetExtendedInfoNoSql.Create(assetInfo));

            return(assetInfo);
        }
Пример #4
0
        public async Task <IWatchList> AddPredefinedAsync(IWatchList watchList)
        {
            await _predefinedWatchListRepository.UpsertAsync(watchList);

            await _myNoSqlWriterPredefined.TryInsertOrReplaceAsync(WatchListPredefinedNoSql.Create(watchList));


            return(watchList);
        }
        public async Task <IAssetPair> AddAsync(IAssetPair assetPair)
        {
            await _assetPairRepository.UpsertAsync(assetPair);

            await _myNoSqlWriter.TryInsertOrReplaceAsync(AssetPairNoSql.Create(assetPair));

            //todo: remove cqrs
            _cqrsEngine.SendCommand(
                new CreateAssetPairCommand {
                AssetPair = Mapper.Map <AssetPair>(assetPair)
            },
                BoundedContext.Name, BoundedContext.Name);

            return(assetPair);
        }
        public Task InitCacheAsync(AssetPairPrice[] pairsToCache)
        {
            var entries = pairsToCache.Select(p => new KeyValuePair <string, AssetPairPrice>(p.AssetPair, p));

            _pairs = new ConcurrentDictionary <string, AssetPairPrice>(entries);

            var tasks = new List <Task>();

            foreach (var pair in _pairs.Values)
            {
                tasks.Add(_redisService.AddAssetPairPriceAsync(pair));
                tasks.Add(_myNoSqlWriterWrapper.TryInsertOrReplaceAsync(AssetPairPriceNoSql.Create(pair)));
            }

            return(Task.WhenAll(tasks));
        }
        public async Task <IAsset> AddAsync(IAsset asset)
        {
            await ValidateAsset(asset);

            await _assetRepository.InsertOrReplaceAsync(asset);

            await _myNoSqlWriter.TryInsertOrReplaceAsync(AssetNoSql.Create(asset));


            //todo: remove cqrs
            _cqrsEngine.SendCommand(
                new CreateAssetCommand {
                Asset = Mapper.Map <Asset>(asset)
            },
                BoundedContext.Name, BoundedContext.Name);

            return(asset);
        }
        public async Task <IEnumerable <IAssetCondition> > GetAssetConditionsByClient(string clientId)
        {
            var assetConditions = await _cacheManager.TryGetAssetConditionsForClientAsync(clientId);

            if (assetConditions != null)
            {
                return(assetConditions);
            }

            var assetDefaultLayer = await _cachedAssetConditionsService.GetDefaultLayerAsync();

            var defaultLayerConditions = await _cachedAssetConditionsService.GetConditionsAsync(assetDefaultLayer.Id);

            var map = new Dictionary <string, AssetCondition>();

            // Initialize asset conditions using default layer conditions
            foreach (var condition in defaultLayerConditions)
            {
                map[condition.Asset] = Mapper.Map <AssetCondition>(condition);
            }

            // Merge client conditions layers
            var layers = await GetLayersAsync(clientId);

            foreach (var layer in layers.OrderBy(e => e.Priority))
            {
                var explicitAssets = new HashSet <string>();

                var conditions = await _cachedAssetConditionsService.GetConditionsAsync(layer.Id);

                // Apply explicit assets conditions
                foreach (var condition in conditions)
                {
                    if (!map.TryGetValue(condition.Asset, out var value))
                    {
                        map[condition.Asset] = Mapper.Map <AssetCondition>(condition);
                    }
                    else
                    {
                        value.Apply(condition);
                    }

                    explicitAssets.Add(condition.Asset);
                }

                var defaultAssetCondition = await _cachedAssetConditionsService.GetDefaultConditionsAsync(layer.Id);

                if (defaultAssetCondition == null)
                {
                    continue;
                }

                // Apply implicit assets conditions
                var implicitAssets = map.Keys.Where(o => !explicitAssets.Contains(o));

                foreach (var asset in implicitAssets)
                {
                    map[asset].Apply(defaultAssetCondition);
                }
            }

            assetConditions = map.Values.Cast <IAssetCondition>().ToList();

            // Update asset conditions cache
            await _cacheManager.SaveAssetConditionsForClientAsync(clientId, assetConditions);

            await _myNoSqlWriter.TryInsertOrReplaceAsync(AssetConditionNoSql.Create(clientId, assetConditions));

            return(assetConditions);
        }