Example #1
0
        /// <summary>
        /// Creates a message object.
        /// </summary>
        /// <param name="Command">The message command.</param>
        /// <param name="MessageID">The message ID.</param>
        /// <param name="TTL">The time to live.</param>
        /// <param name="Encryption">Indicates if the message is encrypted or not.</param>
        /// <param name="Parameters">The list of the parameters.</param>
        /// <param name="BinaryPart">The binary part.</param>
        /// <returns>The message object.</returns>
        public IMessage CreateMessage(Commands Command, string MessageID, int TTL, bool Encryption, string[] Parameters, byte[] BinaryPart)
        {
            IMessage imsgReturn = null;

            #region switch (Command)

            switch (Command)
            {
                case Commands.FS:
                    {
                        if (MessageID == string.Empty)
                        {
                            imsgReturn = new FileSearch(TTL, Encryption, Parameters);
                        }
                        else
                        {
                            imsgReturn = new FileSearch(MessageID, TTL, Encryption, Parameters);
                        }
                        break;
                    }
                case Commands.FF:
                    {
                        if (MessageID == string.Empty)
                        {
                            imsgReturn = new FileFound(TTL, Encryption, Parameters);
                        }
                        else
                        {
                            imsgReturn = new FileFound(MessageID, TTL, Encryption, Parameters);
                        }
                        break;
                    }
                case Commands.FPR:
                    {
                        if (MessageID == string.Empty)
                        {
                            imsgReturn = new FilePackRequest(TTL, Encryption, Parameters);
                        }
                        else
                        {
                            imsgReturn = new FilePackRequest(MessageID, TTL, Encryption, Parameters);
                        }
                        break;
                    }
                case Commands.FP:
                    {
                        if (MessageID == string.Empty)
                        {
                            imsgReturn = new FilePack(TTL, Encryption, Parameters, BinaryPart);
                        }
                        else
                        {
                            imsgReturn = new FilePack(MessageID, TTL, Encryption, Parameters, BinaryPart);
                        }
                        break;
                    }
                case Commands.PI:
                    {
                        if (MessageID == string.Empty)
                        {
                            imsgReturn = new Ping(TTL, Encryption, Parameters);
                        }
                        else
                        {
                            imsgReturn = new Ping(MessageID, TTL, Encryption, Parameters);
                        }
                        break;
                    }
                case Commands.PO:
                    {
                        if (MessageID == string.Empty)
                        {
                            imsgReturn = new Pong(TTL, Encryption, Parameters);
                        }
                        else
                        {
                            imsgReturn = new Pong(MessageID, TTL, Encryption, Parameters);
                        }
                        break;
                    }
                case Commands.XLR:
                    {
                        if (MessageID == string.Empty)
                        {
                            imsgReturn = new XmlListRequest(TTL, Encryption, Parameters);
                        }
                        else
                        {
                            imsgReturn = new XmlListRequest(MessageID, TTL, Encryption, Parameters);
                        }
                        break;
                    }
                case Commands.XL:
                    {
                        if (MessageID == string.Empty)
                        {
                            imsgReturn = new XmlList(TTL, Encryption, Parameters, BinaryPart);
                        }
                        else
                        {
                            imsgReturn = new XmlList(MessageID, TTL, Encryption, Parameters, BinaryPart);
                        }
                        break;
                    }
                case Commands.EI:
                    {
                        if (MessageID == string.Empty)
                        {
                            imsgReturn = new EncryptionInfo(TTL, Encryption, Parameters);
                        }
                        else
                        {
                            imsgReturn = new EncryptionInfo(MessageID, TTL, Encryption, Parameters);
                        }
                        break;
                    }
                case Commands.EK:
                    {
                        if (MessageID == string.Empty)
                        {
                            imsgReturn = new EncryptionKey(TTL, Encryption, Parameters);
                        }
                        else
                        {
                            imsgReturn = new EncryptionKey(MessageID, TTL, Encryption, Parameters);
                        }
                        break;
                    }
                default:
                    {
                        break;
                    }
            }

            #endregion

            return imsgReturn;
        }
