Example #1
0
        public static byte[] ToByteArray(this ICommand cmd)
        {
            var builder = new CommandBuilder(CommandManager.FindNameForType(cmd));

            cmd.Serialize(builder);
            return(builder.ToByteArray());
        }
Example #2
0
        public static void WriteCommand(this IPCWriter writer, ICommand command)
        {
            CommandType type;

            switch (command)
            {
            case Execute _: type = CommandType.Execute; break;

            case FetchMetadata _: type = CommandType.FetchMetadata; break;

            case FetchResultRange _: type = CommandType.FetchResultRange; break;

            case Deploy _: type = CommandType.Deploy; break;

            case ListEnvironmentVariables _: type = CommandType.ListEnvironmentVariables; break;

            case PutFileCommand _: type = CommandType.PutFile; break;

            case PutDirectoryCommand _: type = CommandType.PutDirectory; break;

            case ListFilesCommand _: type = CommandType.ListFiles; break;

            case GetFilesCommand _: type = CommandType.GetFiles; break;

            case GetServerCapabilitiesCommand _: type = CommandType.GetServerCapabilities; break;

            case ExecutionTimedOutActionCommand _: type = CommandType.ExecutionTimedOutAction; break;

            case CompressedCommand _: type = CommandType.CompressedCommand; break;

            default: throw new ArgumentException($"Unable to serialize {command.GetType()}");
            }
            writer.Write((byte)type);
            command.Serialize(writer);
        }
Example #3
0
        public static CommandRequest ToCommandRequest(this ICommand b)
        {
            if (b.GenericPreconditions.Count > 6)
            {
                throw new Exception("Unable to serialize CommandRequest, the maximum number of preconditions supported are 6");
            }
            CommandRequest c = new CommandRequest();

            c.Id                 = b.Id;
            c.Class              = b.GetType().ToString();
            c.Type               = b.WorkType;
            c.ParallelMax        = b.ParallelMax;
            c.ParallelTag        = b.ParallelTag;
            c.Priority           = b.Priority;
            c.Retries            = b.Retries;
            c.Batch              = b.Batch;
            c.Data               = b.Serialize();
            c.RetryFutureSeconds = b.RetryFutureInSeconds;
            c.PreconditionClass1 = SerializePrecondition(b, 0);
            c.PreconditionClass2 = SerializePrecondition(b, 1);
            c.PreconditionClass3 = SerializePrecondition(b, 2);
            c.PreconditionClass4 = SerializePrecondition(b, 3);
            c.PreconditionClass5 = SerializePrecondition(b, 4);
            c.PreconditionClass6 = SerializePrecondition(b, 5);
            return(c);
        }
Example #4
0
        public static byte[] Transform(ICommand cmd)
        {
            List <byte> result = new List <byte>();

            result.Add((byte)cmd.Command);
            result.AddRange(cmd.Serialize());
            return(result.ToArray());
        }
Example #5
0
        public void Send(ICommand command)
        {
            _socket.SendTo(command.Serialize(), _serverEndPoint);

            if (_debugLog != null)
            {
                var commandBase = (CommandBase)command;
                _debugLog.WriteLine("Send " + commandBase.GetType().Name + "   Token: " + commandBase.Token);
            }
        }
Example #6
0
        public static byte[] ToByteArray(this ICommand cmd)
        {
            Tuple <string, ProtocolVersion> nameInfo = CommandManager.FindNameAndVersionForType(cmd);

            if (nameInfo == null)
            {
                throw new Exception($"Missing CommandNameAttribute on type: {cmd.GetType().Name}");
            }

            var builder = new CommandBuilder(nameInfo.Item1);

            cmd.Serialize(builder);
            return(builder.ToByteArray());
        }
Example #7
0
 public void Send(ICommand cmd)
 {
     var buffer = cmd.Serialize(bufferManager);
     client.Send(buffer);
 }
Example #8
0
 public SerializedCommand Serialize(ICommand command)
 {
     return(command.Serialize(Serializer, command.AggregateIdentifier, command.ExpectedVersion));
 }
Example #9
0
 public void Send(IPEndPoint endPoint, ICommand command)
 {
     var data = command.Serialize();
     _server.SendAsync(data, data.Length, endPoint);
 }