Exemplo n.º 1
0
        /// <summary>
        /// Parses a message and creates the appropriate ISocialMessage type.
        /// </summary>
        /// <param name="messageBody">
        /// The ValueSet that contains all of the key-value pairs
        /// </param>
        /// <returns>An ISocialInfoMessage for the operation</returns>
        public static ISocialInfoMessage CreateSocialInfoMessage(ValueSet messageBody)
        {
            // Get the operation type to determine which type of message to create.
            UInt32 type = (UInt32)ParseField(messageBody, MessageBodyPayloadField.Type);

            // Get the version of the message
            UInt32 version = (UInt32)ParseField(messageBody, MessageBodyPayloadField.Version);

            // At this point, we have enough information to construct the specific message type.
            OperationType operationType = (OperationType)(type);

            ISocialInfoMessage message = null;

            switch (operationType)
            {
            case OperationType.GoodBye:
                message = new GoodByeMessage(version);
                break;

            case OperationType.DownloadContactFeed:
            case OperationType.DownloadDashboardFeed:
            case OperationType.DownloadHomeFeed:
                message = ParseDownloadFeedMessage(version, operationType, messageBody);
                break;

            case OperationType.GetNext:
                message = new GetNextOperationMessage(version);
                break;

            case OperationType.OperationResult:
                message = ParseOperationResultMessage(version, messageBody);
                break;

            default:
                throw new ArgumentException("The operation type is not valid.");
            }

            return(message);
        }
        /// <summary>
        /// Parses a message and creates the appropriate ISocialMessage type.
        /// </summary>
        /// <param name="messageBody">
        /// The ValueSet that contains all of the key-value pairs
        /// </param>
        /// <returns>An ISocialInfoMessage for the operation</returns>
        public static ISocialInfoMessage CreateSocialInfoMessage(ValueSet messageBody)
        {
            // Get the operation type to determine which type of message to create.
            UInt32 type = (UInt32)ParseField(messageBody, MessageBodyPayloadField.Type);

            // Get the version of the message
            UInt32 version = (UInt32)ParseField(messageBody, MessageBodyPayloadField.Version);

            // At this point, we have enough information to construct the specific message type.
            OperationType operationType = (OperationType)(type);

            ISocialInfoMessage message = null;
            switch (operationType)
            {
                case OperationType.GoodBye:
                    message = new GoodByeMessage(version);
                    break;

                case OperationType.DownloadContactFeed:
                case OperationType.DownloadDashboardFeed:
                case OperationType.DownloadHomeFeed:
                    message = ParseDownloadFeedMessage(version, operationType, messageBody);
                    break;

                case OperationType.GetNext:
                    message = new GetNextOperationMessage(version);
                    break;

                case OperationType.OperationResult:
                    message = ParseOperationResultMessage(version, messageBody);
                    break;

                default:
                    throw new ArgumentException("The operation type is not valid.");
            }

            return message;
        }