private void ManageGoOnLine() { string userName = socketContext.GetJsonValue("userName"); ManageInfo clientInfo = new ManageInfo() { userName = userName, onLineTime = DateTime.Now }; manageInfoPool.Add(curClientSocket, clientInfo); mJsonResult json = new mJsonResult() { success = true, msg = string.Format("上线成功,上线时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), clientPostType = "retManageGoOnLine" }; SocketMessage sm = new SocketMessage() { Message = json.ToJson(), SendToClients = new Dictionary <Socket, ClientInfo>() { { curClientSocket, null } } }; msgPool.Add(sm); }
public StudentController(StudentService studentService, mJsonResult jsonResult) { this._studentService = studentService; this.json = jsonResult; studentService.Status = "1"; }
private void GetOnlineManageList() { var manageList = (from item in manageInfoPool select item.Value).ToList(); mJsonResult json = new mJsonResult() { success = true, rows = manageList, clientPostType = "retGetOnlineManageList" }; //推送给所有连接的管理页面 Dictionary <Socket, ClientInfo> sendto = ( from a in manageInfoPool select new KeyValuePair <Socket, ClientInfo>(a.Key, null) ).ToDictionary(key => key.Key, value => value.Value); SocketMessage sm = new SocketMessage() { Message = json.ToJson(), SendToClients = sendto }; msgPool.Add(sm); }
private void DeviceGoOnLine() { string deviceSN = socketContext.GetJsonValue("DeviceSN"); DeviceInfo clientInfo = new DeviceInfo() { deviceSN = deviceSN, onLineTime = DateTime.Now }; devicePool.Add(curClientSocket, clientInfo); mJsonResult json = new mJsonResult() { success = true, msg = string.Format("上线成功,上线时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), clientPostType = "retDeviceGoOnLine" }; SocketMessage sm = new SocketMessage() { Message = json.ToJson(), SendToClients = new Dictionary <Socket, ClientInfo>() { { curClientSocket, null } } }; msgPool.Add(sm); //设备上线 推送给所有管理页面 GetOnlineDeviceList(); }
public IActionResult ScreenLogin([FromBody] LoginViewModel model) { var json = new mJsonResult(); if (ModelState.IsValid) { if (model.userName == _settings.ScreenLoginName && model.password == _settings.ScreenPassword) { var claims = new[] { new Claim("name", _settings.ScreenLoginName), new Claim("sub", "admin"), new Claim("adminPolicy", "adminPolicy") }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_settings.SecurityKey)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken( claims: claims, expires: DateTime.Now.AddDays(2), signingCredentials: creds ); json.success = true; json.data = new JwtSecurityTokenHandler().WriteToken(token); } else { json.msg = "用户名或密码错误!"; } } return(Ok(json)); }
public PetCategoryController(mJsonResult jsonResult, PetCategoryManageService petCategoryManageService, FileManageService fileManage) { this.json = jsonResult; this.categoryManageService = petCategoryManageService; this.fileManageService = fileManage; }
public async Task Invoke(HttpContext context, mJsonResult jsonResult, ILogger <ErrorHandlingMiddleware> logger) { try { context.Response.ContentType = "application/json;charset=utf-8"; await _next.Invoke(context); } catch (Exception e) { jsonResult.Success = false; jsonResult.Msg = $"服务器错误:{e.Message}"; logger.LogError($"服务器错误:{e.Message}"); //throw; } finally { try { jsonResult.Code = context.Response.StatusCode; if (jsonResult.Code.ToString().Substring(0, 1) == "4") { jsonResult.Success = false; } context.Response.StatusCode = 200;//axios 根据statuscode判定响应是否成功 var jsonStr = JsonConvert.SerializeObject(jsonResult); await context.Response.WriteAsync(jsonStr); } catch (Exception e) { logger.LogError($"服务器错误:{e.Message}"); } } }
public AccountController(mJsonResult jsonResult, ILogger <AccountController> logger, IOptions <MyOptions> configOptions, IOptionsSnapshot <MyOptions> snapshot) { this.json = jsonResult; this._logger = logger; this.options = configOptions == null ? null : configOptions.Value; this.options2 = configOptions == null ? null : snapshot.Value; }
public async Task <IActionResult> Login([FromBody] LoginViewModel model) { var json = new mJsonResult(); if (ModelState.IsValid) { var user = await _examContext.Users .SingleOrDefaultAsync(x => x.UserName == model.userName && x.UserName == model.password); if (user != null) { var claims = new[] { new Claim("name", user.TrueName), new Claim("sub", "Candidate"), new Claim("uid", user.ID.ToString()), }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_settings.SecurityKey)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken( claims: claims, expires: DateTime.Now.AddDays(2), signingCredentials: creds ); json.success = true; json.data = new JwtSecurityTokenHandler().WriteToken(token); //存redis数据库 await _redisKeyRepository.SetTokenAsync(user.ID.ToString(), json.data); //如果有其他用户正在登陆踢掉 await _hubContext.Clients.Groups(user.ID.ToString().ToLower()).SendAsync("ReceiveMessageFromLogin", 401); } else { json.msg = "用户名或密码错误!"; } } return(Ok(json)); }
public async Task <IActionResult> SumUserProblemScore(int questionNumber = 1) { var json = new mJsonResult(); var userIDList = _examContext.UserExamPartners .Where(x => x.QuestionNumber == questionNumber && x.ChiocePart == (int)eChoicePart.是) .Select(x => x.UserID.ToString().ToLower()).Distinct().ToList(); if (userIDList != null && userIDList.Count() > 0) { var userScoreIDList = _examContext.UserProblemScores .Where(x => x.QuestionNumber == questionNumber && x.ProblemType == (int)eProblemType.狭路相逢 && userIDList.Contains(x.UserID.ToString().ToLower()) && !x.Score.HasValue) .Select(s => new UserProblemScoreViewModel { userProblemScoreID = s.ID, UserID = s.UserID, ProblemScore = s.ProblemScore }).ToList(); List <UserProblemScoreViewModel> list = new List <UserProblemScoreViewModel>(); foreach (var score in userScoreIDList) { var model = new UserProblemScoreViewModel(); model.userProblemScoreID = score.userProblemScoreID; model.UserID = score.UserID; var userExamScore = _examContext.UserExamScores .Where(x => x.UserID == score.UserID).FirstOrDefault(); model.TypeScores3 = (userExamScore.TypeScores3 ?? 0) - score.ProblemScore; model.TotalScores = (userExamScore.TotalScores ?? 0) - score.ProblemScore; list.Add(model); } if (list.Count() > 0) { json.success = await _examService.SumUserExamScore(list); } } json.success = true;//出错好像也做不了东西 return(Ok(json)); }
public async Task <ActionResult> Issue() { var json = new mJsonResult(); try { if (await _examService.Issue()) { json.success = true; json.msg = "发放成功!"; } else { json.msg = "发题失败!"; } } catch (Exception ex) { _logger.Error("考前发题错误{0}", ex.Message); json.msg = "发题出现异常!"; } return(Json(json)); }
public async Task <ActionResult> SaveBaseSetting(BaseSetting model) { var json = new mJsonResult(); try { if (await _examService.SaveBaseSetting(model)) { json.success = true; json.msg = "保存成功!"; } else { json.msg = "保存失败!"; } } catch (Exception ex) { _logger.Error("保存配置出现错误{0}", ex.Message); json.msg = "保存异常!"; } return(Json(json)); }
public async Task <ActionResult> Login(LoginInfoViewModel loginInfo) { var json = new mJsonResult(); try { if (loginInfo.UserName != "admin") { json.msg = "无法登录!"; return(Json(json)); } var user = await _userService.GetUserFromLogin(loginInfo.UserName, loginInfo.UserPassword); if (user != null) { _authenticationService.SignIn(new UserInfo { UserId = user.ID, UserName = user.UserName }, true); json.success = true; json.msg = "登录成功"; return(Json(json)); } else { json.msg = "用户名或密码错误!"; } } catch (Exception ex) { _logger.Error("登录异常" + ex.Message); json.msg = "登录异常!"; } return(Json(json)); }
public async Task <IActionResult> SaveUserExamPartner(UserPartnerViewModel model) { var json = new mJsonResult(); try { //_logger.LogInformation("打印QuestionNumber:{0},打印chiocePart:{1}", model.questionNumber,model.chiocePart); var userId = new Guid(_identityService.GetUserIdentity()); var userPartner = _examContext.UserExamPartners .FirstOrDefault(x => x.UserID == userId && x.QuestionNumber == model.questionNumber); if (userPartner != null) { userPartner.ChiocePart = model.chiocePart; userPartner.AddTime = DateTime.Now; _examContext.UserExamPartners.Update(userPartner); } else { userPartner = new UserExamPartner { QuestionNumber = model.questionNumber, UserID = userId, ChiocePart = model.chiocePart, AddTime = DateTime.Now }; _examContext.UserExamPartners.Add(userPartner); } json.success = await _examContext.SaveChangesAsync() > 0; }catch (Exception ex) { _logger.LogError("狭路相逢选择是否参与错误:{0}", ex.Message); json.msg = "选择是否参与出错" + ex.Message; } return(Ok(json)); }
public PetCategoryManageService(IPetCategoryRepository petCategoryRepository, IFileRepository fileRepository, mJsonResult jsonResult) { json = jsonResult; repository = petCategoryRepository; _fileRepository = fileRepository; }
public FileUploadController(mJsonResult mJsonResult, FileManageService fileManage) { fileManageService = fileManage; json = mJsonResult; }
public void GetCategoryList(int pageIndex, int pageSize, string searchKey) { json = categoryManageService.GetCategoryList(pageIndex, pageSize, searchKey); }
public async Task <ActionResult> ImportExcel() { var json = new mJsonResult(); string filePath = ""; System.Web.HttpFileCollection _file = System.Web.HttpContext.Current.Request.Files; if (_file.Count > 0) { //文件大小 long size = _file[0].ContentLength; //文件类型 string type = _file[0].ContentType; //文件名 string name = _file[0].FileName; //文件格式 string _tp = System.IO.Path.GetExtension(name); if (_tp.ToLower() == ".xls" || _tp.ToLower() == ".xlsx") { //获取文件流 System.IO.Stream stream = _file[0].InputStream; //保存文件 string saveName = DateTime.Now.ToString("yyyyMMddHHmmss") + _tp; string directory = Server.MapPath("/UpLoadFiles/"); //判断目录是否存在 string path = directory + saveName; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (Directory.Exists(path)) { Directory.Delete(path); } _file[0].SaveAs(path); filePath = path; } } if (!string.IsNullOrWhiteSpace(filePath)) { try { List <Problem> list = new List <Problem>(); list.AddRange(ImportSelect(filePath, 0)); list.AddRange(ImportSelect(filePath, 1)); list.AddRange(ImportSelect(filePath, 2)); if (await _examService.InsertProblemList(list)) { json.success = true; json.msg = "导入成功"; } else { json.msg = "导入失败"; } json.success = true; json.msg = "导入成功"; } catch (Exception ex) { _logger.Error("导入问题" + ex.Message); json.msg = "导入失败!"; } } else { json.success = false; json.msg = "请选择文件"; } return(Json(json, "text/html")); }
public async Task <IActionResult> SaveOneProblem(SubmitProblemViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var json = new mJsonResult(); Guid examProblemID = Guid.Parse(model.examProblemID); using (var trans = _examContext.Database.BeginTransaction()) { try { var userProScore = await _examContext.UserProblemScores .FindAsync(examProblemID); if (userProScore != null) { #region 判断(规定时间内答题) if (userProScore.IsSubmitOver == 1)//已经提交的问题不允许提交 { json.msg = "已经提交的问题不能再提交"; return(Ok(json)); } if (!await GetProblemInCountdown(userProScore)) { json.msg = "只能在规定时间内答题"; return(Ok(json)); } #endregion if (userProScore.SubmitAnswer != model.submitAnswer) { userProScore.ExaminationDate = DateTime.Now; userProScore.SubmitAnswer = model.submitAnswer; if (model.isSubmitOver.HasValue) { userProScore.IsSubmitOver = model.isSubmitOver.Value;//代表已提交 } string answer = userProScore.Answer .Replace("\n", "").Replace(" ", "") .Replace("\t", "").Replace("\r", ""); if (userProScore.ProblemType == (int)eProblemType.狭路相逢) { userProScore.Score = model.submitAnswer == answer ? userProScore.ProblemScore : -userProScore.ProblemScore; } else { userProScore.Score = model.submitAnswer == answer ? userProScore.ProblemScore : 0; } _examContext.UserProblemScores.Update(userProScore); _examContext.SaveChanges(); //统计所有 var userId = Guid.Parse(_identityService.GetUserIdentity()); var userExamScore = await _examContext.UserExamScores .SingleOrDefaultAsync(s => s.UserID == userId); var userProblemScore = _examContext.UserProblemScores .Where(x => x.Score.HasValue && x.UserID == userId); switch (userProScore.ProblemType) { case (int)eProblemType.争分夺秒: userExamScore.TypeScores1 = userProblemScore .Where(x => x.ProblemType == (int)eProblemType.争分夺秒) .Sum(s => s.Score); break; case (int)eProblemType.一比高下: userExamScore.TypeScores2 = userProblemScore .Where(x => x.ProblemType == (int)eProblemType.一比高下) .Sum(s => s.Score); break; case (int)eProblemType.狭路相逢: userExamScore.TypeScores3 = userProblemScore .Where(x => x.ProblemType == (int)eProblemType.狭路相逢) .Sum(s => s.Score); break; } userExamScore.TotalScores = (userExamScore.TypeScores1 ?? 0) + (userExamScore.TypeScores2 ?? 0) + (userExamScore.TypeScores3 ?? 0); _examContext.UserExamScores.Update(userExamScore); _examContext.SaveChanges(); trans.Commit();//显式事物提交 json.success = true; } } else { return(NotFound()); } }catch (Exception ex) { trans.Rollback(); _logger.LogError("保存一道题目的时候出错:{0}", ex.Message); //throw new Exception(); } } return(Ok(json)); }