public List <NearUserInfo> GetGroupUsers(string groupGuid) { List <int> userIds = GroupStore.GetGroupUserIds(groupGuid); if (userIds == null || userIds.Count <= 0) { return(null); } List <NearUserInfo> users = db.t_user.Where(u => userIds.Contains(u.id)) .Select(u => new NearUserInfo() { UserId = u.id, UserName = u.name, UserImage = u.head_image, }).ToList(); if (request.IsDistance) { var distDic = UserStore.GetUserDistances(request.UserId, userIds); users.ForEach(f => { if (distDic.ContainsKey(f.UserId)) { f.Distance = distDic[f.UserId] ?? 0; } }); } return(users); }
public override AddGroupUsersResponseBody ExecuteCore() { AddGroupUsersResponseBody res = new AddGroupUsersResponseBody() { Status = ResultStatus.Failed }; //往redis中添加数据 GroupStore.SaveGroupUser(this.request.GroupGuid, this.request.GroupUserIds.ToArray()); List <t_group_user> users = this.request.GroupUserIds.ConvertAll(f => new t_group_user { group_guid = this.request.GroupGuid, user_id = f, add_date = DateTime.Now }); var existsUsers = db.t_group_user.Where(u => u.group_guid == this.request.GroupGuid).ToList(); GroupUserEqualityComparer comparer = new GroupUserEqualityComparer(); var noExistsUsers = users.Except <t_group_user>(existsUsers, comparer).ToList(); if (noExistsUsers == null || noExistsUsers.Count <= 0) { res.Status = ResultStatus.Success; return(res); } db.t_group_user.AddRange(noExistsUsers); db.SaveChanges(); res.Status = ResultStatus.Success; return(res); }
private Tuple <int, int> Process() { //userid,offlineTime Dictionary <int, string> infos = UserStore.GetUserSessionOfflineInfos(); if (infos == null || infos.Count <= 0) { return(new Tuple <int, int>(0, 0)); } int handleCount = 0; DateTime offlineTime; foreach (var item in infos) { if (!string.IsNullOrEmpty(item.Value) && DateTime.TryParse(item.Value, out offlineTime) && offlineTime.AddHours(2) <= DateTime.Now && UserStore.DeleteSessionOfflineUserInfo(item.Key, item.Value)) { //Get near group guid recently used by the user and then remove the user from the group according to near group guid string nearGrouGuid = GroupStore.GetRecentUserInNearGroupGuid(item.Key); GroupStore.DeleteGroupUsers(nearGrouGuid, item.Key); handleCount++; } } return(new Tuple <int, int>(infos.Count, handleCount)); }
public void TestGroupExist() { var gstore = new GroupStore <IdentityGroup>(); var gm = new GroupManager <IdentityGroup>(gstore); gm.GroupExists("group3"); }
public override GroupUsersResponseBody ExecuteCore() { GroupUsersResponseBody res = new GroupUsersResponseBody(); List <int> userIds = GroupStore.GetGroupUserIds(this.request.GroupGuid); //switch (this.request.GroupType) //{ // case GroupType.Near: // userIds = groupAction.GetNearGroupUserIds(this.request.GroupGuid); // break; // case GroupType.User: // userIds = groupAction.GetGroupUserIds(this.request.GroupGuid); // break; //} if (userIds == null || userIds.Count <= 0) { return(res); } res.GroupUserInfos = db.t_user.Where(u => userIds.Contains(u.id)) .Select(u => new GroupUserInfo() { GroupGuid = this.request.GroupGuid, UserId = u.id, UserName = u.name, UserHeadImage = u.head_image, }).ToList(); return(res); }
public async Task <bool> CreateAsync() { GroupStore <IdentityGroup> store = new GroupStore <IdentityGroup>(); var gm = new GroupManager <IdentityGroup>(store); var newGroup = new IdentityGroup("testgroup"); await gm.CreateAsync(newGroup); return(true); }
public ActionResult DiscussionKey(string level_1_id /*board_id*/, string level_2_id /*discussion_id*/) { if (!GroupStore.IsInsider(level_1_id)) { Util.ThrowUnauthorizedException("只有內部群組成員可以看到不公開的留言。"); } string key = Warehouse.DiscussionKeyPond.Get(level_1_id, level_2_id, false); return(Json(new { key = key }, JsonRequestBehavior.AllowGet)); }
public void Testgroupdelete() { var gstore = new GroupStore <IdentityGroup>(); var gm = new GroupManager <IdentityGroup>(gstore); var gr = gm.FindByName("group3"); if (gr != null) { gm.Delete(gr); } }
public string GetVisitorGroupName() { var group = GroupStore.Load(VisitorGroupId); if (group == null) { throw new NullReferenceException(string.Format("Visitor group does not exist - id = {0}", VisitorGroupId)); } return(group.Name); }
public override DeleteGroupUserResponseBody ExecuteCore() { DeleteGroupUserResponseBody res = new DeleteGroupUserResponseBody() { Status = ResultStatus.Failed }; var group = db.t_group.Where(g => g.group_guid == this.request.GroupGuid).FirstOrDefault(); if (group != null) { var grouUser = db.t_group_user.Where(u => u.group_guid == this.request.GroupGuid && u.user_id == this.request.UserId).FirstOrDefault(); if (grouUser != null) { db.t_group_user.Remove(grouUser); group.group_user_count = group.group_user_count - 1; if (group.group_user_count < 0) { group.group_user_count = 0; } } if (group.build_user_id == this.request.UserId) { group.build_user_id = 0; } db.SaveChanges(); } GroupStore.DeleteGroupUsers(this.request.GroupGuid, this.request.UserId); res.Status = ResultStatus.Success; try { if (GroupStore.GetGroupUserCount(this.request.GroupGuid) > 0) { return(res); } //如果redis的群组里没有人了,就直接删除组 var users = db.t_group_user.Where(g => g.group_guid == this.request.GroupGuid).ToList(); if (users != null && users.Count > 0) { if (group != null) { db.t_group.Remove(group); } db.t_group_user.RemoveRange(users); db.SaveChanges(); } } catch (Exception) { } return(res); }
public void TestUpdateGroup() { var gstore = new GroupStore <IdentityGroup>(); var gm = new GroupManager <IdentityGroup>(gstore); var gr = gm.FindByName("group3"); if (gr != null) { gr.Name = "test"; gm.Update(gr); } }
public void TestGroupStores() { GroupStore <IdentityGroup> store = new GroupStore <IdentityGroup>(); var gm = new GroupManager <IdentityGroup>(store); var newGroup = new IdentityGroup("testgroup"); gm.Create(newGroup); var result = CreateAsync().Result; Assert.AreEqual(true, result); }
public void TestFindGroup() { var gstore = new GroupStore <IdentityGroup>(); var gm = new GroupManager <IdentityGroup>(gstore); var gr = gm.FindByName("group3"); if (gr == null) { gr = new IdentityGroup("group3"); gm.Create(gr); } var res = gm.FindById(gr.Id); }
public void TestUpdateGroup2() { var ctx = new IdentityDbContext <IdentityUser>(); var gstore = new GroupStore <IdentityGroup>(ctx); var gm = new GroupManager <IdentityGroup>(gstore); var gr = gm.FindByName("group3"); if (gr != null) { gr.Name = "group3"; gm.Update(gr); } }
public override AddGroupResponseBody ExecuteCore() { AddGroupResponseBody res = new AddGroupResponseBody() { Status = ResultStatus.Failed }; string groupGuid = Guid.NewGuid().ToString(); t_group group = new t_group() { build_user_id = this.request.BuildUserId, group_guid = groupGuid, group_name = this.request.GroupName, group_user_count = this.request.GroupUserIds.Count, build_date = DateTime.Now, update_date = DateTime.Now, group_note = "" }; db.t_group.Add(group); int groupId = db.SaveChanges(); if (groupId <= 0) { throw new Exception("组创建失败"); } List <t_group_user> users = this.request.GroupUserIds.ConvertAll(f => new t_group_user { group_guid = group.group_guid, user_id = f, add_date = DateTime.Now }); db.t_group_user.AddRange(users); db.SaveChanges(); res.Status = ResultStatus.Success; res.GroupGuid = groupGuid; res.BuildTime = GenericUtility.FormatDate2(group.build_date); //不能在这里发送创建成功的消息,因为创建群组是客户端的行为,应由客户端来决定MQ消息的发送规则 //往redis中添加数据 GroupStore.SaveGroupUser(groupGuid, this.request.GroupUserIds.ToArray()); return(res); }
static void Main() { FingerprintLite13Entities db = new FingerprintLite13Entities(); var modelFactory = new ModelFactory(); var textStore = new TextStore(db, modelFactory); var groupStore = new GroupStore(db, modelFactory, textStore); var textTempDb = new List <ITextViewModel>(); var groupTempDb = new List <IGroupViewModel>(); var textController = new TextController(textStore, groupStore, modelFactory); var groupController = new GroupController(textStore, groupStore, modelFactory); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(textController, groupController)); }
protected void GroupStoreRefresh(object sender, StoreRefreshDataEventArgs e) { try { if (_formInfo == null) { _formInfo = FormController.GetInstance().GetForm(_FormName); } List <FormGroupInfo> rs = new List <FormGroupInfo>(); List <FormGroupInfo> formGroupList = FormGroupController.GetInstance().GetFromGroups(_formInfo.ID, -1); GroupStore.DataSource = formGroupList; GroupStore.DataBind(); } catch (Exception ex) { Dialog.ShowError("FormConfigLayout/GroupStoreRefresh = " + ex.Message); } }
public string GetNearGroupGuid(t_user_pos upos) { string groupGuid = GroupStore.GetAvailableNearGroupGuid(upos.lon, upos.lat); if (groupGuid != request.LastGroupGuid && !string.IsNullOrEmpty(request.LastGroupGuid)) { GroupStore.DeleteGroupUsers(request.LastGroupGuid, upos.user_id); } isExistInGroup = GroupStore.ExistsInGroup(groupGuid, request.UserId); if (!isExistInGroup) { GroupStore.SaveGroupUser(groupGuid, upos.user_id); } GroupStore.SaveRecentUserInNearGroupAsync(upos.user_id, groupGuid); return(groupGuid); }
private void DeleteGroupUsers(HWLEntities db) { var groupUsers = db.t_group_user.Where(g => g.group_guid == this.request.GroupGuid).ToList(); if (groupUsers != null) { try { db.t_group_user.RemoveRange(groupUsers); db.SaveChanges(); GroupStore.DeleteGroup(this.request.GroupGuid); } catch (Exception) { //可以忽略这个错误 } } }
public override DeleteGroupResponseBody ExecuteCore() { DeleteGroupResponseBody res = new DeleteGroupResponseBody() { Status = ResultStatus.Failed }; var group = db.t_group.Where(g => g.group_guid == this.request.GroupGuid).FirstOrDefault(); if (group == null) { res.Status = ResultStatus.Success; return(res); } else { if (group.build_user_id != this.request.BuildUserId) { throw new Exception("你没有权限解散群组,你可以退出"); } } db.t_group.Remove(group); var users = db.t_group_user.Where(g => g.group_guid == this.request.GroupGuid).ToList(); if (users != null && users.Count > 0) { db.t_group_user.RemoveRange(users); } db.SaveChanges(); GroupStore.DeleteGroup(group.group_guid); res.Status = ResultStatus.Success; return(res); }
public void TestUser() { //var ctx = new IdentityDbContext(); var store = new UserStore <IdentityUser>(); var usr = new IdentityUser("usertest2"); var um = new UserManager <IdentityUser>(store); var gr = new IdentityGroup("group3"); var gstore = new GroupStore <IdentityGroup>(); var gm = new GroupManager <IdentityGroup>(gstore); if (!gm.Create(gr).Succeeded) { gm.FindByName("group3"); } if (!um.Create(usr).Succeeded) { usr = um.FindByName("usertest2"); } um.SetToGroup(usr.Id, "group3"); //um.Delete(usr); //gr.Name = "groupchange"; //gm.Update(gr); //gm.Delete(gr); }
public void RemoveGroup(Group group) { GroupStore.Remove(group.GetGUID().GetCounter()); }
public Group GetGroupByGUID(ObjectGuid groupId) { return(GroupStore.LookupByKey(groupId.GetCounter())); }
public ActionResult BoardSetting(string level_1_id /*board_id*/, string board_name, string group_id, string add_users, string remove_users, string delta_flags) { if (!Util.IsAjaxRequest(Request)) { Util.ThrowBadRequestException("Not ajax post."); } if (!ReCaptcha.Validate()) { Util.ThrowBadRequestException("驗證碼不正確。"); } if (board_name != null) { if (!GroupStore.IsChairOwner(level_1_id)) { Util.ThrowUnauthorizedException("只有板主可以變更板名。"); } checkBoardName(board_name); BoardInfoStore.SetBoardSetting(level_1_id, board_name + '板'); } else if (delta_flags != null) { if (GroupStore.HasChairOwner(level_1_id) && !GroupStore.IsChairOwner(level_1_id) && !GroupStore.IsSiteOwner()) { Util.ThrowUnauthorizedException("只有板主可以變更留言板設定。"); } checkFlags(delta_flags, null, SandFlags.MT_LOW_KEY + SandFlags.MTV_SEPARATOR + "0", SandFlags.MT_LOW_KEY + SandFlags.MTV_SEPARATOR + "1"); BoardInfoStore.SetBoardFlags(level_1_id, delta_flags); } else if (group_id != null && add_users != null && remove_users != null) { if (GroupStore.HasChairOwner(level_1_id) && !GroupStore.IsChairOwner(level_1_id)) { Util.ThrowUnauthorizedException("只有板主可以變更板主、副板主、或內部群組列表。"); } if (group_id != GroupStore.ChairOwnerGroupName && group_id != GroupStore.ViceOwnerGroupName && group_id != GroupStore.InsiderGroupName) { Util.ThrowBadRequestException("群組ID格式不正確。"); } int add_cnt = SandId.CountUserNameList(add_users); int remove_cnt = SandId.CountUserNameList(remove_users); if (!Warehouse.BsMapPond.Get().IsValidBoardId(level_1_id)) { Util.ThrowBadRequestException("Invalid board ID."); } GroupStore.UpdateGroup(level_1_id, group_id, add_users, remove_users); } return(Json(new { ok = true })); }