private void AddNotification(int type, int member, CultureDataContext db) { MemberNotification n = new MemberNotification(); n.MemberNotification_MemberID = member; n.MemberNotification_NotificationTypeID = type; db.MemberNotifications.InsertOnSubmit(n); db.SubmitChanges(); }
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); }
//Mylinh needs to add Notify proc here public MemberNotification NotifyMember(string aspNetUserId) { try { MemberNotification _memberNotification = null; _baseService.DataProvider.ExecuteCmd(_baseService.GetConnection, "dbo.MemberProfile_Notify", inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@AspNetUserId", aspNetUserId); }, map : delegate(IDataReader reader, short set) { _memberNotification = _baseService.MapToObject <MemberNotification>(reader); }); return(_memberNotification); } catch (Exception ex) { _baseService.LogError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex, "MemberProfileService"); throw; } }
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 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 void Update(MemberNotification entity) { _MemberNotificationRepository.Update(entity); }
public MemberNotification Insert(MemberNotification entity) { return(_MemberNotificationRepository.Add(entity)); }
public void Delete(MemberNotification entity) { _MemberNotificationRepository.Delete(entity); }
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); }