private List <PropertyModel> GetProperties(CryptoAdapterType cryptoAdapterType, DirectionEnum direction) { var result = new List <PropertyModel>(); result = _entity.AdapterTypeItemProperty .Where(atip => atip.AdapterTypeItemId == (int)cryptoAdapterType && atip.DirectionId == (int)direction) .Select(s => new PropertyModel { Id = s.Property.Id, Name = s.Property.Name, PropertyType = (PropertyTypeEnum)s.Property.PropertyTypeId }) .ToList(); return(result); }
public Response <NoValue> SendToMongoDb <T>(List <T> blocks, EnterpriseAdapterModel enterpriseAdapter, string connectionString, CryptoAdapterType cryptoAdapter) { var response = new Response <NoValue>(); try { var stopwatch = Stopwatch.StartNew(); var mongoClient = new MongoClient(connectionString); var db = mongoClient.GetDatabase(enterpriseAdapter.DatabaseName); var collectionName = enterpriseAdapter.Properties.FirstOrDefault().DestinationProperties.FirstOrDefault(sp => sp.Id == (long)PropertyEnum.CollectionName).Value; var collection = db.GetCollection <BsonDocument>($"{cryptoAdapter.ToString()}{collectionName}"); foreach (var block in blocks) { collection.InsertOne(block.ToBsonDocument()); } stopwatch.Stop(); _logger.Information($"MongoDbAdapter.SendToMongoDb(blocks: {blocks.Count}, enterpriseAdapter: {enterpriseAdapter.Id}). Time elapsed: {stopwatch.Elapsed.TotalSeconds} seconds."); response.Status = StatusEnum.Success; } catch (Exception ex) { response.Status = StatusEnum.Error; response.Message = ex.Message; _logger.Information($"MongoDbAdapter.SendToMongoDb(blocks: {blocks.Count}, enterpriseAdapter: {enterpriseAdapter.Id})"); _logger.Error(ex.Message); } return(response); }