/// <summary>
        /// Factory method creates and new, unique message number.
        /// </summary>
        /// <returns>A new message number</returns>
        public static MessageNumber Create()
        {
            MessageNumber result = new MessageNumber();

            result.ProcessId = LocalProcessId;
            result.SeqNumber = GetNextSeqNumber();
            return(result);
        }
        /// <summary>
        /// Factory method that creates and message number from an existing
        /// processId and seqNumber.  This will be used for testing.
        /// </summary>
        /// <param name="processId">process Id to use in the message number</param>
        /// <param name="seqNumber">sequece number to use in the message number</param>
        /// <returns>A new message number</returns>
        public static MessageNumber Create(Int16 processId, Int16 seqNumber)
        {
            MessageNumber result = new MessageNumber();

            result.ProcessId = processId;
            result.SeqNumber = seqNumber;
            return(result);
        }
        /// <summary>
        /// Factory Method that creates a message from a byte string
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        new public static MessageNumber Create(ByteList bytes)
        {
            MessageNumber result = null;

            if (bytes == null || bytes.RemainingToRead < MinimumEncodingLength)
            {
                throw new ApplicationException("Invalid message byte array");
            }
            else if (bytes.PeekInt16() != ClassId)
            {
                throw new ApplicationException("Invalid message class id");
            }
            else
            {
                result = new MessageNumber();
                result.Decode(bytes);
            }
            return(result);
        }
        public static int Compare(MessageNumber a, MessageNumber b)
        {
            int result = 0;

            if (!System.Object.ReferenceEquals(a, b))
            {
                if (((object)a == null) && ((object)b != null))
                {
                    result = -1;
                }
                else if (((object)a != null) && ((object)b == null))
                {
                    result = 1;
                }
                else
                {
                    if (a.ProcessId < b.ProcessId)
                    {
                        result = -1;
                    }
                    else if (a.ProcessId > b.ProcessId)
                    {
                        result = 1;
                    }
                    else if (a.SeqNumber < b.SeqNumber)
                    {
                        result = -1;
                    }
                    else if (a.SeqNumber > b.SeqNumber)
                    {
                        result = 1;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        public static DistributableObject Create(ByteList bytes)
        {
            DistributableObject result = null;

            if (bytes == null || bytes.RemainingToRead < 4)
            {
                throw new ApplicationException("Invalid byte array");
            }

            DISTRIBUTABLE_CLASS_IDS objType = (DISTRIBUTABLE_CLASS_IDS)bytes.PeekInt16();

            switch (objType)
            {
            case DISTRIBUTABLE_CLASS_IDS.MessageNumber:
                result = MessageNumber.Create(bytes);
                break;

            case DISTRIBUTABLE_CLASS_IDS.Bomb:
                result = Bomb.Create(bytes);
                break;

            case DISTRIBUTABLE_CLASS_IDS.AgentInfo:
                result = AgentInfo.Create(bytes);
                break;

            case DISTRIBUTABLE_CLASS_IDS.AgentList:
                result = AgentList.Create(bytes);
                break;

            case DISTRIBUTABLE_CLASS_IDS.EndPoint:
                result = EndPoint.Create(bytes);
                break;

            case DISTRIBUTABLE_CLASS_IDS.Excuse:
                result = Excuse.Create(bytes);
                break;

            case DISTRIBUTABLE_CLASS_IDS.FieldLocation:
                result = FieldLocation.Create(bytes);
                break;

            case DISTRIBUTABLE_CLASS_IDS.GameConfiguration:
                result = GameConfiguration.Create(bytes);
                break;

            case DISTRIBUTABLE_CLASS_IDS.PlayingFieldLayout:
                result = PlayingFieldLayout.Create(bytes);
                break;

            case DISTRIBUTABLE_CLASS_IDS.Tick:
                result = Tick.Create(bytes);
                break;

            case DISTRIBUTABLE_CLASS_IDS.WhiningTwine:
                result = WhiningTwine.Create(bytes);
                break;

            default:
                throw new ApplicationException(string.Format("Invalid Class Id={0}", objType));
            }
            return(result);
        }
        public static int Compare(MessageNumber a, MessageNumber b)
        {
            int result = 0;

            if (!System.Object.ReferenceEquals(a, b))
            {
                if (((object)a == null) && ((object)b != null))
                    result = -1;
                else if (((object)a != null) && ((object)b == null))
                    result = 1;
                else
                {
                    if (a.ProcessId < b.ProcessId)
                        result = -1;
                    else if (a.ProcessId > b.ProcessId)
                        result = 1;
                    else if (a.SeqNumber < b.SeqNumber)
                        result = -1;
                    else if (a.SeqNumber > b.SeqNumber)
                        result = 1;
                }
            }
            return result;
        }
 /// <summary>
 /// Factory method that creates and message number from an existing
 /// processId and seqNumber.  This will be used for testing.
 /// </summary>
 /// <param name="processId">process Id to use in the message number</param>
 /// <param name="seqNumber">sequece number to use in the message number</param>
 /// <returns>A new message number</returns>
 public static MessageNumber Create(Int16 processId, Int16 seqNumber)
 {
     MessageNumber result = new MessageNumber();
     result.ProcessId = processId;
     result.SeqNumber = seqNumber;
     return result;
 }
 /// <summary>
 /// Factory Method that creates a message from a byte string
 /// </summary>
 /// <param name="bytes"></param>
 /// <returns></returns>
 public static new MessageNumber Create(ByteList bytes)
 {
     MessageNumber result = null;
     if (bytes == null || bytes.RemainingToRead < MinimumEncodingLength)
         throw new ApplicationException("Invalid message byte array");
     else if (bytes.PeekInt16() != ClassId)
         throw new ApplicationException("Invalid message class id");
     else
     {
         result = new MessageNumber();
         result.Decode(bytes);
     }
     return result;
 }
 /// <summary>
 /// Factory method creates and new, unique message number.
 /// </summary>
 /// <returns>A new message number</returns>
 public static MessageNumber Create()
 {
     MessageNumber result = new MessageNumber();
     result.ProcessId = LocalProcessId;
     result.SeqNumber = GetNextSeqNumber();
     return result;
 }