public static async Task<UserAppMember> SetNotification(string userId, SimpleMessage[] msgs) { UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy(); var cntx = Cntx; var memb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, userId); if (memb != null) { memb.ChangedMemberCallbacks = (await mbsvc.MaterializeAllMemberCallbacksAsync(cntx, memb)).ToArray(); var notices = new List<MemberNotification>(); foreach (var msg in msgs) { notices.Add(new MemberNotification { ID = Guid.NewGuid().ToString(), Title = msg.Title, NoticeMsg = msg.Message, NoticeData = msg.Data, CreatedDate = DateTime.UtcNow, PriorityLevel = (short)msg.Priority, ReadCount = 0, TypeID = msg.TypeId, UserID = userId, ApplicationID = AppId }); } MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); var results = await nsvc.AddOrUpdateEntitiesAsync(Cntx, new MemberNotificationSet(), notices.ToArray()); for (int i = 0; i < msgs.Length; i++) msgs[i].Id = results.ChangedEntities[i].UpdatedItem.ID; } return memb; }
public static async Task <ConnectionStatus> UserCancelInteraction(string noticeHubId, string hubId, string peerId, string userId, string connectId, string languages) { var cntx = Cntx; MemberCallbackServiceProxy mbcsvc = new MemberCallbackServiceProxy(); ConnectionStatus status = new ConnectionStatus(); var notifier = await mbcsvc.LoadEntityByKeyAsync(cntx, "System", noticeHubId, AppId, peerId); if (notifier != null && notifier.ConnectionID != null && !notifier.IsDisconnected) { status.peerNotifier = notifier; status.status = PeerStatus.Notifiable; } UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); var mbsvc = new UserAppMemberServiceProxy(); var peerMb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, peerId); MemberNotificationTypeServiceProxy ntsvc = new MemberNotificationTypeServiceProxy(); var ntype = await ntsvc.LoadEntityByKeyAsync(cntx, 3); var peerCb = await mbcsvc.LoadEntityByKeyAsync(cntx, userId, hubId, AppId, peerId); string title = string.Format(ResourceUtils.GetString("cdc8520b5121c757e6eb79e098d6baef", "{0} cancelled chatting invitation.", peerMb.AcceptLanguages), u.Username); if (peerCb == null || peerCb.ConnectionID == null || peerCb.IsDisconnected) { MemberNotification n = new MemberNotification { ID = Guid.NewGuid().ToString(), Title = title, CreatedDate = DateTime.UtcNow, PriorityLevel = 0, ReadCount = 0, ApplicationID = AppId, TypeID = 3, UserID = peerId }; n.NoticeMsg = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"msg\": \"" + title + "\", \"isCancel\": true, \"isDisconnect\": false }"; n.IsNoticeDataLoaded = true; MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); var r = await nsvc.AddOrUpdateEntitiesAsync(cntx, new MemberNotificationSet(), new MemberNotification[] { n }); status.noticeType = ntype.TypeName; status.noticeMsg = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"msg\": \"" + title + "\", \"isCancel\": true, \"isDisconnect\": false }"; status.noticeRecId = r.ChangedEntities[0].UpdatedItem.ID; } else { status.noticeMsg = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"msg\": \"" + title + "\", \"isCancel\": true, \"isDisconnect\": true }"; } status.peer = peerCb; return(status); }
public async Task <string> GetSetInfo(string sourceId, string set) { JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; EntitySetType type; if (Enum.TryParse <EntitySetType>(sobj["set"], out type)) { string filter = null; if (sobj.ContainsKey("setFilter")) { filter = sobj["setFilter"]; } switch (type) { case EntitySetType.User: { UserServiceProxy svc = new UserServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return(json); } case EntitySetType.Role: { RoleServiceProxy svc = new RoleServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return(json); } case EntitySetType.MemberNotification: { MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return(json); } } } return(null); }
public async Task<string> GetSetInfo(string sourceId, string set) { JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; EntitySetType type; if (Enum.TryParse<EntitySetType>(sobj["set"], out type)) { string filter = null; if (sobj.ContainsKey("setFilter")) filter = sobj["setFilter"]; switch (type) { case EntitySetType.User: { UserServiceProxy svc = new UserServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return json; } case EntitySetType.Role: { RoleServiceProxy svc = new RoleServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return json; } case EntitySetType.MemberNotification: { MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return json; } } } return null; }
public static async Task <UserAppMember> SetNotification(string userId, SimpleMessage[] msgs) { UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy(); var cntx = Cntx; var memb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, userId); if (memb != null) { memb.ChangedMemberCallbacks = (await mbsvc.MaterializeAllMemberCallbacksAsync(cntx, memb)).ToArray(); var notices = new List <MemberNotification>(); foreach (var msg in msgs) { notices.Add(new MemberNotification { ID = Guid.NewGuid().ToString(), Title = msg.Title, NoticeMsg = msg.Message, NoticeData = msg.Data, CreatedDate = DateTime.UtcNow, PriorityLevel = (short)msg.Priority, ReadCount = 0, TypeID = msg.TypeId, UserID = userId, ApplicationID = AppId }); } MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); var results = await nsvc.AddOrUpdateEntitiesAsync(Cntx, new MemberNotificationSet(), notices.ToArray()); for (int i = 0; i < msgs.Length; i++) { msgs[i].Id = results.ChangedEntities[i].UpdatedItem.ID; } } return(memb); }
public static async Task<string> GetNotifications(string set, string qexpr, string prevlast) { var cntx = Cntx; JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; 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"]); _set.SetFilter = sobj["setFilter"]; string usrId = HttpContext.Current.User.Identity.GetUserId(); if (_set.SetFilter.Contains(usrId)) { // just in case the script was tempered with by clients. _set.SetFilter += " && UserRef.ID == \"" + usrId + "\""; } 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(cntx, _set, _qexpr, _prevlast)).ToArray(); List<dynamic> ar = new List<dynamic>(); Dictionary<int, MemberNotificationType> dic = new Dictionary<int, MemberNotificationType>(); foreach (var e in result) { MemberNotificationType c; if (!dic.TryGetValue(e.TypeID, out c)) { c = await svc.MaterializeMemberNotificationTypeRefAsync(cntx, e); c.TypeName = MapCategoryName(c); dic.Add(e.TypeID, c); } ar.Add(new { categ = new { Id = c.ID, name = c.TypeName }, data = e }); } string json = ser3.Serialize(ar); return json; }
public static async Task <ConnectionStatus> UserConnected(string noticeHubId, string hubId, string peerId, string userId, string connectId, string languages) { var mbsvc = new UserAppMemberServiceProxy(); var cntx = Cntx; cntx.AcceptLanguages = languages; var memb = await mbsvc.LoadEntityGraphRecursAsync(cntx, AppId, userId, null, null); if (memb != null) { memb.StartAutoUpdating = true; memb.LastActivityDate = DateTime.UtcNow; memb.AcceptLanguages = languages; List <MemberCallback> callbacks; if (memb.ChangedMemberCallbacks == null) { callbacks = new List <MemberCallback>(); } else { callbacks = new List <MemberCallback>(memb.ChangedMemberCallbacks); } var cbk = (from d in callbacks where d.HubID == hubId && d.ChannelID == peerId select d).SingleOrDefault(); if (cbk == null) { cbk = new MemberCallback { ApplicationID = AppId, UserID = userId, HubID = hubId, ChannelID = peerId, ConnectionID = connectId, IsDisconnected = false, LastActiveDate = DateTime.UtcNow }; } else { // it is very important to turn this on, otherwise the property will not be marked as modified. // and the service will not save the change! cbk.StartAutoUpdating = true; cbk.ConnectionID = connectId; cbk.IsDisconnected = false; cbk.LastActiveDate = DateTime.UtcNow; } memb.ChangedMemberCallbacks = new MemberCallback[] { cbk }; await mbsvc.AddOrUpdateEntitiesAsync(cntx, new UserAppMemberSet(), new UserAppMember[] { memb }); UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); memb.UserRef = u; var peerMb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, peerId); ConnectionStatus status = new ConnectionStatus(); status.me = cbk; MemberCallbackServiceProxy mbcsvc = new MemberCallbackServiceProxy(); var peerCb = await mbcsvc.LoadEntityByKeyAsync(cntx, userId, hubId, AppId, peerId); if (peerCb == null || peerCb.ConnectionID == null || peerCb.IsDisconnected) { MemberNotificationTypeServiceProxy ntsvc = new MemberNotificationTypeServiceProxy(); var ntype = await ntsvc.LoadEntityByKeyAsync(cntx, 3); var notifier = await mbcsvc.LoadEntityByKeyAsync(cntx, "System", noticeHubId, AppId, peerId); if (notifier != null && notifier.ConnectionID != null && !notifier.IsDisconnected) { status.peerNotifier = notifier; status.status = PeerStatus.Notifiable; } MemberNotification n = new MemberNotification { ID = Guid.NewGuid().ToString(), Title = string.Format(ResourceUtils.GetString("20dc5913998d0e9ed01360475e46a0f9", "{0} invites you to chat, is waiting ...", peerMb.AcceptLanguages), u.Username), CreatedDate = DateTime.UtcNow, PriorityLevel = 0, ReadCount = 0, ApplicationID = AppId, TypeID = 3, UserID = peerId }; n.NoticeMsg = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"msg\": \"" + n.Title + "\", \"isCancel\": false }"; n.IsNoticeDataLoaded = true; MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); var r = await nsvc.AddOrUpdateEntitiesAsync(cntx, new MemberNotificationSet(), new MemberNotification[] { n }); status.noticeType = ntype.TypeName; status.noticeMsg = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"msg\": \"" + n.Title + "\", \"isCancel\": false }"; status.noticeRecId = r.ChangedEntities[0].UpdatedItem.ID; } else { UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy(); UserAssociation utop = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId); DateTime dt = DateTime.UtcNow; if (utop == null) { utop = new UserAssociation { TypeID = ApplicationContext.ChatAssocTypeId, FromUserID = userId, ToUserID = peerId, CreateDate = dt, AssocCount = 1, LastAssoc = dt, InteractCount = 0, Votes = 0 }; } else { utop.AssocCount++; } UserAssociation ptou = await uasvc.LoadEntityByKeyAsync(cntx, peerId, userId, ApplicationContext.ChatAssocTypeId); if (ptou == null) { ptou = new UserAssociation { TypeID = ApplicationContext.ChatAssocTypeId, FromUserID = peerId, ToUserID = userId, CreateDate = dt, AssocCount = 1, LastAssoc = dt, InteractCount = 0, Votes = 0 }; } else { ptou.AssocCount++; } await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), new UserAssociation[] { utop, ptou }); status.status = PeerStatus.Connected; } if (peerCb != null) { peerCb.UserAppMemberRef = peerMb; } status.peer = peerCb; return(status); } return(null); }
public static async Task <string> GetNotifications(string set, string qexpr, string prevlast) { var cntx = Cntx; JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; 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"]); _set.SetFilter = sobj["setFilter"]; string usrId = HttpContext.Current.User.Identity.GetUserId(); if (_set.SetFilter.Contains(usrId)) { // just in case the script was tempered with by clients. _set.SetFilter += " && UserRef.ID == \"" + usrId + "\""; } 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(cntx, _set, _qexpr, _prevlast)).ToArray(); List <dynamic> ar = new List <dynamic>(); Dictionary <int, MemberNotificationType> dic = new Dictionary <int, MemberNotificationType>(); foreach (var e in result) { MemberNotificationType c; if (!dic.TryGetValue(e.TypeID, out c)) { c = await svc.MaterializeMemberNotificationTypeRefAsync(cntx, e); c.TypeName = MapCategoryName(c); dic.Add(e.TypeID, c); } ar.Add(new { categ = new { Id = c.ID, name = c.TypeName }, data = e }); } 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> NextPageBlock(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)); DataContractJsonSerializer ser3 = new DataContractJsonSerializer(typeof(UserPageBlock)); 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.NextPageBlockAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); strm = new System.IO.MemoryStream(); ser3.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return(json); } case EntitySetType.Role: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(Role)); DataContractJsonSerializer ser3 = new DataContractJsonSerializer(typeof(RolePageBlock)); 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.NextPageBlockAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); strm = new System.IO.MemoryStream(); ser3.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return(json); } case EntitySetType.MemberNotification: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(MemberNotification)); DataContractJsonSerializer ser3 = new DataContractJsonSerializer(typeof(MemberNotificationPageBlock)); 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.NextPageBlockAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); strm = new System.IO.MemoryStream(); ser3.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return(json); } case EntitySetType.ShortMessage: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(ShortMessage)); DataContractJsonSerializer ser3 = new DataContractJsonSerializer(typeof(ShortMessagePageBlock)); 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; var svc = new ShortMessageServiceProxy(); var _set = new ShortMessageSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (!sobj.ContainsKey("setFilter")) { throw new Exception("The page is not properly parameterized!"); } else { Func <string, string, int> count = (s, p) => { int _cnt = 0; int i = 0; while ((i = s.IndexOf(p, i)) != -1) { _cnt++; i += p.Length; } return(_cnt); }; string filter = sobj["setFilter"]; if (filter.Contains("ToID is null") && filter.Contains("___usergroups___") && count(filter, "||") == 0) { string[] mbgrpIds = await GroupChatViewContext.UserGroupChatMembers(System.Web.HttpContext.Current.User.Identity.GetUserId()); if (mbgrpIds == null || mbgrpIds.Length == 0) { throw new Exception(ResourceUtils.GetString("234038e6185f013e25d0213c06f5a0e9", "You are not a member of any chat group.")); } string groupexpr = ""; foreach (var gid in mbgrpIds) { groupexpr += (groupexpr != "" ? " || " : "") + "GroupID == \"" + gid + "\""; } _set.SetFilter = filter.Replace("___usergroups___", groupexpr); } else if (filter.EndsWith("&& ToID is not null && GroupID is null && ( ToID == \"{0}\" || FromID == \"{0}\" )") && count(filter, "||") == 1) { filter = string.Format(filter, System.Web.HttpContext.Current.User.Identity.GetUserId()); _set.SetFilter = filter; } else { throw new Exception("The page is not properly parameterized!"); } } ShortMessage _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 ShortMessage; } var result = await svc.NextPageBlockAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); strm = new System.IO.MemoryStream(); ser3.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return(json); } } } return(null); }
public async Task <string> GetSetInfo(string sourceId, string set) { JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; EntitySetType type; if (Enum.TryParse <EntitySetType>(sobj["set"], out type)) { string filter = null; if (sobj.ContainsKey("setFilter")) { filter = sobj["setFilter"]; } switch (type) { case EntitySetType.User: { UserServiceProxy svc = new UserServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return(json); } case EntitySetType.Role: { RoleServiceProxy svc = new RoleServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return(json); } case EntitySetType.MemberNotification: { MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return(json); } case EntitySetType.ShortMessage: { if (filter == null) { throw new Exception("The page is not properly parameterized!"); } else { Func <string, string, int> count = (s, p) => { int _cnt = 0; int i = 0; while ((i = s.IndexOf(p, i)) != -1) { _cnt++; i += p.Length; } return(_cnt); }; if (filter.Contains("ToID is null") && filter.Contains("___usergroups___") && count(filter, "||") == 0) { string[] mbgrpIds = await GroupChatViewContext.UserGroupChatMembers(System.Web.HttpContext.Current.User.Identity.GetUserId()); if (mbgrpIds == null || mbgrpIds.Length == 0) { throw new Exception(ResourceUtils.GetString("234038e6185f013e25d0213c06f5a0e9", "You are not a member of any chat group.")); } string groupexpr = ""; foreach (var gid in mbgrpIds) { groupexpr += (groupexpr != "" ? " || " : "") + "GroupID == \"" + gid + "\""; } filter = filter.Replace("___usergroups___", groupexpr); } else if (filter.EndsWith("&& ToID is not null && GroupID is null && ( ToID == \"{0}\" || FromID == \"{0}\" )") && count(filter, "||") == 1) { filter = string.Format(filter, System.Web.HttpContext.Current.User.Identity.GetUserId()); } else { throw new Exception("The page is not properly parameterized!"); } } ShortMessageServiceProxy svc = new ShortMessageServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return(json); } } } return(null); }
public async Task<string> GetNextFilterOps(string sourceId, string set, string qexpr) { EntitySetType type; if (Enum.TryParse<EntitySetType>(set, out type)) { switch (type) { case EntitySetType.User: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(TokenOptions)); 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(); var result = await svc.GetNextFilterOpsAsync(ApplicationContext.ClientContext, _qexpr, ""); strm = new System.IO.MemoryStream(); ser2.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return json; } case EntitySetType.Role: { var ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); var ser2 = new DataContractJsonSerializer(typeof(TokenOptions)); 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(); var result = await svc.GetNextFilterOpsAsync(ApplicationContext.ClientContext, _qexpr, ""); strm = new System.IO.MemoryStream(); ser2.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return json; } case EntitySetType.MemberNotification: { var ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); var ser2 = new DataContractJsonSerializer(typeof(TokenOptions)); 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(); var result = await svc.GetNextFilterOpsAsync(ApplicationContext.ClientContext, _qexpr, ""); strm = new System.IO.MemoryStream(); ser2.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return json; } case EntitySetType.ShortMessage: { var ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); var ser2 = new DataContractJsonSerializer(typeof(TokenOptions)); 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; var svc = new ShortMessageServiceProxy(); var result = await svc.GetNextFilterOpsAsync(ApplicationContext.ClientContext, _qexpr, ""); strm = new System.IO.MemoryStream(); ser2.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return json; } } } return null; }
public async Task<string> NextPageBlock(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)); DataContractJsonSerializer ser3 = new DataContractJsonSerializer(typeof(UserPageBlock)); 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.NextPageBlockAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); strm = new System.IO.MemoryStream(); ser3.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return json; } case EntitySetType.Role: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(Role)); DataContractJsonSerializer ser3 = new DataContractJsonSerializer(typeof(RolePageBlock)); 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.NextPageBlockAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); strm = new System.IO.MemoryStream(); ser3.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return json; } case EntitySetType.MemberNotification: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(MemberNotification)); DataContractJsonSerializer ser3 = new DataContractJsonSerializer(typeof(MemberNotificationPageBlock)); 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.NextPageBlockAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); strm = new System.IO.MemoryStream(); ser3.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return json; } case EntitySetType.ShortMessage: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(ShortMessage)); DataContractJsonSerializer ser3 = new DataContractJsonSerializer(typeof(ShortMessagePageBlock)); 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; var svc = new ShortMessageServiceProxy(); var _set = new ShortMessageSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (!sobj.ContainsKey("setFilter")) throw new Exception("The page is not properly parameterized!"); else { Func<string, string, int> count = (s, p) => { int _cnt = 0; int i = 0; while ((i = s.IndexOf(p, i)) != -1) { _cnt++; i += p.Length; } return _cnt; }; string filter = sobj["setFilter"]; if (filter.Contains("ToID is null") && filter.Contains("___usergroups___") && count(filter, "||") == 0) { string[] mbgrpIds = await GroupChatViewContext.UserGroupChatMembers(System.Web.HttpContext.Current.User.Identity.GetUserId()); if (mbgrpIds == null || mbgrpIds.Length == 0) throw new Exception(ResourceUtils.GetString("234038e6185f013e25d0213c06f5a0e9", "You are not a member of any chat group.")); string groupexpr = ""; foreach (var gid in mbgrpIds) groupexpr += (groupexpr != "" ? " || " : "") + "GroupID == \"" + gid + "\""; _set.SetFilter = filter.Replace("___usergroups___", groupexpr); } else if (filter.EndsWith("&& ToID is not null && GroupID is null && ( ToID == \"{0}\" || FromID == \"{0}\" )") && count(filter, "||") == 1) { filter = string.Format(filter, System.Web.HttpContext.Current.User.Identity.GetUserId()); _set.SetFilter = filter; } else throw new Exception("The page is not properly parameterized!"); } ShortMessage _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 ShortMessage; } var result = await svc.NextPageBlockAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast); strm = new System.IO.MemoryStream(); ser3.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return json; } } } return null; }
public static async Task<ShotMessageNotice> UpdateUserMessage(string noticeHubId, string chatHubId, string userId, string groupId, string msgId, string message) { var cntx = Cntx; UserGroupServiceProxy gsvc = new UserGroupServiceProxy(); var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); var msg = await msvc.LoadEntityByKeyAsync(cntx, msgId); if (msg == null || msg.FromID != userId) return null; if (msg.MsgText == message) return null; var now = DateTime.UtcNow; msg.MsgTitle = GetLeadText(message); msg.MsgText = message; msg.LastModified = now; await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); msg.User_FromID = u; UserGroupMemberServiceProxy gmsvc = new UserGroupMemberServiceProxy(); var cond = new UserGroupMemberSetConstraints { UserGroupIDWrap = new ForeignKeyData<string> { KeyValue = groupId } }; var qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "UserID" } }); qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "SubscribedTo is not null && SubscribedTo == true" } }); var gmbs = await gmsvc.ConstraintQueryAsync(cntx, new UserGroupMemberSet(), cond, qexpr); List<MemberNotification> notices = new List<MemberNotification>(); List<MemberCallback> noteCbks = new List<MemberCallback>(); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); string noticeMsg = "Group message by " + u.Username + " updated in " + g.DistinctString; MemberNotificationTypeServiceProxy ntsvc = new MemberNotificationTypeServiceProxy(); var ntype = await ntsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.NewMessageNoticeTypeId); foreach (var m in gmbs) { if (m.ActivityNotification.HasValue && m.ActivityNotification.Value) { var cb = await mcbsvc.LoadEntityByKeyAsync(cntx, groupId, noticeHubId, AppId, m.UserID); if (cb.ConnectionID != null && !cb.IsDisconnected) { cb.UserAppMemberRef = await mcbsvc.MaterializeUserAppMemberRefAsync(cntx, cb); noteCbks.Add(cb); } } notices.Add(new MemberNotification { ID = Guid.NewGuid().ToString(), Title = noticeMsg, CreatedDate = now, PriorityLevel = 0, ReadCount = 0, ApplicationID = AppId, TypeID = ApplicationContext.NewMessageNoticeTypeId, UserID = userId }); } var peers = await ListConnectIds(chatHubId, groupId); List<ShortMessageAudience> laud = new List<ShortMessageAudience>(); foreach (var peer in peers) { if (peer.UserID != userId) { var a = new ShortMessageAudience { MsgID = msg.ID, UserID = peer.UserID, VoteCount = 0 }; laud.Add(a); } } if (laud.Count > 0) { ShortMessageAudienceServiceProxy audsvc = new ShortMessageAudienceServiceProxy(); await audsvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageAudienceSet(), laud.ToArray()); } if (notices.Count > 0) { MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); await nsvc.AddOrUpdateEntitiesAsync(cntx, new MemberNotificationSet(), notices.ToArray()); } return new ShotMessageNotice { msg = GetJsonMessage(msg, userId, g, false), brief = noticeMsg, categ = ntype, peers = peers, callbacks = noteCbks }; }
public static async Task<List<MemberNotificationType>> GetRecentCategorized(string userId, SimpleMessage[] msgs, int? typeId, int max) { var cntx = Cntx; MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); MemberNotificationTypeServiceProxy tsvc = new MemberNotificationTypeServiceProxy(); MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); var categs = await tsvc.QueryDatabaseAsync(cntx, new MemberNotificationTypeSet(), null); List<MemberNotificationType> tlist = new List<MemberNotificationType>(); DateTime dt = DateTime.UtcNow.AddDays(-1); foreach (var categ in categs) { if (typeId.HasValue && categ.ID != typeId.Value) continue; var cond = new MemberNotificationSetConstraints { ApplicationIDWrap = new ForeignKeyData<string> { KeyValue = AppId }, UserIDWrap = new ForeignKeyData<string> { KeyValue = userId }, TypeIDWrap = new ForeignKeyData<int> { KeyValue = categ.ID } }; QueryExpresion qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "PriorityLevel" }, new QToken { TkName = "desc" }, new QToken { TkName = "CreatedDate" }, new QToken { TkName = "desc" } }); qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "ReadCount == 0 && CreatedDate >= " + svc.FormatRepoDateTime(dt) } }); foreach (var msg in msgs) { qexpr.FilterTks.Add(new QToken { TkName = " && ID != \"" + msg.Id + "\"" }); } var list = (await nsvc.ConstraintQueryLimitedAsync(cntx, new MemberNotificationSet(), cond, qexpr, max)).ToList(); if (list.Count > 0) { categ.ChangedMemberNotifications = list.ToArray(); tlist.Add(categ); } } return tlist; }
public static async Task<ConnectionStatus> UserConnected(string noticeHubId, string hubId, string peerId, string userId, string connectId, string languages) { var mbsvc = new UserAppMemberServiceProxy(); var cntx = Cntx; cntx.AcceptLanguages = languages; var memb = await mbsvc.LoadEntityGraphRecursAsync(cntx, AppId, userId, null, null); if (memb != null) { memb.StartAutoUpdating = true; memb.LastActivityDate = DateTime.UtcNow; memb.AcceptLanguages = languages; List<MemberCallback> callbacks; if (memb.ChangedMemberCallbacks == null) callbacks = new List<MemberCallback>(); else callbacks = new List<MemberCallback>(memb.ChangedMemberCallbacks); var cbk = (from d in callbacks where d.HubID == hubId && d.ChannelID == peerId select d).SingleOrDefault(); if (cbk == null) { cbk = new MemberCallback { ApplicationID = AppId, UserID = userId, HubID = hubId, ChannelID = peerId, ConnectionID = connectId, IsDisconnected = false, LastActiveDate = DateTime.UtcNow }; } else { // it is very important to turn this on, otherwise the property will not be marked as modified. // and the service will not save the change! cbk.StartAutoUpdating = true; cbk.ConnectionID = connectId; cbk.IsDisconnected = false; cbk.LastActiveDate = DateTime.UtcNow; } memb.ChangedMemberCallbacks = new MemberCallback[] { cbk }; await mbsvc.AddOrUpdateEntitiesAsync(cntx, new UserAppMemberSet(), new UserAppMember[] { memb }); UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); memb.UserRef = u; var peerMb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, peerId); ConnectionStatus status = new ConnectionStatus(); status.me = cbk; MemberCallbackServiceProxy mbcsvc = new MemberCallbackServiceProxy(); UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy(); var peerCb = await mbcsvc.LoadEntityByKeyAsync(cntx, userId, hubId, AppId, peerId); if (peerCb == null || peerCb.ConnectionID == null || peerCb.IsDisconnected) { UserAssociation utop = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId); MemberNotificationTypeServiceProxy ntsvc = new MemberNotificationTypeServiceProxy(); var ntype = await ntsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.PrivateChatNoticeTypeId); var notifier = await mbcsvc.LoadEntityByKeyAsync(cntx, "System", noticeHubId, AppId, peerId); if (notifier != null && notifier.ConnectionID != null && !notifier.IsDisconnected) { if (utop != null && utop.NoMessages != null && utop.NoMessages == true) { status.status = PeerStatus.InBlackList; } else if (utop != null && utop.DoNotNotify != null && utop.DoNotNotify == true) { status.status = PeerStatus.DoNotDisturb; } else if (utop != null && utop.NotifyButBlock != null && utop.NotifyButBlock == true) { status.peerNotifier = notifier; status.status = PeerStatus.NotifyButBlock; } else { status.peerNotifier = notifier; status.status = PeerStatus.Notifiable; } } else { if (utop == null || utop.NoMessages == null || utop.NoMessages == false) status.status = PeerStatus.LeaveMessage; } MemberNotification n = new MemberNotification { ID = Guid.NewGuid().ToString(), Title = string.Format(ResourceUtils.GetString("20dc5913998d0e9ed01360475e46a0f9", "{0} invites you to chat, is waiting ...", peerMb.AcceptLanguages), ""), CreatedDate = DateTime.UtcNow, PriorityLevel = 0, ReadCount = 0, ApplicationID = AppId, TypeID = ApplicationContext.PrivateChatNoticeTypeId, UserID = peerId }; bool hasIcon = !string.IsNullOrEmpty(memb.IconMime); n.NoticeMsg = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"hasIcon\": " + (hasIcon ? "true" : "false") + ", \"msg\": \"" + n.Title + "\", \"isCancel\": false, "; if (utop != null && utop.NoMessages != null && utop.NoMessages == true) n.NoticeMsg += "\"noMessages\": true, "; else n.NoticeMsg += "\"noMessages\": false, "; if (utop != null && utop.DoNotNotify != null && utop.DoNotNotify == true) n.NoticeMsg += "\"notDisturb\": true, "; else n.NoticeMsg += "\"notDisturb\": false, "; if (utop != null && utop.NotifyButBlock != null && utop.NotifyButBlock == true) n.NoticeMsg += "\"keepNotified\": true }"; else n.NoticeMsg += "\"keepNotified\": false }"; n.IsNoticeDataLoaded = true; MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); var r = await nsvc.AddOrUpdateEntitiesAsync(cntx, new MemberNotificationSet(), new MemberNotification[] { n }); status.noticeType = ntype.TypeName; status.noticeMsg = n.NoticeMsg; status.noticeRecId = r.ChangedEntities[0].UpdatedItem.ID; } else { DateTime dt = DateTime.UtcNow; UserAssociation utop = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId); if (utop == null) { utop = new UserAssociation { TypeID = ApplicationContext.ChatAssocTypeId, FromUserID = userId, ToUserID = peerId, CreateDate = dt, AssocCount = 1, LastAssoc = dt, InteractCount = 0, Votes = 0 }; } else utop.AssocCount++; UserAssociation ptou = await uasvc.LoadEntityByKeyAsync(cntx, peerId, userId, ApplicationContext.ChatAssocTypeId); if (ptou == null) { ptou = new UserAssociation { TypeID = ApplicationContext.ChatAssocTypeId, FromUserID = peerId, ToUserID = userId, CreateDate = dt, AssocCount = 1, LastAssoc = dt, InteractCount = 0, Votes = 0 }; } else ptou.AssocCount++; await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), new UserAssociation[] { utop, ptou }); status.status = PeerStatus.Connected; } if (peerCb != null) peerCb.UserAppMemberRef = peerMb; status.peer = peerCb; return status; } return null; }
public static async Task<ConnectionStatus> UserCancelInteraction(string noticeHubId, string hubId, string peerId, string userId, string connectId, string languages) { var cntx = Cntx; MemberCallbackServiceProxy mbcsvc = new MemberCallbackServiceProxy(); ConnectionStatus status = new ConnectionStatus(); var notifier = await mbcsvc.LoadEntityByKeyAsync(cntx, "System", noticeHubId, AppId, peerId); if (notifier != null && notifier.ConnectionID != null && !notifier.IsDisconnected) { status.peerNotifier = notifier; status.status = PeerStatus.Notifiable; } UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); var mbsvc = new UserAppMemberServiceProxy(); var peerMb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, peerId); MemberNotificationTypeServiceProxy ntsvc = new MemberNotificationTypeServiceProxy(); var ntype = await ntsvc.LoadEntityByKeyAsync(cntx, 3); var peerCb = await mbcsvc.LoadEntityByKeyAsync(cntx, userId, hubId, AppId, peerId); string title = string.Format(ResourceUtils.GetString("cdc8520b5121c757e6eb79e098d6baef", "{0} cancelled chatting invitation.", peerMb.AcceptLanguages), u.Username); if (peerCb == null || peerCb.ConnectionID == null || peerCb.IsDisconnected) { MemberNotification n = new MemberNotification { ID = Guid.NewGuid().ToString(), Title = title, CreatedDate = DateTime.UtcNow, PriorityLevel = 0, ReadCount = 0, ApplicationID = AppId, TypeID = 3, UserID = peerId }; n.NoticeMsg = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"msg\": \"" + title + "\", \"isCancel\": true, \"isDisconnect\": false }"; n.IsNoticeDataLoaded = true; MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); var r = await nsvc.AddOrUpdateEntitiesAsync(cntx, new MemberNotificationSet(), new MemberNotification[] { n }); status.noticeType = ntype.TypeName; status.noticeMsg = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"msg\": \"" + title + "\", \"isCancel\": true, \"isDisconnect\": false }"; status.noticeRecId = r.ChangedEntities[0].UpdatedItem.ID; } else { status.noticeMsg = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"msg\": \"" + title + "\", \"isCancel\": true, \"isDisconnect\": true }"; } status.peer = peerCb; return status; }
public static async Task <ShotMessageNotice> UpdateUserMessage(string noticeHubId, string chatHubId, string userId, string groupId, string msgId, string message) { var cntx = Cntx; UserGroupServiceProxy gsvc = new UserGroupServiceProxy(); var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); var msg = await msvc.LoadEntityByKeyAsync(cntx, msgId); if (msg == null || msg.FromID != userId) { return(null); } if (msg.MsgText == message) { return(null); } var now = DateTime.UtcNow; msg.MsgTitle = GetLeadText(message); msg.MsgText = message; msg.LastModified = now; await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); msg.User_FromID = u; UserGroupMemberServiceProxy gmsvc = new UserGroupMemberServiceProxy(); var cond = new UserGroupMemberSetConstraints { UserGroupIDWrap = new ForeignKeyData <string> { KeyValue = groupId } }; var qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "UserID" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "SubscribedTo is not null && SubscribedTo == true" } }); var gmbs = await gmsvc.ConstraintQueryAsync(cntx, new UserGroupMemberSet(), cond, qexpr); List <MemberNotification> notices = new List <MemberNotification>(); List <MemberCallback> noteCbks = new List <MemberCallback>(); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); string noticeMsg = "Group message by " + u.Username + " updated in " + g.DistinctString; MemberNotificationTypeServiceProxy ntsvc = new MemberNotificationTypeServiceProxy(); var ntype = await ntsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.NewMessageNoticeTypeId); foreach (var m in gmbs) { if (m.ActivityNotification.HasValue && m.ActivityNotification.Value) { var cb = await mcbsvc.LoadEntityByKeyAsync(cntx, groupId, noticeHubId, AppId, m.UserID); if (cb.ConnectionID != null && !cb.IsDisconnected) { cb.UserAppMemberRef = await mcbsvc.MaterializeUserAppMemberRefAsync(cntx, cb); noteCbks.Add(cb); } } notices.Add(new MemberNotification { ID = Guid.NewGuid().ToString(), Title = noticeMsg, CreatedDate = now, PriorityLevel = 0, ReadCount = 0, ApplicationID = AppId, TypeID = ApplicationContext.NewMessageNoticeTypeId, UserID = userId }); } var peers = await ListConnectIds(chatHubId, groupId); List <ShortMessageAudience> laud = new List <ShortMessageAudience>(); foreach (var peer in peers) { if (peer.UserID != userId) { var a = new ShortMessageAudience { MsgID = msg.ID, UserID = peer.UserID, VoteCount = 0 }; laud.Add(a); } } if (laud.Count > 0) { ShortMessageAudienceServiceProxy audsvc = new ShortMessageAudienceServiceProxy(); await audsvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageAudienceSet(), laud.ToArray()); } if (notices.Count > 0) { MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); await nsvc.AddOrUpdateEntitiesAsync(cntx, new MemberNotificationSet(), notices.ToArray()); } return(new ShotMessageNotice { msg = GetJsonMessage(msg, userId, g, false), brief = noticeMsg, categ = ntype, peers = peers, callbacks = noteCbks }); }
public async Task<string> GetSetInfo(string sourceId, string set) { JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; EntitySetType type; if (Enum.TryParse<EntitySetType>(sobj["set"], out type)) { string filter = null; if (sobj.ContainsKey("setFilter")) filter = sobj["setFilter"]; switch (type) { case EntitySetType.User: { UserServiceProxy svc = new UserServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return json; } case EntitySetType.Role: { RoleServiceProxy svc = new RoleServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return json; } case EntitySetType.MemberNotification: { MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return json; } case EntitySetType.ShortMessage: { if (filter == null) throw new Exception("The page is not properly parameterized!"); else { Func<string, string, int> count = (s, p) => { int _cnt = 0; int i = 0; while ((i = s.IndexOf(p, i)) != -1) { _cnt++; i += p.Length; } return _cnt; }; if (filter.Contains("ToID is null") && filter.Contains("___usergroups___") && count(filter, "||") == 0) { string[] mbgrpIds = await GroupChatViewContext.UserGroupChatMembers(System.Web.HttpContext.Current.User.Identity.GetUserId()); if (mbgrpIds == null || mbgrpIds.Length == 0) throw new Exception(ResourceUtils.GetString("234038e6185f013e25d0213c06f5a0e9", "You are not a member of any chat group.")); string groupexpr = ""; foreach (var gid in mbgrpIds) groupexpr += (groupexpr != "" ? " || " : "") + "GroupID == \"" + gid + "\""; filter = filter.Replace("___usergroups___", groupexpr); } else if (filter.EndsWith("&& ToID is not null && GroupID is null && ( ToID == \"{0}\" || FromID == \"{0}\" )") && count(filter, "||") == 1) { filter = string.Format(filter, System.Web.HttpContext.Current.User.Identity.GetUserId()); } else throw new Exception("The page is not properly parameterized!"); } ShortMessageServiceProxy svc = new ShortMessageServiceProxy(); var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter); JavaScriptSerializer ser = new JavaScriptSerializer(); string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters }); return json; } } } return null; }
public async Task <string> GetNextFilterOps(string sourceId, string set, string qexpr) { EntitySetType type; if (Enum.TryParse <EntitySetType>(set, out type)) { switch (type) { case EntitySetType.User: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(TokenOptions)); 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(); var result = await svc.GetNextFilterOpsAsync(ApplicationContext.ClientContext, _qexpr, ""); strm = new System.IO.MemoryStream(); ser2.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return(json); } case EntitySetType.Role: { var ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); var ser2 = new DataContractJsonSerializer(typeof(TokenOptions)); 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(); var result = await svc.GetNextFilterOpsAsync(ApplicationContext.ClientContext, _qexpr, ""); strm = new System.IO.MemoryStream(); ser2.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return(json); } case EntitySetType.MemberNotification: { var ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); var ser2 = new DataContractJsonSerializer(typeof(TokenOptions)); 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(); var result = await svc.GetNextFilterOpsAsync(ApplicationContext.ClientContext, _qexpr, ""); strm = new System.IO.MemoryStream(); ser2.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); return(json); } case EntitySetType.ShortMessage: { var ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); var ser2 = new DataContractJsonSerializer(typeof(TokenOptions)); 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; var svc = new ShortMessageServiceProxy(); var result = await svc.GetNextFilterOpsAsync(ApplicationContext.ClientContext, _qexpr, ""); strm = new System.IO.MemoryStream(); ser2.WriteObject(strm, result); string json = System.Text.Encoding.UTF8.GetString(strm.ToArray()); 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 <List <MemberNotificationType> > GetRecentCategorized(string userId, SimpleMessage[] msgs, int?typeId, int max) { var cntx = Cntx; MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); MemberNotificationTypeServiceProxy tsvc = new MemberNotificationTypeServiceProxy(); MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); var categs = await tsvc.QueryDatabaseAsync(cntx, new MemberNotificationTypeSet(), null); List <MemberNotificationType> tlist = new List <MemberNotificationType>(); DateTime dt = DateTime.UtcNow.AddDays(-1); foreach (var categ in categs) { if (typeId.HasValue && categ.ID != typeId.Value) { continue; } var cond = new MemberNotificationSetConstraints { ApplicationIDWrap = new ForeignKeyData <string> { KeyValue = AppId }, UserIDWrap = new ForeignKeyData <string> { KeyValue = userId }, TypeIDWrap = new ForeignKeyData <int> { KeyValue = categ.ID } }; QueryExpresion qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "PriorityLevel" }, new QToken { TkName = "desc" }, new QToken { TkName = "CreatedDate" }, new QToken { TkName = "desc" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "ReadCount == 0 && CreatedDate >= " + svc.FormatRepoDateTime(dt) } }); foreach (var msg in msgs) { qexpr.FilterTks.Add(new QToken { TkName = " && ID != \"" + msg.Id + "\"" }); } var list = (await nsvc.ConstraintQueryLimitedAsync(cntx, new MemberNotificationSet(), cond, qexpr, max)).ToList(); if (list.Count > 0) { categ.ChangedMemberNotifications = list.ToArray(); tlist.Add(categ); } } return(tlist); }