public override int Interpret(ITerminalListExpression <string> creditsIntergalacticWordsList) { ContractUtility.Requires <ArgumentOutOfRangeException>(creditsIntergalacticWordsList != null && creditsIntergalacticWordsList.DataList != null && creditsIntergalacticWordsList.DataList.Count > 0, "normalIntergalacticWordsList and normalIntergalacticWordsList.DataList cannot be null" + "and normalIntergalacticWordsList.DataList should be > 0"); var creditsTypeInputWordJustBeforeIs = creditsIntergalacticWordsList.DataList.LastOrDefault(); var allowedCreditTypes = Enum.GetNames(typeof(CreditsType)); ContractUtility.Requires <ArgumentException>(!String.IsNullOrEmpty(creditsTypeInputWordJustBeforeIs) && allowedCreditTypes.Contains(creditsTypeInputWordJustBeforeIs), "The last word must be any one of " + allowedCreditTypes.Aggregate((a, b) => a + " , " + b) + " ."); ITerminalIsExpression <string, decimal> terminalIsExpression = null; ContractUtility.Requires <InvalidOperationException>(creditsInputMappingsWithTerminalIsExpressions.TryGetValue(creditsTypeInputWordJustBeforeIs, out terminalIsExpression), creditsTypeInputWordJustBeforeIs + " was not supplied in the input provided earlier while storing."); var normalInputWordsListBeforeCreditsType = creditsIntergalacticWordsList.DataList.Except(new List <string> { creditsTypeInputWordJustBeforeIs }).ToList(); var normalInputWordsListBeforeCreditsTypeNumberFormatValue = 1; if (normalInputWordsListBeforeCreditsType.Count > 0) { var normalInputSemanticLanguageExpression = new NormalInputSemanticLanguageExpression(numberFormatCalculator, symbolValues); var normalIntergalacticWordsList = new TerminalListExpression <string>(normalInputWordsListBeforeCreditsType); normalInputWordsListBeforeCreditsTypeNumberFormatValue = normalInputSemanticLanguageExpression.Interpret(normalIntergalacticWordsList); } return(Convert.ToInt32(normalInputWordsListBeforeCreditsTypeNumberFormatValue * terminalIsExpression.RightExpressionData.Data)); }
private void HandleRunQuery <TNextActionType>(Func <IQueryableRepository <TEntity>, TNextActionType> queryableRepositoryOperation, Action <TNextActionType> operationToExecuteBeforeNextOperation) { CheckForObjectAlreadyDisposedOrNot(typeof(QueryableRepository <TEntity>).FullName); ContractUtility.Requires <ArgumentNullException>(queryableRepositoryOperation.IsNotNull(), "queryableRepositoryOperation instance cannot be null"); Action operation = () => { TNextActionType queryReturnValue = _unitOfWork.IsNull() ? ExceptionHandlingUtility.HandleExceptionWithNullCheck( () => queryableRepositoryOperation(this), _exceptionHandler) : queryableRepositoryOperation(this); //TODO - proper exception handling compensating handler needs to be here if (operationToExecuteBeforeNextOperation.IsNotNull()) { operationToExecuteBeforeNextOperation(queryReturnValue); } }; if (_unitOfWork.IsNotNull()) { _unitOfWork.AddOperation(operation); } else { operation(); } }
public UnitOfWork(IsolationLevel isoLevel = IsolationLevel.ReadCommitted, TransactionScopeOption scopeOption = TransactionScopeOption.RequiresNew, ILogger logger = null) { ContractUtility.Requires <ArgumentNullException>(logger.IsNotNull(), "logger instance cannot be null"); _isoLevel = isoLevel; _scopeOption = scopeOption; _operationsQueue = new Queue <OperationData>(); }
public override string ToNumberFormat(int number) { ContractUtility.Requires <ArgumentException>(number > 3999, "Too big - can't exceed 3999"); ContractUtility.Requires <ArgumentException>(number < 1, "Too small - can't be less than 1"); int thousands, hundreds, tens, units; thousands = number / 1000; number %= 1000; hundreds = number / 100; number %= 100; tens = number / 10; units = number % 10; var numberFormat = new StringBuilder(); if (thousands > 0) { numberFormat.Append(roman1[3 - thousands]); } if (hundreds > 0) { numberFormat.Append(roman2[9 - hundreds]); } if (tens > 0) { numberFormat.Append(roman3[9 - tens]); } if (units > 0) { numberFormat.Append(roman4[9 - units]); } return(numberFormat.ToString()); }
public virtual IQueryable <TEntity> Include(Expression <Func <TEntity, object> > subSelector) { CheckForObjectAlreadyDisposedOrNot(typeof(QueryableRepository <TEntity>).FullName); ContractUtility.Requires <ArgumentNullException>(subSelector.IsNotNull(), "subSelector instance cannot be null"); //TODO - proper exception handling compensating handler needs to be here return(ExceptionHandlingUtility.HandleExceptionWithNullCheck(() => _queryable.Include(subSelector), _exceptionHandler)); }
public UnityInstanceProvider(IUnityContainer container, Type type) { ContractUtility.Requires <ArgumentNullException>(container.IsNotNull(), "container cannot be null."); ContractUtility.Requires <ArgumentNullException>(type.IsNotNull(), "type cannot be null."); _container = container; _serviceType = type; }
public CommandDomainService(ICommandRepository <TEntity> repository, ILogger logger) { ContractUtility.Requires <ArgumentNullException>(repository != null, "repository instance cannot be null"); ContractUtility.Requires <ArgumentNullException>(logger != null, "logger instance cannot be null"); _repository = repository; this.logger = logger; }
public IFluentCommands InsertAsync <TEntity>(IEnumerable <TEntity> items, CancellationToken token = default(CancellationToken), Action operationToExecuteBeforeNextOperation = null) where TEntity : class, ICommandAggregateRoot { ContractUtility.Requires <ArgumentNullException>(items.IsNotNull(), "items cannot be null"); ContractUtility.Requires <ArgumentOutOfRangeException>(items.IsNotEmpty(), "items cannot be empty"); return(GetFluentCommandsAfterSettingCommandRepositoryAndPersistanceQueueDataForAsync <TEntity>(x => x.InsertAsync(items, token, operationToExecuteBeforeNextOperation))); }
public IFluentCommands BulkDelete <TEntity>(IEnumerable <TEntity> items, Action operationToExecuteBeforeNextOperation = null) where TEntity : class, ICommandAggregateRoot { ContractUtility.Requires <ArgumentNullException>(items.IsNotNull(), "items cannot be null"); ContractUtility.Requires <ArgumentOutOfRangeException>(items.IsNotEmpty(), "items cannot be empty"); return(GetFluentCommandsAfterSettingCommandRepositoryAndPersistanceQueueData <TEntity>(x => x.BulkDelete(items, operationToExecuteBeforeNextOperation))); }
public QueryableRepository(IUnitOfWork unitOfWork, Queryable.IQuery <TEntity> queryable) { ContractUtility.Requires <ArgumentNullException>(unitOfWork.IsNotNull(), "unitOfWork instance cannot be null"); ContractUtility.Requires <ArgumentNullException>(queryable.IsNotNull(), "queryable instance cannot be null"); _unitOfWork = unitOfWork; _queryable = queryable; }
protected override EventListener GetListener(IListenerCreationData listenerCreationData) { ContractUtility.Requires <ArgumentNullException>(listenerCreationData.IsNotNull(), "Listener Creation Data cannot be null"); var flatFileListenerCreationData = listenerCreationData as FlatFileListenerCreationData; return(FlatFileLog.CreateListener(flatFileListenerCreationData.FileName, flatFileListenerCreationData.EventTextFormatter, flatFileListenerCreationData.IsAsync)); }
protected override EventListener GetListener(IListenerCreationData listenerCreationData) { ContractUtility.Requires <ArgumentNullException>(listenerCreationData.IsNotNull(), "Listener Creation Data cannot be null"); var consoleListenerCreationData = listenerCreationData as ConsoleListenerCreationData; return(ConsoleLog.CreateListener(consoleListenerCreationData.EventTextFormatter, consoleListenerCreationData.ConsoleColorMapper)); }
public void Execute(Boolean shouldAutomaticallyDisposeAllDisposables = false) { ContractUtility.Requires <ArgumentOutOfRangeException>(_operationsQueue.IsNotNullOrEmpty(), "Atleast one operation must be there to be executed."); ContractUtility.Requires <NotSupportedException>(_operationsQueue.All(y => y.AsyncOperation.IsNull()), "Async operations are not supported by Execute method.Use ExecuteAsync instead."); while (_operationsQueue.Count > 0) { OperationData operationData = _operationsQueue.Dequeue(); if (operationData.Operation.IsNotNull()) { operationData.Operation(); } } if (_unitOfWorkData != null && _unitOfWorkData.UnitOfWork != null) { dynamic unitOfWork = _unitOfWorkData.UnitOfWork; unitOfWork.Commit(_unitOfWorkData.ShouldAutomaticallyRollBackOnTransactionException, _unitOfWorkData.ShouldThrowOnException); if (shouldAutomaticallyDisposeAllDisposables) { unitOfWork.Dispose(); } } if (shouldAutomaticallyDisposeAllDisposables && _repositoriesList.IsNotNullOrEmpty()) { _repositoriesList.Select(x => x as IDisposable).Where(x => x.IsNotNull()).CleanUp(); } }
public override void Store(string normalInput) { var trimmedNormalInput = normalInput.Trim(); ContractUtility.Requires <ArgumentException>(trimmedNormalInput.Contains(" is "), "normalInput must contain \" is \""); var normalInputWordsBeforeAndAfterIs = trimmedNormalInput.Split(new string[] { " is " }, StringSplitOptions.None).Where(x => !String.IsNullOrEmpty(x)); var normalInputWordBeforeIs = normalInputWordsBeforeAndAfterIs.FirstOrDefault(); ContractUtility.Requires <ArgumentException>(!String.IsNullOrEmpty(normalInputWordBeforeIs) && !String.IsNullOrWhiteSpace(normalInputWordBeforeIs), "Some data must be there before \"is\" in normalInput"); ContractUtility.Requires <ArgumentException>(!normalInputWordBeforeIs.Trim().Contains(" "), "Cannot have > 1 intergalactic words before \"is\" in normalInput"); ContractUtility.Requires <ArgumentException>(!normalInputMappingsWithTerminalIsExpressions.ContainsKey(normalInputWordBeforeIs), "normalInput is already stored"); var normalSymbolAfterIs = normalInputWordsBeforeAndAfterIs.LastOrDefault(); ContractUtility.Requires <ArgumentException>(!String.IsNullOrEmpty(normalSymbolAfterIs) && !String.IsNullOrWhiteSpace(normalSymbolAfterIs), "Some data must be there after \"is\" in normalInput"); ContractUtility.Requires <ArgumentException>(!normalSymbolAfterIs.Trim().Contains(" "), "Cannot have > 1 symbols after \"is\" in normalInput"); var validSymbols = symbolValues.SymbolValues.Keys; ContractUtility.Requires <ArgumentException>(validSymbols.Select(x => x.ToString()).Contains(normalSymbolAfterIs.Trim()), "The symbol after \"is\" in normalInput must be " + CharactersUtility.GetFormattedCommaSeperatedCharacters(validSymbols, "or") + " ."); var terminalIsExpression = new TerminalIsExpression <string, string>(normalInputWordBeforeIs, normalSymbolAfterIs); normalInputMappingsWithTerminalIsExpressions.Add(normalInputWordBeforeIs, terminalIsExpression); }
public BaseEntityRootMap() { ContractUtility.Requires <ArgumentNullException>(IDColumnName.IsNotNullOrWhiteSpace(), "IDColumnName cannot be null or empty."); ExtendKeyIDWithOtherConfigurations(HasKey(p => p.Id)); ExtendPropertyIDWithOtherConfigurations(Property(p => p.Id).HasColumnName(IDColumnName).HasDatabaseGeneratedOption(DbIdGenerationOption)); SetEntitySpecificProperties(); ToTable(TableName); }
public static IFluentQueryRepository SetUpQueryRepository(IList <dynamic> queryRepositories) { ContractUtility.Requires <ArgumentNullException>(queryRepositories.IsNotNull(), "queryRepositories cannot be null"); ContractUtility.Requires <ArgumentOutOfRangeException>(queryRepositories.IsNotEmpty(), "queryRepositories cannot be empty"); ContractUtility.Requires <ArgumentException>(queryRepositories.All(x => x.GetType().GetGenericTypeDefinition().GetInterface(typeof(IQueryableRepository <>).Name) != null), "All repositories should be of type IQueryableRepository<>"); ContractUtility.Requires <ArgumentException>(queryRepositories.Count() == queryRepositories.Distinct().Count(), "One or more Query Repository has been repeated"); return(new FluentQueryRepository(null, queryRepositories, null)); }
public BaseBatchSeedSelector(IQueryableRepository <TEntity> seedQueryableRepository, int batchSize, ILogger logger) { ContractUtility.Requires <ArgumentNullException>(seedQueryableRepository.IsNotNull(), "seedQueryableRepository cannot be null"); ContractUtility.Requires <ArgumentOutOfRangeException>(batchSize > 0, "batchSize should be greater than 0"); ContractUtility.Requires <ArgumentNullException>(logger.IsNotNull(), "logger cannot be null"); _seedQueryableRepository = seedQueryableRepository; _batchSize = batchSize; _logger = logger ?? LoggerFactory.GetLogger(LoggerType.Default); }
public static IFluentQueryRepository SetUpQueryRepository <TEntity>(IQueryableRepository <TEntity> queryRepository) where TEntity : class, IQueryableAggregateRoot { ContractUtility.Requires <ArgumentNullException>(queryRepository.IsNotNull(), "queryRepository instance cannot be null"); var queryRepositoryList = new List <dynamic> { queryRepository }; return(new FluentQueryRepository(null, queryRepositoryList, null)); }
public RawSQLEntityFramework(DbContext context, Transactions.IsolationLevel isoLevel = Transactions.IsolationLevel.ReadCommitted, Transactions.TransactionScopeOption scopeOption = Transactions.TransactionScopeOption.RequiresNew) { ContractUtility.Requires <ArgumentNullException>(context.IsNotNull(), "context instance cannot be null"); _context = context; //_context.Database.CreateIfNotExists();//Alongwith creating the DB(if the DB does not exist), // this method also creates the tables even if the tables do not exist - also alters the tables if // some changes are there in the structure of domain classes. _isoLevel = isoLevel; _scopeOption = scopeOption; }
protected override EventListener GetListener(IListenerCreationData listenerCreationData) { ContractUtility.Requires <ArgumentNullException>(listenerCreationData.IsNotNull(), "Listener Creation Data cannot be null"); var rollingFileListenerCreationData = listenerCreationData as RollingFileListenerCreationData; return(RollingFlatFileLog.CreateListener(rollingFileListenerCreationData.FileName, rollingFileListenerCreationData.RollSizeKB, rollingFileListenerCreationData.TimestampPattern, rollingFileListenerCreationData.RollFileExistsBehavior, rollingFileListenerCreationData.RollInterval, rollingFileListenerCreationData.Formatter, rollingFileListenerCreationData.MaxArchivedFiles, rollingFileListenerCreationData.IsAsync)); }
public static IFluentCommandAndQueryRepository WithUnitOfWork <TUnitOfWork>(TUnitOfWork unitOfWork, bool shouldAutomaticallyRollBackOnTransactionException = true, bool shouldThrowOnException = true) where TUnitOfWork : class, IUnitOfWork { ContractUtility.Requires <ArgumentNullException>(unitOfWork.IsNotNull(), "unitOfWork instance cannot be null"); var unitOfWorkData = new UnitOfWorkData { UnitOfWork = unitOfWork, ShouldAutomaticallyRollBackOnTransactionException = shouldAutomaticallyRollBackOnTransactionException, ShouldThrowOnException = shouldThrowOnException }; return(new FluentCommandAndQueryRepository(unitOfWorkData)); }
protected override string BuildIntergalacticWordsListAndGetOutputToReturn(string queryInputWordsAfterIsButBeforeQuestionMark) { var queryInputWordsListAfterIsButBeforeQuestionMark = queryInputWordsAfterIsButBeforeQuestionMark.Split(new string[] { " " }, StringSplitOptions.None).Where(x => !String.IsNullOrEmpty(x.Trim())).ToList(); ContractUtility.Requires <ArgumentException>(queryInputWordsListAfterIsButBeforeQuestionMark.Count > 0, "Words count before \"is\" in the input query must be > 0"); var queryInputWordsListAfterIsButBeforeQuestionMarkTerminalListExpression = new TerminalListExpression <string>(queryInputWordsListAfterIsButBeforeQuestionMark); var normalInputSemanticLanguageExpression = new NormalInputSemanticLanguageExpression(numberFormatCalculator, symbolValues); return(queryInputWordsAfterIsButBeforeQuestionMark + " is " + normalInputSemanticLanguageExpression.Interpret(queryInputWordsListAfterIsButBeforeQuestionMarkTerminalListExpression)); }
public static IFluentCommandRepository SetUpCommandRepository <TEntity>(ICommandRepository <TEntity> commandRepository) where TEntity : class, ICommandAggregateRoot { ContractUtility.Requires <ArgumentNullException>(commandRepository.IsNotNull(), "commandRepository instance cannot be null"); var commandRepositoryList = new List <dynamic> { commandRepository }; return(new FluentCommandRepository(null, commandRepositoryList, null)); }
public void RegisterListenerDataWithListener(ListenerData listenerData) { ContractUtility.Requires <ArgumentNullException>(listenerData.ListenerCreationDataAndEventSources.IsNotNull(), "listenerData.ListenerCreationDataAndEventSources instance cannot be null"); ContractUtility.Requires <ArgumentNullException>(listenerData.ListenerCreationDataAndEventSources.ListenerCreationData.IsNotNull(), "The " + "listenerData.ListenerCreationDataAndEventSources.ListenerCreationData instance cannot be null"); if (Bootstrapper.CheckForPermissibleBootstrapedListenerType(listenerData)) { IListener listener = Container.Instance.Resolve <IListener>(listenerData.ListenerType.ToString()); listener.RegisterListener(listenerData.ListenerCreationDataAndEventSources); } }
protected override string BuildIntergalacticWordsListAndGetOutputToReturn(string queryInputWordsAfterIsButBeforeQuestionMark) { var allowedCreditTypes = Enum.GetNames(typeof(CreditsType)); ContractUtility.Requires <ArgumentException>(allowedCreditTypes.Any(x => queryInputWordsAfterIsButBeforeQuestionMark.Trim().EndsWith(x)), "The last word in the query after \"is\" but before \"?\" should be any of " + allowedCreditTypes.Aggregate((a, b) => a + " , " + b) + "."); var queryInputWordsListAfterIsButBeforeQuestionMark = queryInputWordsAfterIsButBeforeQuestionMark.Split(new string[] { " " }, StringSplitOptions.None).Where(x => !String.IsNullOrEmpty(x)).ToList(); var queryInputWordsListAfterIsButBeforeQuestionMarkTerminalListExpression = new TerminalListExpression <string>(queryInputWordsListAfterIsButBeforeQuestionMark); var creditsInputSemanticLanguageExpression = new CreditslInputSemanticLanguageExpression(numberFormatCalculator, symbolValues); return(queryInputWordsAfterIsButBeforeQuestionMark + " is " + creditsInputSemanticLanguageExpression.Interpret(queryInputWordsListAfterIsButBeforeQuestionMarkTerminalListExpression) + " Credits"); }
public void RegisterListenerDataWithListeners(IList <ListenerData> listenerDataList) { ContractUtility.Requires <ArgumentNullException>(listenerDataList.IsNotNull(), "listenerDataList instance cannot be null"); ContractUtility.Requires <ArgumentOutOfRangeException>(listenerDataList.IsNotEmpty(), "listenerDataList must contain atleast 1 Listener Data"); listenerDataList.Where(x => x.IsNotNull()).ToList().ForEach(x => { RegisterListenerDataWithListener(x); } ); }
private int PerformDMLWithRawSQLWithinTransaction(String query, params Object[] parameters) { ContractUtility.Requires <ArgumentNullException>(!query.IsNullOrWhiteSpace(), "query instance cannot be null or empty"); Transactions.TransactionScope scope = TransactionUtility.GetTransactionScope(_isoLevel, _scopeOption); using (scope) { int retValue = _context.Database.ExecuteSqlCommand(query, parameters); scope.Complete(); return(retValue); } }
public IFluentCommands SetUpCommandPersistance <TEntity>(ICommand <TEntity> command) where TEntity : class, ICommandAggregateRoot { ContractUtility.Requires <ArgumentNullException>(command.IsNotNull(), "command instance cannot be null"); string commandRepositoryTypeName = typeof(ICommandRepository <>).Name; dynamic commandRepository = _repositoriesList.SingleOrDefault(x => x != null && x.GetType().GetGenericTypeDefinition().GetInterface(commandRepositoryTypeName) != null && x.GetType().GenericTypeArguments[0] == typeof(TEntity)); ContractUtility.Requires <ArgumentNullException>(commandRepository != null, string.Format("No Command Repository has been set up for {0}.", typeof(TEntity).Name)); commandRepository.SetCommand(command); return(new FluentCommands(_unitOfWorkData, _repositoriesList, _operationsQueue)); }
public IFluentQueries SetUpQueryPersistance <TEntity>(IQuery <TEntity> query) where TEntity : class, IQueryableAggregateRoot { ContractUtility.Requires <ArgumentNullException>(query.IsNotNull(), "query instance cannot be null"); var queryableRepositoryTypeName = typeof(IQueryableRepository <>).Name; var queryRepository = _repositoriesList.SingleOrDefault(x => x != null && x.GetType().GetGenericTypeDefinition().GetInterface(queryableRepositoryTypeName) != null && x.GetType().GenericTypeArguments[0] == typeof(TEntity)); ContractUtility.Requires <ArgumentNullException>(queryRepository != null, string.Format("No Query Repository has been not set up for {0}.", typeof(TEntity).Name)); queryRepository.SetCommand(query); return(new FluentQueries(_unitOfWorkData, _repositoriesList, _operationsQueue)); }
public void Update(TEntity item) { ContractUtility.Requires <ArgumentNullException>(item.IsNotNull(), "item instance cannot be null"); EntityEntry entry = _dbContext.Entry(item); if (entry.State == EntityState.Detached) { _dbSet.Attach(item); } entry.State = EntityState.Modified; SaveChanges(); }