コード例 #1
0
        public static async Task <string> LoadMessageDetails(string noteHubId, string groupId, string userId, string msgId)
        {
            var cntx = Cntx;
            var gsvc = new UserGroupServiceProxy();
            var svc  = new ShortMessageServiceProxy();
            var g    = await gsvc.LoadEntityByKeyAsync(cntx, groupId);

            var rmsg = await svc.LoadEntityByKeyAsync(cntx, msgId);

            while (rmsg.ReplyToID != null)
            {
                rmsg = await svc.LoadEntityByKeyAsync(cntx, rmsg.ReplyToID);
            }
            EntitySetType[] excludes = new EntitySetType[]
            {
                EntitySetType.UserGroup,
                EntitySetType.ShortMessageAudience
            };
            EntitySetRelation[] drills = new EntitySetRelation[]
            {
                new EntitySetRelation
                {
                    SetType     = EntitySetType.User,
                    RelatedSets = new EntitySetType[]
                    {
                        EntitySetType.UserAppMember,
                    }
                }
            };
            var msg = await svc.LoadEntityGraphRecursAsync(cntx, rmsg.ID, excludes, drills);

            var msgstr = GetJsonMessage(msg, userId, g, true, msgId);

            return(msgstr);
        }
コード例 #2
0
 public static async Task<ChatContextVM> ListChatRooms(string uId)
 {
     UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
     var m = new ChatContextVM();
     var cntx = Cntx;
     QueryExpresion qexpr = new QueryExpresion();
     qexpr.OrderTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "GroupName" }
     });
     qexpr.FilterTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "GroupTypeID == " + ApplicationContext.ChatGroupTypeID + " && ParentID is null" }
     });
     m.TopRooms = new List<EntityAbs<UserGroup>>();
     var roots = await gsvc.QueryDatabaseAsync(cntx, new UserGroupSet(), qexpr);
     foreach (var r in roots)
     {
         var top = await gsvc.LoadEntityFullHierarchyRecursAsync(cntx, r);
         if (top != null)
             m.TopRooms.Add(top);
     }
     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 = "UserGroupRef.GroupTypeID == " + ApplicationContext.ChatGroupTypeID + " && UserID == \"" + uId + "\""  }
     });
     var recs = await uigsvc.QueryDatabaseAsync(cntx, new UserGroupMemberSet(), qexpr);
     if (recs.Count() > 0)
         m.MemberIds = (from d in recs select d.UserGroupID).ToArray();
     else
         m.MemberIds = new string[] { };
     return m;
 }
コード例 #3
0
        public static async Task <ChatContextVM> ListChatRooms(string uId)
        {
            UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
            var            m           = new ChatContextVM();
            var            cntx        = Cntx;
            QueryExpresion qexpr       = new QueryExpresion();

            qexpr.OrderTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "GroupName"
                }
            });
            qexpr.FilterTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "GroupTypeID == " + ApplicationContext.ChatGroupTypeID + " && ParentID is null"
                }
            });
            m.TopRooms = new List <EntityAbs <UserGroup> >();
            var roots = await gsvc.QueryDatabaseAsync(cntx, new UserGroupSet(), qexpr);

            foreach (var r in roots)
            {
                var top = await gsvc.LoadEntityFullHierarchyRecursAsync(cntx, r);

                if (top != null)
                {
                    m.TopRooms.Add(top);
                }
            }
            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 = "UserGroupRef.GroupTypeID == " + ApplicationContext.ChatGroupTypeID + " && UserID == \"" + uId + "\""
                }
            });
            var recs = await uigsvc.QueryDatabaseAsync(cntx, new UserGroupMemberSet(), qexpr);

            if (recs.Count() > 0)
            {
                m.MemberIds = (from d in recs select d.UserGroupID).ToArray();
            }
            else
            {
                m.MemberIds = new string[] { }
            };
            return(m);
        }