Example #2
0
        /// <summary>
        /// Creates a message object.
        /// </summary>
        /// <param name="Command">The message command.</param>
        /// <param name="MessageID">The message ID.</param>
        /// <param name="TTL">The time to live.</param>
        /// <param name="Encryption">Indicates if the message is encrypted or not.</param>
        /// <param name="Parameters">The list of the parameters.</param>
        /// <param name="BinaryPart">The binary part.</param>
        /// <returns>The message object.</returns>
        public IMessage CreateMessage(Commands Command, string MessageID, int TTL, bool Encryption, string[] Parameters, byte[] BinaryPart)
        {
            IMessage imsgReturn = null;

            #region switch (Command)

            switch (Command)
            {
            case Commands.FS:
            {
                if (MessageID == string.Empty)
                {
                    imsgReturn = new FileSearch(TTL, Encryption, Parameters);
                }
                else
                {
                    imsgReturn = new FileSearch(MessageID, TTL, Encryption, Parameters);
                }
                break;
            }

            case Commands.FF:
            {
                if (MessageID == string.Empty)
                {
                    imsgReturn = new FileFound(TTL, Encryption, Parameters);
                }
                else
                {
                    imsgReturn = new FileFound(MessageID, TTL, Encryption, Parameters);
                }
                break;
            }

            case Commands.FPR:
            {
                if (MessageID == string.Empty)
                {
                    imsgReturn = new FilePackRequest(TTL, Encryption, Parameters);
                }
                else
                {
                    imsgReturn = new FilePackRequest(MessageID, TTL, Encryption, Parameters);
                }
                break;
            }

            case Commands.FP:
            {
                if (MessageID == string.Empty)
                {
                    imsgReturn = new FilePack(TTL, Encryption, Parameters, BinaryPart);
                }
                else
                {
                    imsgReturn = new FilePack(MessageID, TTL, Encryption, Parameters, BinaryPart);
                }
                break;
            }

            case Commands.PI:
            {
                if (MessageID == string.Empty)
                {
                    imsgReturn = new Ping(TTL, Encryption, Parameters);
                }
                else
                {
                    imsgReturn = new Ping(MessageID, TTL, Encryption, Parameters);
                }
                break;
            }

            case Commands.PO:
            {
                if (MessageID == string.Empty)
                {
                    imsgReturn = new Pong(TTL, Encryption, Parameters);
                }
                else
                {
                    imsgReturn = new Pong(MessageID, TTL, Encryption, Parameters);
                }
                break;
            }

            case Commands.XLR:
            {
                if (MessageID == string.Empty)
                {
                    imsgReturn = new XmlListRequest(TTL, Encryption, Parameters);
                }
                else
                {
                    imsgReturn = new XmlListRequest(MessageID, TTL, Encryption, Parameters);
                }
                break;
            }

            case Commands.XL:
            {
                if (MessageID == string.Empty)
                {
                    imsgReturn = new XmlList(TTL, Encryption, Parameters, BinaryPart);
                }
                else
                {
                    imsgReturn = new XmlList(MessageID, TTL, Encryption, Parameters, BinaryPart);
                }
                break;
            }

            case Commands.EI:
            {
                if (MessageID == string.Empty)
                {
                    imsgReturn = new EncryptionInfo(TTL, Encryption, Parameters);
                }
                else
                {
                    imsgReturn = new EncryptionInfo(MessageID, TTL, Encryption, Parameters);
                }
                break;
            }

            case Commands.EK:
            {
                if (MessageID == string.Empty)
                {
                    imsgReturn = new EncryptionKey(TTL, Encryption, Parameters);
                }
                else
                {
                    imsgReturn = new EncryptionKey(MessageID, TTL, Encryption, Parameters);
                }
                break;
            }

            default:
            {
                break;
            }
            }

            #endregion

            return(imsgReturn);
        }