public Service() { InitializeComponent(); ObjectFactory.Initialize(x => { x.For <IScheduleMessageHandler>() .AddInstances(i => { i.Type <HandlerAddSchedule>(); i.Type <HandlerChangeLogging>(); i.Type <HandlerChangeSchedule>(); i.Type <HandlerPublishConfiguration>(); i.Type <HandlerPublishSchedule>(); i.Type <HandlerRemoveSchedule>(); i.Type <HandlerResumeSchedule>(); i.Type <HandlerStopTask>(); }); x.Scan(s => { s.AssembliesFromApplicationBaseDirectory(); s.AddAllTypesOf <IMiramarTaskFactory>(); }); }); logger = InfrastructureFactory.CreateLogger("Service"); serviceSource = new CancellationTokenSource(); }
public TrainEventsReader( InfrastructureFactory infrastructureFactory, IOptions <TrainEventsReaderOptions> readerOptions) { _eventDirectory = readerOptions.Value.EventDirectory; _eventHubReaderWriter = infrastructureFactory.GetClientEventsEventHub(); }
public void SetUp() { _stubTicker = new TimerStub(); InfrastructureFactory.ProvideTimer(_stubTicker); _assistant = new Assistant(); }
public void ShouldFailIfUserDoesNotExists() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldFailIfUserDoesNotExists)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); var handler = new GetUserCommandHandler(unitOfWork); Assert.ThrowsAsync <UserNotFoundException>(() => handler.Handle(new GetUserCommand("johndoe"), default)); }
private static void RunModules() { IModuleRunner moduleRunner = InfrastructureFactory.CreateModuleRunner(); moduleRunner.RegisterModule(new RollbackEngineSamples()); moduleRunner.Run(); }
public ScheduleService(IMessageQueueFactory queueFactory, IMiramarTaskProvider taskProvider, IMiramarScheduleProvider scheduleProvider, IMiramarContextProvider contextProvider) { this.contextProvider = contextProvider; this.queueFactory = queueFactory; this.taskProvider = taskProvider; this.scheduleProvider = scheduleProvider; logger = InfrastructureFactory.CreateLogger("ScheduleQueue"); }
public async Task ShouldFailIfAttemptingToCreateExistingUser() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldFailIfAttemptingToCreateExistingUser)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); await unitOfWork.AddAndSaveAsync(EntityFactory.GetUser("johndoe", "Pass@123")); var handler = new CreateUserCommandHandler(unitOfWork, InfrastructureFactory.GetMachineDateTime(), InfrastructureFactory.GetSha1Hasher()); Assert.ThrowsAsync <CreatingExistingUserException>(() => handler.Handle(new CreateUserCommand("johndoe", "Pass@123"), default)); }
public Assistant() { _timeElapsed = TimeSpan.Zero; _timer = InfrastructureFactory.CreateTimer(); _timer.Tick += _timer_Tick; this.WorkTime = DEFAULT_WORK_TIME; this.ShortBreakTime = DEFAULT_SHORT_BREAK; this.LongBreakTime = DEFAULT_LONG_BREAK; }
protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_DE_1006 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Base(); //Put your code here P_L5EM_GEFE_1150 par = new P_L5EM_GEFE_1150(); par.EmployeeID = Parameter.CMN_BPT_EMP_EmployeeID; L5EM_GEFE_1150 employee = cls_Get_Employee_For_EmployeeID.Invoke(Connection, Transaction, par, securityTicket).Result; ORM_CMN_BPT_EMP_Employee whereInstanceEmployee = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_Employee>(); whereInstanceEmployee.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID; CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, whereInstanceEmployee); var enterpriseService = InfrastructureFactory.CreateEnterpriseService(); KeyPerformanceIndicator action = new KeyPerformanceIndicator(); action.PerformedByAccountID = securityTicket.AccountID; action.PerformedByApplicationID = Parameter.ApplicationID; action.PerformedOn = DateTime.Now; action.PerformedByTenantID = securityTicket.TenantID; action.KeyPerformanceIndicatorID = Guid.Parse("4dda967a-5399-4929-afae-7af64699895b"); action.Value = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result.Length; var result = enterpriseService.SendMessage(action.ToPayload(), KeyPerformanceIndicator.MESSAGE_TYPE, Parameter.ApplicationID, EMessageRecipient.CUSTOMER_MANAGEMENT_PLATFORM); ORM_CMN_BPT_EMP_EmploymentRelationship whereInstanceContract = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_EmploymentRelationship>(); whereInstanceContract.CMN_BPT_EMP_EmploymentRelationshipID = employee.CMN_BPT_EMP_EmploymentRelationshipID; CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, whereInstanceContract); ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query searchInstanceWorkingContract = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query(); searchInstanceWorkingContract.WorkingContract_RefID = employee.CMN_BPT_EMP_EmploymentRelationshipID; List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> employmentRelationshipToWorkingContract = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, searchInstanceWorkingContract); if (employmentRelationshipToWorkingContract != null) { foreach (var relationShipToContract in employmentRelationshipToWorkingContract) { ORM_CMN_BPT_EMP_WorkingContract workingContractQuery = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_WorkingContract>(); workingContractQuery.CMN_BPT_EMP_WorkingContractID = relationShipToContract.WorkingContract_RefID; CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, workingContractQuery); ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason allowedreasons = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason>(); allowedreasons.WorkingContract_RefID = relationShipToContract.WorkingContract_RefID; CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, allowedreasons); } } return(returnValue); #endregion UserCode }
public async Task ShouldGetEntityFromDbContext() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldGetEntityFromDbContext)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); var user = EntityFactory.GetUser("johndoe", "Pass@123"); await unitOfWork.AddAndSaveAsync(user); user = await unitOfWork.GetSingleAsync <UserEntity>(u => u.Nickname == "johndoe"); Assert.NotNull(user); }
public async Task ShouldFailAuthenticationIfWrongPassword() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldFailAuthenticationIfWrongPassword)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); var user = EntityFactory.GetUser("johndoe", "Pass@123"); await unitOfWork.AddAndSaveAsync(user); var handler = new AuthenticateUserCommandHandler(unitOfWork, InfrastructureFactory.GetSha1Hasher(), InfrastructureFactory.GetMachineDateTime()); Assert.ThrowsAsync <UserAuthenticationFailedException>(() => handler.Handle(new AuthenticateUserCommand("johndoe", "Pass@13", UserAuthConstants.TokenExpirationTime), default)); }
public MiramarController() { var connectionString = ConfigurationManager.ConnectionStrings["BillingAdmin"].ConnectionString; adminDataAccess = new AdminDataAccess(connectionString); logger = InfrastructureFactory.CreateLogger("Controller"); publisher = new MiramarPublisher(); allowMetaData = false; }
public async Task ShouldAddEntityToDbContext() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldAddEntityToDbContext)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); var user = EntityFactory.GetUser("johndoe", "Pass@123"); await unitOfWork.AddAndSaveAsync(user); user = await dbContext.Users.FindAsync("johndoe"); Assert.NotNull(user); Assert.AreEqual("johndoe", user.Nickname); }
public async Task ShouldCreateNewUser() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldCreateNewUser)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); var handler = new CreateUserCommandHandler(unitOfWork, InfrastructureFactory.GetMachineDateTime(), InfrastructureFactory.GetSha1Hasher()); await handler.Handle(new CreateUserCommand("johndoe", "Pass@123"), default); var user = unitOfWork.GetSingleAsync <UserEntity>(u => u.Nickname == "johndoe"); Assert.NotNull(user); }
public async Task ShouldReturnUser() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldReturnUser)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); await unitOfWork.AddAndSaveAsync(EntityFactory.GetUser("johndoe", "Pass@123")); var handler = new GetUserCommandHandler(unitOfWork); var user = await handler.Handle(new GetUserCommand("johndoe"), default); Assert.NotNull(user); }
public MiramarScheduleProvider(TaskScheduleModel[] collection) { this.collection = new List <TaskScheduleModel>(collection); logger = InfrastructureFactory.CreateLogger("Scheduler"); publisher = new MiramarPublisher(); schedules = new Dictionary <string, DateTime>(); executionPlans = new Dictionary <string, List <string> >(); PushTasksForInitialConsideration(collection); }
public void Execute(EncryptFileContext context, CancellationToken token) { var cspDunsPorts = clientDataAccess.ListCspDunsPort(); foreach (var port in cspDunsPorts) { if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } if (!port.EncryptionEnabledFlag) { continue; } logger.TraceFormat( "Identified CSP DUNS Port {0} for LDC \"{1}\" \nDirectory In: \"{2}\" \nDirectory Out: \"{3}\" \n", port.CspDunsPortId, port.LdcShortName, port.DirectoryIn, port.DirectoryOut); IPgpEncryption pgpEncryption; try { pgpEncryption = InfrastructureFactory .CreatePgpEncryptor(port.PgpEncryptionKey, port.PgpSignatureKey, port.PgpPassphrase); } catch (IOException ex) { logger.ErrorFormat(ex, "Unable to create PGP Encryption class for Csp Duns Port \"{0}\".", port.CspDunsPortId); continue; } var identifier = port.TradingPartnerId.Substring(0, 3); var ldcId = port.LdcId ?? 0; if (ldcId == 0) { var clientSearchPattern = string.Format("*{0}*", identifier); EncryptFiles(pgpEncryption, context, clientSearchPattern, token); } else { var fileExtension = port.ProviderId == 2 ? ".x12" : ".txt"; var extendedSearchPattern = string.Format("*{0}*{1}*{2}", identifier, port.LdcShortName, fileExtension); EncryptFiles(pgpEncryption, context, extendedSearchPattern, token); } } MoveFiles(context, "*", token); }
public async Task ShouldReturnAuthenticatedUser() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldReturnAuthenticatedUser)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); var user = EntityFactory.GetUser("johndoe", "Pass@123"); await unitOfWork.AddAndSaveAsync(user); var handler = new AuthenticateUserCommandHandler(unitOfWork, InfrastructureFactory.GetSha1Hasher(), InfrastructureFactory.GetMachineDateTime()); var authentication = await handler.Handle(new AuthenticateUserCommand("johndoe", "Pass@123", UserAuthConstants.TokenExpirationTime), default); Assert.AreEqual("johndoe", authentication.User.Nickname); Assert.IsFalse(string.IsNullOrEmpty(authentication.Token)); }
public async Task ShouldCreateTokenOnSucesfulAuth() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldChangePasswordSaltAndReHashPasswordOnSuccesfulAuth)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); var user = EntityFactory.GetUser("johndoe", "Pass@123"); await unitOfWork.AddAndSaveAsync(user); var handler = new AuthenticateUserCommandHandler(unitOfWork, InfrastructureFactory.GetSha1Hasher(), InfrastructureFactory.GetMachineDateTime()); var authentication = await handler.Handle(new AuthenticateUserCommand("johndoe", "Pass@123", UserAuthConstants.TokenExpirationTime), default); var tokenCount = await dbContext.UserTokens.CountAsync(u => u.Nickname == "johndoe"); Assert.AreEqual(1, tokenCount); }
protected IServiceProvider InitDependencyInjection(Action <IServiceCollection> servicesAction = null, Action <ContainerBuilder> containerBuilderAction = null) { IServiceProviderFactory <ContainerBuilder> factory = new InfrastructureFactory(); var services = new ServiceCollection(); servicesAction?.Invoke(services); ContainerBuilder containerBuilder = factory.CreateBuilder(services); containerBuilderAction?.Invoke(containerBuilder); return(factory.CreateServiceProvider(containerBuilder)); }
public void EncryptFiles(ErcotFileContext context, CspDunsPortModel port, MarketFileModel[] models, CancellationToken token) { var pgpEncryption = InfrastructureFactory.CreatePgpEncryptor(port.PgpEncryptionKey, port.PgpSignatureKey, port.PgpPassphrase); var options = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }; foreach (var marketFile in models) { if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } var sourcePath = Path.Combine(context.DirectoryDecrypted, marketFile.FileName); var sourceInfo = new FileInfo(sourcePath); if (!sourceInfo.Exists) { logger.WarnFormat("Unable to encrypt file \"{0}\". File does not exist or has been deleted.", marketFile.FileName); continue; } try { using (var scope = new TransactionScope(TransactionScopeOption.Required, options)) { var archivePath = Path.Combine(context.DirectoryArchive, DateTime.Now.ToString("yyyyMM"), marketFile.FileName); sourceInfo.CopyTo(archivePath, true); var targetPath = Path.Combine(context.DirectoryEncrypted, marketFile.FileName); var targetName = string.Concat(targetPath, ".pgp"); pgpEncryption.EncryptFile(sourceInfo.FullName, targetName); marketFile.Status = MarketFileStatusOptions.Encrypted; marketFile.ProcessDate = DateTime.Now; marketDataAccess.UpdateMarketFile(marketFile); scope.Complete(); } } catch (Exception ex) { logger.ErrorFormat(ex, "Unknown error occurred while encrypting file \"{0}\".", marketFile.FileName); } } }
public async Task ShouldNotifyChatMessageSent() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldNotifyChatMessageSent)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); await unitOfWork.AddAndSaveAsync(EntityFactory.GetUser("johndoe", "Pass@123")); await unitOfWork.AddAndSaveAsync(EntityFactory.GetChat("test", "johndoe")); var notifier = InfrastructureFactory.GetNotifierSubstitute(); var handler = new ChatMessageSentEventHandler(unitOfWork, InfrastructureFactory.GetMachineDateTime(), notifier); await handler.Handle(new ChatMessageSentEvent("Test Message", "johndoe", "test"), default); await notifier.Received(1).NotifyAsync("test", ChatConstants.MessageSentActionName, Arg.Any <ChatMessage>()); }
public async Task ShouldReturnTrueIfTokenHasNotExpired() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldReturnTrueIfTokenHasNotExpired)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); var dateTime = new TransientDateTime(); dateTime.Now = new DateTime(2020, 5, 3); await unitOfWork.AddAndSaveAsync(EntityFactory.GetUser("johndoe", "Pass@123")); await unitOfWork.AddAndSaveAsync(EntityFactory.GetToken("TOKEN", "johndoe", dateTime.Now.AddDays(1))); var handler = new CheckAuthorizationCommandHandler(unitOfWork, dateTime); Assert.IsTrue(await handler.Handle(new CheckAuthorizationCommand("TOKEN"), default)); }
public async Task ShouldGetAllTheChats() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldGetAllTheChats)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); await unitOfWork.AddAndSaveAsync(EntityFactory.GetUser("johndoe", "Pass@123")); await unitOfWork.AddAndSaveAsync(EntityFactory.GetChat("chat1", "johndoe")); await unitOfWork.AddAndSaveAsync(EntityFactory.GetChat("chat2", "johndoe")); var handler = new GetAllChatsCommandHandler(unitOfWork); var chats = await handler.Handle(new GetAllChatsCommand(), default); Assert.AreEqual(2, chats.Count()); }
static void CancelAndWait(CancellationTokenSource source, IMessageQueueFactory messageFactory, params Task[] tasks) { source.Cancel(); Task.WaitAll(tasks); InfrastructureFactory.ForceLogFlush(); InfrastructureFactory.CloseLogTargets(); if (messageFactory != null) { if (messageFactory.IsOpen) { messageFactory.Dispose(); } } }
public async Task ShouldOnlyReturnSpecifiedNumberOfMessages() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldOnlyReturnSpecifiedNumberOfMessages)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); await unitOfWork.AddAndSaveAsync(EntityFactory.GetUser("johndoe", "Pass@123")); await unitOfWork.AddAndSaveAsync(EntityFactory.GetChat("foo", "johndoe")); await unitOfWork.CreateChatMessages("foo", "owner", "Message", 12, new DateTime(2020, 5, 4)); var handler = new GetChatMessagesCommandHandler(unitOfWork); var messages = await handler.Handle(new GetChatMessagesCommand("foo", 10), default); Assert.AreEqual(10, messages.Count()); }
public async Task ShouldUpdateEntityOnDbContext() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldUpdateEntityOnDbContext)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); var user = EntityFactory.GetUser("johndoe", "Pass@123"); await unitOfWork.AddAndSaveAsync(user); var dateTime = DateTime.Now; user.LastLoginDate = dateTime; await unitOfWork.UpdateAndSaveAsync(user); user = await dbContext.Users.FindAsync("johndoe"); Assert.AreEqual(dateTime, user.LastLoginDate); }
public async Task ShouldSaveMessageSent() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldSaveMessageSent)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); await unitOfWork.AddAndSaveAsync(EntityFactory.GetUser("johndoe", "Pass@123")); await unitOfWork.AddAndSaveAsync(EntityFactory.GetChat("test", "johndoe")); var handler = new ChatMessageSentEventHandler(unitOfWork, InfrastructureFactory.GetMachineDateTime(), InfrastructureFactory.GetNotifierSubstitute()); await handler.Handle(new ChatMessageSentEvent("Test Message", "johndoe", "test"), default); var message = await unitOfWork.GetSingleAsync <ChatMessageEntity>(m => m.Stock == "test"); Assert.AreEqual("johndoe", message.FromNickName); Assert.AreEqual("Test Message", message.Message); }
public async Task ShouldSortMessagesBySentTime() { var dbContext = InfrastructureFactory.GetInMemoryContext(nameof(ShouldSortMessagesBySentTime)); var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext); await unitOfWork.AddAndSaveAsync(EntityFactory.GetUser("johndoe", "Pass@123")); await unitOfWork.AddAndSaveAsync(EntityFactory.GetChat("foo", "johndoe")); await unitOfWork.CreateChatMessages("foo", "owner", "Message", 2, new DateTime(2020, 5, 4)); var handler = new GetChatMessagesCommandHandler(unitOfWork); var messages = await handler.Handle(new GetChatMessagesCommand("foo"), default); Assert.AreEqual(2, messages.Count()); Assert.AreEqual(6, messages.First().SentTime.Day); Assert.AreEqual(5, messages.Last().SentTime.Day); }
/// <summary> /// Method for logging out /// Removes the cookie from the session /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { FormsAuthentication.SignOut(); Session.Clear(); Session.Abandon(); var bopSession = InfrastructureFactory.CreateSessionManager(); var singInURL = bopSession.CreateSignInURL(FilterPreviousUrl(), CASSession_Timeout()); String urlSession = String.Empty; #if DEBUG urlSession = "&urlSession=true"; #endif string logoutUrL = bopSession.CreateSignoutURL(singInURL + urlSession); Response.Redirect(logoutUrL, false); }