コード例 #4
0
        /// <summary>
        /// A message in a particular room will be broadcasted to all connected members in sub-tree of rooms
        /// </summary>
        /// <param name="groupId">The room id</param>
        /// <returns>A list of active connection ids covered.</returns>
        public static async Task <MemberCallback[]> SubTreeMembers(string hubId, string groupId)
        {
            UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
            var cntx = Cntx;
            List <MemberCallback> callbacks = new List <MemberCallback>();
            var top = await gsvc.LoadEntityByKeyAsync(cntx, groupId);

            if (top != null)
            {
                var tree = await gsvc.LoadEntityHierarchyRecursAsync(cntx, top, 0, -1);
                await _groupMembersRecurs(hubId, cntx, tree, callbacks);
            }
            return(callbacks.ToArray());
        }
コード例 #5
0
 public static async Task<UserGroup[]> UserGroupChatGroups(string userId)
 {
     var svc = new UserGroupServiceProxy();
     var qexpr = new QueryExpresion();
     // check this
     qexpr.OrderTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "ID" },
         new QToken { TkName = "asc" }
     });
     qexpr.FilterTks = new List<QToken>(new QToken[] {
         new QToken { TkName = "GroupTypeID == " + ApplicationContext.ChatGroupTypeID + " && UserGroupMember.UserID == \"" + userId + "\"" }
     });
     var gl = await svc.QueryDatabaseAsync(Cntx, new UserGroupSet(), qexpr);
     return gl == null ? null : (from d in gl select d).ToArray();
 }
コード例 #6
0
        private static async Task _listSupervisors(string hubId, string groupId, List <MemberCallback> list)
        {
            var cntx = Cntx;
            UserGroupServiceProxy      gsvc = new UserGroupServiceProxy();
            MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy();
            var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId);

            while (g.ParentID != null)
            {
                g = await gsvc.MaterializeUpperRefAsync(cntx, g);

                var qexpr = getConnectedGroupMemberFilter(hubId, g.ID, true);
                var peers = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).ToArray();
                if (peers.Length > 0)
                {
                    list.AddRange(peers);
                }
            }
        }
コード例 #7
0
        public static async Task <UserGroup[]> UserGroupChatGroups(string userId)
        {
            var svc   = new UserGroupServiceProxy();
            var qexpr = new QueryExpresion();

            // check this
            qexpr.OrderTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "ID"
                },
                new QToken {
                    TkName = "asc"
                }
            });
            qexpr.FilterTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "GroupTypeID == " + ApplicationContext.ChatGroupTypeID + " && UserGroupMember.UserID == \"" + userId + "\""
                }
            });
            var gl = await svc.QueryDatabaseAsync(Cntx, new UserGroupSet(), qexpr);

            return(gl == null ? null : (from d in gl select d).ToArray());
        }
コード例 #8
0
        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
            });
        }
