Exemple #1
0
        public async Task CreateRetrieveAssetDefinitionCommand(params string[] urls)
        {
            foreach (var url in urls)
            {
                var context = new UpdateAssetDataContext
                {
                    AssetDefinitionUrl = url
                };

                await _queue.PutRawMessageAsync(context.ToJson());
            }
        }
        public async Task RetrieveAssetDefinition(UpdateAssetDataContext context)
        {
            try
            {
                _console.Write(nameof(AssetDataCommandQueueConsumer), nameof(RetrieveAssetDefinition), context.ToJson(), "Started");
                var assetData = await _assetDefinitionReader.ReadAssetDataAsync(context.AssetDefinitionUrl);

                if (assetData != null)
                {
                    await _assetDefinitionRepository.InsertOrReplaceAsync(assetData);

                    if (assetData.IsValid())
                    {
                        await _assetImageCommandProducer.CreateUpsertAssetImageCommand(assetData.AssetIds, assetData.IconUrl,
                                                                                       assetData.ImageUrl);
                    }
                }
                else
                {
                    await _assetDefinitionRepository.InsertEmptyAsync(context.AssetDefinitionUrl);
                }

                _console.Write(nameof(AssetDataCommandQueueConsumer), nameof(RetrieveAssetDefinition), context.ToJson(), "Done");
            }
            catch (Exception e)
            {
                await _log.WriteWarningAsync(nameof(AssetDataCommandQueueConsumer), nameof(RetrieveAssetDefinition), context.ToJson(), e.ToString());

                if (!await _assetDefinitionRepository.IsAssetExistsAsync(context.AssetDefinitionUrl))
                {
                    await _assetDefinitionRepository.InsertEmptyAsync(context.AssetDefinitionUrl);
                }
            }
        }