Esempio n. 1
0
        public static Command Create(CommandType type, string[] parameters, CommandRequest commandRequest)
        {
            Command command = null;

            switch (type)
            {
            case CommandType.CreateEvent:
                command = new CreateEventCommand(parameters, commandRequest);
                break;

            case CommandType.SubscribeToEvent:
                command = new SubscribeToEventCommand(parameters, commandRequest);
                break;

            case CommandType.Split:
                command = new SplitFixCommand(parameters, commandRequest, CommandType.Split);
                break;

            case CommandType.Fix:
                command = new SplitFixCommand(parameters, commandRequest, CommandType.Fix);
                break;

            case CommandType.PayFor:
                command = new PayForCommand(parameters, commandRequest);
                break;

            case CommandType.AddReminder:
                command = new AddReminderCommand(parameters, commandRequest);
                break;
            }

            return(command);
        }
Esempio n. 2
0
        public Message Deserialize(byte[] bytes)
        {
            using (var stream = new MemoryStream(bytes))
            {
                switch (stream.ReadByte())
                {
                case 1:
                    var createObjectOfTypeCommand = new CreateObjectOfTypeCommand(stream.ReadInt());
                    createObjectOfTypeCommand.AssemblyPath = stream.ReadString();
                    createObjectOfTypeCommand.TypeFullName = stream.ReadString();
                    return(createObjectOfTypeCommand);

                case 2:
                    var invokeCommand = new EventInvokeCommand(stream.ReadInt());
                    invokeCommand.EventName = stream.ReadString();
                    invokeCommand.Arguments = ( object[] )stream.ReadObject(_formatter);
                    return(invokeCommand);

                case 3:
                    var methodCallCommand = new MethodCallCommand(stream.ReadInt());
                    methodCallCommand.MethodName = stream.ReadString();
                    methodCallCommand.MethodId   = stream.ReadString();
                    methodCallCommand.Arguments  = ( object[] )stream.ReadObject(_formatter);
                    return(methodCallCommand);

                case 4:
                    var methodCallResultAnswer = new MethodCallResultAnswer(stream.ReadInt());
                    methodCallResultAnswer.AnswerTo  = stream.ReadInt();
                    methodCallResultAnswer.Result    = stream.ReadObject(_formatter);
                    methodCallResultAnswer.Exception = ( Exception )stream.ReadObject(_formatter);
                    return(methodCallResultAnswer);

                case 5:
                    var subscribeToEventCommand = new SubscribeToEventCommand(stream.ReadInt());
                    subscribeToEventCommand.EventName = stream.ReadString();
                    return(subscribeToEventCommand);

                case 6:
                    return(new UnexpectedExceptionMessage(stream.ReadInt())
                    {
                        Exception = ( Exception )stream.ReadObject(_formatter)
                    });

                case 7:
                    return(new UnsubscribeFromEventCommand(stream.ReadInt())
                    {
                        EventName = stream.ReadString()
                    });

                default:
                    throw new NotImplementedException();
                }
            }
        }