public void SaveConversation() { try { var options = CreateNewContextOptions(); using (var db = new ConversationContext(options)) { ConversationTestHelper.PopulateDefaultDataCtx(db); } using (var db = new ConversationContext(options)) { var repository = new ConversationRepository(db);; var item = GenerateModel(); Assert.DoesNotThrow(() => repository.Save(item)); Assert.DoesNotThrow(() => repository.Delete(item)); Assert.Greater(item.Id, 0); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void StartConversation() { try { var options = CreateNewContextOptions(); using (var db = new ConversationContext(options)) { ConversationTestHelper.PopulateDefaultDataCtx(db); } using (var db = new ConversationContext(options)) { var repository = new ConversationRepository(db); var item = GenerateModel(); var mess = GenerateMessage(); var members = new List <User> { new User { Id = 1 }, new User { Id = 2 } }; Assert.DoesNotThrow(() => repository.StartConversation(item, members, mess, members.First().Id)); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void GetMembers2() { try { var options = CreateNewContextOptions(); using (var db = new ConversationContext(options)) { ConversationTestHelper.PopulateDefaultDataCtx(db); } using (var db = new ConversationContext(options)) { var repository = new ConversationRepository(db); var item = GenerateModel(); var member = new User { Id = 1 }; IEnumerable <User> result = null; Assert.DoesNotThrow(() => repository.Save(item)); Assert.DoesNotThrow(() => repository.AddMember(member, item)); Assert.DoesNotThrow(() => result = repository.GetMembers(item.Id)); Assert.True(result != null && result.Any()); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void GetUserConversations_UserIdPassed_ListIsNotEmpty() { //Arrange var context = new Mock <DatabaseContext>(); var dbSetMock = new Mock <DbSet <Conversation> >(); var dbSetMockUserConversations = new Mock <DbSet <UserConversation> >(); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.Provider).Returns(conversationList.Provider); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.Expression).Returns(conversationList.Expression); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.ElementType).Returns(conversationList.ElementType); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.GetEnumerator()).Returns(conversationList.GetEnumerator()); dbSetMockUserConversations.As <IQueryable <UserConversation> >().Setup(m => m.Provider).Returns(userConversations.Provider); dbSetMockUserConversations.As <IQueryable <UserConversation> >().Setup(m => m.Expression).Returns(userConversations.Expression); dbSetMockUserConversations.As <IQueryable <UserConversation> >().Setup(m => m.ElementType).Returns(userConversations.ElementType); dbSetMockUserConversations.As <IQueryable <UserConversation> >().Setup(m => m.GetEnumerator()).Returns(userConversations.GetEnumerator()); context.Setup(x => x.Conversations).Returns(dbSetMock.Object); context.Setup(x => x.UserConversations).Returns(dbSetMockUserConversations.Object); var repository = new ConversationRepository(context.Object); //Act var allConversations = repository.GetUserConversations(2); //Assert Assert.IsTrue(allConversations.Any()); }
public async Task UserLeft_UserNull() { //assemble var queryContext = AssembleMocks.GetQueryContext(); var commandContext = AssembleMocks.GetCommandContext(); var userSummaryRepo = new UserSummaryRepository(queryContext.Object); var conversationRepo = new ConversationRepository(queryContext.Object, commandContext.Object); var messageRepo = new MessageRepository(queryContext.Object, commandContext.Object); var conversationContext = new ConversationBoundedContext(conversationRepo, userSummaryRepo, messageRepo); var conversation = await conversationContext.GetById(4); var userSummary = await userSummaryRepo.GetById(1); var userSummaryTest = await userSummaryRepo.GetById(5); conversation.UserJoined(userSummary); //workaround since can't seem to mock a working Include() Assert.IsTrue(conversation.ActiveUsers.Count() == 1); //act conversation.UserLeft(userSummaryTest); //assert Assert.IsNull(userSummaryTest); Assert.IsTrue(conversation.ActiveUsers.Count() == 1); }
public void IsUserInConversation_ConversationIdAndUserIdPassed_ReturnsTrue() { //Arrange var context = new Mock <DatabaseContext>(); var dbSetMock = new Mock <DbSet <Conversation> >(); var dbSetMockUserConversations = new Mock <DbSet <UserConversation> >(); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.Provider).Returns(conversationList.Provider); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.Expression).Returns(conversationList.Expression); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.ElementType).Returns(conversationList.ElementType); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.GetEnumerator()).Returns(conversationList.GetEnumerator()); dbSetMockUserConversations.As <IQueryable <UserConversation> >().Setup(m => m.Provider).Returns(userConversations.Provider); dbSetMockUserConversations.As <IQueryable <UserConversation> >().Setup(m => m.Expression).Returns(userConversations.Expression); dbSetMockUserConversations.As <IQueryable <UserConversation> >().Setup(m => m.ElementType).Returns(userConversations.ElementType); dbSetMockUserConversations.As <IQueryable <UserConversation> >().Setup(m => m.GetEnumerator()).Returns(userConversations.GetEnumerator()); context.Setup(x => x.Conversations).Returns(dbSetMock.Object); context.Setup(x => x.UserConversations).Returns(dbSetMockUserConversations.Object); var repository = new ConversationRepository(context.Object); //Act var result = repository.IsUserInConversation(2, 23); //Assert Assert.IsTrue(result); }
public void RemoveMember() { try { var options = CreateNewContextOptions(); using (var db = new ConversationContext(options)) { ConversationTestHelper.PopulateDefaultDataCtx(db); } using (var db = new ConversationContext(options)) { var repository = new ConversationRepository(db); var item = GenerateModel(); var member = new User { Id = 1 }; Assert.DoesNotThrow(() => repository.Save(item)); Assert.DoesNotThrow(() => repository.AddMember(member, item)); Assert.DoesNotThrow(() => repository.RemoveMember(member, item)); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void AddConversationEntityTest() { var conversation = new Conversation(1); var conversationRepository = new ConversationRepository(); conversationRepository.AddEntity(conversation); Assert.AreEqual(conversation, conversationRepository.FindEntityById(conversation.Id)); }
public void AddsNewContributionToConversation() { HandleMessage(contributionRequest); Conversation contributionConversation = ConversationRepository.FindEntityById(contributionRequest.Contribution.ConversationId); IContribution lastContributionAdded = contributionConversation.LastContribution; Assert.IsTrue(lastContributionAdded.ContributorUserId.Equals(contributionRequest.Contribution.ContributorUserId)); }
public void NewContributionGetsAssignedId() { HandleMessage(contributionRequest); Conversation contributionConversation = ConversationRepository.FindEntityById(contributionRequest.Contribution.ConversationId); IContribution lastContributionAdded = contributionConversation.LastContribution; Assert.IsTrue(lastContributionAdded.Id != 0); }
public ForceConversation(PlayerEventModel playerEventModel) : base(playerEventModel) { var conversationRepository = new ConversationRepository(ContextMap.DefaultMap); var conversationId = uint.Parse(playerEventModel.EventModel.EventContentsModel.Arg[0]); this.conversationModel = conversationRepository.Get(conversationId); this.isAlive = true; }
public bool SendChatMessage(Message message) { try { Room room; if (ChatRooms.TryGetValue(message.ConversationId, out room)) { message.Id = Guid.NewGuid().ToString(); message.MsgDate = DateTime.Now; var useridto = room.InitiatedTo; if (useridto == message.UserId) { useridto = room.InitiatedBy; } User user; var appfrom = string.Empty; if (ChatUsers.TryGetValue(message.UserId, out user)) { appfrom = user.AppFrom; } var listHistory = ConversationRepository.GetHistoryConversation(message.UserId, useridto, appfrom); Clients.Group(message.ConversationId).receiveChatMessage(message, room, listHistory); //save message to data var conversation = new Conversation { MsgId = message.Id, Msg = message.MessageText, MsgDate = message.MsgDate, ConversationId = message.ConversationId, InitiatedBy = message.UserId, InitiatedTo = useridto, AppFrom = appfrom, UserName = message.UserName, FullName = message.FullName }; ConversationRepository.SaveConversation(conversation); return(true); } return(false); } catch { const string msg = "Gặp sự cố trong việc gửi message!"; Clients.Caller.OnErrorMessage(msg); return(false); } }
public void Get() { try { var options = CreateNewContextOptions(); using (var db = new ConversationContext(options)) { ConversationTestHelper.PopulateDefaultDataCtx(db); } using (var db = new ConversationContext(options)) { var repository = new ConversationRepository(db); var item = GenerateModel(); IEnumerable <Conv> result = null; Assert.DoesNotThrow(() => repository.Save(item)); Assert.DoesNotThrow(() => repository.AddMember(new User { Id = 1 }, item)); var filter = new ConversationFilter <int> { UserId = item.UserStartedId, ConversationTypeId = item.ConversationTypeId, }; Assert.DoesNotThrow(() => result = repository.Get(filter)); Assert.True(result != null && result.Any()); filter.Code = "Conv1"; Assert.DoesNotThrow(() => result = repository.Get(filter)); Assert.True(result != null && result.Any()); filter.Title = "Conversation"; Assert.DoesNotThrow(() => result = repository.Get(filter)); Assert.True(result != null && result.Any()); filter.DateCreatedInterval = new Interval <DateTime?> { Start = DateTime.Now.AddDays(-2) }; Assert.DoesNotThrow(() => result = repository.Get(filter)); Assert.True(result != null && result.Any()); filter.DateCreatedInterval.Start = null; filter.DateCreatedInterval.End = DateTime.Now.AddDays(2); Assert.DoesNotThrow(() => result = repository.Get(filter)); Assert.True(result != null && result.Any()); filter.DateCreatedInterval.Start = DateTime.Now.AddDays(-2); Assert.DoesNotThrow(() => result = repository.Get(filter)); Assert.True(result != null && result.Any()); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public async Task Create_NotNullTopic() { //assemble var queryContext = AssembleMocks.GetQueryContext(); var commandContext = AssembleMocks.GetCommandContext(); var conversationRepo = new ConversationRepository(queryContext.Object, commandContext.Object); //act var conversation = await conversationRepo.Create("New Topic"); //assert Assert.IsNotNull(conversation); }
public async Task GetBySignalRConnectionIdWithActiveUser_NotFound() { //assemble var queryContext = AssembleMocks.GetQueryContext(true); var commandContext = AssembleMocks.GetCommandContext(true); var conversationRepo = new ConversationRepository(queryContext.Object, commandContext.Object); //act var conversationId = await conversationRepo.GetConversationIdBySignalRId("bc0444a5-c967-4d9f-86eb-0d9359d1bda3"); //assert Assert.IsTrue(conversationId == 0); }
public async Task GetById_NotFound() { //assemble var queryContext = AssembleMocks.GetQueryContext(); var commandContext = AssembleMocks.GetCommandContext(); var conversationRepo = new ConversationRepository(queryContext.Object, commandContext.Object); //act var conversation = await conversationRepo.GetById(15, null); //assert Assert.IsNull(conversation); }
public void AddConversationEntitiesTest() { var conversationRepository = new ConversationRepository(); var conversations = new List <Conversation> { new Conversation(1), new Conversation(2) }; foreach (Conversation conversation in conversations) { conversationRepository.AddEntity(conversation); } Assert.AreEqual(conversations, conversationRepository.GetAllEntities()); }
//Para poder acessar esse método sem ele ter sido instanciado //é necessário que ele seja estático. public static ApplicationServices GetInstance() { if (_instance == null) { //Pseudo Injeção de Dependência context = new SocialNetworkContext(); IUserRepository userRepository = new UserRepository(context); IConversationRepository conversationRepository = new ConversationRepository(context); IMessageRepository messageRepository = new MessageRepository(context); IUserService userServices = new UserServices(userRepository); IMessageService messageService = new MessageService(messageRepository); IConversationService conversationService = new ConversationService(conversationRepository, messageRepository); _instance = new ApplicationServices(userServices, messageService); } return(_instance); }
public void ReturnsCorrectRepository() { IEntityRepository userRepository = new UserRepository(); IEntityRepository conversationRepository = new ConversationRepository(); IEntityRepository participationRepository = new ParticipationRepository(); var repositoryManager = new RepositoryManager(); repositoryManager.AddRepository <User>(userRepository); repositoryManager.AddRepository <Conversation>(conversationRepository); repositoryManager.AddRepository <Participation>(participationRepository); IReadOnlyEntityRepository <Conversation> retrievedConversationRepository = repositoryManager.GetRepository <Conversation>(); Assert.AreEqual(conversationRepository, retrievedConversationRepository); }
public AppearConversationCharacter(PlayerEventModel playerEventModel) : base(playerEventModel) { // TODO : この辺のレポジトリを使いまわしできるようにしたい。 var conversationRepository = new ConversationRepository(ContextMap.DefaultMap); var appearCharacterRepository = new AppearCharacterRepository(ContextMap.DefaultMap); var rewardRepository = new RewardRepository(ContextMap.DefaultMap); Debug.Assert(playerEventModel.EventModel.EventContentsModel.Arg.Length >= 3, "AppearConversationCharacter: コンテンツ引数の要素数が3未満です"); var appearCharacterId = uint.Parse(playerEventModel.EventModel.EventContentsModel.Arg[0]); var conversationId = uint.Parse(playerEventModel.EventModel.EventContentsModel.Arg[1]); var rewardId = uint.Parse(playerEventModel.EventModel.EventContentsModel.Arg[2]); this.appearCharacterModel = appearCharacterRepository.Get(appearCharacterId); this.conversationModel = conversationRepository.Get(conversationId); this.rewardModel = rewardRepository.Get(rewardId); }
public async Task Persist() { //assemble var queryContext = AssembleMocks.GetQueryContext(); var commandContext = AssembleMocks.GetCommandContext(); var conversationRepo = new ConversationRepository(queryContext.Object, commandContext.Object); var conversation = await conversationRepo.GetById(1, null); string newTopic = Guid.NewGuid().ToString(); //act conversation.Topic = newTopic; var response = await conversationRepo.Persist(conversation); //assert Assert.IsTrue(response.Topic == newTopic); }
public void GetConversation_ConversationIdPassed_CorrectConversationReturned() { //Arrange var context = new Mock <DatabaseContext>(); var dbSetMock = new Mock <DbSet <Conversation> >(); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.Provider).Returns(conversationList.Provider); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.Expression).Returns(conversationList.Expression); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.ElementType).Returns(conversationList.ElementType); dbSetMock.As <IQueryable <Conversation> >().Setup(m => m.GetEnumerator()).Returns(conversationList.GetEnumerator()); context.Setup(x => x.Conversations).Returns(dbSetMock.Object); var repository = new ConversationRepository(context.Object); //Act var conversation = repository.GetConversation(23); //Assert Assert.IsTrue(conversation.ConversationID == 23); }
public async Task UserJoined_UserNull() { //assemble var queryContext = AssembleMocks.GetQueryContext(); var commandContext = AssembleMocks.GetCommandContext(); var userSummaryRepo = new UserSummaryRepository(queryContext.Object); var conversationRepo = new ConversationRepository(queryContext.Object, commandContext.Object); var messageRepo = new MessageRepository(queryContext.Object, commandContext.Object); var conversationContext = new ConversationBoundedContext(conversationRepo, userSummaryRepo, messageRepo); var conversation = await conversationContext.GetById(5); var userSummary = await userSummaryRepo.GetById(5); //act conversation.UserJoined(userSummary); //assert Assert.IsNull(userSummary); Assert.IsTrue(conversation.ActiveUsers.Count() == 0); }
/// <summary> /// Adds a game object to the database. /// </summary> /// <param name="gameObject">The game object to add to the database. This will be type-converted and added to the correct table when run.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public GameObjectBase AddToDatabase(GameObjectBase gameObject, string connectionString = "") { GameObjectBase resultGameObject; try { if (gameObject.GameObjectType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Area); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository()) { resultGameObject = repo.Add(gameObject as Conversation); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Creature); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Item); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Placeable); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Script); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Tileset); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.GameModule) { using (GameModuleRepository repo = new GameModuleRepository()) { resultGameObject = repo.Add(gameObject as GameModule); } } else { throw new NotSupportedException(); } } catch { throw; } return resultGameObject; }
/// <summary> /// Deletes an object with the specified resref from the database. /// </summary> /// <param name="resref">The resource reference to search for.</param> /// <param name="resourceType">The type of resource to remove.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public void DeleteFromDatabase(int resourceID, GameObjectTypeEnum resourceType, string connectionString = "") { if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.GameModule) { using (GameModuleRepository repo = new GameModuleRepository()) { repo.Delete(resourceID); } } else { throw new NotSupportedException(); } }
private async Task ResumeAfterMotorQuoteFormDialog(IDialogContext context, IAwaitable <MotorQuote> result) { var state = await result; var reply = context.MakeMessage(); try { var quoteRepository = new QuoteRepository(Connection); var conversationRepository = new ConversationRepository(Connection); var motorService = new Common.RelayFullCycleMotorService.RelayFullCycleMotorService(); var riskData = MotorQuote.BuildIrishMQRiskInfo(state); var messageRequestInfo = MotorQuote.BuildMessageRequestInfo(); var quotes = motorService.GetNewBusinessXBreakDownsSpecified(riskData, 100, true, null, messageRequestInfo); if (quotes.Quotations != null) { if (quotes.Quotations.Length > 0) { quoteRepository.StoreQuote ( context.Activity.Conversation.Id, quotes.TransactionID, new JavaScriptSerializer().Serialize(quotes.Quotations[0]) ); reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments = GetQuoteReceipts(quotes.Quotations); if (SendEmails) { var emailToUserBody = EmailHandler.BuildMotorEmailBodyForUser(quotes.Quotations, state.FirstName, state.LastName, state.DateOfBirth, state.PrimaryContactNumber, state.EmailAddress, state.VehicleRegistration, state.Vehicle.Description, state.VehicleValue, state.AreaVehicleIsKept, state.LicenceType.GetDescription(), state.NoClaimsDiscount.GetDescription()); EmailHandler.SendEmailToUser(state.EmailAddress, $"{state.FirstName} {state.LastName}", emailToUserBody); var emailToBrokerBody = EmailHandler.BuildMotorEmailBodyForBroker(quotes.Quotations, state.FirstName, state.LastName, state.DateOfBirth, state.PrimaryContactNumber, state.EmailAddress, state.VehicleRegistration, state.Vehicle.Description, state.VehicleValue, state.AreaVehicleIsKept, state.LicenceType.GetDescription(), state.NoClaimsDiscount.GetDescription()); EmailHandler.SendEmailToBroker(state.EmailAddress, $"{state.FirstName} {state.LastName}", emailToBrokerBody); } await context.PostAsync(reply); } } else { await context.PostAsync("Sorry, we were unable to get your a quote at this point."); } conversationRepository.StoreConversation ( context.Activity.Conversation.Id, context.Activity.From.Id, DateTime.Now.ToString(new CultureInfo("en-GB")), new JavaScriptSerializer().Serialize(context) ); } catch (Exception exception) { ErrorRepository.LogError(context.Activity.Conversation.Id, context.Activity.From.Id, DateTime.Now.ToString(new CultureInfo("en-GB")), context.ConversationData.ToString(), exception.ToString()); throw; } finally { context.Done(state); } }
public ConversationRepoTests() { _mockContext = new Mock<DataContext>(); _mockRepo = new ConversationRepository(_mockContext.Object, Mock.Of<ILogger<ConversationRepository>>()); }
public ConversationService(DatabaseContext databaseContext) { this.messageRepository = new MessageRepository(databaseContext); this.conversationRepository = new ConversationRepository(databaseContext); }
private static async Task ResumeAfterHomeQuoteFormDialog(IDialogContext context, IAwaitable <HomeQuote> result) { var state = await result; try { var quoteRepository = new QuoteRepository(Connection); var conversationRepository = new ConversationRepository(Connection); var reply = context.MakeMessage(); var homeService = new Household(); var homeWebServiceRequest = HomeQuote.BuildHomeWebServiceRequest(state); var quotes = new List <HomeQuoteWebServiceResult>(); var response = homeService.GetQuotes(homeWebServiceRequest); if (response.Quotes != null) { foreach (var quote in response.Quotes) { quotes.Add(quote); } reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments = GetQuoteReceipts(quotes); quoteRepository.StoreQuote ( context.Activity.Conversation.Id, response.Quotes[0].RelayQuoteId, new JavaScriptSerializer().Serialize(quotes) ); } else { reply.Text = "Sorry, we couldn't get any quotes for you."; } await context.PostAsync(reply); if (SendEmails) { var emailBodyForUser = EmailHandler.BuildHomeEmailBodyForUser(response.Quotes, state.FirstName, state.LastName, state.PrimaryContactNumber, state.EmailAddress, state.FirstLineOfAddress, state.Town, state.County, state.PropertyType.GetDescription(), state.ResidenceType.GetDescription(), state.YearBuilt, state.NumberOfBedrooms.ToString()); EmailHandler.SendEmailToUser(state.EmailAddress, $"{state.FirstName} {state.LastName}", emailBodyForUser); var emailBodyForBroker = EmailHandler.BuildHomeEmailBodyForBroker(response.Quotes, state.FirstName, state.LastName, state.PrimaryContactNumber, state.EmailAddress, state.FirstLineOfAddress, state.Town, state.County, state.PropertyType.GetDescription(), state.ResidenceType.GetDescription(), state.YearBuilt, state.NumberOfBedrooms.ToString()); EmailHandler.SendEmailToBroker(state.EmailAddress, $"{state.FirstName} {state.LastName}", emailBodyForBroker); } conversationRepository.StoreConversation ( context.Activity.Conversation.Id, context.Activity.From.Id, DateTime.Now.ToString(new CultureInfo("en-GB")), new JavaScriptSerializer().Serialize(context) ); } catch (Exception exception) { var errorRepository = new ErrorRepository(Connection); errorRepository.LogError(context.Activity.Conversation.Id, context.Activity.From.Id, DateTime.Now.ToString(), context.ConversationData.ToString(), exception.ToString()); throw; } finally { context.Done(state); } }
public void UpsertInDatabase(GameObjectBase gameObject, string connectionString = "") { if (gameObject.GameObjectType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { repo.Upsert(gameObject as Area); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { repo.Upsert(gameObject as Conversation); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { repo.Upsert(gameObject as Creature); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { repo.Upsert(gameObject as Item); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { repo.Upsert(gameObject as Placeable); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { repo.Upsert(gameObject as Script); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { repo.Upsert(gameObject as Tileset); } } else { throw new NotSupportedException(); } }
public ConversationController(ConversationRepository conversationRepository) { _conversationRepository = conversationRepository; }
/// <summary> /// Returns all objects from the database that have a matching resource category. /// </summary> /// <param name="resourceCategory">The resource category all return values must match</param> /// <param name="resourceType">The type of resource to look for.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> /// <returns></returns> public List<GameObjectBase> GetAllFromDatabaseByResourceCategory(Category resourceCategory, GameObjectTypeEnum resourceType, string connectionString = "") { List<GameObjectBase> retList = new List<GameObjectBase>(); if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else { throw new NotSupportedException(); } }
/// <summary> /// Delete all objects from database that match a specified resource category. /// </summary> /// <param name="resourceCategory">The resource category to remove all objects from.</param> /// <param name="resourceType">The type of resource to look for.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public void DeleteFromDatabaseByCategory(Category resourceCategory, GameObjectTypeEnum resourceType, string connectionString = "") { if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else { throw new NotSupportedException(); } // Now remove the category itself. using (CategoryRepository repo = new CategoryRepository()) { Category dbCategory = repo.GetByID(resourceCategory.ResourceID); repo.Delete(dbCategory); } }
public bool InitiateChat(string fromUserId, string fromUserName, string toUserId, string toUserName) { try { if (string.IsNullOrEmpty(fromUserId) || string.IsNullOrEmpty(fromUserName) || string.IsNullOrEmpty(toUserId) || string.IsNullOrEmpty(toUserName)) { return(false); } var fromUser = GetChatUserByUserId(fromUserId); var toUser = GetChatUserByUserId(toUserId); if (fromUser != null && toUser != null) { if (!CheckIfRoomExists(fromUser, toUser)) { //Create New Chat Room var chatRoom = new Room(); chatRoom.InitiatedBy = fromUser.Id; chatRoom.InitiatedTo = toUser.Id; chatRoom.Users.Add(fromUser); chatRoom.Users.Add(toUser); fromUser.RoomIds.Add(chatRoom.RoomId); toUser.RoomIds.Add(chatRoom.RoomId); //Create SignalR Group for this chat room and add users connection to it Groups.Add(fromUser.ConnectionId, chatRoom.RoomId); Groups.Add(toUser.ConnectionId, chatRoom.RoomId); //Add Chat room object to collection if (ChatRooms.TryAdd(chatRoom.RoomId, chatRoom)) { //Generate Client UI for this room Clients.Caller.initiateChatUI(chatRoom); //Load history var listHistory = ConversationRepository.GetHistoryConversation(fromUser.Id, toUser.Id, fromUser.AppFrom); Clients.Caller.loadHistoryUI(chatRoom, listHistory); } } else { var chatRoom = GetRoomId(fromUser, toUser); if (true) { var listHistory = ConversationRepository.GetHistoryConversation(fromUser.Id, toUser.Id, fromUser.AppFrom); //Generate Client UI for this room Clients.Caller.initiateChatUI(chatRoom); //Load history Clients.Caller.loadHistoryUI(chatRoom, listHistory); } } } return(true); } catch { const string msg = "Gặp sự cố trong việc khởi động chat!"; Clients.Caller.OnErrorMessage(msg); return(false); } }
/// <summary> /// Returns True if an object exists in the database. /// Returns False if an object does not exist in the database. /// </summary> /// <param name="resref">The resource reference to search for.</param> /// <param name="resourceType">The resource type to look for.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> /// <returns></returns> public bool DoesObjectExistInDatabase(string resref, GameObjectTypeEnum resourceType, string connectionString = "") { if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { return repo.Exists(resref); } } else { throw new NotSupportedException(); } }
private void PopulateToolsetViewModel() { ClearViewModelPopulation(); using (GameModuleRepository repo = new GameModuleRepository()) { ViewModel.ActiveModule = repo.GetModule(); } using (ContentPackageResourceRepository repo = new ContentPackageResourceRepository()) { ViewModel.TilesetSpriteSheetsList = repo.GetAllUIObjects(ContentPackageResourceTypeEnum.Tileset, false); } using (ItemRepository repo = new ItemRepository()) { ViewModel.ItemList = repo.GetAllUIObjects(); } using (ScriptRepository repo = new ScriptRepository()) { ViewModel.ScriptList = repo.GetAllUIObjects(); } using (GenderRepository repo = new GenderRepository()) { ViewModel.GenderList = repo.GetAllUIObjects(); } using (ConversationRepository repo = new ConversationRepository()) { ViewModel.ConversationList = repo.GetAllUIObjects(); } using (RaceRepository repo = new RaceRepository()) { ViewModel.RaceList = repo.GetAllUIObjects(); } using (FactionRepository repo = new FactionRepository()) { ViewModel.FactionList = repo.GetAllUIObjects(); } using (TilesetRepository repo = new TilesetRepository()) { ViewModel.TilesetList = repo.GetAllUIObjects(); } using (AbilityRepository repo = new AbilityRepository()) { ViewModel.AbilityList = repo.GetAll(); } using (SkillRepository repo = new SkillRepository()) { ViewModel.SkillList = repo.GetAll(); } using (LevelRequirementRepository repo = new LevelRequirementRepository()) { ViewModel.LevelRequirementList = repo.GetAll(); } }
public GameObjectBase GetFromDatabaseByID(int resourceID, GameObjectTypeEnum gameResourceType) { if (gameResourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository()) { return repo.GetByID(resourceID); } } else { throw new NotSupportedException(); } }
private void LoadTreeViewData(object sender, JavascriptMethodEventArgs e) { try { JSTreeNode areaRootNode; JSTreeNode creatureRootNode; JSTreeNode itemRootNode; JSTreeNode placeableRootNode; JSTreeNode conversationRootNode; JSTreeNode scriptRootNode; JSTreeNode tilesetRootNode; // Get each category's children for each object type using (AreaRepository repo = new AreaRepository()) { areaRootNode = repo.GenerateJSTreeHierarchy(); } using (CreatureRepository repo = new CreatureRepository()) { creatureRootNode = repo.GenerateJSTreeHierarchy(); } using (ItemRepository repo = new ItemRepository()) { itemRootNode = repo.GenerateJSTreeHierarchy(); } using (PlaceableRepository repo = new PlaceableRepository()) { placeableRootNode = repo.GenerateJSTreeHierarchy(); } using (ConversationRepository repo = new ConversationRepository()) { conversationRootNode = repo.GenerateJSTreeHierarchy(); } using (ScriptRepository repo = new ScriptRepository()) { scriptRootNode = repo.GenerateJSTreeHierarchy(); } using (TilesetRepository repo = new TilesetRepository()) { tilesetRootNode = repo.GenerateJSTreeHierarchy(); } AsyncJavascriptCallback("LoadTreeViews_Callback", JsonConvert.SerializeObject(areaRootNode), JsonConvert.SerializeObject(creatureRootNode), JsonConvert.SerializeObject(itemRootNode), JsonConvert.SerializeObject(placeableRootNode), JsonConvert.SerializeObject(conversationRootNode), JsonConvert.SerializeObject(scriptRootNode), JsonConvert.SerializeObject(tilesetRootNode)); } catch { throw; } }
private void SaveConversation(object sender, GameObjectSaveEventArgs e) { using (ConversationRepository repo = new ConversationRepository()) { repo.Upsert(e.ActiveConversation); } }
public DatabaseService(BotService bot, FirestoreDb db) { Repos = new ConversationRepository(bot, db); }