protected GenericRepositoryAsync(IMongoDbConnector connector, string collectionName, DeliveryStrategy strategy = null) { Connector = connector; CollectionName = collectionName; Collection = Connector.Db.GetCollection <T>(collectionName); CollectionExist = Collection != null; Strategy = strategy ?? DeliveryStrategy.DefaultDeliveryStrategy(); }
/// <summary> /// Initializes a new instance of the <see cref="YottoBus"/> class. /// </summary> /// <param name="container">The IoC container.</param> public YottoBus(IKernel container) { _container = container; Loggers = _container.GetAll <IBusLogger>().ToList(); DeliveryStrategy = _container.Get <DeliveryStrategyBase>(); DeliveryStrategy.AddLoggers(Loggers); }
protected virtual async Task <IEnumerable <object> > GetCollection(Expression <Func <T, bool> > filter, DeliveryStrategy strategy, CancellationToken token = default(CancellationToken)) { if (!CollectionExist) { return(new List <object>()); } try { var collection = filter == null?Collection.Find(_ => true) : Collection.Find(filter); var sortingBuilder = new SortDefinitionBuilder <T>(); var sorts = new List <SortDefinition <T> >(); if (strategy.SortingSettings != null) { sorts.AddRange(from sf in strategy.SortingSettings where !sf.IsNull select sf.SortingMode == SortingModes.Ascending ? sortingBuilder.Ascending(sf.FieldName) : sortingBuilder.Descending(sf.FieldName)); } collection.Sort(sortingBuilder.Combine(sorts)); if (!string.IsNullOrEmpty(strategy.ProjectionString)) { collection.Project(strategy.ProjectionString); } if (strategy.PagingSettings == null) { return((IEnumerable <object>) await collection.ToListAsync(CancellationToken.None)); } if (strategy.PagingSettings.Skip != null) { collection = collection.Skip(strategy.PagingSettings.Skip); } if (strategy.PagingSettings.Limit != null) { collection = collection.Limit(strategy.PagingSettings.Limit); } return((IEnumerable <object>) await collection.ToListAsync(token)); } catch (Exception e) { throw new Exception(e.Message); } }
protected Order(DeliveryStrategy delivery) { Delivery = delivery; }