コード例 #9
0
        public static async Task <string[]> LoadMessages(string groupId, string userId, int maxMessages, bool dialog)
        {
            var gsvc   = new UserGroupServiceProxy();
            var svc    = new MembershipPlusServiceProxy();
            var msgsvc = new ShortMessageServiceProxy();
            var cntx   = Cntx;
            var g      = await gsvc.LoadEntityByKeyAsync(cntx, groupId);

            DateTime dt   = DateTime.UtcNow.AddMinutes(-InitMsgTimeWindow);
            var      cond = new ShortMessageSetConstraints
            {
                ApplicationIDWrap = new ForeignKeyData <string> {
                    KeyValue = AppId
                },
                TypeIDWrap = new ForeignKeyData <int> {
                    KeyValue = ApplicationContext.ChatShortMsgTypeId
                },
                GroupIDWrap = new ForeignKeyData <string> {
                    KeyValue = groupId
                },
                ToIDWrap = new ForeignKeyData <string> {
                    KeyValue = null
                }
            };
            var 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 = "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));
                }
            }
            return(jsonMsgs.ToArray());
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        public static async Task <dynamic> LoadRoomSummary(string hubId, string id)
        {
            UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
            var    cntx  = Cntx;
            string descr = await gsvc.LoadEntityGroupDescriptionAsync(cntx, id);

            MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy();
            var  qexpr = getConnectedGroupMemberFilter(hubId, id);
            long cnt   = await mcbsvc.QueryEntityCountAsync(cntx, new MemberCallbackSet(), qexpr);

            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 == \"" + id + "\" && SubscribedTo is not null && SubscribedTo == true"
                }
            });
            long scnt = await uigsvc.QueryEntityCountAsync(cntx, new UserGroupMemberSet(), qexpr);

            qexpr          = new QueryExpresion();
            qexpr.OrderTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "Username"
                }
            });
            qexpr.FilterTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "UsersInRole_UserID.RoleRef.UserGroupAdminRole.GroupID == \"" + id + "\""
                }
            });
            UserServiceProxy usvc = new UserServiceProxy();
            var admins            = await usvc.QueryDatabaseAsync(cntx, new UserSet(), qexpr);

            List <dynamic> ladms = new List <dynamic>();

            if (admins.Count() > 0)
            {
                RoleServiceProxy rsvc = new RoleServiceProxy();
                foreach (var u in admins)
                {
                    qexpr          = new QueryExpresion();
                    qexpr.OrderTks = new List <QToken>(new QToken[] {
                        new QToken {
                            TkName = "ID"
                        }
                    });
                    qexpr.FilterTks = new List <QToken>(new QToken[] {
                        new QToken {
                            TkName = "UserGroupAdminRole.GroupID == \"" + id + "\" && UsersInRole.UserID == \"" + u.ID + "\""
                        }
                    });
                    var role = (await rsvc.QueryDatabaseAsync(cntx, new RoleSet(), qexpr)).First();
                    ladms.Add(new { id = u.ID, name = u.Username, role = role.DisplayName });
                }
            }
            dynamic r = new { descr = descr, active = cnt, subscribers = scnt, admins = ladms };

            return(r);
        }
コード例 #12
0
 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;
 }
コード例 #13
0
 /// <summary>
 /// A message in a particular room will be broadcasted to all connected members in sub-tree of rooms
 /// </summary>
 /// <param name="groupId">The room id</param>
 /// <returns>A list of active connection ids covered.</returns>
 public static async Task<MemberCallback[]> SubTreeMembers(string hubId, string groupId)
 {
     UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
     var cntx = Cntx;
     List<MemberCallback> callbacks = new List<MemberCallback>();
     var top = await gsvc.LoadEntityByKeyAsync(cntx, groupId);
     if (top != null)
     {
         var tree = await gsvc.LoadEntityHierarchyRecursAsync(cntx, top, 0, -1);
         await _groupMembersRecurs(hubId, cntx, tree, callbacks);
     }
     return callbacks.ToArray();
 }
コード例 #14
0
 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 };
 }
コード例 #15
0
 private static async Task _listSupervisors(string hubId, string groupId, List<MemberCallback> list)
 {
     var cntx = Cntx;
     UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
     MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy();
     var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId);
     while (g.ParentID != null)
     {
         g = await gsvc.MaterializeUpperRefAsync(cntx, g);
         var qexpr = getConnectedGroupMemberFilter(hubId, g.ID, true);
         var peers = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).ToArray();
         if (peers.Length > 0)
             list.AddRange(peers);
     }
 }
