public static WebhookCommand DetermineWebhookCommand(MessageContentType messageContentType, WebhookCacheOperation webhookCacheOperation)
        {
            switch (webhookCacheOperation)
            {
            case WebhookCacheOperation.CreateOrUpdate:
                switch (messageContentType)
                {
                case MessageContentType.LmiSocSummary:
                    return(WebhookCommand.TransformAllSocToJobGroup);

                case MessageContentType.LmiSocItem:
                    return(WebhookCommand.TransformSocToJobGroup);
                }

                break;

            case WebhookCacheOperation.Delete:
                switch (messageContentType)
                {
                case MessageContentType.LmiSocSummary:
                    return(WebhookCommand.PurgeAllJobGroups);

                case MessageContentType.LmiSocItem:
                    return(WebhookCommand.PurgeJobGroup);
                }

                break;
            }

            return(WebhookCommand.None);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Called when [init].
        /// </summary>
        /// <param name = "peer">The peer.</param>
        /// <param name = "data">The data.</param>
        public void OnInit(IPhotonPeer peer, byte[] data, byte channelCount)
        {
            try
            {
                if (log.IsDebugEnabled)
                {
                    Encoding utf8Encoding = Encoding.UTF8;
                    log.DebugFormat("OnInit - {0}", utf8Encoding.GetString(data));
                }

                if (data[0] == '<' && data[21] == '>')
                {
                    byte[] bytes = peer.GetLocalPort() == 943 ? this.silverlightPolicyBytesUtf8 : this.policyBytesUtf8;

                    // in case the policy app ever serves a websocket port...
                    MessageContentType contentType = peer.GetListenerType() == ListenerType.WebSocketListener
                                                         ? MessageContentType.Text
                                                         : MessageContentType.Binary;

                    peer.Send(bytes, MessageReliablity.Reliable, 0, contentType);

                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Policy sent.");
                    }
                }

                peer.DisconnectClient(); // silverlight does not disconnect by itself
            }
            catch (Exception e)
            {
                log.Error(e);
                throw;
            }
        }
Ejemplo n.º 3
0
        public static WebhookCommand DetermineWebhookCommand(MessageContentType messageContentType, WebhookCacheOperation webhookCacheOperation)
        {
            switch (webhookCacheOperation)
            {
            case WebhookCacheOperation.CreateOrUpdate:
                switch (messageContentType)
                {
                case MessageContentType.Publish:
                    return(WebhookCommand.PublishFromDraft);
                }

                break;

            case WebhookCacheOperation.Delete:
                switch (messageContentType)
                {
                case MessageContentType.Publish:
                    return(WebhookCommand.PurgeFromPublished);
                }

                break;
            }

            return(WebhookCommand.None);
        }
Ejemplo n.º 4
0
        private void ReadData(NetIncomingMessage msgInc)
        {
            int id;
            MessageContentType contentType = (MessageContentType)msgInc.ReadByte();

            switch (contentType)
            {
            case MessageContentType.RequestSpawn:
                Player newPlayer = new Player();
                id = Map.AddObject(newPlayer);
                NetOutgoingMessage msgOut = Server.CreateMessage();
                msgOut.Write((byte)MessageContentType.ApproveSpawn);
                msgOut.Write(id);
                Server.SendMessage(msgOut, msgInc.SenderConnection, NetDeliveryMethod.ReliableUnordered);
                break;

            case MessageContentType.MapData:
                GameObject obj;
                id = msgInc.ReadInt32();
                if (Map.Objects.TryGetValue(id, out obj))
                {
                    msgInc.ReadByte();     // Ignore GameObjectType
                    obj.ReadFrom(msgInc);
                }
                break;

            case MessageContentType.RequestProjectile:
                Vector2 position = new Vector2(msgInc.ReadFloat(), msgInc.ReadFloat());
                Vector2 velocity = new Vector2(msgInc.ReadFloat(), msgInc.ReadFloat());
                SpawnProjectile(position, velocity);
                break;
            }
        }
