public void PerformCharge(Charge charge) { var card = charge.Card; var messages = LocalizationFactory.CreateLocalResources(); if (card != null) { if (charge.Status != ChargeStatus.Pending) { throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_InvalidStateForCharge)); } if (card.CanWithdraw(charge.Amount)) { card.WithdrawMoney(charge.Amount, MovementType.CON, messages.GetStringResource(LocalizationKeys.Domain.messages_ChargeMessageDescription), messages.GetStringResource(LocalizationKeys.Domain.messages_ChargeMessageDisplayName), charge.Movements.FirstOrDefault() ); charge.Status = ChargeStatus.Accepted; charge.GenerateOperationCode(); charge.ImageUrl = GenerateChargeUrl(); } else { charge.Status = ChargeStatus.Canceled; } } else { throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_PerformChargeCardIsNull)); } }
private static void SingleInstanceMain() { App app = new App(); ApiRequestEngine.Information += app.OnCoreInformation; ApiRequestEngine.Warning += app.OnCoreWarning; ApiRequestEngine.Error += app.OnCoreError; app.DispatcherUnhandledException += app.OnDispatcherUnhandledException; LogManager.LoggingShutdown += app.LogManager_LoggingShutdown; var assemblyName = typeof(App).Assembly .GetName().Name; LocalizationFactory = LocalizationFactory .Create(assemblyName, "MEMENIM"); LocalizationManager.SetCurrentFactory( assemblyName, LocalizationFactory); LocalizationUtils.LocalizationChanged += app.LocalizationUtils_LocalizationChanged; LocalizationUtils.LocalizationsNotFound += app.LocalizationUtils_LocalizationsNotFound; LocalizationUtils.LocalizationFileNotFound += app.LocalizationUtils_LocalizationFileNotFound; LocalizationUtils.LocalizedCultureNotFound += app.LocalizationUtils_LocalizedCultureNotFound; app.InitializeComponent(); app.Run(Memenim.MainWindow.Instance); }
public ChargeAppService(IChargeRepository chargeRepository, ICardChargeService cardChargeService) { _chargeRepository = chargeRepository; _cardChargeService = cardChargeService; _resources = LocalizationFactory.CreateLocalResources(); }
public ClientAppService(IClientRepository clientRepository, ILogger <ClientAppService> logger) { _clientRepository = clientRepository; _logger = logger; _resources = LocalizationFactory.CreateLocalResources(); }
/// <summary> /// Create a new instance /// </summary> public BankAppService(IBankAccountRepository bankAccountRepository, // the bank account repository dependency ICustomerRepository customerRepository, // the customer repository dependency IBankTransferService transferService, ILogger <BankAppService> logger) { //check preconditions if (bankAccountRepository == null) { throw new ArgumentNullException("bankAccountRepository"); } if (customerRepository == null) { throw new ArgumentNullException("customerRepository"); } if (transferService == null) { throw new ArgumentNullException("trasferService"); } _bankAccountRepository = bankAccountRepository; _customerRepository = customerRepository; _transferService = transferService; _logger = logger; _resources = LocalizationFactory.CreateLocalResources(); }
/// <summary> /// Create a new instance of sales management service /// </summary> /// <param name="orderRepository">The associated order repository</param> /// <param name="productRepository">The associated product repository</param> /// <param name="customerRepository">The associated customer repository</param> public SalesAppService(IProductRepository productRepository, //associated product repository IOrderRepository orderRepository, //associated order repository ICustomerRepository customerRepository, //the associated customer repository ILogger <SalesAppService> logger) { if (orderRepository == null) { throw new ArgumentNullException("orderRepository"); } if (productRepository == null) { throw new ArgumentNullException("productRepository"); } if (customerRepository == null) { throw new ArgumentNullException("customerRepository"); } _orderRepository = orderRepository; _productRepository = productRepository; _customerRepository = customerRepository; _logger = logger; _resources = LocalizationFactory.CreateLocalResources(); }
public CardAppService(IContactRepository contactRepository, ICardRepository cardRepository) { _contactRepository = contactRepository; _cardRepository = cardRepository; _resources = LocalizationFactory.CreateLocalResources(); }
public ContactAppService(IContactRepository contactRepository, ILogger <ContactAppService> logger) { _contactRepository = contactRepository; _logger = logger; _resources = LocalizationFactory.CreateLocalResources(); }
public void ProvideTranslationFromHighlyPrioritizedSource() { var inMemorySource = new InMemorySource(); inMemorySource.SaveString("greeting", enCulture, "Hello from memory!"); CreateFileWithTranslations(localizationsFilePath, new [] { new LocalFileSource.StringTranslationRecord { TextCode = "greeting", CultureId = enCulture.LCID, Translation = "Hello from file!" } }); var localFileSource = new LocalFileSource(localizationsFilePath); var sourcesList = new LocalizationSourcesList(); var localizationFactory = new LocalizationFactory(sourcesList); localizationFactory.RegisterSource(inMemorySource, 0); localizationFactory.RegisterSource(localFileSource, 1); var code = new LocalizationCode("greeting"); var translatedString = localizationFactory.GetString(code); Assert.AreEqual("Hello from file!", translatedString); }
public AuthenticationController(IAuthenticationAppService authenticationAppService, IConfiguration configuration) { _authenticationAppService = authenticationAppService; _smsManager = new SMSManager(configuration); _tokenManager = new TokenManager(configuration); _resources = LocalizationFactory.CreateLocalResources(); }
public void PerformTransfer(decimal amount, BankAccount originAccount, BankAccount destinationAccount) { if (originAccount != null && destinationAccount != null) { var messages = LocalizationFactory.CreateLocalResources(); if (originAccount.BankAccountNumber == destinationAccount.BankAccountNumber) // if transfer in same bank account { throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_CannotTransferMoneyWhenFromIsTheSameAsTo)); } // Check if customer has required credit and if the BankAccount is not locked if (originAccount.CanBeWithdrawed(amount)) { //Domain Logic //Process: Perform transfer operations to in-memory Domain-Model objects // 1.- Charge money to origin acc // 2.- Credit money to destination acc //Charge money originAccount.WithdrawMoney(amount, string.Format(messages.GetStringResource(LocalizationKeys.Domain.messages_TransactionFromMessage), destinationAccount.Id)); //Credit money destinationAccount.DepositMoney(amount, string.Format(messages.GetStringResource(LocalizationKeys.Domain.messages_TransactionToMessage), originAccount.Id)); } else { throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_BankAccountCannotWithdraw)); } } }
/// <summary> /// The get <paramref name="key"/> from enum. /// </summary> /// <param name="key"> /// The key. /// </param> /// <typeparam name="T">d d /// </typeparam> /// <returns> /// The <see cref="string"/>. /// </returns> /// <exception cref="ArgumentException">Argument Exception /// </exception> private string GetKeyFromEnum <T>(T key) where T : struct, IConvertible { if (!typeof(T).GetTypeInfo().IsEnum) { throw new ArgumentException(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.ExceptionInvalidEnumeratedType)); } return($"{typeof(T).Name}_{key.ToString()}"); }
public void TestSetUp() { this.factory = LocalizationFactory.GetInstance(); this.factory.Register <DataSourceMock>(); this.factory.Register(new DataBaseMock()); this.ruCulture = new CultureInfo("ru-RU"); this.enCulture = new CultureInfo("en-US"); this.deCulture = new CultureInfo("de-DE"); }
public BlogsService(IBlogRepository blogRepository, IPostRepository postRepository) : base(blogRepository) { _blogRepository = blogRepository; _postRepository = postRepository; _resources = LocalizationFactory.CreateLocalResources(); _validator = EntityValidatorFactory.CreateValidator(); }
public TransferAppService(IContactRepository contactRepository, ICardRepository cardRepository, ITransferRepository transferRepository, ICardTransferService transferService) { _contactRepository = contactRepository; _cardRepository = cardRepository; _transferRepository = transferRepository; _transferService = transferService; _resources = LocalizationFactory.CreateLocalResources(); }
public LoadAppService(IClientRepository clientRepository, IContactRepository contactRepository, ICardTypeRepository cardTypeRepository, ICardRechargeService rechargeService) { _clientRepository = clientRepository; _contactRepository = contactRepository; _cardTypeRepository = cardTypeRepository; _rechargeService = rechargeService; _resources = LocalizationFactory.CreateLocalResources(); }
public virtual void Modify(TEntity item) { if (item != (TEntity)null) { _UnitOfWork.SetModified(item); } else { _logger.LogInformation(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.info_CannotModifyNullEntity), typeof(TEntity).ToString()); } }
public virtual void Add(TEntity item) { if (item != (TEntity)null) { GetSet().Add(item); // add new item in this set } else { _logger.LogInformation(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.info_CannotAddNullEntity), typeof(TEntity).ToString()); } }
public virtual void TrackItem(TEntity item) { if (item != (TEntity)null) { _UnitOfWork.Attach <TEntity>(item); } else { _logger.LogInformation(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.info_CannotTrackNullEntity), typeof(TEntity).ToString()); } }
private void InitializeFactories() { EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); var dto = new BlogDTO(); // this is only to force current domain to load de .DTO assembly and all profiles var adapterfactory = new AutomapperTypeAdapterFactory(); TypeAdapterFactory.SetCurrent(adapterfactory); //Localization LocalizationFactory.SetCurrent(new ResourcesManagerFactory()); }
public PostDTOValidator() { var _resources = LocalizationFactory.CreateLocalResources(); RuleFor(b => b.Title) .NotEmpty().WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_PostDto_Empty_Title)); RuleFor(b => b.Content) .NotEmpty().WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_PostDto_Empty_Content)); RuleFor(b => b.BlogId) .LessThan(0).WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_PostDto_Invalid_BlogId)); }
public BlogDTOValidator() { var _resources = LocalizationFactory.CreateLocalResources(); RuleFor(b => b.Name) .NotEmpty().WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_BlogDto_Empty_Name)); RuleFor(b => b.Url) .NotEmpty().WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_BlogDto_Empty_Url)); RuleFor(b => b.Rating) .GreaterThan(-1).LessThan(6).WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_BlogDto_Invalid_Rating)); }
public void PerformTransfer(Transfer transfer) { var messages = LocalizationFactory.CreateLocalResources(); var originCard = transfer.OriginCard; var destinyCard = transfer.DestinyCard; if (originCard is null) { throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_PerformTransferOriginCardIsNull)); } if (destinyCard is null) { throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_PerformTransferDestinyCardIsNull)); } if (originCard.Id == destinyCard.Id) { throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_InvalidTransferToSameCard)); } if (originCard.Contact.ClientId != destinyCard.Contact.ClientId) { throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_InvalidTransferDifferentContactClient)); } if (originCard.CanWithdraw(transfer.Amount)) { var movementBatchs = originCard.WithdrawMoney( transfer.Amount, MovementType.STR, messages.GetStringResource(LocalizationKeys.Domain.messages_TransferFromMessageDescription), messages.GetStringResource(LocalizationKeys.Domain.messages_TransferFromMessageDisplayName), movement: null, transfer ); destinyCard.DepositMoneyFromTransfer( transfer.Amount, movementBatchs, messages.GetStringResource(LocalizationKeys.Domain.messages_TransferToMessageDescription), messages.GetStringResource(LocalizationKeys.Domain.messages_TransferToMessageDisplayName), transfer ); } else { throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_NoEnoughMoneyToTransfer)); } transfer.ImageUrl = GenerateTransferUrl(); }
public AuthenticationAppService(IContactRepository contactRepository, ISMSCodeRepository smsCodeRepository, ICashierRepository cashierRepository, IAdminRepository adminRepository, IConfiguration configuration, ILogger <AuthenticationAppService> logger) { _contactRepository = contactRepository; _smsCodeRepository = smsCodeRepository; _cashierRepository = cashierRepository; _adminRepository = adminRepository; _logger = logger; _resources = LocalizationFactory.CreateLocalResources(); }
public void ConfigureServices(IServiceCollection services) { // Configure EntityFramework to use an InMemory database. //services.AddDbContext<MyBlogContext>(options => // options.UseMySql(Configuration.GetConnectionString("MyBlogContext"))); services.AddDbContext <UnitOfWork>(options => { options.EnableSensitiveDataLogging(); options.UseMySql(Configuration.GetConnectionString("MyBlogContext")); }); services.AddControllersWithViews().AddRazorRuntimeCompilation(); //services.AddControllersWithViews(options => //{ // options.Filters.Add(new ValidateModelAttribute()); // an instance // options.Filters.Add(typeof(LoggerAttribute)); //}).AddRazorRuntimeCompilation(); ////Custom Exception and validation Filter //services.AddScoped<CustomExceptionFilterAttribute>(); //Repositories services.AddScoped <IBlogInfoRepository, BlogInfoRepository>(); services.AddScoped <IBlogUserRepository, BlogUserRepository>(); services.AddScoped <IBlogClassRepository, BlogClassRepository>(); //DomainServices services.AddScoped <IBlogDomainService, BlogDomainService>(); services.AddScoped <IUserDomainService, UserDomainService>(); services.AddScoped <IClassDomainService, ClassDomainService>(); //AppServices services.AddScoped <IBlogInfoAppService, BlogInfoAppService>(); services.AddScoped <IBlogUserAppService, BlogUserAppService>(); services.AddScoped <IBlogClassAppService, BlogClassAppService>(); services.AddAutoMapper(typeof(CommonProfile)); //Validator EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); //Localization LocalizationFactory.SetCurrent(new ResourcesManagerFactory()); }
public virtual void Add(IEnumerable <TEntity> items) { if (items != null) { foreach (var item in items) { this.Add(item); } } else { _logger.LogInformation(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.info_CannotAddNullEntity), typeof(TEntity).ToString()); } }
public virtual void Remove(TEntity item) { if (item != (TEntity)null) { //attach item if not exist _UnitOfWork.Attach(item); //set as "removed" GetSet().Remove(item); } else { _logger.LogInformation(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.info_CannotRemoveNullEntity), typeof(TEntity).ToString()); } }
public void ProvideTranslationFromSpecificSource() { var inMemorySource = new InMemorySource(); inMemorySource.SaveString("greeting", enCulture, "Hello world!"); var sourcesList = new LocalizationSourcesList(); var localizationFactory = new LocalizationFactory(sourcesList); localizationFactory.RegisterSource(inMemorySource, 0); var code = new LocalizationCode("greeting", LocalizationSourceType.InMemory); var translatedString = localizationFactory.GetString(code, enCulture); Assert.AreEqual("Hello world!", translatedString); }
public void ProvideCorrectTranslation_WhenSeveralTranslationsExist() { var inMemorySource = new InMemorySource(); inMemorySource.SaveString("greeting", enCulture, "Hello world!"); inMemorySource.SaveString("greeting", ruCulture, "Привет мир!"); var sourcesList = new LocalizationSourcesList(); var localizationFactory = new LocalizationFactory(sourcesList); localizationFactory.RegisterSource(inMemorySource, 0); var code = new LocalizationCode("greeting", LocalizationSourceType.InMemory); var translatedString = localizationFactory.GetString(code, ruCulture); Assert.AreEqual("Привет мир!", translatedString); }
/// <summary> /// Order by order number /// </summary> /// <param name="orderNumber">Find orders using the order number</param> /// <returns>Related specification for this criterion</returns> public static ISpecification <Order> OrdersByNumber(string orderNumber) { var messages = LocalizationFactory.CreateLocalResources(); string orderNumberPattern = @"\d{4}/\d{1,2}-\d+"; if (Regex.IsMatch(orderNumber, orderNumberPattern)) { int sequenceNumber = Int32.Parse(Regex.Split(orderNumber, "-")[1]); return(new DirectSpecification <Order>(o => o.SequenceNumberOrder == sequenceNumber)); } else { throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_OrderNumberSpecificationInvalidOrderNumberPattern)); } }