public void Initialize() { InitializeCommunity(); var companyAlan = _individualAlan.CreateCompany(); companyAlan.Name = "Encom"; var companyFlynn = _individualFlynn.CreateCompany(); companyFlynn.Name = "Flynn's"; Synchronize(); _moderator = new ModeratorService( _domainModerator.CreateGame(_domainModerator.Companies)); Synchronize(); var gameAlan = companyAlan.Games.Single(); var gameFlynn = companyFlynn.Games.Single(); _alan = new CompanyGameService(companyAlan, gameAlan); _flynn = new CompanyGameService(companyFlynn, gameFlynn); _actuator = new Actuator(); _alan.RegisterWith(_actuator); _flynn.RegisterWith(_actuator); _actuator.Start(); }
public void AddImageTest() { IModeratorService moderatorService = new ModeratorService(this.serviceOptions); // Add Image (with labels) // See label details in the response documentation: https://developer.microsoftmoderator.com/docs/services/54f7932727037412a0cda396/operations/54f793272703740c70627a24 using (Stream stream = new FileStream(TestImageContent, FileMode.Open, FileAccess.Read)) { ImageModeratableContent imageContent = new ImageModeratableContent(new BinaryContent(stream, "image/jpeg")); var addResponse = moderatorService.ImageAddAsync(imageContent); var addResult = addResponse.Result; Assert.IsTrue(addResult != null, "Expected valid result, Response: {0}", JsonConvert.SerializeObject(addResult)); Assert.IsTrue(string.IsNullOrWhiteSpace(addResult.ImageId) || string.Compare(addResult.Status.Description, "Error occurred while processing request :: Failure Adding a valid image :: Image already exists") == 0, "Image Id can be null only if the Image already exists, Response: {0}", JsonConvert.SerializeObject(addResult)); // Refresh index var refreshResponse = moderatorService.RefreshImageIndexAsync(); var refreshResult = refreshResponse.Result; Assert.IsTrue(refreshResult.IsUpdateSuccess, "Expected update Success on refresh, Response: {0}", JsonConvert.SerializeObject(refreshResult)); } using (Stream stream = new FileStream(TestImageContent, FileMode.Open, FileAccess.Read)) { ImageModeratableContent imageContent = new ImageModeratableContent(new BinaryContent(stream, "image/jpeg")); // Match var matchResponse = moderatorService.MatchImageAsync(imageContent); var matchResult = matchResponse.Result; Assert.IsTrue(matchResult.IsMatch, "Expected match, Response: {0}", JsonConvert.SerializeObject(matchResult)); } }
public void AddTermTest() { IModeratorService moderatorService = new ModeratorService(this.serviceOptions); // We are creating a term "FakeProfanity" in english (thus provide tha same english translation), then matching against it. TextModeratableContent textContent = new TextModeratableContent(text: "FakeProfanity", englishTranslation: "FakeProfanity"); var taskResult = moderatorService.AddTermAsync(textContent, "eng"); var actualResult = taskResult.Result; Assert.IsTrue((actualResult.StatusCode != System.Net.HttpStatusCode.Created) || (actualResult.StatusCode != System.Net.HttpStatusCode.MultipleChoices), "Expected valid result for AddTerm"); var refreshTask = moderatorService.RefreshTextIndexAsync("eng"); var refreshResult = refreshTask.Result; Assert.IsTrue(refreshResult != null, "Expected valid result for RefreshIndex"); var screenResponse = moderatorService.ScreenTextAsync(new TextModeratableContent("This is a FakeProfanity!"), "eng"); var screenResult = screenResponse.Result; Assert.IsTrue(screenResult.MatchDetails != null, "Expected valid terms"); var deleteTask = moderatorService.RemoveTermAsync(textContent, "eng"); var deleteResult = deleteTask.Result; Assert.IsTrue(deleteResult.IsSuccessStatusCode, "Expected valid result for DeleteTerm"); }
public async Task ReadyToTrade(int orderId, int moderatorId) { var order = await OrderService.Get(orderId); if (order == null) { throw new EntityNotFoundException($"OrderId:{orderId} not found", "Order"); } if ((await GetCurrentState(orderId)).Status != OrderStatus.Accepted) { throw new OrderStatusException("Only accepted orders can be read for trade"); } if (!await ModeratorService.IsExist(moderatorId)) { throw new EntityNotFoundException($"ModeratorId:{moderatorId} not found", "Moderator"); } if (!order.ModeratorId.Equals(moderatorId)) { throw new AccessViolationException($"Only a order moderator can change the order state. Order moderatorId:{order.ModeratorId}, function moderatorId:{moderatorId}"); } await SetCurrentStatus(orderId, OrderStatus.ReadyForTrade); }
public ModeratorController() { forumService = new ForumService(); boardService = new ForumBoardService(); userService = new UserService(); moderatorService = new ModeratorService(); }
public void ScreenTextTest() { IModeratorService moderatorService = new ModeratorService(this.serviceOptions); // Import the term list. This needs to only be done once before screen moderatorService.ImportTermListAsync("eng").Wait(); moderatorService.RefreshTextIndexAsync("eng").Wait(); // Run screen to match, validating match result string text = "My evil freaking text!"; TextModeratableContent textContent = new TextModeratableContent(text); var screenResponse = moderatorService.ScreenTextAsync(textContent, "eng"); var screenResult = screenResponse.Result; Assert.IsTrue(screenResult != null, "Expected valid result"); Assert.IsTrue(screenResult.MatchDetails != null, "Expected valid Match Details"); Assert.IsTrue(screenResult.MatchDetails.MatchFlags != null, "Expected valid Match Flags"); var matchFlag = screenResult.MatchDetails.MatchFlags.FirstOrDefault(); Assert.IsTrue(matchFlag != null, "Expected to see a match flag!"); Assert.AreEqual("freaking", matchFlag.Source, "Expected term to match"); }
public ModeratorModel(ForumDbContext context, ForumTreeService forumService, UserService userService, IAppCache cache, CommonUtils utils, LanguageProvider languageProvider, ModeratorService moderatorService, PostService postService, OperationLogService operationLogService) : base(context, forumService, userService, cache, utils, languageProvider) { _moderatorService = moderatorService; _postService = postService; _operationLogService = operationLogService; }
public PostController() { boardService = new ForumBoardService(); topicService = new ForumTopicService(); postService = new ForumPostService(); attachService = new AttachmentService(); moderatorService = new ModeratorService(); buyService = new ForumBuyLogService(); incomeService = new UserIncomeService(); }
public ForumController() { forumService = new ForumService(); boardService = new ForumBoardService(); categoryService = new ForumCategoryService(); topicService = new ForumTopicService(); moderatorService = new ModeratorService(); logService = new ForumLogService(); postService = new ForumPostService(); }
public void IdentifyLanguageTest() { IModeratorService moderatorService = new ModeratorService(this.serviceOptions); TextModeratableContent textContent = new TextModeratableContent("Hola este es un texto en otro idioma"); var identifyLanguageResponse = moderatorService.IdentifyLanguageAsync(textContent); var actualResult = identifyLanguageResponse.Result; Assert.IsTrue(actualResult != null, "Expected valid result"); Assert.AreEqual("spa", actualResult.DetectedLanguage, "Expected valid result"); }
public void Initialize() { this.serviceOptions = new ModeratorServiceOptions() { HostUrl = ConfigurationManager.AppSettings["HostUrl"], ImageServicePath = ConfigurationManager.AppSettings["ImageServicePath"], ImageServiceCustomListPath = ConfigurationManager.AppSettings["ImageServiceCustomListPath"], ImageServiceKey = ConfigurationManager.AppSettings["ImageServiceKey"], ImageServiceCustomListKey = ConfigurationManager.AppSettings["ImageServiceCustomListKey"] }; IModeratorService moderatorService = new ModeratorService(this.serviceOptions); }
public void EvaluateImageUrlTest() { IModeratorService moderatorService = new ModeratorService(this.serviceOptions); ImageModeratableContent imageContent = new ImageModeratableContent(TestImageUrl); var moderateResult = moderatorService.EvaluateImageAsync(imageContent); var actualResult = moderateResult.Result; Assert.IsTrue(actualResult != null, "Expected valid result, Response: {0}", JsonConvert.SerializeObject(actualResult)); Assert.IsTrue(actualResult.AdvancedInfo != null, "AdvancedInfo is NULL, Response: {0}", JsonConvert.SerializeObject(actualResult)); var score = actualResult.AdvancedInfo.First(x => string.Equals(x.Key, "score", StringComparison.OrdinalIgnoreCase)); Assert.AreNotEqual("0.000", score.Value, "score value, Response: {0}", JsonConvert.SerializeObject(actualResult)); }
public void CheckPolimorphism() { IUsersService usrService = new UsersService(); usrService.Read(); IModeratorService modService = new ModeratorService(); modService.Update(new Moderator()); IAdminService admService = new AdminService(); Guid newAdmin = admService.Create(); admService.Delete(newAdmin); }
public async Task AssignModerator(int orderId, int moderatorId) { var order = await Get(orderId); if (order == null) { throw new EntityNotFoundException($"OrderId:{orderId} not found", "Order"); } if (!await ModeratorService.IsExist(moderatorId)) { throw new EntityNotFoundException($"ModeratorId:{moderatorId} not found", "Moderator"); } order.ModeratorId = moderatorId; await Repository.Update(order); await Repository.Save(); }
public void EvaluateImageContentTest() { using (Stream stream = new FileStream(TestImageContent, FileMode.Open, FileAccess.Read)) { IModeratorService moderatorService = new ModeratorService(this.serviceOptions); ImageModeratableContent imageContent = new ImageModeratableContent(new BinaryContent(stream, "image/jpeg")); var moderateResult = moderatorService.EvaluateImageAsync(imageContent); var actualResult = moderateResult.Result; Assert.IsTrue(actualResult != null, "Expected valid result, Response: {0}", JsonConvert.SerializeObject(actualResult)); Assert.IsTrue(actualResult.AdvancedInfo != null, "Expected valid result, Response: {0}", JsonConvert.SerializeObject(actualResult)); var score = actualResult.AdvancedInfo.First( x => string.Equals(x.Key, "score", StringComparison.OrdinalIgnoreCase)); double scoreValue = double.Parse(score.Value); Assert.IsTrue(scoreValue > 0, "Expected higher than 0 score value for test image, Response: {0}", JsonConvert.SerializeObject(actualResult)); } }
public async Task Accept(int orderId, int moderatorId) { var order = await OrderService.Get(orderId); if (order == null) { throw new EntityNotFoundException($"OrderId:{orderId} not found", "Order"); } if (!await ModeratorService.IsExist(moderatorId)) { throw new EntityNotFoundException($"ModeratorId:{moderatorId} not found", "Moderator"); } if ((await GetCurrentState(orderId)).Status != OrderStatus.New) { throw new OrderStatusException("Only new orders can be accepted"); } await SetCurrentStatus(orderId, OrderStatus.Accepted); await OrderService.AssignModerator(orderId, moderatorId); }
public void ExtractTextTest() { IModeratorService moderatorService = new ModeratorService(this.serviceOptions); using (Stream stream = new FileStream(TestImageContent, FileMode.Open, FileAccess.Read)) { ImageModeratableContent imageContent = new ImageModeratableContent(new BinaryContent(stream, "image/jpeg")); // extract var extractResponse = moderatorService.ExtractTextAsync(imageContent, "eng"); var extractResult = extractResponse.Result; Assert.IsTrue(extractResult != null, "Expected valid result, Response: {0}", JsonConvert.SerializeObject(extractResult)); Assert.IsTrue(extractResult.AdvancedInfo != null, "Expected valid result, Response: {0}", JsonConvert.SerializeObject(extractResult)); var text = extractResult.AdvancedInfo.First( x => string.Equals(x.Key, "Text", StringComparison.OrdinalIgnoreCase)); Assert.AreEqual("Windows10 \r\nSatya Nadella \r\n", text.Value, "Text message was unexpected, Response: {0}", JsonConvert.SerializeObject(extractResult)); } }
//---------------------------------------------------------------------- public static IList GetTopicAdminCmds(User user, ForumBoard board, MvcContext ctx) { IList results = new ArrayList(); // 1、获取用户的角色 SecurityTool tool = ForumSecurityService.GetSecurityTool(board, ctx); IList actions = tool.GetActionsByRole(user.Role); addAdminActionsToResults(actions, results); // 2、获取用户的等级 if (user.RankId > 0) { actions = tool.GetActionsByRole(user.Rank); addAdminActionsToResults(actions, results); } // 3、owner的角色 if (ctx.owner.obj.GetType() != typeof(Site)) { IRole roleInOwner = ctx.owner.obj.GetUserRole(user); actions = tool.GetActionsByRole(roleInOwner); addAdminActionsToResults(actions, results); } // 3、版主 ModeratorService moderatorService = new ModeratorService(); if (moderatorService.IsModerator(board, user)) { IList moderatorActions = tool.GetActionsByRole(ForumRole.Moderator); addAdminActionsToResults(moderatorActions, results); } return(results); }
private static Boolean hasAction(ISecurity objSecurity, MvcContext ctx) { // 未提供权限配置的页面通过 if (objSecurity == null) { return(true); } SecurityTool securityTool = ForumSecurityService.GetSecurityTool(objSecurity, ctx); // objSecurity.SecurityTool; // 不需要权限管理的页面通过 if (securityTool.IsForbiddenAction(ctx.route.getControllerAndActionPath()) == false) { return(true); } // 空页面——通过 String currentPath = ctx.url.Path; if (strUtil.IsNullOrEmpty(currentPath)) { return(true); } // 编辑权限例外:用户可以编辑自己的帖子 // 只要系统角色,或论坛角色之一具有权限,则用户具有权限(当用户具有多重身份之时) // 1、获取用户的角色 //系统角色 SiteRole role = ((User)ctx.viewer.obj).Role; IList actions = securityTool.GetActionsByRole(role); if (hasAction_private(actions, ctx)) { return(true); } // 2、获取用户在特定owner中的角色 if (ctx.owner.obj.GetType() != typeof(Site)) { IRole roleInOwner = ctx.owner.obj.GetUserRole(ctx.viewer.obj); IList ownerRoleActions = securityTool.GetActionsByRole(roleInOwner); if (hasAction_private(ownerRoleActions, ctx)) { return(true); } } // 3、获取用户的等级 SiteRank rank = ((User)ctx.viewer.obj).Rank; if (rank.Id > 0) { actions = securityTool.GetActionsByRole(rank); if (hasAction_private(actions, ctx)) { return(true); } } // 4、是否在论坛担任角色 if (objSecurity is ForumBoard) { ModeratorService moderatorService = new ModeratorService(); if (moderatorService.IsModerator(objSecurity as ForumBoard, (User)ctx.viewer.obj)) { IList moderatorActions = securityTool.GetActionsByRole(ForumRole.Moderator); if (hasAction_private(moderatorActions, ctx)) { return(true); } } } return(false); }
public ModeratorModule(ModeratorService moderatorService, LoggingService loggingService) { this._moderatorService = moderatorService; this._log = loggingService; }
public ModeratorModule(ModeratorService service) { _service = service; }