/// <summary> /// Get a list of <c ref="VenueLocations" />. /// </summary> /// <returns>Json formatted results.</returns> // GET Api/Typeahead/VenueLocations public NewtonsoftJsonResult VenueLocations() { const string cacheKey = "Typeahead:VenueLocations"; var result = (NewtonsoftJsonResult)CacheHandler.Get(cacheKey); if (result == null) { result = new NewtonsoftJsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = db.VenueLocations.Select(x => new TypeAheadVenueLocationResult { VenueLocationId = x.VenueLocationId, LocationName = x.LocationName, ParentVenueLocation = x.ParentVenueLocation.LocationName }) .OrderBy( x => !x.ParentVenueLocation.Equals("UNITED KINGDOM", StringComparison.CurrentCultureIgnoreCase)) .ThenBy(x => x.LocationName) .ThenBy(x => x.ParentVenueLocation) .ToArray() }; CacheHandler.Add(cacheKey, result, new TimeSpan(0, 5, 0)); } return(result); }
private void SetCacheLevel(string AccountName, int AccountID, string channelId) { try { object value = null; try { value = CacheHandler.Get(AccountName + "_" + channelId); } catch (Exception ex) { value = null; } bool _Enable = true; if (value == null) { //AbstractDAOFactory.Instance().CreateAccountInfoDao().SP_Chat_Check(AccountID, out _Enable); NLogManager.LogMessage(string.Format(">>> SetCacheLevel AccountName: {0} | AccountID: {1} | Enable: {2}", AccountName, AccountID, _Enable)); CacheHandler.Add(AccountName + "_" + channelId, _Enable == true ? 1 : 0); } } catch (Exception ex) { NLogManager.LogMessage(">>> Exception SetCacheLevel:" + ex.Message); } }
public void Utilities_CacheHandler_IfDataWithKeyWasAdded_ExistMethodReturnsTrue() { var key = GetRandomKey(); CacheHandler.Add(new object(), key, null); var result = CacheHandler.Exists(key); Assert.IsTrue(result); }
public void Utilities_CacheHandler_IfDataWithKeyWasAddedAndNotNull_GetWithCacheMethodReturnsData <T>(T data) { var key = GetRandomKey(); CacheHandler.Add(data, key, null); var result = CacheHandler.Get <T>(null, key); Assert.AreEqual(data, result); }
public void Utilities_CacheHandler_IfAddedItemsWereDeleted_ExistMethodReturnsFalseForAllDeletedItems() { var keys = new[] { GetRandomKey(), GetRandomKey() }; CacheHandler.Add(new object(), keys[0], null); CacheHandler.Add(new object(), keys[1], null); CacheHandler.Delete(It.IsAny <bool>(), keys); Assert.IsFalse(CacheHandler.Exists(keys[0])); Assert.IsFalse(CacheHandler.Exists(keys[1])); }
public BigJackpotInfo GetBigJackpotInfo() { var bigJackpotInfo = (BigJackpotInfo)CacheHandler.Get("minipoker_BigJackpotInfo"); if (bigJackpotInfo == null) { bigJackpotInfo = AbstractDAOFactory.Instance().CreateMiniPokerBigJackpotDAO().GetBigJackpotInfo(); CacheHandler.Add("minipoker_BigJackpotInfo", bigJackpotInfo, 10); } return(bigJackpotInfo); }
public List <BigJackpotHistory> GetBigJackpotHistory() { List <BigJackpotHistory> bigJackpotHis = (List <BigJackpotHistory>)CacheHandler.Get("minipoker_BigJackpotHis"); if (bigJackpotHis == null) { bigJackpotHis = AbstractDAOFactory.Instance().CreateMiniPokerBigJackpotDAO().GetBigJackpotHistory(); CacheHandler.Add("minipoker_BigJackpotHis", bigJackpotHis, 30); } return(bigJackpotHis); }
private static void LoadAccountBlock() { try { string key = "ACCOUNTBLOCK_FILE"; if (CacheHandler.Get(key) == null) { XDocument xmldoc = XDocument.Load(ACCOUNTBLOCK_FILE); IEnumerable <XElement> q = from xe in xmldoc.Descendants("key") select xe; var dt = new DataTable(); dt.Columns.Add("key"); dt.Columns.Add("name"); dt.Columns.Add("accountid"); dt.Columns.Add("reasonblock"); dt.Columns.Add("namereasonblock"); dt.Columns.Add("typeblock"); dt.Columns.Add("endtimeblock"); dt.Columns.Add("createDate"); foreach (XElement xe in q) { DataRow row = dt.NewRow(); row[0] = xe.Attribute("key").Value; row[1] = xe.Attribute("name").Value; row[2] = xe.Attribute("accountid").Value; row[3] = xe.Attribute("reasonblock").Value; row[4] = xe.Attribute("namereasonblock").Value; row[5] = xe.Attribute("typeblock").Value; row[6] = xe.Attribute("endtimeblock").Value; row[7] = xe.Attribute("createDate").Value; dt.Rows.Add(row); // Thêm dòng mới vào dtb } List <ListAccountBlock> Data = ListAccountBlock = dt.AsEnumerable().Select(m => new ListAccountBlock() { key = m.Field <string>("key"), name = m.Field <string>("name"), accountid = m.Field <string>("accountid"), reasonblock = m.Field <string>("reasonblock"), namereasonblock = m.Field <string>("namereasonblock"), typeblock = m.Field <string>("typeblock"), endtimeblock = m.Field <string>("endtimeblock"), createDate = m.Field <string>("createDate") }).ToList(); CacheHandler.Add(key, Data); } else { ListAccountBlock = (List <ListAccountBlock>)CacheHandler.Get(key); } } catch (Exception ex) { NLogManager.LogMessage(">> Ex LoadAccountBlock:" + ex.Message); } }
public List <Notification> GetNotification() { List <Notification> cached = (List <Notification>)CacheHandler.Get("Notification"); if (cached != null) { return(cached); } cached = AbstractDAOFactory.Instance().CreateGateDAO().GetNotification(""); CacheHandler.Add("Notification", cached, 180); return(cached); }
/// <summary> /// Get the user types. /// </summary> /// <param name="db"> /// The db. /// </param> /// <returns> /// The <see cref="IEnumerable" />. /// </returns> private static List <SelectListItem> GetUserTypes(ProviderPortalEntities db) { var items = (List <SelectListItem>)CacheHandler.Get(UserTypesCacheKey); if (items == null) { items = new SelectList(db.ProviderUserTypes.OrderBy(x => x.ProviderUserTypeId), "ProviderUserTypeId", "ProviderUserTypeName").ToList(); CacheHandler.Add(UserTypesCacheKey, items); } return(items); }
public List <Jackpot> GetAllJackpot() { List <Jackpot> jackpotList = (List <Jackpot>)CacheHandler.Get("Jackpot_JackpotList"); if (jackpotList == null) { jackpotList = AbstractDAOFactory.Instance().CreateJackpotDAO().GetAllJackpot(); if (jackpotList != null) { CacheHandler.Add("Jackpot_JackpotList", jackpotList, 5); } } return(jackpotList); }
public ActionResult GetListedPage() { Session["calledPage"] = "G"; List <CompanyEntity> TopVotedCompanyList = new List <CompanyEntity>(); if (CacheHandler.Exists("TopVoteCompaniesList")) { CacheHandler.Get("TopVoteCompaniesList", out TopVotedCompanyList); } else { TopVotedCompanyList = new CompanyService().GetTopVoteCompanies(); CacheHandler.Add(TopVotedCompanyList, "TopVoteCompaniesList"); } return(View("~/Views/Login/GetListed.cshtml", TopVotedCompanyList)); }
/// <summary> /// Get the user roles. /// </summary> /// <param name="db"> /// The db. /// </param> /// <param name="roles"> /// The roles. /// </param> /// <returns> /// The <see cref="IEnumerable" />. /// </returns> private static List <AspNetRole> GetAspNetRoles(ProviderPortalEntities db, IEnumerable <SelectListItem> roles) { string contextRolesKey = GetContextRolesKey(); string userTypeRolesKey = GetUserTypeRolesKey(); string cacheKey = String.Format(AspNetRolesCacheKey, contextRolesKey, userTypeRolesKey); var items = (List <AspNetRole>)CacheHandler.Get(cacheKey); if (items == null) { IEnumerable <string> roleNames = roles.Select(x => x.Value); items = db.AspNetRoles.Where(x => roleNames.Contains(x.Name)).OrderBy(x => x.Name).ToList(); CacheHandler.Add(cacheKey, items); } return(items); }
public ActionResult Company() { try { Session["calledPage"] = "C"; string companyName = Convert.ToString(Request.Url.Segments[2]).Trim(); CompanyViewModel companyViewModel = null; if (companyName != string.Empty) { Session["CompanyName"] = companyName; } if (CacheHandler.Exists(companyName.ToLower())) { companyViewModel = new CompanyViewModel(); CacheHandler.Get(companyName.ToLower(), out companyViewModel); } else { CompanyFilterEntity companyFilter = new CompanyFilterEntity { CompanyName = companyName.Replace("-", " "), MinRate = 0, MaxRate = 0, MinEmployee = 0, MaxEmployee = 0, SortBy = "DESC", FocusAreaID = 0, Location = "0", SubFocusArea = "0", UserID = Convert.ToInt32(Session["UserID"]), PageNo = 1, PageSize = 10, OrderColumn = 1 }; companyViewModel = new CompanyService().GetCompany(companyFilter); CacheHandler.Add(companyViewModel, companyName); } companyViewModel.WebBaseURL = _webBaseURL; return(View(companyViewModel)); } catch (Exception) { return(null); } }
public List <BigWinPlayers> GetBigWinPlayers() { List <BigWinPlayers> cached = (List <BigWinPlayers>)CacheHandler.Get("BigWinPlayersList"); if (cached != null) { return(cached); } //var test = AbstractDAOFactory.Instance().CreateGateDAO().GetNotification(""); cached = AbstractDAOFactory.Instance().CreateGateDAO().GeBigWinPlayersByID(0, 15); List <BigWinPlayers> list2 = AbstractDAOFactory.Instance().CreateGateDAO().GeBigWinPlayersByID(5, 3); cached.AddRange(list2); RandomUtil.Shuffle <BigWinPlayers>(cached); CacheHandler.Add("BigWinPlayersList", cached, 30); return(cached); }
/// <summary> /// Get a list of <c ref="QualficationTitles" />. /// </summary> /// <returns>Json formatted results.</returns> // GET Api/Typeahead/QualificationTitles public NewtonsoftJsonResult QualificationTitles() { const string cacheKey = "Typeahead:QualificationTitles"; var result = (NewtonsoftJsonResult)CacheHandler.Get(cacheKey); if (result == null) { result = new NewtonsoftJsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = db.QualificationTitles.Select(x => new TypeAheadQualificationTitleResult { QualificationTitle = x.QualficationTitle }).ToArray() }; CacheHandler.Add(cacheKey, result, new TimeSpan(0, 5, 0)); } return(result); }
/// <summary> /// Get a list of <c ref="CourseLanguages" />. /// </summary> /// <returns>Json formatted results.</returns> // GET Api/Typeahead/CourseLanguages public NewtonsoftJsonResult CourseLanguages() { const string cacheKey = "Typeahead:CourseLanguages"; var result = (NewtonsoftJsonResult)CacheHandler.Get(cacheKey); if (result == null) { result = new NewtonsoftJsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = db.CourseLanguages.OrderBy(x => x.DisplayOrder).Select(x => new TypeAheadCourseLanguageResult { Language = x.Language }).ToArray() }; CacheHandler.Add(cacheKey, result, new TimeSpan(0, 5, 0)); } return(result); }
public ActionResult Softwares() { try { Session["calledPage"] = "N"; string softwareName = Convert.ToString(Request.Url.Segments[2]).Trim(); SoftwareViewModel softwareViewModel = null; if (softwareName != string.Empty) { Session["SoftwareName"] = softwareName; } if (CacheHandler.Exists(softwareName.ToLower())) { softwareViewModel = new SoftwareViewModel(); CacheHandler.Get(softwareName.ToLower(), out softwareViewModel); } else { SoftwareFilterEntity companyFilter = new SoftwareFilterEntity { SoftwareName = softwareName.Replace("-", " "), SortBy = "DESC", SoftwareCategoryId = 0, UserID = Convert.ToInt32(Session["UserID"]), PageNo = 1, PageSize = 10, OrderColumn = 1 }; softwareViewModel = new SoftwareService().GetSoftware(companyFilter); CacheHandler.Add(softwareViewModel, softwareName); } softwareViewModel.WebBaseUrl = _webBaseURL; return(View(softwareViewModel)); } catch (Exception) { return(null); } }
/// <summary> /// Get a list of <c ref="LearningAimAwardOrgs" />. /// </summary> /// <returns>Json formatted results.</returns> // GET Api/Typeahead/AwardingOrganisations public NewtonsoftJsonResult AwardingOrganisations() { const string cacheKey = "Typeahead:AwardingOrgnisations"; var result = (NewtonsoftJsonResult)CacheHandler.Get(cacheKey); if (result == null) { result = new NewtonsoftJsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = db.LearningAimAwardOrgs.Select(x => new TypeAheadAwardingOrganisationResult { LearningAimAwardOrgCode = x.LearningAimAwardOrgCode, AwardOrgName = x.AwardOrgName }).ToArray() }; CacheHandler.Add(cacheKey, result, new TimeSpan(0, 5, 0)); } return(result); }
/// <summary> /// Get a list of <c ref="LearnDirectClassifications" />. /// </summary> /// <returns>Json formatted results.</returns> // GET Api/Typeahead/LearnDirectClassifications public NewtonsoftJsonResult LearnDirectClassifications() { const string cacheKey = "Typeahead:LearnDirectClassifications"; var result = (NewtonsoftJsonResult)CacheHandler.Get(cacheKey); if (result == null) { result = new NewtonsoftJsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = db.LearnDirectClassifications.Select(x => new TypeAheadLearnDirectClassificationResult { LearnDirectClassificationRef = x.LearnDirectClassificationRef, LearnDirectClassSystemCodeDesc = x.LearnDirectClassSystemCodeDesc + " (" + x.LearnDirectClassificationRef + ")" }).ToArray() }; CacheHandler.Add(cacheKey, result, new TimeSpan(0, 5, 0)); } return(result); }
private void GetCategoryHeadLine(string urlFocusAreaName, CompanyViewModel companyViewModel, string Country, string urlSubFocusAreaName) { Country = Country == "0" ? "globe" : Country; Country = Country.ToUpper() == "UNITED STATES" ? "USA" : Country; int year = DateTime.Now.Year; string headLine = "Top ";//Country == "globe" ? "Top " : "Top 10+ "; string cachename = urlFocusAreaName.Trim() + urlSubFocusAreaName.Trim(); CategoryMetaTagsDetails metaTagObj; if (CacheHandler.Exists(cachename)) { metaTagObj = new CategoryMetaTagsDetails(); CacheHandler.Get(cachename, out metaTagObj); } else { metaTagObj = new CategoryMetaTagsDetails(); metaTagObj = new CompanyService().GetCategoryMetaTags(urlFocusAreaName.Trim(), urlSubFocusAreaName.Trim()); CacheHandler.Add(metaTagObj, cachename); } //if(Country.ToLower() == "chicago" && urlFocusAreaName.Trim() == "mobile-application-developers") //{ // companyViewModel.CategoryHeadLine = "MOBILE APP DEVELOPERS IN "+ Country.ToUpper() + " "; // companyViewModel.CategoryReviewHeadLine = "MOBILE APP DEVELOPERS"; // companyViewModel.Title = "Top App Developers in "+ Country + " - 2021 Reviews | Upvotes.co"; // companyViewModel.IsSpecific = true; //} //else //{ companyViewModel.IsSpecific = true; companyViewModel.CategoryHeadLine = metaTagObj.Title.ToUpper() + (Country.ToUpper() != "GLOBE" ? Country.ToUpper() : ""); companyViewModel.CategoryReviewHeadLine = metaTagObj.Title.Replace(" in ", " ").ToUpper(); companyViewModel.Title = headLine + metaTagObj.Title + Country + "- " + year + " | upvotes.co"; //} companyViewModel.MetaTag = CategoryMetaTags(metaTagObj, Country); }
private void GetSoftwareCategoryHeadLine(string urlSoftwareCategory, SoftwareViewModel softwareViewModel) { int year = DateTime.Now.Year; string cachename = urlSoftwareCategory.Trim(); CategoryMetaTagsDetails metaTagObj; if (CacheHandler.Exists(cachename)) { metaTagObj = new CategoryMetaTagsDetails(); CacheHandler.Get(cachename, out metaTagObj); } else { metaTagObj = new CategoryMetaTagsDetails(); metaTagObj = new SoftwareService().GetSoftwareCategoryMetaTags(urlSoftwareCategory.Trim()); CacheHandler.Add(metaTagObj, cachename); } softwareViewModel.CategoryHeadLine = metaTagObj.Title.ToUpper(); softwareViewModel.Title = metaTagObj.TwitterTitle.Replace("{Year}", year.ToString()); softwareViewModel.MetaTag = SoftwareCategoryMetaTags(metaTagObj); }
/// <summary> /// Get a list of <c ref="StandardsAndFrameworks" />. /// </summary> /// <returns>Json formatted results.</returns> // GET Api/Typeahead/StandardsAndFrameworks public NewtonsoftJsonResult StandardsAndFrameworks() { const string cacheKey = "Typeahead:StandardsAndFrameworks"; var result = (NewtonsoftJsonResult)CacheHandler.Get(cacheKey); if (result == null) { var frameworks = db.Frameworks.Where(x => x.RecordStatusId == (int)Constants.RecordStatus.Live) .ToList() .Select(x => new { Id = "F" + x.FrameworkCode + "-" + x.ProgType + "-" + x.PathwayCode, Name = x.Details(), Url = (string)null }).ToList(); var standards = db.Standards.Where(x => x.RecordStatusId == (int)Constants.RecordStatus.Live) .ToList() .Select(x => new { Id = "S" + x.StandardCode + "-" + x.Version, Name = x.Details(), Url = x.URLLink }); result = new NewtonsoftJsonResult { // [FrameworkCode], [ProgType], [PathwayCode] // [StandardCode], [Version] JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = frameworks.Union(standards).OrderBy(x => x.Name) }; CacheHandler.Add(cacheKey, result, new TimeSpan(0, 5, 0)); } return(result); }
private static void LoadKeywordReplace() { try { string key = "KEYWORDREPLACE_FILE"; if (CacheHandler.Get(key) == null) { XDocument xmldoc = XDocument.Load(KEYWORDREPLACE_FILE); IEnumerable <XElement> q = from xe in xmldoc.Descendants("key") select xe; var dt = new DataTable(); dt.Columns.Add("text"); dt.Columns.Add("replace"); foreach (XElement xe in q) { DataRow row = dt.NewRow(); row[0] = xe.Attribute("text").Value; row[1] = xe.Attribute("replace").Value; dt.Rows.Add(row); // Thêm dòng mới vào dtb } List <ObjKeywordReplace> Data = dt.AsEnumerable().Select(m => new ObjKeywordReplace() { text = m.Field <string>("text"), replace = m.Field <string>("replace"), }).ToList(); KeywordReplace = Data; CacheHandler.Add(key, KeywordReplace); } else { KeywordReplace = (List <ObjKeywordReplace>)CacheHandler.Get(key); } } catch (Exception ex) { NLogManager.PublishException(ex); } }
/// <summary> /// Get the available AspNetRoles that can be created by the current user in the current context. /// </summary> /// <returns>The available roles.</returns> private static List <SelectListItem> GetRoles() { string contextRolesKey = GetContextRolesKey(); string userTypeRolesKey = GetUserTypeRolesKey(); string cacheKey = String.Format(RolesCacheKey, contextRolesKey, userTypeRolesKey); var items = (List <SelectListItem>)CacheHandler.Get(cacheKey); if (items == null) { List <string> contextRoles = String.IsNullOrEmpty(contextRolesKey) ? new List <string>() : Constants.ConfigSettings[contextRolesKey].Value.ToString().Split(';').ToList(); List <string> userTypeRoles = String.IsNullOrEmpty(userTypeRolesKey) ? new List <string>() : Constants.ConfigSettings[userTypeRolesKey].Value.ToString().Split(';').ToList(); items = contextRoles.Intersect(userTypeRoles).OrderBy(x => x) .Select(x => new SelectListItem { Text = x.Trim(), Value = x.Trim() }).ToList(); if (items.Count() > 1) { items.Insert(0, new SelectListItem { Value = string.Empty, Text = AppGlobal.Language.GetText("Account_AddUser_SelectRole", "Select a role") }); } CacheHandler.Add(cacheKey, items); } return(items); }
private static void LoadBlackList() { string key = "BLACKLIST_FILE"; if (CacheHandler.Get(key) == null) { XDocument xmldoc = XDocument.Load(BLACKLIST_FILE); IEnumerable <XElement> q = from xe in xmldoc.Descendants("key") select xe; var dt = new DataTable(); dt.Columns.Add("text"); foreach (XElement xe in q) { DataRow row = dt.NewRow(); row[0] = xe.Attribute("text").Value; dt.Rows.Add(row); // Thêm dòng mới vào dtb } BadWords = dt.AsEnumerable().Select(r => r.Field <string>("text")).ToList(); CacheHandler.Add(key, BadWords); } else { BadWords = (List <string>)CacheHandler.Get(key); } }
public DataCacheItemVersion Add(string key, object value) { return(_cacheHandler.Add(key, value)); }
/// <summary> /// Gửi message chat /// </summary> /// <param name="hubCallerContext"></param> /// <param name="message"></param> /// <param name="channelId"></param> /// <returns></returns> public bool SendMessage(HubCallerContext hubCallerContext, string message, string channelId) { NLogManager.LogMessage(">>Start SendMessage"); try { if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["CloseChatServer"].ToString())) { return(false); } if (MAX_MESSAGE_LENGTH < message.Length) { broadcastMessage(hubCallerContext.ConnectionId, string.Format("Nội dung chát không quá {0} kí tự!", MAX_MESSAGE_LENGTH)); return(false); } //NLogManager.LogMessage(string.Format(">>Statr chat:{0}", channelId)); LoadListAdmin(); LoadTimeSendMessage(); long accountId = GetAccountId(hubCallerContext); if (accountId < 1) { NLogManager.LogMessage(string.Format("Sending message: not authenticated accountId: {0} - channel: {1} - content={2}", accountId, channelId, message)); return(false); } ChatChannel chatChannel = GetChannel(channelId); if (chatChannel == null) { NLogManager.LogMessage(string.Format("Sending message: accountId: {0} - not has channel: {1} - content={2}", accountId, channelId, message)); return(false); } if (message.IndexOf('/') == 0) { string notice; bool ret = RunCommand(message, out notice); if (!string.IsNullOrEmpty(notice)) { Instance.ClientSystemMessage(channelId, notice, 0); } if (ret) { NLogManager.LogMessage(string.Format("Account: {0} - run command: {1}", accountId, message)); return(true); } } ChatUser chatUser = GetUser(accountId); if (chatUser == null) { NLogManager.LogMessage(string.Format("Sending message: not chat user: {0} in channel={1} - content={2}", accountId, channelId, message)); return(false); } if (CMSAllGame != "1") { if (!ADMINS.Contains(chatUser.UserName)) { try { object level = CacheHandler.Get(chatUser.UserName + "_" + channelId); if (level == null) { SetCacheLevel(chatUser.UserName, (int)chatUser.AccountID, channelId); } else if (int.Parse(level.ToString()) == 0) { NLogManager.LogMessage(string.Format("Tổng đặt trong 7 ngày của bạn chưa đủ 2.000.000 Sao để tham gia chat!: {0} ", chatUser.UserName)); broadcastMessage(hubCallerContext.ConnectionId, string.Format("Tổng đặt trong 7 ngày của bạn chưa đủ 2.000.000 Sao để tham gia chat!")); return(false); } } catch (Exception ex) { NLogManager.LogMessage(string.Format("{0} Null Cache level", chatUser.UserName)); SetCacheLevel(chatUser.UserName, (int)chatUser.AccountID, channelId); } } } string filteredMessage = message; string tempFilteredMessage = message; bool flag = false; //WaitCallback callBack = new WaitCallback(InsertChat); //var chatchat = new Insert_Chat(); //chatchat.AccountID = int.Parse(chatUser.AccountID.ToString()); //chatchat.UserName = string.Format("{0}({1})", chatUser.UserName, chatUser.NickName); //chatchat.channelId = channelId; //chatchat.filteredMessage = filteredMessage; //ThreadPool.QueueUserWorkItem(callBack, chatchat); //khong phai admin thi loc bad link if (!ADMINS.Contains(chatUser.UserName)) { ChatFilter.RemoveBadLinks(tempFilteredMessage, out flag); } //Check thời gian chát theo quy định if (!ADMINS.Contains(chatUser.UserName)) { try { object value = CacheHandler.Get(chatUser.UserName); if (value == null) { CacheHandler.Add(chatUser.UserName, DateTime.Now.ToString()); } else { if (DateTime.Now != DateTime.Parse(value.ToString())) { var lastTime = (DateTime.Now - DateTime.Parse(value.ToString())).TotalSeconds; var a = MIN_MESSAGE_TIME_SECOND; if (lastTime < int.Parse(MIN_MESSAGE_TIME_SECOND)) { broadcastMessage(hubCallerContext.ConnectionId, string.Format("Chưa hết thời gian chờ {0}s, t/g chờ còn {1}s", MIN_MESSAGE_TIME_SECOND, System.Math.Round((int.Parse(MIN_MESSAGE_TIME_SECOND) - lastTime), 2))); return(false); } } CacheHandler.Add(chatUser.UserName, DateTime.Now.ToString()); } } catch (Exception ex) { NLogManager.LogMessage(string.Format("{0} Null Cache TimeChat", chatUser.UserName)); CacheHandler.Add(chatUser.UserName, DateTime.Now.ToString()); } } if (CheckBanUsers(chatUser.UserName)) { NLogManager.LogMessage(string.Format(">> {0} - Tài khoản đang bị Block! ", chatUser.UserName)); broadcastMessage(hubCallerContext.ConnectionId, ReturnCheckBanUsers(chatUser.UserName)); return(false); } //nếu nội dung chat có bad links thì block gói tin và ghi log if (flag) { chatUser.CountBadLinks += 1; filteredMessage = "***"; if (chatUser.CountBadLinks > 5) { ChatFilter.BanUser(chatUser.UserName); } NLogManager.LogMessage(string.Format("User sent bad link: accountId={0}, username={1} - channelId={2} - content={3} - \n\rAgent: {4}", chatUser.AccountID, chatUser.UserName, channelId, message, chatUser.UserAgent)); } else { //khong phai admin thi loc bad word if (!ADMINS.Contains(chatUser.UserName)) { filteredMessage = ChatFilter.RemoveBadWords(message, out flag); } NLogManager.LogMessage(flag ? string.Format( "User sent bad word: accountId={0}, username={1} - channelId={2} - content={3}", chatUser.AccountID, chatUser.UserName, channelId, message) : string.Format("User sent message: accountId={0}, username={1} - channelId={2} - content={3}", chatUser.AccountID, chatUser.UserName, channelId, message)); } //khong phai admin thi loc bad word if (!ADMINS.Contains(chatUser.UserName)) { filteredMessage = RemoveBadWords(message, out flag); } //Thay thế từ khóa if (!ADMINS.Contains(chatUser.UserName)) { filteredMessage = ReplaceKeyword(filteredMessage); } //admin thì text chat màu đỏ ChatMessage chatMessage = new ChatMessage(channelId, chatUser.AccountID, !ADMINS.Contains(chatUser.UserName) ? chatUser.NickName : string.Format("<span style='color:red; font-weight:bold'>ADMIN ({0})</span>", chatUser.NickName), !ADMINS.Contains(chatUser.UserName) ? filteredMessage : string.Format("{0}", filteredMessage)); bool canSend; if (!ADMINS.Contains(chatUser.UserName)) { canSend = chatChannel.AddMessage(chatMessage); } else { canSend = chatChannel.AddMessageAdmin(chatMessage); } if (canSend) { canSend = chatUser.AddMessage(channelId, chatMessage); } if (canSend) { ClientReceiveMessage(chatMessage); return(true); } } catch (Exception ex) { NLogManager.PublishException(ex); } NLogManager.LogMessage(string.Format(">>Gửi tin nhắn không thành công! ")); return(false); }