Пример #1
0
 public Message ToMessage()
 {
     Message msg = new Message();
     msg.Type = MessageType.Execute;
     using (MemoryStream mem = new MemoryStream())
     {
         using (BinaryWriter writer = new BinaryWriter(mem))
         {
             writer.Write(Command);
             writer.Write(ArgumentCount);
             foreach (var arg in Arguments)
             {
                 writer.Write(arg);
             }
             writer.Write(MemoryLimit);
             writer.Write(OutputLimit);
             writer.Write(TimeLimit);
             writer.Write((int)Restriction);
             writer.Write(InputBlob);
         }
         msg.Body = mem.ToArray();
     }
     msg.Size = msg.Body.Length;
     return msg;
 }
Пример #2
0
 public Message Receive(MessageType expectedType)
 {
     Message msg = new Message(reader);
     if (msg.Type != expectedType)
     {
         throw new Exception("收到的消息类型不匹配");
     }
     return msg;
 }
Пример #3
0
 public Message ToMessage()
 {
     Message msg = new Message();
     msg.Type = MessageType.GetBlob;
     using (MemoryStream mem = new MemoryStream())
     {
         using (BinaryWriter writer = new BinaryWriter(mem))
         {
             writer.Write(Name);
         }
         msg.Body = mem.ToArray();
     }
     msg.Size = msg.Body.Length;
     return msg;
 }
Пример #4
0
 internal ExecuteResult(Message msg)
 {
     using (MemoryStream mem = new MemoryStream(msg.Body))
     {
         using (BinaryReader reader = new BinaryReader(mem))
         {
             ExitStatus = reader.ReadInt32();
             Type = (ExecuteResultType)reader.ReadInt32();
             OutputBlob = reader.ReadString();
             ErrorBlob = reader.ReadString();
             Memory = reader.ReadInt64();
             UserTime = reader.ReadInt32();
             RealTime = reader.ReadInt32();
         }
     }
 }
Пример #5
0
 public void Send(Message msg)
 {
     msg.Send(writer);
 }
Пример #6
0
        /// <summary>
        /// 判断某File是否存在
        /// </summary>
        public bool HasFile(string name)
        {
            using (MemoryStream mem = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(mem))
                {
                    bw.Write(name);
                }
                Message msg = new Message
                {
                    Type = MessageType.HasFile,
                    Body = mem.ToArray()
                };
                msg.Size = msg.Body.Length;
                session.Send(msg);

                Message reply = session.Receive(MessageType.HasFileReply);
                return BitConverter.ToInt32(reply.Body, 0) == 1;
            }
        }