public async Task SendAlertToAll(SandBoxMessage sandBoxMessage) { var totalUserAmount = await sandBoxDataAccessor.Count <UserAccountEntry>(); var length = Math.Round(totalUserAmount / 100.0) + 1; for (int step = 0; step < length; step++) { var msgBoxList = new List <SandBoxMessage>(); var userList = await sandBoxDataAccessor.ListAsync <UserAccountEntry>(x => x.Id != sandBoxMessage.FromUserAccountId, step * 100, 100); foreach (var user in userList) { msgBoxList.Add(new SandBoxMessage { Id = Guid.NewGuid(), CreateTime = DateTime.Now, Content = sandBoxMessage.Content, FromUserAccountId = sandBoxMessage.FromUserAccountId, MessageType = sandBoxMessage.MessageType, TimeStamp = TimeStamp.Get(), ToUserAccountId = user.Id }); } await sandBoxDataAccessor.AddRange(msgBoxList); } }
/// <summary> /// 发送消息逻辑, 如果用户不在线就记录未读 /// </summary> /// <param name="msg"></param> public async Task SendMessage(TextChatMessageViewModel msg) { var userOnline = socialMsgManager.HasOnline(msg.ToId.ToString()); var chatRelationShip = await chatLogDataAccessor.OneAsync <ChatLog>(x => x.ChatCollection.Any(c => c.UserId == msg.FromId) && x.ChatCollection.Any(c => c.UserId == msg.ToId), "ChatCollection", "ChatMessageList"); if (chatRelationShip == null) { chatRelationShip = new ChatLog { Id = Guid.NewGuid(), ChatCollection = new List <ChatCollection> { new ChatCollection { Id = Guid.NewGuid(), CreateTime = DateTime.Now, UserId = msg.FromId }, new ChatCollection { Id = Guid.NewGuid(), CreateTime = DateTime.Now, UserId = msg.ToId } } }; await chatLogDataAccessor.Add(chatRelationShip); } var msgModel = new ChatMessage(); msgModel.MessageContent = msg.Content; msgModel.TimeStamp = TimeStamp.Get(); msgModel.MsgType = MessageType.Text; msgModel.ChageLog = chatRelationShip; msgModel.FromUserId = msg.FromId; msgModel.ToUserId = msg.ToId; msgModel.CreateTime = DateTime.Now; if (userOnline) { msgModel.IsReaded = true; } else { msgModel.IsReaded = false; } await chatLogDataAccessor.Add(msgModel); //当前 var jsonSetting = new JsonSerializerSettings(); jsonSetting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; var contentJson = JsonConvert.SerializeObject(msg, jsonSetting); socialMsgManager.SendMssage(msg.ToId.ToString(), msg.Content); }
public static async Task AnalysisPost(IWebElement element, Dictionary <string, string> state, WebDriverWrapper webDriverWrapper) { var tagList = element.FindElements(By.CssSelector(".dm-tag.dm-tag-a")); var createTiem = element.FindElement(By.CssSelector(".meta-info.mb20 span")).GetAttribute("innerText"); var content = Encoding.UTF8.GetString(Encoding.Default.GetBytes(element.FindElement(By.CssSelector(".content")).GetAttribute("innerHTML"))); var postImgUrlList = element.FindElements(By.CssSelector(".album .inner-container img")); var nickName = state["nickName"]; var avatar = state["avatar"]; var userModel = GetOrSetUser(nickName, avatar); var dbContext = GetDbContext(); var postImgList = new List <PostEntryFile>(); var imgindex = 1; if (dbContext.PostEntry.Any(x => x.TextContent == content)) { return; } foreach (var item in postImgUrlList) { var oldPath = item.GetAttribute("src"); var key = "postEntryFile/" + nickName + "/" + Guid.NewGuid().ToString(); await UploadQiniu(oldPath, key); postImgList.Add(new PostEntryFile { ActualPath = "https://mioto.milbit.com/" + key, Name = key, Type = PostEntryFileType.Image, Order = imgindex, Tag = "半次元" }); imgindex++; } var postEntry = new PostEntry { Id = Guid.NewGuid(), CreateTime = DateTime.Parse(createTiem), TimeStamp = TimeStamp.Get(), TextContent = content, PostEntryFileList = postImgList, UserId = userModel.Id, PostEntryTags = new List <PostEntryTag> { new PostEntryTag { CreateTime = DateTime.Now, Id = Guid.NewGuid(), Name = "Coser" } } }; dbContext.PostEntry.Add(postEntry); await dbContext.SaveChangesAsync(); }
public static void UpdateDAT() { var dbContext = GetDbContext(); var zeroPostEntry = dbContext.PostEntry; foreach (var item in zeroPostEntry) { item.TimeStamp = TimeStamp.Get(item.CreateTime); } dbContext.SaveChanges(); }
public async Task SetPostEntryComments(Guid userId, Guid?postId, string text, Guid?ParentCommentId) { await postEntryDataAccessor.Add(new PostEntryComments { Id = Guid.NewGuid(), UserAccountId = userId, Content = text, CreateTime = DateTime.Now, TimeStamp = TimeStamp.Get(), PostEntryId = postId, ParentCommentId = ParentCommentId }); }
void Reply(int idx) { if (!userReplied) { // Set the reply reply.timeReply = TimeStamp.Get(); reply.idReply = qst.idPossibleReplies[idx]; reply.success = qst.idCorrectAnswer == qst.idPossibleReplies[idx]; // Get idx of correct answer int idxCorrectAnswer = qst.idPossibleReplies.IndexOf(qst.idCorrectAnswer); // Stop glowing effet for new question if (qst.newQuestion) { Anim(replyButton[idxCorrectAnswer], glow: false); } // Disable the buttons for (int i = 0; i < replyButton.Count; i++) { replyButton[i].interactable = false; replyButton[i].image.color = colorDisabled; } // Put in green the correct answer replyButton[idxCorrectAnswer].image.color = colorCorrect; // Put in red the wrong answer if applicable if (!reply.success) { replyButton[idx].image.color = colorIncorrect; replyButton[idxCorrectAnswer].interactable = true; Anim(replyButton[idxCorrectAnswer], glow: true); userReplied = true; } else { Invoke("UserReplied", timeDisplayingCorrect); } } else { replyButton[idx].interactable = false; UserReplied(); } }
public async Task CreateContentCommentExtPostEntry(Comment comment) { var contentModel = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == comment.ContentEntry.Id, "Category"); var topicTxt = contentModel.Category.Name + "|" + contentModel.Title; //设置话题为漫画名 var topic = new PostEntryTopic() { CreateTime = DateTime.Now, Id = Guid.NewGuid(), Text = topicTxt, PosterId = comment.UserAccount.Id }; var topicExt = new ContentExtPostEntryTopic() { Id = Guid.NewGuid(), TopicText = topicTxt, LinkId = contentModel.Id, LinkType = "category" }; //评论 var postentryModel = new PostEntry() { Id = Guid.NewGuid(), CreateTime = DateTime.Now, PostEntryTopic = topicTxt, UserId = comment.UserAccount.Id, TimeStamp = TimeStamp.Get(), TextContent = comment.Content }; //目前是一条漫画评论对应一个话题, 为防止以后出现多话题, 保留此表 var contentPostentryMapping = new ContentPostEntryMapping() { Id = Guid.NewGuid(), ContentId = contentModel.Id, PostEntryId = postentryModel.Id, CreateTime = DateTime.Now }; await ContentAccessor.Add(topic); await ContentAccessor.Add(topicExt); await ContentAccessor.Add(postentryModel); await ContentAccessor.Add(contentPostentryMapping); }
public async Task <IActionResult> JsApiPackage(string url) { string AppId = configuration["Ciyuanya:Wx:WebAppId"];//"wx568e40eaad7d6736"; string AppSecret = configuration["Ciyuanya:Wx:WebSecret"]; url = Uri.UnescapeDataString(url.Trim()); string timestamp = TimeStamp.Get().ToString(); //生成签名的时间戳 string nonceStr = WxPayApi.GenerateNonceStr(); //生成签名的随机串 //string url = url;//当前的地址 string jsapi_ticket = ""; //ticket 缓存7200秒 var jsapi_ticket_cache = await distributedCache.GetValue <string>("jsapi_ticket"); if (jsapi_ticket_cache != null && !jsapi_ticket_cache.IsExpired) { jsapi_ticket = jsapi_ticket_cache.Value; } else { var jsapi_ticket_jstr = await jsapi_Ticket.Get();//{"errcode":0,"errmsg":"ok","ticket":"HoagFKDcsGMVCIY2vOjf9j2_hOCCXe2SnD-zgYvJabyCVaPRPj2H8mQ0E3G_WEDY_Jj4YtnRnU1iELVemAwt2g","expires_in":7200} var jobj = Newtonsoft.Json.Linq.JObject.Parse(jsapi_ticket_jstr); jsapi_ticket = jobj["ticket"].ToString(); await distributedCache.SetValue(new RedisDocument <string> { ExpireTime = DateTime.Now.AddSeconds(7200), Key = "jsapi_ticket", SetTime = DateTime.Now, Value = jsapi_ticket }); } string[] ArrayList = { "jsapi_ticket=" + jsapi_ticket, "timestamp=" + timestamp, "noncestr=" + nonceStr, "url=" + url }; Array.Sort(ArrayList); string signature = string.Join("&", ArrayList); // signature = FormsAuthentication.HashPasswordForStoringInConfigFile(signature, "SHA1").ToLower(); var sha1 = System.Security.Cryptography.SHA1.Create(); byte[] buffer = Encoding.UTF8.GetBytes(signature); var hash = sha1.ComputeHash(buffer); //var hashString = Convert.ToBase64String(hash).ToLower(); var hashString = BitConverter.ToString(hash).Replace("-", "").ToLower(); //string addrSign = FormsAuthentication.HashPasswordForStoringInConfigFile(param, "SHA1"); return(Content("{\"appId\":\"" + AppId + "\", \"timestamp\":" + timestamp + ",\"nonceStr\":\"" + nonceStr + "\",\"signature\":\"" + hashString + "\"}", "application/Json")); }
// ----------------------------------- // void UserStart() { Debug.Log("[UIController] User clicked on starting button."); startButton.interactable = false; Anim(startButton, visible: false); Anim(homeScreen, visible: false); // Set time step reply.timeReply = TimeStamp.Get(); // Get settings reply.registerReplies = registerReplies.isOn; reply.nIteration = nIteration; reply.teacher = teacher; gameController.UserReplied(reply); }
public async Task <IActionResult> PostEntryList(long startTimeStamp, long endTimeStamp, int skipCount, int pageSize = 10) { var userIdStr = User.Claims?.FirstOrDefault(x => x.Type == "OryxUser")?.Value; Guid?userId; if (!string.IsNullOrEmpty(userIdStr)) { userId = Guid.Parse(userIdStr); } else { userId = null; } startTimeStamp = TimeStamp.Get(); var apiMsg = await ApiMessage.Wrap(async() => { return(await postEntryBusiness.GetPostEntryList(userId, startTimeStamp, endTimeStamp, skipCount, pageSize)); }); return(Json(apiMsg)); }
public async Task <IActionResult> CreatEntry([FromBody] PostEntry model) { var userIdStr = User.Claims.FirstOrDefault(x => x.Type == "OryxUser").Value; if (string.IsNullOrEmpty(userIdStr)) { return(Content("Empty User")); } model.UserId = Guid.Parse(userIdStr); if (model != null) { model.CreateTime = DateTime.Now; model.TimeStamp = TimeStamp.Get(); } var apiMsg = await ApiMessage.Wrap(async() => { await postEntryBusiness.CreatePostEntry(model); }); return(Json(apiMsg)); }
// -------------------------------- // public void SetQuestion(Question question) { if (question.t != -1) { userReplied = false; // Update question object qst = question; // Update question display questionText.text = qst.question; Anim(questionText); // Update progression bar Anim(progressionTool); UpdateProgression(qst.t, qst.nIteration); // Update reply button if (!qst.newQuestion) { for (int i = 0; i < replyButton.Count; i++) { replyText[i].text = qst.possibleReplies[i]; replyButton[i].image.color = colorNeutral; replyButton[i].interactable = true; Anim(replyButton[i], glow: false); } } else { // Get idx of correct answer int idxCorrectAnswer = qst.idPossibleReplies.IndexOf(qst.idCorrectAnswer); for (int i = 0; i < replyButton.Count; i++) { replyText[i].text = qst.possibleReplies[i]; if (i == idxCorrectAnswer) { replyButton[i].image.color = colorCorrect; replyButton[i].interactable = true; Anim(replyButton[i], glow: true); } else { replyButton[i].image.color = colorNeutral; replyButton[i].interactable = false; Anim(replyButton[i], glow: false); } } } // Specific if new question // Prepare sending of the reply to the server reply.userId = qst.userId; reply.t = qst.t; reply.idQuestion = qst.idQuestion; reply.idPossibleReplies = qst.idPossibleReplies; reply.timeDisplay = TimeStamp.Get(); } else { Anim(endScreen); } }
public async Task CreateCategoryCommentExtPostEntry(CategoryComment comment) { var categoryModel = await ContentAccessor.OneAsync <Categories>(x => x.Status != ContentStatus.Close && x.Id == comment.CategoryId); //设置话题为漫画名 var topic = new PostEntryTopic() { CreateTime = DateTime.Now, Id = Guid.NewGuid(), Text = categoryModel.Name, PosterId = comment.UserAccountId }; var topicExt = new ContentExtPostEntryTopic() { Id = Guid.NewGuid(), TopicText = categoryModel.Name, LinkId = categoryModel.Id, LinkType = "category" }; //评论 var postentryModel = new PostEntry() { Id = Guid.NewGuid(), CreateTime = DateTime.Now, PostEntryTopic = categoryModel.Name, UserId = comment.UserAccountId, TimeStamp = TimeStamp.Get(), TextContent = comment.Content, }; //目前是一条漫画评论对应一个话题, 为防止以后出现多话题, 保留此表 var categoryPostentryMapping = new CategoryPostEntryMapping() { Id = Guid.NewGuid(), CategoryId = categoryModel.Id, PostEntryId = postentryModel.Id, CreateTime = DateTime.Now }; await ContentAccessor.Add(topic); await ContentAccessor.Add(topicExt); await ContentAccessor.Add(postentryModel); await ContentAccessor.Add(categoryPostentryMapping); var sandBoxMsg = new SandBoxMessage() { Content = $"您在漫画{topic}的回复,收到了新的评论.", CreateTime = DateTime.Now, FromUserAccountId = comment.UserAccountId, ToUserAccountId = postentryModel.UserId, Id = Guid.NewGuid(), IsRead = false, MessageType = SandBoxMessageType.PostEntryComment, TimeStamp = TimeStamp.Get(), RecieveToken = "" }; await sandBoxBusiness.SendAlertTo(sandBoxMsg); }