Ejemplo n.º 1
0
        public void SendLinkStatsRequest(int linkId, int topicId)
        {
            if (peer == null || peer.PeerState != PeerStateValue.Connected)
            {
                return;
            }

            peer.OpCustom((byte)DiscussionOpCode.LinkReportRequest,
                          LinkReportRequest.Write(linkId, topicId),
                          true);
        }
Ejemplo n.º 2
0
        public void HandleLinkReportRequest(LitePeer peer,
                                            OperationRequest operationRequest,
                                            SendParameters sendParameters)
        {
            var req = LinkReportRequest.Read(operationRequest.Parameters);

            var linkSh = _doc.TryGetShape(req.LinkShapeId);

            if (linkSh == null)
            {
                _room.Broadcast(peer,
                                (Dictionary <byte, object>)null,
                                sendParameters,
                                (byte)DiscussionEventCode.LinkStatsEvent,
                                BroadcastTo.RoomAll);
                return;
            }

            var resp = default(LinkReportResponse);

            resp.linkShId     = linkSh.Id();
            resp.Caption      = TryGetTextCaption(linkSh);
            resp.topicId      = req.TopicId;
            resp.initialOwner = linkSh.InitialOwner();

            var fwdEdge = _topology.GetForwardEdge(linkSh.Id());

            //endpoint 1
            if (fwdEdge.curr is Clusterable)
            {
                resp.EndpointArgPoint1 = true;
                resp.ArgPointId1       = fwdEdge.curr.GetId();

                //badge id -> arg.point id
                var badgeSh = _doc.TryGetShape(resp.ArgPointId1);
                if (badgeSh == null)
                {
                    _room.Broadcast(peer,
                                    (Dictionary <byte, object>)null,
                                    sendParameters,
                                    (byte)DiscussionEventCode.LinkStatsEvent,
                                    BroadcastTo.RoomAll);
                    return;
                }
                resp.ArgPointId1     = badgeSh.Tag();
                resp.ClusterCaption1 = null;
            }
            else
            {
                resp.EndpointArgPoint1 = false;
                resp.ArgPointId1       = -1;

                var clusterSh = _doc.TryGetShape(fwdEdge.curr.GetId());
                if (clusterSh == null)
                {
                    _room.Broadcast(peer,
                                    (Dictionary <byte, object>)null,
                                    sendParameters,
                                    (byte)DiscussionEventCode.ClusterStatsEvent,
                                    BroadcastTo.RoomAll);
                    return;
                }

                resp.ClusterCaption1 = TryGetTextCaption(clusterSh);
                resp.IdOfCluster1    = clusterSh.Id();
            }

            //endpoint 2
            if (fwdEdge.next is Clusterable)
            {
                resp.EndpointArgPoint2 = true;
                resp.ArgPointId2       = fwdEdge.next.GetId();

                //badge id -> arg.point id
                var badgeSh = _doc.TryGetShape(resp.ArgPointId2);
                if (badgeSh == null)
                {
                    _room.Broadcast(peer,
                                    (Dictionary <byte, object>)null,
                                    sendParameters,
                                    (byte)DiscussionEventCode.LinkStatsEvent,
                                    BroadcastTo.RoomAll);
                    return;
                }
                resp.ArgPointId2     = badgeSh.Tag();
                resp.ClusterCaption2 = null;
            }
            else
            {
                resp.EndpointArgPoint2 = false;
                resp.ArgPointId2       = -1;

                var clusterSh = _doc.TryGetShape(fwdEdge.next.GetId());
                if (clusterSh == null)
                {
                    _room.Broadcast(peer,
                                    (Dictionary <byte, object>)null,
                                    sendParameters,
                                    (byte)DiscussionEventCode.ClusterStatsEvent,
                                    BroadcastTo.RoomAll);
                    return;
                }

                resp.ClusterCaption2 = TryGetTextCaption(clusterSh);
                resp.IdOfCluster2    = clusterSh.Id();
            }

            _room.Broadcast(peer,
                            resp.ToDict(),
                            sendParameters,
                            (byte)DiscussionEventCode.LinkStatsEvent,
                            BroadcastTo.RoomAll);
        }