Ejemplo n.º 1
0
        public void HandleCreateShape(LitePeer peer,
                                      OperationRequest operationRequest,
                                      SendParameters sendParameters)
        {
            var req = CreateShape.Read(operationRequest.Parameters);

            var newSh = new ServerBaseVdShape(req.shapeId, req.ownerId, req.shapeType, req.tag);

            switch (req.shapeType)
            {
            case VdShapeType.Cluster:
                _topology.CreateCluster(newSh.Id());
                _doc.AddShape(newSh);
                break;

            case VdShapeType.FreeForm:
                _doc.AddShape(newSh);
                EventLogger.LogAndBroadcast(
                    new DiscCtx(Discussions.ConfigManager.ConnStr),
                    _room,
                    StEvent.FreeDrawingCreated,
                    req.ownerId,
                    _topicId);
                break;

            default:
                _doc.AddShapeAndLock(newSh);
                break;
            }

            _room.Broadcast(peer,
                            operationRequest,
                            sendParameters,
                            (byte)DiscussionEventCode.CreateShapeEvent,
                            BroadcastTo.RoomExceptSelf);
            //don't include self, we play shape creation locally without continuation

            _pendingChanges = true;
        }
Ejemplo n.º 2
0
        public void OnEvent(EventData eventData)
        {
            switch (eventData.Code)
            {
            case (byte)LiteEventCode.Join:
                int[] actNrs   = (int[])eventData.Parameters[(byte)ParameterKey.Actors];
                int   ActorNr  = (int)eventData.Parameters[(byte)ParameterKey.ActorNr];
                var   actProps = (Hashtable)eventData.Parameters[(byte)ParameterKey.ActorProperties];

                Console.WriteLine("Join event actors.len={0}", actNrs.Length);
                List <int> unknownPeersNrs = new List <int>();
                for (int i = 0; i < actNrs.Length; i++)
                {
                    if (!usersOnline.ContainsKey(actNrs[i]))
                    {
                        if (!unknownPeersNrs.Contains(actNrs[i]))
                        {
                            unknownPeersNrs.Add(actNrs[i]);
                        }
                    }
                }
                requestPeersInfo(unknownPeersNrs.ToArray());
                DbgPrintOnlineList();
                break;

            case (byte)EventCode.Leave:
                actNrs = (int[])eventData.Parameters[(byte)ParameterKey.Actors];
                int leftActNr = (int)eventData.Parameters[(byte)ParameterKey.ActorNr];
                Console.WriteLine("Leave event, actors.len={0}", actNrs.Length);
                if (usersOnline.ContainsKey(leftActNr))
                {
                    if (userLeaves != null)
                    {
                        DiscUser leaving = usersOnline[leftActNr];
                        userLeaves(leaving);
                    }
                    usersOnline.Remove(leftActNr);
                }
                DbgPrintOnlineList();
                break;

            case (byte)DiscussionEventCode.InstantUserPlusMinus:
                if (smbdLeaved != null)
                {
                    smbdLeaved();
                }
                break;

            case (byte)DiscussionEventCode.StructureChanged:
                int initiater = (int)eventData.Parameters[(byte)DiscussionParamKey.UserId];
                int devType   = (int)eventData.Parameters[(byte)DiscussionParamKey.DeviceType];
                if (eventData.Parameters.ContainsKey((byte)DiscussionParamKey.ForceSelfNotification))
                {
                    //topic updated
                    if (onStructChanged != null)
                    {
                        onStructChanged(Serializers.ReadChangedTopicId(eventData.Parameters),
                                        initiater, (DeviceType)devType);
                    }
                }
                else if (initiater != -1 && initiater != localUsr.ActNr)
                {
                    if (onStructChanged != null)
                    {
                        onStructChanged(Serializers.ReadChangedTopicId(eventData.Parameters),
                                        initiater, (DeviceType)devType);
                    }
                }
                break;

            case (byte)DiscussionEventCode.ArgPointChanged:
                var changeType = PointChangedType.Modified;
                int topicId;
                int personId;
                int argPointId = Serializers.ReadChangedArgPoint(eventData.Parameters, out changeType, out topicId, out personId);
                if (argPointChanged != null)
                {
                    argPointChanged(argPointId, topicId, changeType, personId);
                }
                break;

            case (byte)DiscussionEventCode.UserAccPlusMinus:
                if (userAccPlusMinus != null)
                {
                    userAccPlusMinus();
                }
                break;

            case (byte)DiscussionEventCode.StatsEvent:
                if (onStatsEvent != null)
                {
                    StEvent    e;
                    int        userId       = -1;
                    int        discussionId = -1;
                    int        statsTopicId = -1;
                    DeviceType devTyp;
                    Serializers.ReadStatEventParams(eventData.Parameters, out e, out userId, out discussionId,
                                                    out statsTopicId, out devTyp);
                    onStatsEvent(e, userId, discussionId, statsTopicId, devTyp);
                }
                break;

            case (byte)DiscussionEventCode.CursorEvent:
                if (cursorEvent != null)
                {
                    cursorEvent(CursorEvent.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.CreateShapeEvent:
                if (createShapeEvent != null)
                {
                    createShapeEvent(CreateShape.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.UnselectAllEvent:
                if (unselectAll != null)
                {
                    unselectAll(UnselectAllEvent.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.DeleteSingleShapeEvent:
                if (deleteSingleShape != null)
                {
                    deleteSingleShape(DeleteSingleShapeEvent.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.ApplyPointEvent:
                if (applyPoint != null)
                {
                    applyPoint(PointMove.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.StateSyncEvent:
                if (syncStateEvent != null)
                {
                    syncStateEvent(ShapeState.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.LinkCreateEvent:
                if (onLinkCreateEvent != null)
                {
                    onLinkCreateEvent(LinkCreateMessage.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.UnclusterBadgeEvent:
                if (onUnclusterBadgeEvent != null)
                {
                    onUnclusterBadgeEvent(UnclusterBadgeMessage.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.ClusterBadgeEvent:
                if (onClusterBadgeEvent != null)
                {
                    onClusterBadgeEvent(ClusterBadgeMessage.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.InkEvent:
                if (inkEvent != null)
                {
                    inkEvent(InkMessage.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.SceneLoadingDone:
                if (loadingDoneEvent != null)
                {
                    loadingDoneEvent();
                }
                break;

            case (byte)DiscussionEventCode.DEditorReportEvent:
                if (dEditorReportResponse != null)
                {
                    dEditorReportResponse(DEditorStatsResponse.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.ClusterStatsEvent:
                if (clusterStatsResponse != null)
                {
                    if (eventData.Parameters == null || eventData.Parameters.Count() == 0)
                    {
                        clusterStatsResponse(default(ClusterStatsResponse), false);
                    }
                    else
                    {
                        clusterStatsResponse(ClusterStatsResponse.Read(eventData.Parameters), true);
                    }
                }
                break;

            case (byte)DiscussionEventCode.LinkStatsEvent:
                if (linkStatsResponseEvent != null)
                {
                    if (eventData.Parameters == null || eventData.Parameters.Count() == 0)
                    {
                        linkStatsResponseEvent(default(LinkReportResponse), false);
                    }
                    else
                    {
                        linkStatsResponseEvent(LinkReportResponse.Read(eventData.Parameters), true);
                    }
                }
                break;

            case (byte)DiscussionEventCode.BadgeViewEvent:
                if (onBadgeViewRequest != null)
                {
                    onBadgeViewRequest(BadgeViewMessage.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.SourceViewEvent:
                if (onSourceViewRequest != null)
                {
                    onSourceViewRequest(ExplanationModeSyncMsg.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.CommentReadEvent:
                if (onCommentRead != null)
                {
                    onCommentRead(CommentsReadEvent.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.AttachLaserPointerEvent:
                if (onAttachLaserPointer != null)
                {
                    onAttachLaserPointer(LaserPointer.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.DetachLaserPointerEvent:
                if (onDetachLaserPointer != null)
                {
                    onDetachLaserPointer(LaserPointer.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.LaserPointerMovedEvent:
                if (onLaserPointerMoved != null)
                {
                    onLaserPointerMoved(LaserPointer.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.ImageViewerManipulatedEvent:
                if (onImageViewerManipulated != null)
                {
                    onImageViewerManipulated(ImageViewerMatrix.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.BrowserScrollChangedEvent:
                if (onBrowserScroll != null)
                {
                    onBrowserScroll(BrowserScrollPosition.Read(eventData.Parameters));
                }
                break;

            case (byte)DiscussionEventCode.PdfScrollChangedEvent:
                if (onPdfScroll != null)
                {
                    onPdfScroll(PdfScrollPosition.Read(eventData.Parameters));
                }
                break;

            default:
                Console.WriteLine("Unhandled event " + eventData.Code);
                break;
            }
        }