Esempio n. 1
0
        /// <summary>
        /// Sends the passed in data as the passed in message type and closes the socket.
        /// </summary>
        /// <param name="messageType"></param>
        /// <param name="data"></param>
        public void WriteAndClose(MessageType messageType, byte[] data = null)
        {
            //make sure we have a real message type
            if (messageType == null) {
                throw new ArgumentNullException("messageType");
            }

            //get the message type in bytes
            byte[] messageTypeEncoded = ASCIIEncoding.ASCII.GetBytes(messageType);

            //combine the messagetype and data byte arrays
            List<byte> output = new List<byte>();
            output.AddRange(messageTypeEncoded);
            if (data != null) {
                output.AddRange(data);
            }

            //send the data
            write(output.ToArray());

            //close the socket
            CloseSocket();
        }
Esempio n. 2
0
 /// <summary>
 /// The static constructor for the MessageType enum.
 /// </summary>
 static MessageType()
 {
     UNKOWN = new MessageType("99999999");
     CONNECT = new MessageType("00000001");
     CONNECTION_ACCEPTED = new MessageType("00000002");
     CONNECTION_EXISTS = new MessageType("00000003");
     ASSEMBLY_TRANSFER_MASTER = new MessageType("10000000");
     ASSEMBLY_TRANSFER_SLAVE = new MessageType("10000001");
     ASSEMBLY_TRANSFER_COMPLETE = new MessageType("10000002");
     DOMAIN_UNLOAD = new MessageType("10000003");
     MISSING_ASSEMBLY = new MessageType("20000000");
     EXECUTION_BEGIN = new MessageType("20000001");
     EXECUTION_COMPLETE = new MessageType("20000002");
     EXECUTION_DENIED = new MessageType("20000003");
     VERIFY = new MessageType("30000001");
     VERIFICATION_RESPONSE = new MessageType("30000002");
     STATUS_TERMINAL = new MessageType("30000003");
     USER_MESSAGE = new MessageType("40000001");
 }
Esempio n. 3
0
 /// <summary>
 /// Write data to the socket stream according to the passed in Message Type and String message
 /// </summary>
 /// <param name="mType">The message type  of the message.</param>
 /// <param name="message">The message as a string.</param>
 public void Write(MessageType mType, string message = null)
 {
     if (message != null) {
         byte[] bytes = ASCIIEncoding.ASCII.GetBytes(message);
         Write(mType, bytes);
     } else {
         Write(mType, new byte[0]);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Write data to the socket stream according to the passed in message type and byte data array
        /// </summary>
        /// <param name="mType">The message type of the message.</param>
        /// <param name="data">The byte array of the message.</param>
        public void Write(MessageType mType, byte[] data)
        {
            //get the message type in bytes
            byte[] messageTypeEncoded = ASCIIEncoding.ASCII.GetBytes(mType);

            //combine the messagetype and data byte arrays
            List<byte> output = new List<byte>();
            output.AddRange(messageTypeEncoded);
            if (data != null && data.Length != 0) {
                output.AddRange(data);
            }

            //Write the output
            write(output.ToArray());
        }
Esempio n. 5
0
 /// <summary>
 /// Sets a dispatch action to the dispatch list and triggers that action according to the message type.
 /// </summary>
 /// <param name="messageType">The message type from the Presto.Common.Net.MessageType struct.</param>
 /// <param name="dispatchAction">An Action that recieves a server state object as its only parameter.</param>
 public void RegisterDispatchAction(MessageType messageType, Action<ServerState> dispatchAction)
 {
     dispatchList[messageType] = dispatchAction;
 }