public void Initialize() { var inMemoryUserRepository = new InMemoryUserRepository(); var inMemoryGroupRepository = new InMemoryGroupRepository(); var inMemoryKeyRepository = new InMemoryKeysRepository(); var inMemorySanctionRepository = new InMemorySanctionRepository(); var inMemoryEventRepository = new InMemoryEventRepository(); var groupSettings = new GroupSettings(2, 10, 0, 1000); var emailSender = new Mock <IEmailSender>(); var publisher = new Mock <IEventPublisher>(); userSettings = new UserSettings(""); var adminKey = new Key("email", KeyAppointment.BecomeAdmin); inMemoryKeyRepository.AddKey(adminKey); _sanctionFacade = new SanctionFacade(inMemorySanctionRepository, inMemoryUserRepository, publisher.Object); _groupFacade = new GroupFacade(inMemoryGroupRepository, inMemoryUserRepository, inMemorySanctionRepository, new GroupSettings(3, 100, 0, 1000), publisher.Object); _userFacade = new UserFacade(inMemoryUserRepository, inMemoryGroupRepository, inMemoryEventRepository, publisher.Object); _accountFacade = new AccountFacade(inMemoryKeyRepository, inMemoryUserRepository, emailSender.Object, userSettings); var creatorId = _accountFacade.RegUser("Alena", new Credentials("email", "password"), true, adminKey.Value); _groupCreator = _userFacade.GetUser(creatorId); }
public void Initialize() { var inMemoryUserRepository = new InMemoryUserRepository(); var inMemoryGroupRepository = new InMemoryGroupRepository(); var inMemoryKeyRepository = new InMemoryKeysRepository(); var inMemorySanctionRepository = new InMemorySanctionRepository(); var groupSettings = new GroupSettings(2, 10, 0, 1000); var emailSender = new Mock <IEmailSender>(); var publisher = new Mock <IEventPublisher>(); userSettings = new UserSettings(""); _groupFacade = new GroupFacade(inMemoryGroupRepository, inMemoryUserRepository, inMemorySanctionRepository, new GroupSettings(3, 100, 0, 1000), publisher.Object); _accountFacade = new AccountFacade(inMemoryKeyRepository, inMemoryUserRepository, emailSender.Object, userSettings); _groupEditFacade = new GroupEditFacade(inMemoryGroupRepository, groupSettings, publisher.Object); _groupCreatorId = _accountFacade.RegUser("Alena", new Credentials("email", "password"), true); }
public void Initialize() { var keyRepository = new InMemoryKeysRepository(); _userRepository = new InMemoryUserRepository(); var sanctionRepository = new InMemorySanctionRepository(); _groupRepository = new InMemoryGroupRepository(); var publisher = new Mock <IEventPublisher>(); var groupSettings = new GroupSettings(3, 100, 100, 1000); var sender = new Mock <IEmailSender>(); var groupFacade = new GroupFacade(_groupRepository, _userRepository, sanctionRepository, groupSettings, publisher.Object); userSettings = new UserSettings(""); var accountFacade = new AccountFacade(keyRepository, _userRepository, sender.Object, userSettings); _creatorId = accountFacade.RegUser("Alena", Credentials.FromRawData("email", "password"), true); _testGroupId = groupFacade.CreateGroup(_creatorId, "Some group", new List <string> { "c#" }, "Interesting", 3, 100, false, GroupType.Lecture); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { StartLoggly(); services.AddWebSocketManager(); IFileRepository fileRepository; IGroupRepository groupRepository; IKeysRepository keysRepository; ITagRepository tagRepository; IUserRepository userRepository; ISanctionRepository sanctionRepository; IEventRepository eventRepository; if (bool.Parse(Configuration.GetValue <string>("UseDB"))) { var dbContext = Configuration.GetValue <string>("MysqlConnectionString"); using (var context = new EduhubContext(dbContext)) { if (bool.Parse(Configuration.GetValue <string>("DeleteDB"))) { context.Database.EnsureDeleted(); } if (context.Database.EnsureCreated()) { var dbName = dbContext.Split("database=")[1].Split(";")[0]; context.Database.ExecuteSqlCommand( "ALTER DATABASE " + dbName + " CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;"); var modelNames = context.Model.GetEntityTypes(); foreach (var modelname in modelNames) { var mapping = context.Model.FindEntityType(modelname.Name).Relational(); var tableName = mapping.TableName; context.Database.ExecuteSqlCommand( "alter table " + tableName.ToLower() + " convert to character set utf8mb4 collate utf8mb4_bin;"); } } context.Database.Migrate(); } fileRepository = new InMysqlFileRepository(dbContext); groupRepository = new InMysqlGroupRepository(dbContext); keysRepository = new InMysqlKeyRepository(dbContext); tagRepository = new InMysqlTagRepository(dbContext); userRepository = new InMysqlUserRepository(dbContext); sanctionRepository = new InMysqlSanctionRepository(dbContext); eventRepository = new InMemoryEventRepository(); } else { fileRepository = new InMemoryFileRepository(); groupRepository = new InMemoryGroupRepository(); keysRepository = new InMemoryKeysRepository(); tagRepository = new InMemoryTagRepository(); sanctionRepository = new InMemorySanctionRepository(); userRepository = new InMemoryUserRepository(); eventRepository = new InMemoryEventRepository(); } var emailSettings = new EmailSettings(Configuration.GetValue <string>("EmailLogin"), Configuration.GetValue <string>("Email"), Configuration.GetValue <string>("EmailPassword"), Configuration.GetValue <string>("SmtpAddress"), Configuration.GetValue <string>("ConfirmAddress"), int.Parse(Configuration.GetValue <string>("SmtpPort"))); var defaultAvatarFilename = Configuration.GetValue <string>("DefaultAvatarFilename"); var defaultAvatarContentType = Configuration.GetValue <string>("DefaultAvatarContentType"); var userSettings = new UserSettings(defaultAvatarFilename); if (!fileRepository.DoesFileExists(defaultAvatarFilename)) { fileRepository.AddFile(new UserFile(defaultAvatarFilename, defaultAvatarContentType)); } var tagFacade = new TagFacade(tagRepository); var emailSender = new EmailSender(emailSettings); var notificationsDistributor = new NotificationsDistributor(groupRepository, userRepository, emailSender); var groupSettings = new GroupSettings(Configuration.GetValue <int>("MinGroupSize"), Configuration.GetValue <int>("MaxGroupSize"), Configuration.GetValue <double>("MinGroupValue"), Configuration.GetValue <double>("MaxGroupValue")); var eventBusSettings = new EventBusSettings(Configuration.GetValue <string>("RabbitMqServerHostName"), Configuration.GetValue <string>("RabbitMqServerVirtualHost"), Configuration.GetValue <string>("RabbitMqAdminUserName"), Configuration.GetValue <string>("RabbitMqAdminPassword")); var eventBus = new EventBus(eventBusSettings); eventBus.StartListening(); var adminsEventConsumer = new AdminsEventConsumer(notificationsDistributor, eventRepository); var courseEventConsumer = new CourseEventConsumer(notificationsDistributor, eventRepository); var curriculumEventConsumer = new CurriculumEventConsumer(notificationsDistributor, eventRepository); var groupEventsConsumer = new GroupEventsConsumer(notificationsDistributor, eventRepository); var invitationConsumer = new InvitationConsumer(notificationsDistributor, eventRepository); var memberActionsConsumer = new MemberActionsConsumer(notificationsDistributor, eventRepository); eventBus.RegisterConsumer(new TagPopularityConsumer(tagFacade)); eventBus.RegisterConsumer <ReportMessageEvent>(adminsEventConsumer); eventBus.RegisterConsumer <SanctionsAppliedEvent>(adminsEventConsumer); eventBus.RegisterConsumer <SanctionCancelledEvent>(adminsEventConsumer); eventBus.RegisterConsumer <TeacherFoundEvent>(courseEventConsumer); eventBus.RegisterConsumer <CourseFinishedEvent>(courseEventConsumer); eventBus.RegisterConsumer <ReviewReceivedEvent>(courseEventConsumer); eventBus.RegisterConsumer <CurriculumAcceptedEvent>(curriculumEventConsumer); eventBus.RegisterConsumer <CurriculumDeclinedEvent>(curriculumEventConsumer); eventBus.RegisterConsumer <CurriculumSuggestedEvent>(curriculumEventConsumer); eventBus.RegisterConsumer <NewCreatorEvent>(groupEventsConsumer); eventBus.RegisterConsumer <GroupIsFormedEvent>(groupEventsConsumer); eventBus.RegisterConsumer <InvitationAcceptedEvent>(invitationConsumer); eventBus.RegisterConsumer <InvitationDeclinedEvent>(invitationConsumer); eventBus.RegisterConsumer <InvitationReceivedEvent>(invitationConsumer); eventBus.RegisterConsumer <NewMemberEvent>(memberActionsConsumer); eventBus.RegisterConsumer <MemberLeftEvent>(memberActionsConsumer); var publisher = eventBus.GetEventPublisher(); var userFacade = new UserFacade(userRepository, groupRepository, eventRepository, publisher); var groupEditFacade = new GroupEditFacade(groupRepository, groupSettings, publisher); var userEditFacade = new UserEditFacade(userRepository, fileRepository, sanctionRepository); var groupFacade = new GroupFacade(groupRepository, userRepository, sanctionRepository, groupSettings, publisher); var fileFacade = new FileFacade(fileRepository); var chatFacade = new ChatFacade(groupRepository, userRepository); var sanctionsFacade = new SanctionFacade(sanctionRepository, userRepository, publisher); var userAccountFacade = new AccountFacade(keysRepository, userRepository, emailSender, userSettings); var reportFacade = new ReportFacade(userRepository, eventRepository, publisher); services.AddSingleton <IUserFacade>(userFacade); services.AddSingleton <IGroupFacade>(groupFacade); services.AddSingleton <IFileFacade>(fileFacade); services.AddSingleton <IChatFacade>(chatFacade); services.AddSingleton <IGroupEditFacade>(groupEditFacade); services.AddSingleton <IUserEditFacade>(userEditFacade); services.AddSingleton <ITagFacade>(tagFacade); services.AddSingleton <ISanctionFacade>(sanctionsFacade); services.AddSingleton <IAccountFacade>(userAccountFacade); services.AddSingleton <IReportFacade>(reportFacade); services.AddSingleton(Env); userAccountFacade.CheckAdminExistence(Configuration.GetValue <string>("AdminEmail")); services.AddSwaggerGen(current => { current.SwaggerDoc("v1", new Info { Title = "EduHub API", Version = "v1" }); current.AddSecurityDefinition("Bearer", new ApiKeyScheme { Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", In = "header", Type = "apiKey" }); current.OperationFilter <ExamplesOperationFilter>(); current.DescribeAllEnumsAsStrings(); var a = string.Format(@"{0}\EduHub.xml", AppDomain.CurrentDomain.BaseDirectory); current.IncludeXmlComments(string.Format(@"{0}/EduHub.xml", AppDomain.CurrentDomain.BaseDirectory)); }); ConfigureSecurity(services); if (Configuration.GetValue <bool>("Authorization")) { services.AddMvc(o => { o.Filters.Add(new ExceptionFilter()); o.Filters.Add(new ActionFilter()); }); } else { services.AddMvc(o => { o.Filters.Add(new AllowAnonymousFilter()); o.Filters.Add(new ExceptionFilter()); o.Filters.Add(new ActionFilter()); }); } services.AddCors(options => { options.AddPolicy("AllowAnyOrigin", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); }); }