public static async Task <string> GetMembers(string set, string qexpr, string prevlast) { JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; UserServiceProxy svc = new UserServiceProxy(); UserSet _set = new UserSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) { _set.SetFilter = sobj["setFilter"]; } User _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as User; } var result = await svc.GetPageItemsAsync(Cntx, _set, _qexpr, _prevlast); var ar = new List <dynamic>(); string appId = ApplicationContext.App.ID; UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy(); foreach (var e in result) { //var membs = svc.MaterializeAllUserAppMembers(Cntx, e); //var memb = (from d in membs where d.ApplicationID == appId select d).SingleOrDefault(); var cond = new UserAppMemberSetConstraints { ApplicationIDWrap = new ForeignKeyData <string> { KeyValue = appId }, UserIDWrap = new ForeignKeyData <string> { KeyValue = e.ID } }; var memb = (await mbsvc.ConstraintQueryAsync(Cntx, new UserAppMemberSet(), cond, null)).SingleOrDefault(); ar.Add(new { data = e, member = memb, hasIcon = memb != null && !string.IsNullOrEmpty(memb.IconMime) }); } string json = ser3.Serialize(ar); return(json); }
public static async Task<string> GetMembers(string set, string qexpr, string prevlast) { JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; UserServiceProxy svc = new UserServiceProxy(); UserSet _set = new UserSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) _set.SetFilter = sobj["setFilter"]; User _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as User; } var result = await svc.GetPageItemsAsync(Cntx, _set, _qexpr, _prevlast); var ar = new List<dynamic>(); string appId = ApplicationContext.App.ID; UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy(); foreach (var e in result) { //var membs = svc.MaterializeAllUserAppMembers(Cntx, e); //var memb = (from d in membs where d.ApplicationID == appId select d).SingleOrDefault(); UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy(); var cond = new UserAppMemberSetConstraints { ApplicationIDWrap = new ForeignKeyData<string> { KeyValue = appId }, UserIDWrap = new ForeignKeyData<string> { KeyValue = e.ID } }; var memb = (await mbsvc.ConstraintQueryAsync(Cntx, new UserAppMemberSet(), cond, null)).SingleOrDefault(); ar.Add(new { data = e, member = memb, hasIcon = memb != null && !string.IsNullOrEmpty(memb.IconMime) }); } string json = ser3.Serialize(ar); return json; }
public async Task<string> GetPageItems(string sourceId, string set, string qexpr, string prevlast) { JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; EntitySetType type; if (Enum.TryParse<EntitySetType>(sobj["set"], out type)) { switch (type) { case EntitySetType.User: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; UserServiceProxy svc = new UserServiceProxy(); UserSet _set = new UserSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) _set.SetFilter = sobj["setFilter"]; User _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as User; } var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); var ar = new List<dynamic>(); foreach (var e in result) { ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString }); } string json = ser3.Serialize(ar); return json; } case EntitySetType.Role: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(Role)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; RoleServiceProxy svc = new RoleServiceProxy(); RoleSet _set = new RoleSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) _set.SetFilter = sobj["setFilter"]; Role _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as Role; } var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); var ar = new List<dynamic>(); foreach (var e in result) { ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString }); } string json = ser3.Serialize(ar); return json; } case EntitySetType.MemberNotification: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(MemberNotification)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy(); MemberNotificationSet _set = new MemberNotificationSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) _set.SetFilter = sobj["setFilter"]; MemberNotification _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as MemberNotification; } var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); var ar = new List<dynamic>(); foreach (var e in result) { ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString }); } string json = ser3.Serialize(ar); return json; } } } return null; }
public async Task <string> GetPageItems(string sourceId, string set, string qexpr, string prevlast) { JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; EntitySetType type; if (Enum.TryParse <EntitySetType>(sobj["set"], out type)) { switch (type) { case EntitySetType.User: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; UserServiceProxy svc = new UserServiceProxy(); UserSet _set = new UserSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) { _set.SetFilter = sobj["setFilter"]; } User _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as User; } var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); var ar = new List <dynamic>(); foreach (var e in result) { ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString }); } string json = ser3.Serialize(ar); return(json); } case EntitySetType.Role: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(Role)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; RoleServiceProxy svc = new RoleServiceProxy(); RoleSet _set = new RoleSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) { _set.SetFilter = sobj["setFilter"]; } Role _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as Role; } var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); var ar = new List <dynamic>(); foreach (var e in result) { ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString }); } string json = ser3.Serialize(ar); return(json); } case EntitySetType.MemberNotification: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(MemberNotification)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy(); MemberNotificationSet _set = new MemberNotificationSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) { _set.SetFilter = sobj["setFilter"]; } MemberNotification _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as MemberNotification; } var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); var ar = new List <dynamic>(); foreach (var e in result) { ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString }); } string json = ser3.Serialize(ar); return(json); } } } return(null); }
public static async Task<string> GetManagedUsers(string adminId, string set, string qexpr, string prevlast) { var maxp = await GetMaxPriority(adminId); JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; EntitySetType type; if (Enum.TryParse<EntitySetType>(sobj["set"], out type)) { switch (type) { case EntitySetType.User: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; UserServiceProxy svc = new UserServiceProxy(); UserSet _set = new UserSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) _set.SetFilter = sobj["setFilter"]; User _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as User; } RoleServiceProxy rsvc = new RoleServiceProxy(); var roles = await rsvc.QueryDatabaseAsync(Cntx, new RoleSet(), null); var result = await svc.GetPageItemsAsync(Cntx, _set, _qexpr, _prevlast); var ar = new List<dynamic>(); string appId = ApplicationContext.App.ID; UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy(); foreach (var e in result) { List<Role> rlist = new List<Role>(); foreach (var r in roles) { if (r.RolePriority <= maxp.Major) rlist.Add(r); } var p = await GetMaxPriority(e); List<dynamic> rolelist = new List<dynamic>(); var _roles = await svc.MaterializeAllUsersInRole_UserIDsAsync(Cntx, e); dynamic _max = null; if (_roles != null) { List<UsersInRole> _rlist = new List<UsersInRole>(); foreach (var ir in _roles) { ir.RoleRef = uirsvc.MaterializeRoleRef(Cntx, ir); _rlist.Add(ir); } foreach (var ir in from d in _rlist orderby d.RoleRef.RolePriority descending, d.SubPriority descending select d) { bool op = adminId != e.ID && (ir.RoleRef.RolePriority < maxp.Major || ir.RoleRef.RolePriority == maxp.Major && ir.SubPriority <= maxp.Minor); var _r = new { id = ir.RoleRef.ID, uid = ir.UserID, name = ir.RoleRef.RoleName, path = Utils.GetHtmlRolePath(ir.RoleRef.DistinctString), level = ir.SubPriority, op = op }; if (ir.RoleRef.ID == p.MaxRole.ID) _max = _r; rolelist.Add(_r); int ptr = -1; for (int i = 0; i < rlist.Count; i++) { if (rlist[i].ID == ir.RoleRef.ID) { ptr = i; break; } } if (ptr != -1) rlist.RemoveAt(ptr); } } List<dynamic> availablers = new List<dynamic>(); //if (adminId != e.ID) { foreach (var r in rlist) availablers.Add(new { id = r.ID, name = r.RoleName, path = Utils.GetHtmlRolePath(r.DistinctString), op = true }); } var membs = svc.MaterializeAllUserAppMembers(Cntx, e); ar.Add(new { data = e, member = (from d in membs where d.ApplicationID == appId select d).SingleOrDefault(), roles = rolelist.ToArray(), maxrole = _max, availableRoles = availablers.ToArray(), CanEdit = p.IsLowerOrEqual(maxp) }); } string json = ser3.Serialize(ar); return json; } } } return null; }
public static async Task<string> GetMembers(string nhubId, string userId, string set, string qexpr, string prevlast, bool outgoing) { JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; UserServiceProxy svc = new UserServiceProxy(); UserSet _set = new UserSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) _set.SetFilter = sobj["setFilter"]; User _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as User; } var cntx = Cntx; var result = await svc.GetPageItemsAsync(cntx, _set, _qexpr, _prevlast); var ar = new List<dynamic>(); string appId = ApplicationContext.App.ID; UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy(); MemberCallbackServiceProxy cbsvc = new MemberCallbackServiceProxy(); UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-ApplicationContext.OnlineUserInactiveTime); foreach (var e in result) { var cond = new UserAppMemberSetConstraints { ApplicationIDWrap = new ForeignKeyData<string> { KeyValue = appId }, UserIDWrap = new ForeignKeyData<string> { KeyValue = e.ID } }; var memb = (await mbsvc.ConstraintQueryAsync(cntx, new UserAppMemberSet(), cond, null)).SingleOrDefault(); bool notify; if (outgoing) { var notifier = await cbsvc.LoadEntityByKeyAsync(cntx, "System", nhubId, appId, e.ID); notify = memb.LastActivityDate > dt && notifier != null && notifier.ConnectionID != null && !notifier.IsDisconnected; } else notify = false; var cond2 = new UserAssociationSetConstraints(); if (!outgoing) { cond2.FromUserIDWrap = new ForeignKeyData<string> { KeyValue = userId }; cond2.ToUserIDWrap = new ForeignKeyData<string> { KeyValue = e.ID }; cond2.TypeIDWrap = null; } else { cond2.FromUserIDWrap = new ForeignKeyData<string> { KeyValue = e.ID }; cond2.ToUserIDWrap = new ForeignKeyData<string> { KeyValue = userId }; cond2.TypeIDWrap = null; } var assocs = await uasvc.ConstraintQueryAsync(cntx, new UserAssociationSet(), cond2, null); var a = new { data = e, member = memb, hasIcon = memb != null && !string.IsNullOrEmpty(memb.IconMime), notify = notify, types = new List<int>() }; foreach (var assoc in assocs) a.types.Add(assoc.TypeID); ar.Add(a); } string json = ser3.Serialize(ar); return json; }
public static async Task <string> GetManagedUsers(string adminId, string set, string qexpr, string prevlast) { var maxp = await GetMaxPriority(adminId); JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; EntitySetType type; if (Enum.TryParse <EntitySetType>(sobj["set"], out type)) { switch (type) { case EntitySetType.User: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; UserServiceProxy svc = new UserServiceProxy(); UserSet _set = new UserSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) { _set.SetFilter = sobj["setFilter"]; } User _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as User; } RoleServiceProxy rsvc = new RoleServiceProxy(); var roles = await rsvc.QueryDatabaseAsync(Cntx, new RoleSet(), null); var result = await svc.GetPageItemsAsync(Cntx, _set, _qexpr, _prevlast); var ar = new List <dynamic>(); string appId = ApplicationContext.App.ID; UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy(); foreach (var e in result) { List <Role> rlist = new List <Role>(); foreach (var r in roles) { if (r.RolePriority <= maxp.Major) { rlist.Add(r); } } var p = await GetMaxPriority(e); List <dynamic> rolelist = new List <dynamic>(); var _roles = await svc.MaterializeAllUsersInRole_UserIDsAsync(Cntx, e); dynamic _max = null; if (_roles != null) { List <UsersInRole> _rlist = new List <UsersInRole>(); foreach (var ir in _roles) { ir.RoleRef = uirsvc.MaterializeRoleRef(Cntx, ir); _rlist.Add(ir); } foreach (var ir in from d in _rlist orderby d.RoleRef.RolePriority descending, d.SubPriority descending select d) { bool op = adminId != e.ID && (ir.RoleRef.RolePriority < maxp.Major || ir.RoleRef.RolePriority == maxp.Major && ir.SubPriority <= maxp.Minor); var _r = new { id = ir.RoleRef.ID, uid = ir.UserID, name = ir.RoleRef.RoleName, path = Utils.GetHtmlRolePath(ir.RoleRef.DistinctString), level = ir.SubPriority, op = op }; if (ir.RoleRef.ID == p.MaxRole.ID) { _max = _r; } rolelist.Add(_r); int ptr = -1; for (int i = 0; i < rlist.Count; i++) { if (rlist[i].ID == ir.RoleRef.ID) { ptr = i; break; } } if (ptr != -1) { rlist.RemoveAt(ptr); } } } List <dynamic> availablers = new List <dynamic>(); //if (adminId != e.ID) { foreach (var r in rlist) { availablers.Add(new { id = r.ID, name = r.RoleName, path = Utils.GetHtmlRolePath(r.DistinctString), op = true }); } } var membs = svc.MaterializeAllUserAppMembers(Cntx, e); ar.Add(new { data = e, member = (from d in membs where d.ApplicationID == appId select d).SingleOrDefault(), roles = rolelist.ToArray(), maxrole = _max, availableRoles = availablers.ToArray(), CanEdit = p.IsLowerOrEqual(maxp) }); } string json = ser3.Serialize(ar); return(json); } } } return(null); }
public static async Task <string> GetMembers(string nhubId, string userId, string set, string qexpr, string prevlast, bool outgoing) { JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; UserServiceProxy svc = new UserServiceProxy(); UserSet _set = new UserSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) { _set.SetFilter = sobj["setFilter"]; } User _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as User; } var cntx = Cntx; var result = await svc.GetPageItemsAsync(cntx, _set, _qexpr, _prevlast); var ar = new List <dynamic>(); string appId = ApplicationContext.App.ID; UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy(); MemberCallbackServiceProxy cbsvc = new MemberCallbackServiceProxy(); UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-ApplicationContext.OnlineUserInactiveTime); foreach (var e in result) { var cond = new UserAppMemberSetConstraints { ApplicationIDWrap = new ForeignKeyData <string> { KeyValue = appId }, UserIDWrap = new ForeignKeyData <string> { KeyValue = e.ID } }; var memb = (await mbsvc.ConstraintQueryAsync(cntx, new UserAppMemberSet(), cond, null)).SingleOrDefault(); bool notify; if (outgoing) { var notifier = await cbsvc.LoadEntityByKeyAsync(cntx, "System", nhubId, appId, e.ID); notify = memb.LastActivityDate > dt && notifier != null && notifier.ConnectionID != null && !notifier.IsDisconnected; } else { notify = false; } var cond2 = new UserAssociationSetConstraints(); if (!outgoing) { cond2.FromUserIDWrap = new ForeignKeyData <string> { KeyValue = userId }; cond2.ToUserIDWrap = new ForeignKeyData <string> { KeyValue = e.ID }; cond2.TypeIDWrap = null; } else { cond2.FromUserIDWrap = new ForeignKeyData <string> { KeyValue = e.ID }; cond2.ToUserIDWrap = new ForeignKeyData <string> { KeyValue = userId }; cond2.TypeIDWrap = null; } var assocs = await uasvc.ConstraintQueryAsync(cntx, new UserAssociationSet(), cond2, null); var a = new { data = e, member = memb, hasIcon = memb != null && !string.IsNullOrEmpty(memb.IconMime), notify = notify, types = new List <int>() }; foreach (var assoc in assocs) { a.types.Add(assoc.TypeID); } ar.Add(a); } string json = ser3.Serialize(ar); return(json); }