Ejemplo n.º 5
0
        public static TSms AsType <TSms>(this TSms sms, MessageContentType type)
            where TSms : Sms
        {
            Contract.Requires(sms != null);
            Contract.Ensures(Contract.Result <TSms>() == sms);

            return(sms.Assign(s => s.Type = type));
        }
        public void LmiWebhookReceiverServiceDetermineWebhookCommandReturnsExpected(MessageContentType messageContentType, WebhookCacheOperation webhookCacheOperation, WebhookCommand expectedResult)
        {
            // Arrange

            // Act
            var result = LmiWebhookReceiverService.DetermineWebhookCommand(messageContentType, webhookCacheOperation);

            // Assert
            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 7
0
        private void ReadData(NetIncomingMessage msg)
        {
            MessageContentType contentType = (MessageContentType)msg.ReadByte();

            switch (contentType)
            {
            case MessageContentType.StartGame:
                Game.ActiveState = new ClientBattleGameState(Game);
                break;
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 ///   OnReceive callback.
 /// </summary>
 /// <param name = "peer">
 ///   The peer.
 /// </param>
 /// <param name = "userData">
 ///   The user data.
 /// </param>
 /// <param name = "data">
 ///   The data.
 /// </param>
 /// <param name = "reliability">
 ///   The reliability.
 /// </param>
 /// <param name = "channelId">
 ///   The channel id.
 /// </param>
 /// /// <param name = "rtt">The round trip time.</param>
 /// <param name = "rttVariance">The round trip time variance.</param>
 /// <param name = "numFailures">The number of failures. </param>
 public void OnReceive(
     IPhotonPeer peer,
     object userData,
     byte[] data,
     MessageReliablity reliability,
     byte channelId,
     MessageContentType messageContentType,
     int rtt,
     int rttVariance,
     int numFailures)
 {
 }
        public bool BroadcastEvent(IPhotonPeer[] peerList, byte[] data, MessageReliablity reliability, byte channelId, MessageContentType messageContentType, out SendResults[] results)
        {

            results = new SendResults[peerList.Length];

            for (int i = 0; i < peerList.Length; i++)
            {
                results[i] = peerList[i].Send(data, reliability, channelId, messageContentType);
            }

            return true; 
        }
Ejemplo n.º 10
0
        static public MemoryStream Deserialize(MemoryStream ms, MessageContentType msgContentType)
        {
            if (msgContentType == MessageContentType.Xml)
            {
                return(ms); // Either already in XML or an explicit serialization will be called by Comm. Manager
            }
            else if (msgContentType == MessageContentType.FastInfoSet)
            {
                return(FastInfoSetSerializer.DeSerialize(ms));
            }

            throw new ArgumentOutOfRangeException("msgContentType");
        }
Ejemplo n.º 11
0
        public async Task MessageHandlerReturnsExceptionWhenEmptyServiceBusMessageSupplied()
        {
            // arrange
            const MessageAction      messageAction      = MessageAction.Published;
            const MessageContentType messageContentType = MessageContentType.Pages;
            var serviceBusMessage = new Message(Encoding.ASCII.GetBytes(string.Empty));

            serviceBusMessage.UserProperties.Add("ActionType", messageAction);
            serviceBusMessage.UserProperties.Add("CType", messageContentType);
            serviceBusMessage.UserProperties.Add("Id", Guid.NewGuid());

            // act
            await Assert.ThrowsAsync <ArgumentException>(async() => await MessageHandler.Run(serviceBusMessage, messageProcessor, messagePropertiesService, logger).ConfigureAwait(false)).ConfigureAwait(false);
        }
Ejemplo n.º 12
0
        public async Task MessageHandlerReturnsExceptionWhenMessageActionIsInvalid()
        {
            // arrange
            const int messageAction = -1;
            const MessageContentType messageContentType = MessageContentType.Pages;
            var model             = A.Fake <ContentPageMessage>();
            var message           = JsonConvert.SerializeObject(model);
            var serviceBusMessage = new Message(Encoding.ASCII.GetBytes(message));

            serviceBusMessage.UserProperties.Add("ActionType", messageAction);
            serviceBusMessage.UserProperties.Add("CType", messageContentType);
            serviceBusMessage.UserProperties.Add("Id", Guid.NewGuid());

            // act
            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await MessageHandler.Run(serviceBusMessage, messageProcessor, messagePropertiesService, logger).ConfigureAwait(false)).ConfigureAwait(false);
        }
        public async Task ProcessAsyncWithBadMessageMessageActionReturnsException()
        {
            // arrange
            const string             message            = "{}";
            const long               sequenceNumber     = 1;
            const MessageContentType messageContentType = MessageContentType.Pages;

            A.CallTo(() => mappingService.MapToContentPageModel(message, sequenceNumber)).Returns(A.Fake <ContentPageModel>());

            // act
            var exceptionResult = await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await messageProcessor.ProcessAsync(message, sequenceNumber, messageContentType, (MessageAction)(-1)).ConfigureAwait(false)).ConfigureAwait(false);

            // assert
            A.CallTo(() => mappingService.MapToContentPageModel(message, sequenceNumber)).MustHaveHappenedOnceExactly();
            Assert.Equal("Invalid message action '-1' received, should be one of 'Published,Deleted,Draft' (Parameter 'messageAction')", exceptionResult.Message);
        }
Ejemplo n.º 14
0
 public void SendMessage(MessageContentType type, int player, IMessageContent data)
 {
     lock (messageLock)
     {
         NetworkMessage msg;
         if (data != null)
         {
             msg = new NetworkMessage(data, type);
             SendBuffer(msg.Encode(), player);
         }
         else
         {
             SendBuffer(NetworkMessage.EmptyMessage(type), player);
         }
     }
 }
        public async Task SitefinityMessageHandlerReturnsExceptionWhenMessageActionIsInvalid()
        {
            // arrange
            const int messageAction = -1;
            const MessageContentType messageContentType = MessageContentType.WorkingHoursDetails;
            var model             = A.Fake <PatchWorkingHoursDetailModel>();
            var message           = JsonConvert.SerializeObject(model);
            var serviceBusMessage = new Message(Encoding.ASCII.GetBytes(message));

            serviceBusMessage.UserProperties.Add("ActionType", messageAction);
            serviceBusMessage.UserProperties.Add("CType", messageContentType);
            serviceBusMessage.UserProperties.Add("Id", Guid.NewGuid());

            // act
            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await sitefinityMessageHandler.Run(serviceBusMessage).ConfigureAwait(false)).ConfigureAwait(false);
        }
