示例#1
0
        public override ITargettedMessageSet <IBlockchainEventsRehydrationFactory> RehydrateMessage(IByteArray data, TargettedHeader header, IBlockchainEventsRehydrationFactory rehydrationFactory)
        {
            IDataRehydrator dr = DataSerializationFactory.CreateRehydrator(data);

            IByteArray messageBytes = NetworkMessageSet.ExtractMessageBytes(dr);

            NetworkMessageSet.ResetAfterHeader(dr);
            IDataRehydrator messageRehydrator = DataSerializationFactory.CreateRehydrator(messageBytes);

            IBlockchainTargettedMessageSet messageSet = null;

            try {
                if (data?.Length == 0)
                {
                    throw new ApplicationException("null message");
                }

                short workflowType = 0;
                ComponentVersion <SimpleUShort> version = null;

                messageRehydrator.Peek(rehydrator => {
                    workflowType = rehydrator.ReadShort();

                    if (workflowType != NeuraliumWorkflowIDs.TEST)
                    {
                        throw new ApplicationException("Invalid workflow type");
                    }

                    version = rehydrator.Rehydrate <ComponentVersion <SimpleUShort> >();
                });

                switch (version.Type.Value)
                {
                case MESS1:

                    if (version == (1, 0))
                    {
                        messageSet = this.CreateTestWorkflowTriggerSet(header);
                    }

                    break;

                case MESS2:

                    if (version == (1, 0))
                    {
                        messageSet = this.CreateServerAnswerSet(header);
                    }

                    break;

                default:

                    throw new ApplicationException("invalid message type");
                }

                if (messageSet?.BaseMessage == null)
                {
                    throw new ApplicationException("Invalid message type or version");
                }

                messageSet.BaseHeader = header;                 // set the header explicitely
                messageSet.RehydrateRest(dr, rehydrationFactory);
            } catch (Exception ex) {
                Log.Error(ex, "Invalid data sent");
            }

            return(messageSet);
        }
示例#2
0
        private BlockchainTriggerMessageSet <TestTrigger> CreateTestWorkflowTriggerSet(TargettedHeader triggerHeader)
        {
            var messageSet = this.MainMessageFactory.CreateTriggerMessageSet <BlockchainTriggerMessageSet <TestTrigger>, TestTrigger>(triggerHeader);

            return(messageSet);
        }
示例#3
0
 public BlockchainTargettedMessageSet <ServerAnswer> CreateServerAnswerSet(TargettedHeader triggerHeader = null)
 {
     return(this.MainMessageFactory.CreateTargettedMessageSet <BlockchainTargettedMessageSet <ServerAnswer>, ServerAnswer>(triggerHeader));
 }
示例#4
0
        public override ITargettedMessageSet <IBlockchainEventsRehydrationFactory> RehydrateMessage(IByteArray data, TargettedHeader header, IBlockchainEventsRehydrationFactory rehydrationFactory)
        {
            IDataRehydrator dr = DataSerializationFactory.CreateRehydrator(data);

            IByteArray messageBytes = NetworkMessageSet.ExtractMessageBytes(dr);

            NetworkMessageSet.ResetAfterHeader(dr);
            IDataRehydrator messageRehydrator = DataSerializationFactory.CreateRehydrator(messageBytes);

            short workflowType = messageRehydrator.ReadShort();

            if (workflowType == 0)
            {
                throw new ApplicationException("Invalid workflow type");
            }

            switch (workflowType)
            {
            case NeuraliumWorkflowIDs.TEST:

                return(new TestFactory((BlockchainServiceSet)this.serviceSet).RehydrateMessage(data, header, rehydrationFactory));

                // default:
                //     throw new ApplicationException("Workflow message factory not found");
            }

            return(base.RehydrateMessage(data, header, rehydrationFactory));
        }