Esempio n. 1
0
        /// <summary>
        /// Handles messages received from the client/server. Derived
        /// classes must override this method to process messages. Derived
        /// classes should call the base method after processing the message.
        /// </summary>
        /// <param name="rawMessage"></param>
        protected virtual void HandleMessage(byte[] rawMessage)
        {
            MessageType    type         = (MessageType)rawMessage[4];
            NetworkMessage basicMessage = new NetworkMessage(rawMessage);

            //Make sure we don't somehow handle the same request more than once
            if (ProcessedMessageIds.Contains(basicMessage.MessageId))
            {
                ISLogger.Write("Ignoring duplicate message ID");
                return;
            }

            if (CheckAwaitingMessages(basicMessage, rawMessage))
            {
                return;
            }

            if (type == MessageType.ClipboardData)
            {
                HandleClipboardData(new ClipboardDataMessage(rawMessage));
            }
            else if (type == MessageType.DragDropData)
            {
                HandleDragDropMessage(new DragDropDataMessage(rawMessage));
            }
            else if (type == MessageType.DragDropSuccess)
            {
                DragDropSuccess?.Invoke(this, new EventArgs());
            }
            else if (type == MessageType.DragDropCancelled)
            {
                DragDropCancelled?.Invoke(this, new EventArgs());
            }
            else if (type == MessageType.RequestFileGroupToken)
            {
                RequestGroupTokenMessage requestMsg = new RequestGroupTokenMessage(rawMessage);
                RequestedFileToken?.Invoke(this, new FileTokenRequestArgs(requestMsg.MessageId, requestMsg.FileGroupId));
            }
            else if (type == MessageType.FileStreamReadRequest)
            {
                FileStreamReadRequestMessage requestMsg = new FileStreamReadRequestMessage(rawMessage);
                RequestedStreamRead?.Invoke(this, new RequestStreamReadArgs(requestMsg.MessageId, requestMsg.Token, requestMsg.FileRequestId, requestMsg.ReadSize));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles messages received from the client/server. Derived
        /// classes must override this method to process messages. Derived
        /// classes should call the base method after processing the message.
        /// </summary>
        /// <param name="message"></param>
        protected virtual void HandleMessage(byte[] message)
        {
            MessageType    type = (MessageType)message[4];
            NetworkMessage msg  = new NetworkMessage(message);

            //Make sure we don't somehow handle the same request more than once
            if (ProcessedMessageIds.Contains(msg.MessageId))
            {
                ISLogger.Write("Ignoring duplicate message ID");
                return;
            }

            if (type == MessageType.ClipboardData)
            {
                HandleClipboardData(new ClipboardDataMessage(message));
            }
            else if (type == MessageType.DragDropData)
            {
                HandleDragDropMessage(new DragDropDataMessage(message));
            }
            else if (type == MessageType.DragDropSuccess)
            {
                DragDropSuccessMessage sMsg = new DragDropSuccessMessage(message);
                DragDropSuccess?.Invoke(this, sMsg.OperationId);
            }
            else if (type == MessageType.DragDropCancelled)
            {
                DragDropCancelledMessage cMsg = new DragDropCancelledMessage(message);
                DragDropCancelled?.Invoke(this, cMsg.OperationId);
            }
            else if (type == MessageType.RequestFileGroupToken)
            {
                RequestGroupTokenMessage requestMsg = new RequestGroupTokenMessage(message);
                RequestedFileToken?.Invoke(this, new FileTokenRequestArgs(requestMsg.MessageId, requestMsg.FileGroupId));
            }
            else if (type == MessageType.FileStreamReadRequest)
            {
                FileStreamReadRequestMessage requestMsg = new FileStreamReadRequestMessage(message);
                RequestedStreamRead?.Invoke(this, new RequestStreamReadArgs(requestMsg.MessageId, requestMsg.Token, requestMsg.FileRequestId, requestMsg.ReadSize));
            }
            else if (type == MessageType.FileStreamCloseRequest)
            {
                FileStreamCloseStreamMessage closeMsg = new FileStreamCloseStreamMessage(message);
                RequestedCloseStream?.Invoke(this, new RequestCloseStreamArgs(closeMsg.Token, closeMsg.FileId));
            }
            else if (type == MessageType.DragDropComplete)
            {
                DragDropCompleteMessage ddcMsg = new DragDropCompleteMessage(message);
                DragDropOperationComplete?.Invoke(this, ddcMsg.OperationId);
            }

            lock (awaitingCollectionsLock)
            {
                if (awaitingMessageIds.Contains(msg.MessageId))
                {
                    //TODO
                    if (type == MessageType.RequestFileGroupTokenReponse)
                    {
                        awaitingReturnMessages.Add(msg.MessageId, new RequestGroupTokenResponseMessage(message));
                    }
                    else if (type == MessageType.FileStreamReadResponse)
                    {
                        awaitingReturnMessages.Add(msg.MessageId, new FileStreamReadResponseMessage(message));
                    }
                    else if (type == MessageType.RemoteFileError)
                    {
                        awaitingReturnMessages.Add(msg.MessageId, new FileErrorMessage(message));
                    }

                    awaitingReturnMethods.TryGetValue(msg.MessageId, out AutoResetEvent evt);
                    evt.Set();
                }
            }
        }