Ejemplo n.º 16
0
        static public MemoryStream Serialize(MemoryStream ms, MessageContentType msgContentType)
        {
            if (ms == null)
            {
                throw new ArgumentNullException("ms");
            }

            if (msgContentType == MessageContentType.Xml)
            {
                return(ms); // Already in XML
            }
            else if (msgContentType == MessageContentType.FastInfoSet)
            {
                return(FastInfoSetSerializer.Serialize(ms));
            }

            throw new ArgumentOutOfRangeException("msgContentType");
        }
        public async Task ProcessAsyncRequirementTestReturnsOk(MessageContentType messageContentType)
        {
            // arrange
            const HttpStatusCode expectedResult = HttpStatusCode.OK;
            const string         message        = "{}";
            const long           sequenceNumber = 1;

            A.CallTo(() => mapper.Map <PatchRequirementsModel>(A <PatchRequirementsServiceBusModel> .Ignored)).Returns(A.Fake <PatchRequirementsModel>());
            A.CallTo(() => httpClientService.PatchAsync(A <PatchRequirementsModel> .Ignored, A <string> .Ignored)).Returns(expectedResult);

            // act
            var result = await messageProcessor.ProcessAsync(message, sequenceNumber, messageContentType, MessageAction.Published).ConfigureAwait(false);

            // assert
            A.CallTo(() => mapper.Map <PatchRequirementsModel>(A <PatchRequirementsServiceBusModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => httpClientService.PatchAsync(A <PatchRequirementsModel> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal(expectedResult, result);
        }
        public static WebhookCommand DetermineWebhookCommand(MessageContentType messageContentType, WebhookCacheOperation webhookCacheOperation)
        {
            switch (webhookCacheOperation)
            {
            case WebhookCacheOperation.CreateOrUpdate:
                switch (messageContentType)
                {
                case MessageContentType.JobGroup:
                    return(WebhookCommand.ReportDeltaForAll);

                case MessageContentType.JobGroupItem:
                    return(WebhookCommand.ReportDeltaForSoc);
                }

                break;
            }

            return(WebhookCommand.None);
        }
        public async Task ProcessAsyncJobProfileDeletedTestReturnsOk()
        {
            // arrange
            const HttpStatusCode     expectedResult     = HttpStatusCode.OK;
            const string             message            = "{}";
            const long               sequenceNumber     = 1;
            const MessageContentType messageContentType = MessageContentType.Pages;

            A.CallTo(() => mappingService.MapToContentPageModel(message, sequenceNumber)).Returns(A.Fake <ContentPageModel>());
            A.CallTo(() => httpClientService.DeleteAsync(A <Guid> .Ignored)).Returns(expectedResult);

            // act
            var result = await messageProcessor.ProcessAsync(message, sequenceNumber, messageContentType, MessageAction.Deleted).ConfigureAwait(false);

            // assert
            A.CallTo(() => mappingService.MapToContentPageModel(message, sequenceNumber)).MustHaveHappenedOnceExactly();
            A.CallTo(() => httpClientService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal(expectedResult, result);
        }
        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);
        }
Ejemplo n.º 21
0
        public static void Serialize(object obj, Stream stm, MessageContentType contentType)
        {
            if (contentType == MessageContentType.Text)
            {
                SerializeText(obj, stm);
            }
            else if (contentType == MessageContentType.SerializedBinary)
            {
                //SoapFormatter bf = new SoapFormatter(new RemotingSurrogateSelector(), new StreamingContext(StreamingContextStates.Persistence));
                BinaryFormatter bf = new BinaryFormatter(new RemotingSurrogateSelector(), new StreamingContext(StreamingContextStates.Persistence));
                bf.Serialize(stm, obj);
            }
            else if (contentType == MessageContentType.SerializedSoap)
            {
                //SoapFormatter bf = new SoapFormatter(new RemotingSurrogateSelector(), new StreamingContext(StreamingContextStates.Persistence));
                //bf.Serialize(stm, obj);
                throw new NotImplementedException();
            }
            else if (contentType == MessageContentType.Binary)
            {
                Stream input = obj as Stream;
                if (input == null)
                {
                    byte[] data = obj as byte[];
                    if (data != null)
                        input = new MemoryStream(data);
                    else
                        throw new Exception("Only byte[] or Stream object is allowed with binary content type");
                }

                byte[] buf = new byte[1000];
                int n;
                while ((n = input.Read(buf, 0, buf.Length)) > 0)
                {
                    stm.Write(buf, 0, n);
                }
            }
            else throw new ArgumentException("contentType");
        }
Ejemplo n.º 22
0
 public static object Deserialize(Stream stm, MessageContentType contentType)
 {
     if (contentType == MessageContentType.SerializedBinary)
     {
         BinaryFormatter bf = new BinaryFormatter(new RemotingSurrogateSelector(), new StreamingContext(StreamingContextStates.Persistence));
         return bf.Deserialize(stm);
     }
     else if (contentType == MessageContentType.SerializedSoap)
     {
         //SoapFormatter bf = new SoapFormatter(new RemotingSurrogateSelector(), new StreamingContext(StreamingContextStates.Persistence));
         //return bf.Deserialize(stm);
         throw new NotImplementedException();
     }
     else if (contentType == MessageContentType.Text)
     {
         return DeserializeText(stm);
     }
     else if (contentType == MessageContentType.Binary)
     {
         return stm;
     }
     else throw new ArgumentException("contentType");
 }
Ejemplo n.º 23
0
        public async Task MessageHandlerReturnsSuccessForSegmentUpdated(HttpStatusCode expectedResult)
        {
            // arrange
            const MessageAction      messageAction      = MessageAction.Published;
            const MessageContentType messageContentType = MessageContentType.Pages;
            const long sequenceNumber    = 123;
            var        model             = A.Fake <ContentPageMessage>();
            var        message           = JsonConvert.SerializeObject(model);
            var        serviceBusMessage = new Message(Encoding.ASCII.GetBytes(message));

            serviceBusMessage.UserProperties.Add("ActionType", messageAction);
            serviceBusMessage.UserProperties.Add("CType", messageContentType);
            serviceBusMessage.UserProperties.Add("Id", Guid.NewGuid());

            A.CallTo(() => messagePropertiesService.GetSequenceNumber(serviceBusMessage)).Returns(sequenceNumber);
            A.CallTo(() => messageProcessor.ProcessAsync(message, sequenceNumber, messageContentType, messageAction)).Returns(expectedResult);

            // act
            await MessageHandler.Run(serviceBusMessage, messageProcessor, messagePropertiesService, logger).ConfigureAwait(false);

            // assert
            A.CallTo(() => messagePropertiesService.GetSequenceNumber(serviceBusMessage)).MustHaveHappenedOnceExactly();
            A.CallTo(() => messageProcessor.ProcessAsync(message, sequenceNumber, messageContentType, messageAction)).MustHaveHappenedOnceExactly();
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Constructs an instance of the <see cref="MessageBusMessage"/> class with the content type.
 /// </summary>
 /// <param name="contentType">The content type of the message.</param>
 public MessageBusMessage(MessageContentType contentType)
     : base(MessageType.Envelope, contentType)
 {
 }
        public void LmiWebhookReceiverServiceDetermineMessageContentTypeReturnsExpected(string?apiEndpoint, MessageContentType expectedResult)
        {
            // Arrange

            // Act
            var result = LmiWebhookReceiverService.DetermineMessageContentType(apiEndpoint);

            // Assert
            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 26
0
        public async Task <HttpStatusCode> ProcessContentAsync(bool isDraft, Guid eventId, Guid?contentId, string?apiEndpoint, MessageContentType messageContentType)
        {
            if (!Uri.TryCreate(apiEndpoint, UriKind.Absolute, out Uri? url))
            {
                throw new InvalidDataException($"Invalid Api url '{apiEndpoint}' received for Event Id: {eventId}");
            }

            switch (messageContentType)
            {
            case MessageContentType.SharedContentItem:
                logger.LogInformation($"Event Id: {eventId} - processing shared content for: {url}");
                return(await ProcessSharedContentAsync(eventId, url).ConfigureAwait(false));

            case MessageContentType.JobGroup:
                if (isDraft)
                {
                    logger.LogInformation($"Event Id: {eventId} - processing draft LMI SOC refresh for: {url}");
                    var result = await jobGroupCacheRefreshService.ReloadAsync(url).ConfigureAwait(false);

                    if (result == HttpStatusCode.OK || result == HttpStatusCode.Created)
                    {
                        await PostDraftEventAsync($"Draft all SOCs to delta-report API", eventGridClientOptions.ApiEndpoint, Guid.NewGuid()).ConfigureAwait(false);
                    }

                    return(result);
                }
                else
                {
                    logger.LogInformation($"Event Id: {eventId} - processing published LMI SOC refresh from draft for: {url}");
                    return(await jobGroupPublishedRefreshService.ReloadAsync(url).ConfigureAwait(false));
                }

            case MessageContentType.JobGroupItem:
                if (isDraft)
                {
                    logger.LogInformation($"Event Id: {eventId} - processing draft LMI SOC item for: {url}");
                    var result = await jobGroupCacheRefreshService.ReloadItemAsync(url).ConfigureAwait(false);

                    if (result == HttpStatusCode.OK || result == HttpStatusCode.Created)
                    {
                        var eventGridEndpoint = new Uri($"{eventGridClientOptions.ApiEndpoint}/{contentId}", UriKind.Absolute);
                        await PostDraftEventAsync($"Draft individual SOC to delta-report API", eventGridEndpoint, contentId).ConfigureAwait(false);
                    }

                    return(result);
                }
                else
                {
                    logger.LogInformation($"Event Id: {eventId} - processing published LMI SOC item from draft for: {url}");
                    return(await jobGroupPublishedRefreshService.ReloadItemAsync(url).ConfigureAwait(false));
                }
            }

            return(HttpStatusCode.BadRequest);
        }
        public void WebhooksServiceDetermineMessageContentTypeReturnsExpected(string?apiEndpoint, MessageContentType expectedResponse)
        {
            // Arrange

            // Act
            var result = WebhooksService.DetermineMessageContentType(apiEndpoint);

            // Assert
            Assert.Equal(expectedResponse, result);
        }
Ejemplo n.º 28
0
 public ContentAttribute(MessageContentType type, MessageContentPersistFlag flag)
 {
     this.type = (int)type;
     this.flag = flag;
 }
Ejemplo n.º 29
0
        public bool BroadcastEvent(IPhotonPeer[] peerList, byte[] data, MessageReliablity reliability, byte channelId, MessageContentType messageContentType, out SendResults[] results)
        {
            results = new SendResults[peerList.Length];

            for (int i = 0; i < peerList.Length; i++)
            {
                results[i] = peerList[i].Send(data, reliability, channelId, messageContentType);
            }

            return(true);
        }
Ejemplo n.º 30
0
        public async Task <HttpStatusCode> ProcessDeleteAsync(Guid eventId, Guid contentId, MessageContentType messageContentType)
        {
            switch (messageContentType)
            {
            case MessageContentType.SharedContentItem:
                logger.LogInformation($"Event Id: {eventId} - deleting shared content for: {contentId}");
                return(await DeleteContentAsync(contentId).ConfigureAwait(false));

            case MessageContentType.JobGroup:
                logger.LogInformation($"Event Id: {eventId} - purging LMI SOC");
                return(await PurgeSocAsync().ConfigureAwait(false));

            case MessageContentType.JobGroupItem:
                logger.LogInformation($"Event Id: {eventId} - deleting LMI SOC item {contentId}");
                return(await DeleteSocItemAsync(contentId).ConfigureAwait(false));
            }

            return(HttpStatusCode.BadRequest);
        }
Ejemplo n.º 31
0
 public MessageContentEntity(MessageContentType type, string guid)
 {
     this.Type = type;
     this.Guid = guid;
     //this.Contents = contents;
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Constructs an instance of the <see cref="EventMessage"/> class with the content type.
 /// </summary>
 /// <param name="contentType">The content type of the message.</param>
 public EventMessage(MessageContentType contentType)
     : base(MessageType.Event, contentType)
 {
 }
        public async Task <HttpStatusCode> ProcessAsync(string message, long sequenceNumber, MessageContentType messageContentType, MessageAction actionType)
        {
            switch (messageContentType)
            {
            case MessageContentType.JobProfileSoc:
                var serviceBusJobProfileSocMessage = JsonConvert.DeserializeObject <PatchJobProfileSocServiceBusModel>(message);
                var patchSocDataModel = mapper.Map <PatchJobProfileSocModel>(serviceBusJobProfileSocMessage);
                patchSocDataModel.ActionType     = actionType;
                patchSocDataModel.SequenceNumber = sequenceNumber;

                return(await httpClientService.PatchAsync(patchSocDataModel, $"{messageContentType}").ConfigureAwait(false));

            case MessageContentType.ApprenticeshipFrameworks:
                var serviceBusApprenticeshipFrameworksMessage = JsonConvert.DeserializeObject <PatchApprenticeshipFrameworksServiceBusModel>(message);
                var patchApprenticeshipFrameworksModel        = mapper.Map <PatchApprenticeshipFrameworksModel>(serviceBusApprenticeshipFrameworksMessage);
                patchApprenticeshipFrameworksModel.ActionType     = actionType;
                patchApprenticeshipFrameworksModel.SequenceNumber = sequenceNumber;

                return(await httpClientService.PatchAsync(patchApprenticeshipFrameworksModel, $"{messageContentType}").ConfigureAwait(false));

            case MessageContentType.ApprenticeshipStandards:
                var serviceBusApprenticeshipStandardsMessage = JsonConvert.DeserializeObject <PatchApprenticeshipStandardsServiceBusModel>(message);
                var patchApprenticeshipStandardsModel        = mapper.Map <PatchApprenticeshipStandardsModel>(serviceBusApprenticeshipStandardsMessage);
                patchApprenticeshipStandardsModel.ActionType     = actionType;
                patchApprenticeshipStandardsModel.SequenceNumber = sequenceNumber;

                return(await httpClientService.PatchAsync(patchApprenticeshipStandardsModel, $"{messageContentType}").ConfigureAwait(false));

            case MessageContentType.JobProfile:
                return(await ProcessJobProfileMessageAsync(message, actionType, sequenceNumber).ConfigureAwait(false));

            default:
                throw new ArgumentOutOfRangeException(nameof(messageContentType), $"Unexpected sitefinity content type '{messageContentType}'");
            }
        }
Ejemplo n.º 34
0
        /// <summary>
        ///   Send data to the peer.
        /// </summary>
        /// <param name = "data">
        ///   The serialized data.
        /// </param>
        /// <param name = "reliability">
        ///   The reliability.
        /// </param>
        /// <param name = "channelId">
        ///   The channel id.
        /// </param>
        /// <returns>
        ///   Always <see cref = "SendResults.SentOk" />.
        /// </returns>
        public SendResults Send(byte[] data, MessageReliablity reliability, byte channelId, MessageContentType messageContentType)
        {
            RtsMessageHeader messageType;
            if (this.Protocol.TryParseMessageHeader(data, out messageType) == false)
            {
                throw new InvalidOperationException();
            }

            switch (messageType.MessageType)
            {
                case RtsMessageType.Event:
                    {
                        EventData eventData;
                        if (this.Protocol.TryParseEventData(data, out eventData))
                        {
                            Interlocked.Increment(ref eventsReceived);
                            this.eventList.Add(eventData);

                            if (log.IsDebugEnabled)
                            {
                                if (eventData.Parameters.ContainsKey((byte)ParameterCode.ItemId))
                                {
                                    log.DebugFormat(
                                        "{0} receives event, {1} total - code {2}, source {3}", 
                                        this.username, 
                                        this.eventList.Count, 
                                        (EventCode)eventData.Code,
                                        eventData.Parameters[(byte)ParameterCode.ItemId]);
                                }
                                else
                                {
                                    log.DebugFormat(
                                        "{0} receives event, {1} total - code {2}", 
                                        this.username, 
                                        this.eventList.Count,
                                        (EventCode)eventData.Code);
                                }
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException();
                        }

                        break;
                    }

                case RtsMessageType.OperationResponse:
                    {
                        OperationResponse response;
                        if (this.Protocol.TryParseOperationResponse(data, out response))
                        {
                            Interlocked.Increment(ref responseReceived);
                            this.responseList.Add(response);

                            if (response.ReturnCode != (int)ReturnCode.Ok)
                            {
                                log.ErrorFormat(
                                    "ERR {0}, OP {1}, DBG {2}", (ReturnCode)response.ReturnCode, (OperationCode)response.OperationCode, response.DebugMessage);
                            }
                            else if (log.IsDebugEnabled)
                            {
                                if (response.Parameters.ContainsKey((byte)ParameterCode.ItemId))
                                {
                                    log.DebugFormat(
                                        "{0} receives response, {1} total - code {2}, source {3}", 
                                        this.username, 
                                        this.responseList.Count, 
                                        (OperationCode)response.OperationCode,
                                        response.Parameters[(byte)ParameterCode.ItemId]);
                                }
                                else
                                {
                                    log.DebugFormat(
                                        "{0} receives response, {1} total - code {2}", 
                                        this.username, 
                                        this.responseList.Count, 
                                        (OperationCode)response.OperationCode);
                                }
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException();
                        }

                        break;
                    }
            }

            return SendResults.SentOk;
        }
Ejemplo n.º 35
0
 SendResults IPhotonPeer._InternalBroadcastSend(byte[] data, MessageReliablity reliability, byte channelId, MessageContentType messageContentType)
 {
     return new SendResults();
 }
Ejemplo n.º 36
0
        /// <summary>
        ///   The send.
        /// </summary>
        /// <param name = "data">
        ///   The data.
        /// </param>
        /// <param name = "reliability">
        ///   The reliability.
        /// </param>
        /// <param name = "channelId">
        ///   The channel id.
        /// </param>
        /// <param name="messageContentType">The message content type.</param>
        /// <returns>
        ///   Always Ok.
        /// </returns>
        public SendResults Send(byte[] data, MessageReliablity reliability, byte channelId, MessageContentType messageContentType)
        {
            RtsMessageHeader messageType;
            if (this.Protocol.TryParseMessageHeader(data, out messageType) == false)
            {
                throw new InvalidOperationException();
            }

            switch (messageType.MessageType)
            {
                case RtsMessageType.Event:
                    {
                        EventData eventData;
                        if (this.Protocol.TryParseEventData(data, out eventData))
                        {
                            this.fiber.Enqueue(
                                () =>
                                    {
                                        lock (this.syncRootEvents)
                                        {
                                            this.eventList.Add(eventData);

                                            if (log.IsDebugEnabled)
                                            {
                                                log.DebugFormat(
                                                    "{0} receives event, {1} total - code {2}", this.SessionId, this.eventList.Count, eventData.Code);
                                            }
                                        }

                                        this.resetEvent.Set();
                                    });
                        }
                        else
                        {
                            throw new InvalidOperationException();
                        }

                        break;
                    }

                case RtsMessageType.OperationResponse:
                    {
                        OperationResponse operationResponse;
                        if (this.Protocol.TryParseOperationResponse(data, out operationResponse))
                        {
                            this.fiber.Enqueue(
                                () =>
                                    {
                                        lock (this.syncRootResponse)
                                        {
                                            this.responseList.Add(operationResponse);

                                            if (log.IsDebugEnabled)
                                            {
                                                log.DebugFormat(
                                                    "{0} receives response, {1} total - code {2}",
                                                    this.SessionId,
                                                    this.responseList.Count,
                                                    operationResponse.OperationCode);
                                            }
                                        }

                                        this.resetResponse.Set();
                                    });
                        }
                        else
                        {
                            throw new InvalidOperationException();
                        }

                        break;
                    }
            }

            return SendResults.SentOk;
        }
Ejemplo n.º 37
0
 /*
 public SQLMessageInputPort(string connectionString, string tableName, string queueId, MessageContentType contentType)
 {
     _tableName = tableName;
     _queueId = queueId;
     _connStr = connectionString;
     _queueName = string.Format("sql://{0}/{1}", _tableName, _queueId);
     _serializationType = contentType;
 }
 */
 public SQLMessageInputPort(string queueName, MessageContentType contentType)
 {
     if (!SQLQueueProcessor.ParseQueueName(queueName, out _queueDb, out _tableName, out _queueId))
         throw new Exception("Invalid queue name: " + queueName);
     _queueName = queueName;
     _serializationType = contentType;
     //_connStr = Atmo.AtmoConfig.GetString(string.Format("Atmo.MessageBus.SQL.{0}.ConnectionString", _queueDb), "");
 }