public bool SendMessage(Byte[] data, MessageContentType contentType)
        {
            int opcodes = 0;

            if (contentType == MessageContentType.Binary)
            {
                opcodes = Opcodes.BinaryFrame;
            }
            else if (contentType == MessageContentType.Text)
            {
                opcodes = Opcodes.TextFrame;
            }
            else
            {
                logger.Warn("不支持的命令格式:" + contentType.ToString());
                return(false);
            }
            if (!IsConnected())
            {
                Debug.WriteLine("连接已断开,无法发送命令");
                return(false);
            }

            FrameCommandBase command = WebSocketCommandFactory.CreateCommand(data, opcodes);

            //Debug.WriteLine("Client Socket Status(SendMessage):" + SessionID + " " + ClientSocket.Connected.ToString());
            Protocol.WriteCommand(command as INetCommand, this);
            //if (isClosed || (clientSocket != null && !clientSocket.Connected))
            //{
            //    logger.Warn("连接已断开,命令未正确写入");
            //    return false;
            //}

            logger.Trace("SendCommand:{0} {1}\r\n{2}", SessionID, EndPoint, command);
            //lock (objLock)
            //{
            //    SendingMessages++;
            //}
            return(true);
        }
Esempio n. 2
0
        public async Task <HttpStatusCode> ProcessAsync(string message, long sequenceNumber, MessageContentType messageContentType, MessageAction messageAction)
        {
            var routeName = GetMappedRouteName(messageContentType.ToString());

            switch (messageContentType)
            {
            case MessageContentType.ApprenticeshipLink:
            case MessageContentType.CollegeLink:
            case MessageContentType.UniversityLink:
            {
                var serviceBusMessage = JsonConvert.DeserializeObject <PatchLinksServiceBusModel>(message);
                var patchLinksModel   = mapper.Map <PatchLinksModel>(serviceBusMessage);
                patchLinksModel.RouteName      = routeName;
                patchLinksModel.MessageAction  = messageAction;
                patchLinksModel.SequenceNumber = sequenceNumber;

                return(await httpClientService.PatchAsync(patchLinksModel, "links").ConfigureAwait(false));
            }

            case MessageContentType.ApprenticeshipRequirement:
            case MessageContentType.UniversityRequirement:
            case MessageContentType.CollegeRequirement:
            {
                var serviceBusMessage      = JsonConvert.DeserializeObject <PatchRequirementsServiceBusModel>(message);
                var patchRequirementsModel = mapper.Map <PatchRequirementsModel>(serviceBusMessage);
                patchRequirementsModel.RouteName      = routeName;
                patchRequirementsModel.MessageAction  = messageAction;
                patchRequirementsModel.SequenceNumber = sequenceNumber;

                return(await httpClientService.PatchAsync(patchRequirementsModel, "requirements").ConfigureAwait(false));
            }

            case MessageContentType.ApprenticeshipEntryRequirements:
            case MessageContentType.UniversityEntryRequirements:
            case MessageContentType.CollegeEntryRequirements:
            {
                var serviceBusMessage = JsonConvert.DeserializeObject <PatchSimpleClassificationServiceBusModel>(message);
                var patchSimpleClassificationModel = mapper.Map <PatchSimpleClassificationModel>(serviceBusMessage);
                patchSimpleClassificationModel.RouteName      = routeName;
                patchSimpleClassificationModel.MessageAction  = messageAction;
                patchSimpleClassificationModel.SequenceNumber = sequenceNumber;

                return(await httpClientService.PatchAsync(patchSimpleClassificationModel, "entryRequirement").ConfigureAwait(false));
            }

            case MessageContentType.Registration:
            {
                var serviceBusMessage       = JsonConvert.DeserializeObject <PatchRegistrationsServiceBusModel>(message);
                var patchRegistrationsModel = mapper.Map <PatchRegistrationModel>(serviceBusMessage);
                patchRegistrationsModel.RouteName      = routeName;
                patchRegistrationsModel.MessageAction  = messageAction;
                patchRegistrationsModel.SequenceNumber = sequenceNumber;

                return(await httpClientService.PatchAsync(patchRegistrationsModel, "registration").ConfigureAwait(false));
            }

            case MessageContentType.JobProfile:
                return(await ProcessFullJobProfile(message, sequenceNumber, messageAction).ConfigureAwait(false));

            default:
                throw new ArgumentOutOfRangeException(nameof(messageContentType), $"Unexpected sitefinity content type '{messageContentType}'");
            }
        }