예제 #1
0
 /// <summary>
 /// Creates a database handler instance by data context reference.
 /// </summary>
 /// <param name="databaseContext">Reference to Mongo database context.</param>
 /// <param name="modelContainer">Assembly which contains the mongo data models.</param>
 /// <param name="updateOperationHandler">Custom update operation defintion</param>
 /// <param name="logger">Reference to logger instance</param>
 public DatabaseHandler(IMongoDatabase databaseContext, Assembly modelContainer, ICustomUpdateOperation updateOperationHandler, ILogger logger)
 {
     _logger                 = logger;
     _databaseContext        = databaseContext;
     _updateOperationHandler = updateOperationHandler;
     _dataModelContainer     = modelContainer;
 }
예제 #2
0
        /// <summary>
        /// Create a instance by data collection type.
        /// </summary>
        /// <param name="collection">Reference to data store collection</param>
        /// <param name="data">Json configuration of the current data collection</param>
        /// <param name="updateOperationHandler">Custom operation handler</param>
        /// <param name="logger">Reference to logger instance</param>
        public GenericCollectionOperator(IMongoCollection <T> collection, JToken data, ICustomUpdateOperation updateOperationHandler, ILogger logger)
        {
            _logger = logger;
            _updateOperationHandler = updateOperationHandler;
            _collection             = collection;
            _keys = data["keys"].Values <string>().ToArray();
            _logger.LogDebug(_keys.Length + " key fields were found.");

            _idPropertyName = GetIdPropertyName();
            _logger.LogDebug("Name of id property: " + _idPropertyName);

            _items = new Dictionary <T, JToken>();
            foreach (var item in data["items"])
            {
                _items.Add(item.ToObject <T>(), item);
            }
            _logger.LogDebug(_items.Count + " items were found.");
        }
예제 #3
0
 /// <summary>
 /// Creates a instance by Mongo data context and update operation handler.
 /// </summary>
 /// <param name="databaseContext">Reference to the mongo data context which contains the MongoDatabase property.</param>
 /// <param name="modelContainer">Assembly which contains the mongo data models.</param>
 /// <param name="logger">Reference to the logger instance</param>
 /// <param name="updateOperationHandler">Custom update operation handler</param>
 public Initializer(IMongoDatabase databaseContext, Assembly modelContainer, ILogger logger, ICustomUpdateOperation updateOperationHandler)
 {
     _logger = logger;
     if (updateOperationHandler == null)
     {
         updateOperationHandler = new DefaultUpdateOperation();
     }
     _databaseHandler = new DatabaseHandler(databaseContext, modelContainer, updateOperationHandler, logger);
 }