public void CacheTest_StoreTwoPostsIntoNotEmptyCache() { // Arrange var storedPosts = new List <Post> { new Post { Filename = "MyPost" }, new Post { Filename = "MySecondPost" }, new Post { Filename = "MyAnotherOnePost" } }; var cache = new PostCache(new ConcurrentCache <Post>(storedPosts)); var posts = new List <Post> { new Post { Filename = "MyAwesomePost" }, new Post { Filename = "MySecondAwesomePost" } }; // Act cache.Store(posts); // Assert cache.Posts.Count.Should().Be(5); }
public void CacheTest_StoreThreePostsWithCollisionsInCache() { // Arrange var storedPosts = new List <Post> { new Post { Filename = "MyPost" }, new Post { Filename = "MySecondPost" }, new Post { Filename = "MyAnotherOnePost" } }; var cache = new PostCache(new ConcurrentCache <Post>(storedPosts)); var posts = new List <Post> { new Post { Filename = "MyPost" }, new Post { Filename = "AwesomePost" }, }; // Act cache.Store(posts); // Assert cache.Posts.Count.Should().Be(4); }
public void CacheTest_StoreOnePostIntoEmptyCache() { // Arrange var cache = new PostCache(new ConcurrentCache <Post>()); var post = new Post { Filename = "MyPost" }; // Act cache.Store(new List <Post> { post }); // Assert cache.Posts.Count.Should().Be(1); }
public async Task AddPostTest() { var postCache = new PostCache() { Id = 17, ForumId = 1, CreateUserId = 1, CreateUserName = "******", CreateUserNickname = "夜莫白", CreateUserAvatar = "defaultAvatar", CreateTime = DateTime.Parse("2019-02-13 17:36:01"), Subject = "实在是扛不住压力了", Context = "哈哈哈哈哈哈", IsDelete = 0, EndReplyTime = DateTime.Parse("2019-02-15 16:55:32"), EndReplyUserId = 4, Comments = new List <CommentCache> { new CommentCache { Id = 3, PostId = 1, Context = "老弟怎么了啊,什么事啊", CommentTime = DateTime.Parse("2019-02-15 15:27:00"), CommentUserId = 4, CommentUserName = "******", CommentUserNickname = "终点", CommentUserAvatar = "" }, new CommentCache { Id = 3, PostId = 1, Context = "老弟怎么了啊,什么事啊", CommentTime = DateTime.Parse("2019-02-15 16:55:32"), CommentUserId = 4, CommentUserName = "******", CommentUserNickname = "终点", CommentUserAvatar = "" } } }; await postMongoDbRepository.AddAsync(postCache); }
/// <summary> /// Post to a a URL endpoint with required field(s) and gives an optional response handler. /// </summary> /// <param name="url">The URL to post to.</param> /// <param name="responseHandler">An Action that handles the response (optional).</param> public void PostURL(string url, Dictionary <string, object> fields, Action <Dictionary <string, object> > responseHandler = null) { // Kill networking immediately if no connection // if(Application.internetReachability == NetworkReachability.NotReachable) // KillNetwork(true); if (_ignoreNetwork) { fields.Add("local", true); responseHandler(fields); return; } string absoluteURL = DataManager.RemoteURL + url; // Send form as raw byte array System.Text.StringBuilder output = new System.Text.StringBuilder(); JsonWriter writer = new JsonWriter(output); if (_sessionCookie != null) { fields.Add("sessionID", System.Convert.ChangeType(_sessionCookie, typeof(object))); } // If no session cookie, client has no auth, so cache this request to do later else if (url != "/auth/") { PostCache cacheObj = new PostCache(); cacheObj.url = url; cacheObj.fields = fields; cacheObj.responseHandler = responseHandler; _cachedRequests.Add(cacheObj); return; } writer.Write(fields); // Encode output as UTF8 bytes _currentRoutine = WaitForForm(absoluteURL, Encoding.UTF8.GetBytes(output.ToString()), responseHandler); StartCoroutine(_currentRoutine); }
public void Update(PostCache entity) { var post = Collection.Find <PostCache>(x => x.Id == entity.Id); if (post != null) { if (post.Equals(entity)) { if (!entity.Comments.IsNullOrEmpty()) { //说明这时候要更新或插入评论了 var filterDefintion = Builders <PostCache> .Filter.And(Builders <PostCache> .Filter.Where(x => x.Id == entity.Id)); var updateDefintion = Builders <PostCache> .Update.PushEach(x => entity.Comments, entity.Comments); var updateResult = Collection.UpdateOne(filterDefintion, updateDefintion); } } } }
public void CacheTest_StoreTwoPostsIntoEmptyCache() { // Arrange var cache = new PostCache(new ConcurrentCache <Post>()); var posts = new List <Post> { new Post { Filename = "MyPost" }, new Post { Filename = "MySecondPost" } }; // Act cache.Store(posts); // Assert cache.Posts.Count.Should().Be(2); }
private PostCache Mapping(PostDto postDto) { var postCache = new PostCache() { Id = postDto.Id, Context = postDto.Context, Subject = postDto.Subject, CreateTime = DateTime.UtcNow, ForumId = postDto.ForumId, CreateUserAvatar = postDto.CreateUserAvatar, CreateUserId = postDto.CreateUserId, CreateUserName = postDto.CreateUserName, CreateUserNickname = postDto.CreateUserNickname, EndReplyTime = postDto.EndReplyTime, EndReplyUserId = postDto.EndReplyUserId, EndReplyUserNickname = postDto.EndReplyUserNickname, }; return(postCache); }
public void Add(PostCache entity) { Collection.InsertOne(entity); }
public async Task AddAsync(PostCache entity) { //获取集合 await Collection.InsertOneAsync(entity); }
public string ImportLabor() { LaborprotectionBLL laborprotectionbll = new LaborprotectionBLL(); PostCache postCache = new PostCache(); PostBLL postBLL = new PostBLL(); DepartmentBLL departmentBLL = new DepartmentBLL(); //获取到已选数据 List <LaborprotectionEntity> laborlist = laborprotectionbll.GetLaborList(); var currUser = OperatorProvider.Provider.Current(); string orgId = OperatorProvider.Provider.Current().OrganizeId;//所属公司 int error = 0; string message = "请选择格式正确的文件再导入!"; string falseMessage = ""; int count = HttpContext.Request.Files.Count; if (count > 0) { HttpPostedFileBase file = HttpContext.Request.Files[0]; if (string.IsNullOrEmpty(file.FileName)) { return(message); } if (!(file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xls") || file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xlsx"))) { return(message); } string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file.FileName); file.SaveAs(Server.MapPath("~/Resource/temp/" + fileName)); Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(); wb.Open(Server.MapPath("~/Resource/temp/" + fileName)); Aspose.Cells.Cells cells = wb.Worksheets[0].Cells; if (cells.MaxDataRow == 0) { message = "没有数据,请选择先填写模板在进行导入!"; return(message); } DataTable dt = cells.ExportDataTable(0, 0, cells.MaxDataRow + 1, cells.MaxColumn + 1, true); int order = 1; IList <LaborprotectionEntity> LaborList = new List <LaborprotectionEntity>(); IEnumerable <DepartmentEntity> deptlist = new DepartmentBLL().GetList(); OrganizeBLL orgbll = new OrganizeBLL(); //先获取到原始的一个编号 string no = laborprotectionbll.GetNo(); int ysno = Convert.ToInt32(no); DataItemDetailBLL dataItemDetailBLL = new DataItemDetailBLL(); var dataitem = dataItemDetailBLL.GetDataItemListByItemCode("'LaborName'").ToList(); List <LaborprotectionEntity> insertpro = new List <LaborprotectionEntity>(); List <LaborinfoEntity> insertinfo = new List <LaborinfoEntity>(); //先获取人员 List <UserEntity> userlist = new UserBLL().GetListForCon(it => it.IsPresence == "1" && it.Account != "System").ToList(); List <LaborequipmentinfoEntity> eqlist = new List <LaborequipmentinfoEntity>(); for (int i = 0; i < dt.Rows.Count; i++) { order = i; string Name = dt.Rows[i]["名称"].ToString(); string Model = dt.Rows[i]["型号"].ToString(); string Type = dt.Rows[i]["类型"].ToString(); string DeptName = dt.Rows[i]["使用部门"].ToString(); string OrgName = dt.Rows[i]["使用单位"].ToString(); string PostName = dt.Rows[i]["使用岗位"].ToString().Trim(); string Unit = dt.Rows[i]["劳动防护用品单位"].ToString().Trim(); string Time = dt.Rows[i]["使用期限"].ToString().Trim(); string TimeType = dt.Rows[i]["使用期限单位"].ToString().Trim(); string deptId = "", deptCode = "", PostId = ""; //---****值存在空验证*****-- if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Unit) || string.IsNullOrEmpty(DeptName) || string.IsNullOrEmpty(OrgName) || string.IsNullOrEmpty(PostName)) { falseMessage += "</br>" + "第" + (i + 2) + "行值存在空,未能导入."; error++; continue; } //验证机构是不是和自己一个机构 DepartmentEntity org = deptlist.Where(it => it.FullName == OrgName).FirstOrDefault(); if (org == null) { falseMessage += "</br>" + "第" + (i + 2) + "行使用单位名称不存在,未能导入."; error++; continue; } //如果导入的机构id和本人的机构id不一致 if (org.DepartmentId != currUser.OrganizeId) { falseMessage += "</br>" + "第" + (i + 2) + "行使用单位不是导入者的单位,未能导入."; error++; continue; } //验证所填部门是否存在 var deptFlag = false; var entity1 = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.FullName == DeptName).FirstOrDefault(); if (entity1 == null) { falseMessage += "</br>" + "第" + (i + 2) + "行使用部门不存在,未能导入."; error++; deptFlag = true; break; } else { deptId = entity1.DepartmentId; deptCode = entity1.EnCode; } //var deptFlag = false; //var array = DeptName.Split('/'); //for (int j = 0; j < array.Length; j++) //{ // if (j == 0) // { // if (currUser.RoleName.Contains("省级")) // { // var entity1 = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity1 == null) // { // falseMessage += "</br>" + "第" + (i + 2) + "行部门不存在,未能导入."; // error++; // deptFlag = true; // break; // } // else // { // deptId = entity1.DepartmentId; // deptCode = entity1.EnCode; // } // } // else // { // var entity = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "厂级" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity == null) // { // entity = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "部门" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity == null) // { // entity = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "承包商" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity == null) // { // falseMessage += "</br>" + "第" + (i + 2) + "行部门不存在,未能导入."; // error++; // deptFlag = true; // break; // } // else // { // deptId = entity.DepartmentId; // deptCode = entity.EnCode; // } // } // else // { // deptId = entity.DepartmentId; // deptCode = entity.EnCode; // } // } // else // { // deptId = entity.DepartmentId; // deptCode = entity.EnCode; // } // } // } // else if (j == 1) // { // var entity1 = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "专业" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity1 == null) // { // entity1 = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "班组" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity1 == null) // { // falseMessage += "</br>" + "第" + (i + 2) + "行专业/班组不存在,未能导入."; // error++; // deptFlag = true; // break; // } // else // { // deptId = entity1.DepartmentId; // deptCode = entity1.EnCode; // } // } // else // { // deptId = entity1.DepartmentId; // deptCode = entity1.EnCode; // } // } // else // { // var entity1 = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "班组" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity1 == null) // { // falseMessage += "</br>" + "第" + (i + 2) + "行班组不存在,未能导入."; // error++; // deptFlag = true; // break; // } // else // { // deptId = entity1.DepartmentId; // deptCode = entity1.EnCode; // } // } //} if (deptFlag) { continue; } //检验所填岗位是否属于其公司或者部门 if (string.IsNullOrEmpty(deptId) || deptId == "undefined") { //所属公司 RoleEntity data = postCache.GetList(orgId, "true").OrderBy(x => x.SortCode).Where(a => a.FullName == PostName).FirstOrDefault(); if (data == null) { falseMessage += "</br>" + "第" + (i + 2) + "行岗位不属于该公司,未能导入."; error++; continue; } } else { //所属部门 //所属公司 RoleEntity data = postCache.GetList(orgId, deptId).OrderBy(x => x.SortCode).Where(a => a.FullName == PostName).FirstOrDefault(); if (data == null) { falseMessage += "</br>" + "第" + (i + 2) + "行岗位不属于该部门,未能导入."; error++; continue; } } //--**验证岗位是否存在**-- RoleEntity re = postBLL.GetList().Where(a => a.FullName == PostName && a.OrganizeId == orgId).FirstOrDefault(); if (!(string.IsNullOrEmpty(deptId) || deptId == "undefined")) { re = postBLL.GetList().Where(a => a.FullName == PostName && a.OrganizeId == orgId && a.DeptId == deptId).FirstOrDefault(); if (re == null) { re = postBLL.GetList().Where(a => a.FullName == PostName && a.OrganizeId == orgId && a.Nature == departmentBLL.GetEntity(deptId).Nature).FirstOrDefault(); } } if (re == null) { falseMessage += "</br>" + "第" + (i + 2) + "行岗位有误,未能导入."; error++; continue; } else { PostId = re.RoleId; } LaborinfoEntity linfo = new LaborinfoEntity(); linfo.PostId = PostId; linfo.DeptCode = deptCode; linfo.DeptId = deptId; linfo.DeptName = DeptName; linfo.LaboroPerationTime = DateTime.Now; linfo.LaboroPerationUserName = currUser.UserName; linfo.Model = Model; linfo.Name = Name; linfo.OrgCode = currUser.OrganizeCode; linfo.OrgId = currUser.OrganizeId; linfo.OrgName = currUser.OrganizeName; linfo.Type = Type; if (Time == "" || !isInt(Time)) { linfo.TimeNum = null; } else { linfo.TimeNum = Convert.ToInt32(Time); linfo.TimeType = TimeType; } linfo.PostName = PostName; linfo.Unit = Unit; linfo.Create(); //如果已存在物品库中 LaborprotectionEntity lp = laborlist.Where(it => it.Name == Name).FirstOrDefault(); if (lp != null) { linfo.No = lp.No; linfo.LId = lp.ID; //如果库里有值 则使用库里的值 linfo.Type = linfo.Type; linfo.TimeNum = lp.TimeNum; linfo.TimeType = lp.TimeType; } else { LaborprotectionEntity newlp = new LaborprotectionEntity(); newlp.Create(); newlp.Name = Name; newlp.No = ysno.ToString(); newlp.LaborOperationTime = DateTime.Now; newlp.LaborOperationUserName = currUser.UserName; newlp.Model = Model; newlp.Type = Type; newlp.Unit = Unit; newlp.TimeNum = linfo.TimeNum; newlp.TimeType = TimeType; linfo.No = ysno.ToString(); linfo.LId = newlp.ID; ysno++; insertpro.Add(newlp); } int num = 0; List <UserEntity> ulist = userlist.Where(it => it.DepartmentId == deptId && it.DutyId == PostId).ToList(); for (int j = 0; j < ulist.Count; j++) { //添加岗位关联人员 LaborequipmentinfoEntity eq = new LaborequipmentinfoEntity(); eq.UserName = ulist[j].RealName; eq.AssId = linfo.ID; eq.LaborType = 0; eq.ShouldNum = 1; num++; eq.UserId = ulist[j].UserId; if (linfo.Type == "衣服") { eq.Size = "L"; } else if (linfo.Type == "鞋子") { eq.Size = "40"; } else { eq.Size = ""; } eq.Create(); eqlist.Add(eq); } linfo.ShouldNum = num; insertinfo.Add(linfo); } laborinfobll.ImportSaveForm(insertinfo, insertpro, eqlist); count = dt.Rows.Count; message = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条"; message += "</br>" + falseMessage; } return(message); }
/// <summary> /// Post to a a URL endpoint with required field(s) and gives an optional response handler. /// </summary> /// <param name="url">The URL to post to.</param> /// <param name="responseHandler">An Action that handles the response (optional).</param> public void PostURL(string url, Dictionary<string, object> fields, Action<Dictionary<string, object>> responseHandler=null) { // Kill networking immediately if no connection // if(Application.internetReachability == NetworkReachability.NotReachable) // KillNetwork(true); if(_ignoreNetwork) { fields.Add("local", true); responseHandler(fields); return; } string absoluteURL = DataManager.RemoteURL + url; // Send form as raw byte array System.Text.StringBuilder output = new System.Text.StringBuilder(); JsonWriter writer = new JsonWriter (output); if(_sessionCookie != null) fields.Add("sessionID", System.Convert.ChangeType(_sessionCookie, typeof(object))); // If no session cookie, client has no auth, so cache this request to do later else if(url != "/auth/") { PostCache cacheObj = new PostCache(); cacheObj.url = url; cacheObj.fields = fields; cacheObj.responseHandler = responseHandler; _cachedRequests.Add(cacheObj); return; } writer.Write(fields); // Encode output as UTF8 bytes _currentRoutine = WaitForForm(absoluteURL, Encoding.UTF8.GetBytes(output.ToString()), responseHandler); StartCoroutine(_currentRoutine); }