コード例 #16
0
 public static async Task<string[]> LoadMessages(string groupId, string userId, int maxMessages, bool dialog)
 {
     var gsvc = new UserGroupServiceProxy();
     var svc = new MembershipPlusServiceProxy();
     var msgsvc = new ShortMessageServiceProxy();
     var cntx = Cntx;
     var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId);
     DateTime dt = DateTime.UtcNow.AddMinutes(-InitMsgTimeWindow);
     var cond = new ShortMessageSetConstraints
     {
         ApplicationIDWrap = new ForeignKeyData<string> { KeyValue = AppId },
         TypeIDWrap = new ForeignKeyData<int> { KeyValue = ApplicationContext.ChatShortMsgTypeId },
         GroupIDWrap = new ForeignKeyData<string> { KeyValue = groupId },
         ToIDWrap = new ForeignKeyData<string> { KeyValue = null }
     };
     var 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 = "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));
         }
     }
     return jsonMsgs.ToArray();
 }
コード例 #17
0
 public static async Task<string> LoadMessageDetails(string noteHubId, string userId, string msgId)
 {
     var cntx = Cntx;
     var gsvc = new UserGroupServiceProxy();
     var svc = new ShortMessageServiceProxy();
     var rmsg = await svc.LoadEntityByKeyAsync(cntx, msgId);
     var msg0 = rmsg;
     while (rmsg.ReplyToID != null)
         rmsg = await svc.LoadEntityByKeyAsync(cntx, rmsg.ReplyToID);
     EntitySetType[] excludes = new EntitySetType[]
             {
                 EntitySetType.UserGroup,
                 EntitySetType.ShortMessageAudience
             };
     EntitySetRelation[] drills = new EntitySetRelation[]
             {
                 new EntitySetRelation
                 {
                     SetType = EntitySetType.User,
                     RelatedSets = new EntitySetType[] 
                     {
                         EntitySetType.UserAppMember,
                     }
                 }
             };
     var msg = await svc.LoadEntityGraphRecursAsync(cntx, rmsg.ID, excludes, drills);
     var msgstr = GetJsonMessage(msg, userId, true, msgId);
     if (msg0.IsNotReceived == false)
     {
         msg0.IsNotReceived = false;
         await svc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg0 });
     }
     return msgstr;
 }
コード例 #18
0
 public static async Task<dynamic> LoadRoomSummary(string hubId, string id)
 {
     UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
     var cntx = Cntx;
     string descr = await gsvc.LoadEntityGroupDescriptionAsync(cntx, id);
     MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy();
     var qexpr = getConnectedGroupMemberFilter(hubId, id);
     long cnt = await mcbsvc.QueryEntityCountAsync(cntx, new MemberCallbackSet(), qexpr);
     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 == \"" + id + "\" && SubscribedTo is not null && SubscribedTo == true"  }
     });
     long scnt = await uigsvc.QueryEntityCountAsync(cntx, new UserGroupMemberSet(), qexpr);
     qexpr = new QueryExpresion();
     qexpr.OrderTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "Username" }
     });
     qexpr.FilterTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "UsersInRole_UserID.RoleRef.UserGroupAdminRole.GroupID == \"" + id + "\"" }
     });
     UserServiceProxy usvc = new UserServiceProxy();
     var admins = await usvc.QueryDatabaseAsync(cntx, new UserSet(), qexpr);
     List<dynamic> ladms = new List<dynamic>();
     if (admins.Count() > 0)
     {
         RoleServiceProxy rsvc = new RoleServiceProxy();
         foreach (var u in admins)
         {
             qexpr = new QueryExpresion();
             qexpr.OrderTks = new List<QToken>(new QToken[] { 
                 new QToken { TkName = "ID" }
             });
             qexpr.FilterTks = new List<QToken>(new QToken[] { 
                 new QToken { TkName = "UserGroupAdminRole.GroupID == \"" + id + "\" && UsersInRole.UserID == \"" + u.ID + "\"" }
             });
             var role = (await rsvc.QueryDatabaseAsync(cntx, new RoleSet(), qexpr)).First();
             ladms.Add(new { id = u.ID, name = u.Username, role = role.DisplayName });
         }
     }
     dynamic r = new { descr = descr, active = cnt, subscribers = scnt, admins = ladms };
     return r;
 }