public ActionResult OnlineUsers() { var svc = new MembershipPlusServiceProxy(); string filter = "UserAppMember.Application_Ref.ID == \"" + ApplicationContext.App.ID + "\" && ( UserAppMember.SearchListing is null || UserAppMember.SearchListing == true ) && "; filter += "UserAppMember.ConnectionID is not null && UserAppMember.LastActivityDate > "; ViewBag.SetFilter = filter; ViewBag.TimeWindow = ApplicationContext.OnlineUserInactiveTime; ViewBag.AppNam = ApplicationContext.App.Name; return View(); }
public ActionResult OnlineUsers() { var svc = new MembershipPlusServiceProxy(); string filter = "UserAppMember.Application_Ref.ID == \"" + ApplicationContext.App.ID + "\" && ( UserAppMember.SearchListing is null || UserAppMember.SearchListing == true ) && "; filter += "UserAppMember.ConnectionID is not null && UserAppMember.LastActivityDate > "; ViewBag.SetFilter = filter; ViewBag.TimeWindow = ApplicationContext.OnlineUserInactiveTime; ViewBag.AppNam = ApplicationContext.App.Name; return(View()); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Enable the application to use a cookie to store information for the signed in user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login") }); MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); if (ClientContext == null) { ClientContext = svc.SignInService(new CallContext(), null); } CallContext cctx = ClientContext.CreateCopy(); // Get encryption and decryption key information from the configuration Configuration cfg = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath); var machineKey = (MachineKeySection)cfg.GetSection("system.web/machineKey"); if (machineKey.ValidationKey.Contains("AutoGenerate")) { throw new Exception("Hashed or Encrypted passwords " + "are not supported with auto-generated keys."); } string ApplicationName = ConfigurationManager.AppSettings["ApplicationName"]; try { cctx.DirectDataAccess = true; Application_ServiceProxy apprepo = new Application_ServiceProxy(); List <Application_> apps = apprepo.LoadEntityByNature(cctx, ApplicationName); if (apps == null || apps.Count == 0) { cctx.OverrideExisting = true; var tuple = apprepo.AddOrUpdateEntities(cctx, new Application_Set(), new Application_[] { new Application_ { Name = ApplicationName } }); App = tuple.ChangedEntities.Length == 1 && IsValidUpdate(tuple.ChangedEntities[0].OpStatus) ? tuple.ChangedEntities[0].UpdatedItem : null; cctx.OverrideExisting = false; } else { App = apps[0]; } MemberInitSuccess = true; } catch { } }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Enable the application to use a cookie to store information for the signed in user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login") }); MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); if (ClientContext == null) ClientContext = svc.SignInService(new CallContext(), null); CallContext cctx = ClientContext.CreateCopy(); // Get encryption and decryption key information from the configuration Configuration cfg = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath); var machineKey = (MachineKeySection)cfg.GetSection("system.web/machineKey"); if (machineKey.ValidationKey.Contains("AutoGenerate")) { throw new Exception("Hashed or Encrypted passwords " + "are not supported with auto-generated keys."); } string ApplicationName = ConfigurationManager.AppSettings["ApplicationName"]; try { cctx.DirectDataAccess = true; Application_ServiceProxy apprepo = new Application_ServiceProxy(); List<Application_> apps = apprepo.LoadEntityByNature(cctx, ApplicationName); if (apps == null || apps.Count == 0) { cctx.OverrideExisting = true; var tuple = apprepo.AddOrUpdateEntities(cctx, new Application_Set(), new Application_[] { new Application_ { Name = ApplicationName } }); App = tuple.ChangedEntities.Length == 1 && IsValidUpdate(tuple.ChangedEntities[0].OpStatus) ? tuple.ChangedEntities[0].UpdatedItem : null; cctx.OverrideExisting = false; } else App = apps[0]; MemberInitSuccess = true; } catch { } }
private static QueryExpresion getConnectedGroupMemberFilter(string hubId, string groupId, bool supervisor = false) { MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-ApplicationContext.OnlineUserInactiveTime); QueryExpresion qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "UserID" }, new QToken { TkName = "asc" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "HubID == \"" + hubId + "\" && ChannelID == \"" + groupId + "\" && ConnectionID is not null && IsDisconnected == false" + (!supervisor ? "" : " && SupervisorMode is not null && SupervisorMode == true") }, new QToken { TkName = "&&" }, new QToken { TkName = "ApplicationID == \"" + AppId + "\"" }, new QToken { TkName = "&&" }, new QToken { TkName = "UserAppMemberRef.UserRef.UserGroupMember.UserGroupID == \"" + groupId + "\"" }, new QToken { TkName = "&&" }, new QToken { TkName = "UserAppMemberRef.LastActivityDate > " + svc.FormatRepoDateTime(dt) } }); return(qexpr); }
public static async Task <MemberCallback> FindPeer(string chatHubId, string userId, string peerId) { var cntx = Cntx; MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-ApplicationContext.OnlineUserInactiveTime); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); var qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "UserID" }, new QToken { TkName = "asc" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "HubID == \"" + chatHubId + "\" && ChannelID == \"" + userId + "\" && ConnectionID is not null && IsDisconnected == false" }, new QToken { TkName = "&&" }, new QToken { TkName = "ApplicationID == \"" + AppId + "\" && UserID == \"" + peerId + "\"" }, new QToken { TkName = "&&" }, new QToken { TkName = "UserAppMemberRef.LastActivityDate > " + svc.FormatRepoDateTime(dt) } }); MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy(); return((await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).SingleOrDefault()); }
public static async Task <string[]> LoadMessages(string peerId, string userId, int maxMessages, bool dialog) { var svc = new MembershipPlusServiceProxy(); var usvc = new UserServiceProxy(); var msgsvc = new ShortMessageServiceProxy(); var cntx = Cntx; var peer = await usvc.LoadEntityByKeyAsync(cntx, peerId); DateTime dt = DateTime.UtcNow.AddMinutes(-InitMsgTimeWindow); var cond = new ShortMessageSetConstraints { ApplicationIDWrap = new ForeignKeyData <string> { KeyValue = AppId }, TypeIDWrap = new ForeignKeyData <int> { KeyValue = 1 }, GroupIDWrap = new ForeignKeyData <string> { KeyValue = null } }; var qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "CreatedDate" }, new QToken { TkName = "desc" } }); // ToIDWrap = new ForeignKeyData<string> { KeyValue = peerId }, qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "( FromID == \"" + peerId + "\" && ToID == \"" + userId + "\" || FromID == \"" + userId + "\" && ToID == \"" + peerId + "\" ) && CreatedDate > " + svc.FormatRepoDateTime(dt) } }); if (dialog) { qexpr.FilterTks.Add(new QToken { TkName = " && ReplyToID is null" }); } var msgs = (await msgsvc.ConstraintQueryLimitedAsync(cntx, new ShortMessageSet(), cond, qexpr, maxMessages)).ToArray(); List <string> jsonMsgs = new List <string>(); if (msgs.Length > 0) { for (int i = msgs.Length - 1; i >= 0; i--) { EntitySetType[] excludes; if (dialog) { excludes = new EntitySetType[] { EntitySetType.UserGroup, //EntitySetType.ShortMessageAudience, EntitySetType.ShortMessageAttachment }; } else { excludes = new EntitySetType[] { EntitySetType.UserGroup, //EntitySetType.ShortMessageAudience, EntitySetType.ShortMessageAttachment, EntitySetType.ShortMessage }; } msgs[i] = await msgsvc.LoadEntityGraphRecursAsync(cntx, msgs[i].ID, excludes, null); jsonMsgs.Add(GetJsonMessage(msgs[i], userId, peer, dialog)); } } return(jsonMsgs.ToArray()); }
public static async Task <PeerShotMessage> AddUserMessage(string chatHubId, string userId, string peerId, string replyId, string message, bool record) { var cntx = Cntx; UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); var peer = await usvc.LoadEntityByKeyAsync(cntx, peerId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); PeerShotMessage m = new PeerShotMessage(); var now = DateTime.UtcNow; ShortMessage msg = new ShortMessage { ID = Guid.NewGuid().ToString(), ApplicationID = AppId, TypeID = 1, GroupID = null, FromID = userId, ToID = peerId, ReplyToID = string.IsNullOrEmpty(replyId) ? null : replyId, CreatedDate = now, LastModified = now, MsgText = message }; if (record) { var r = await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); var _msg = r.ChangedEntities[0].UpdatedItem; _msg.User_FromID = u; m.msg = GetJsonMessage(_msg, userId, peer, false); } else { msg.User_FromID = u; m.msg = GetJsonMessage(msg, userId, peer, false); } UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy(); var utop = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId); if (utop != null) { utop.InteractCount = utop.InteractCount == null ? 1 : utop.InteractCount + 1; utop.LastInteract = DateTime.UtcNow; await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), new UserAssociation[] { utop }); } MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-ApplicationContext.OnlineUserInactiveTime); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); var qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "UserID" }, new QToken { TkName = "asc" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "HubID == \"" + chatHubId + "\" && ChannelID == \"" + userId + "\" && ConnectionID is not null && IsDisconnected == false" }, new QToken { TkName = "&&" }, new QToken { TkName = "ApplicationID == \"" + AppId + "\" && UserID == \"" + peerId + "\"" }, new QToken { TkName = "&&" }, new QToken { TkName = "UserAppMemberRef.LastActivityDate > " + svc.FormatRepoDateTime(dt) } }); MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy(); m.peer = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).SingleOrDefault(); return(m); }
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<string[]> LoadMessages(string peerId, string userId, int maxMessages, bool dialog) { var svc = new MembershipPlusServiceProxy(); var usvc = new UserServiceProxy(); var msgsvc = new ShortMessageServiceProxy(); var cntx = Cntx; var peer = await usvc.LoadEntityByKeyAsync(cntx, peerId); DateTime dt = DateTime.UtcNow.AddMinutes(-InitMsgTimeWindow); var cond = new ShortMessageSetConstraints { ApplicationIDWrap = new ForeignKeyData<string> { KeyValue = AppId }, TypeIDWrap = new ForeignKeyData<int> { KeyValue = 1 }, GroupIDWrap = new ForeignKeyData<string> { KeyValue = null } }; var qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "CreatedDate" }, new QToken { TkName = "desc" } }); // ToIDWrap = new ForeignKeyData<string> { KeyValue = peerId }, qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "( FromID == \"" + peerId + "\" && ToID == \"" + userId + "\" || FromID == \"" + userId + "\" && ToID == \"" + peerId + "\" ) && CreatedDate > " + svc.FormatRepoDateTime(dt) } }); if (dialog) { qexpr.FilterTks.Add(new QToken { TkName = " && ReplyToID is null" }); } var msgs = (await msgsvc.ConstraintQueryLimitedAsync(cntx, new ShortMessageSet(), cond, qexpr, maxMessages)).ToArray(); List<string> jsonMsgs = new List<string>(); if (msgs.Length > 0) { for (int i = msgs.Length - 1; i >= 0; i--) { EntitySetType[] excludes; if (dialog) { excludes = new EntitySetType[] { EntitySetType.UserGroup, //EntitySetType.ShortMessageAudience, EntitySetType.ShortMessageAttachment }; } else { excludes = new EntitySetType[] { EntitySetType.UserGroup, //EntitySetType.ShortMessageAudience, EntitySetType.ShortMessageAttachment, EntitySetType.ShortMessage }; } msgs[i] = await msgsvc.LoadEntityGraphRecursAsync(cntx, msgs[i].ID, excludes, null); jsonMsgs.Add(GetJsonMessage(msgs[i], userId, peer, dialog)); } } return jsonMsgs.ToArray(); }
public static async Task<MemberCallback> FindPeer(string chatHubId, string userId, string peerId) { var cntx = Cntx; MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-ApplicationContext.OnlineUserInactiveTime); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); var qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "UserID" }, new QToken { TkName = "asc" } }); qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "HubID == \"" + chatHubId + "\" && ChannelID == \"" + userId + "\" && ConnectionID is not null && IsDisconnected == false" }, new QToken { TkName = "&&" }, new QToken { TkName = "ApplicationID == \"" + AppId + "\" && UserID == \"" + peerId + "\"" }, new QToken { TkName = "&&" }, new QToken { TkName = "UserAppMemberRef.LastActivityDate > " + svc.FormatRepoDateTime(dt) } }); MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy(); return (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).SingleOrDefault(); }
public static async Task<PeerShotMessage> UpdateUserMessage(string chatHubId, string userId, string peerId, string msgId, string message) { var cntx = Cntx; UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); var peer = await usvc.LoadEntityByKeyAsync(cntx, peerId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); PeerShotMessage m = new PeerShotMessage(); ShortMessage msg = await msvc.LoadEntityByKeyAsync(cntx, msgId); if (msg == null || msg.FromID != userId || msg.ToID != peerId) return null; var now = DateTime.UtcNow; msg.MsgText = message; msg.LastModified = now; var r = await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); var _msg = r.ChangedEntities[0].UpdatedItem; _msg.User_FromID = u; m.msg = GetJsonMessage(_msg, userId, peer, false); UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy(); var utop = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId); if (utop != null) { utop.InteractCount = utop.InteractCount == null ? 1 : utop.InteractCount + 1; utop.LastInteract = DateTime.UtcNow; await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), new UserAssociation[] { utop }); } MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-ApplicationContext.OnlineUserInactiveTime); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); var qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "UserID" }, new QToken { TkName = "asc" } }); qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "HubID == \"" + chatHubId + "\" && ChannelID == \"" + userId + "\" && ConnectionID is not null && IsDisconnected == false" }, new QToken { TkName = "&&" }, new QToken { TkName = "ApplicationID == \"" + AppId + "\" && UserID == \"" + peerId + "\"" }, new QToken { TkName = "&&" }, new QToken { TkName = "UserAppMemberRef.LastActivityDate > " + svc.FormatRepoDateTime(dt) } }); MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy(); m.peer = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).SingleOrDefault(); return m; }
public static async Task <ChatRoomVM> LoadChatRoom(string hubId, string groupId, string userId, int maxMessages, bool dialog = false) { UserGroupServiceProxy gsvc = new UserGroupServiceProxy(); var cntx = Cntx; ChatRoomVM m = new ChatRoomVM() { RoomExists = false, DialogMode = dialog }; if (!string.IsNullOrEmpty(groupId)) { var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId); if (g != null) { m.RoomExists = true; m.ID = groupId; m.RoomPath = g.DistinctString.Split('/'); m.RoomInfo = await gsvc.LoadEntityGroupDescriptionAsync(cntx, g.ID); UserGroupMemberServiceProxy gmsvc = new UserGroupMemberServiceProxy(); UserGroupMember uig = await gmsvc.LoadEntityByKeyAsync(cntx, groupId, userId); if (uig == null) { uig = new UserGroupMember { UserID = userId, UserGroupID = groupId, SubscribedTo = false, ActivityNotification = false }; await gmsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig }); } cntx.DirectDataAccess = true; MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy(); var qexpr = getConnectedGroupMemberFilter(hubId, g.ID); var peers = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).ToArray(); List <string> jsonPeers = new List <string>(); if (peers.Length > 0) { for (int i = 0; i < peers.Length; i++) { // retrieve the related entity graph peers[i] = await cbsv.LoadEntityGraphRecursAsync(cntx, groupId, hubId, AppId, peers[i].UserID, null, null); jsonPeers.Add(GetJsonPeer(peers[i])); } } m.ActivePeers = jsonPeers.ToArray(); cntx.DirectDataAccess = false; ShortMessageServiceProxy msgsvc = new ShortMessageServiceProxy(); var cond = new ShortMessageSetConstraints { ApplicationIDWrap = new ForeignKeyData <string> { KeyValue = AppId }, TypeIDWrap = new ForeignKeyData <int> { KeyValue = ApplicationContext.ChatShortMsgTypeId }, GroupIDWrap = new ForeignKeyData <string> { KeyValue = groupId } }; UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy(); qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "UserID" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "UserGroupID == \"" + g.ID + "\" && SubscribedTo is not null && SubscribedTo == true" } }); m.Subscribers = (int)(await uigsvc.QueryEntityCountAsync(cntx, new UserGroupMemberSet(), qexpr)); var svc = new MembershipPlusServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-InitMsgTimeWindow); qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "CreatedDate" }, new QToken { TkName = "desc" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "ToID is null && CreatedDate > " + svc.FormatRepoDateTime(dt) } }); if (dialog) { qexpr.FilterTks.Add(new QToken { TkName = " && ReplyToID is null" }); } var msgs = (await msgsvc.ConstraintQueryLimitedAsync(cntx, new ShortMessageSet(), cond, qexpr, maxMessages)).ToArray(); List <string> jsonMsgs = new List <string>(); if (msgs.Length > 0) { for (int i = msgs.Length - 1; i >= 0; i--) { EntitySetType[] excludes; if (dialog) { excludes = new EntitySetType[] { EntitySetType.UserGroup, //EntitySetType.ShortMessageAudience, EntitySetType.ShortMessageAttachment }; } else { excludes = new EntitySetType[] { EntitySetType.UserGroup, //EntitySetType.ShortMessageAudience, EntitySetType.ShortMessageAttachment, EntitySetType.ShortMessage }; } msgs[i] = await msgsvc.LoadEntityGraphRecursAsync(cntx, msgs[i].ID, excludes, null); jsonMsgs.Add(GetJsonMessage(msgs[i], userId, g, dialog)); } } m.RecentMsgs = jsonMsgs.ToArray(); } } return(m); }
private static QueryExpresion getConnectedGroupMemberFilter(string hubId, string groupId, bool supervisor = false) { MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-ApplicationContext.OnlineUserInactiveTime); QueryExpresion qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "UserID" }, new QToken { TkName = "asc" } }); qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "HubID == \"" + hubId + "\" && ChannelID == \"" + groupId + "\" && ConnectionID is not null && IsDisconnected == false" + (!supervisor ? "" : " && SupervisorMode is not null && SupervisorMode == true") }, new QToken { TkName = "&&" }, new QToken { TkName = "ApplicationID == \"" + AppId + "\"" }, new QToken { TkName = "&&" }, new QToken { TkName = "UserAppMemberRef.UserRef.UserGroupMember.UserGroupID == \"" + groupId + "\"" }, new QToken { TkName = "&&" }, new QToken { TkName = "UserAppMemberRef.LastActivityDate > " + svc.FormatRepoDateTime(dt) } }); return qexpr; }
public static async Task<ChatRoomVM> LoadChatRoom(string hubId, string groupId, string userId, int maxMessages, bool dialog = false) { UserGroupServiceProxy gsvc = new UserGroupServiceProxy(); var cntx = Cntx; ChatRoomVM m = new ChatRoomVM() { RoomExists = false, DialogMode = dialog }; if (!string.IsNullOrEmpty(groupId)) { var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId); if (g != null) { m.RoomExists = true; m.ID = groupId; m.RoomPath = g.DistinctString.Split('/'); m.RoomInfo = await gsvc.LoadEntityGroupDescriptionAsync(cntx, g.ID); UserGroupMemberServiceProxy gmsvc = new UserGroupMemberServiceProxy(); UserGroupMember uig = await gmsvc.LoadEntityByKeyAsync(cntx, groupId, userId); if (uig == null) { uig = new UserGroupMember { UserID = userId, UserGroupID = groupId, SubscribedTo = false, ActivityNotification = false }; await gmsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig }); } cntx.DirectDataAccess = true; MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy(); var qexpr = getConnectedGroupMemberFilter(hubId, g.ID); var peers = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).ToArray(); List<string> jsonPeers = new List<string>(); if (peers.Length > 0) { for (int i = 0; i < peers.Length; i++) { // retrieve the related entity graph peers[i] = await cbsv.LoadEntityGraphRecursAsync(cntx, groupId, hubId, AppId, peers[i].UserID, null, null); jsonPeers.Add(GetJsonPeer(peers[i])); } } m.ActivePeers = jsonPeers.ToArray(); cntx.DirectDataAccess = false; ShortMessageServiceProxy msgsvc = new ShortMessageServiceProxy(); var cond = new ShortMessageSetConstraints { ApplicationIDWrap = new ForeignKeyData<string> { KeyValue = AppId }, TypeIDWrap = new ForeignKeyData<int> { KeyValue = ApplicationContext.ChatShortMsgTypeId }, GroupIDWrap = new ForeignKeyData<string> { KeyValue = groupId } }; UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy(); qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "UserID" } }); qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "UserGroupID == \"" + g.ID + "\" && SubscribedTo is not null && SubscribedTo == true" } }); m.Subscribers = (int)(await uigsvc.QueryEntityCountAsync(cntx, new UserGroupMemberSet(), qexpr)); var svc = new MembershipPlusServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-InitMsgTimeWindow); qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "CreatedDate" }, new QToken { TkName = "desc" } }); qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "ToID is null && CreatedDate > " + svc.FormatRepoDateTime(dt) } }); if (dialog) { qexpr.FilterTks.Add(new QToken { TkName = " && ReplyToID is null" }); } var msgs = (await msgsvc.ConstraintQueryLimitedAsync(cntx, new ShortMessageSet(), cond, qexpr, maxMessages)).ToArray(); List<string> jsonMsgs = new List<string>(); if (msgs.Length > 0) { for (int i = msgs.Length - 1; i >= 0; i--) { EntitySetType[] excludes; if (dialog) { excludes = new EntitySetType[] { EntitySetType.UserGroup, //EntitySetType.ShortMessageAudience, EntitySetType.ShortMessageAttachment }; } else { excludes = new EntitySetType[] { EntitySetType.UserGroup, //EntitySetType.ShortMessageAudience, EntitySetType.ShortMessageAttachment, EntitySetType.ShortMessage }; } msgs[i] = await msgsvc.LoadEntityGraphRecursAsync(cntx, msgs[i].ID, excludes, null); jsonMsgs.Add(GetJsonMessage(msgs[i], userId, g, dialog)); } } m.RecentMsgs = jsonMsgs.ToArray(); } } return m; }
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); }