Microsoft.Protocols.TestTools.StackSdk.BranchCache.Pchc.PCHCClient.CreateInitialOfferMessage C# (CSharp) Method

CreateInitialOfferMessage() public method

Create INITIAL_OFFER_MESSAGE package.
public CreateInitialOfferMessage ( int connectionInfoPort, byte hash ) : INITIAL_OFFER_MESSAGE
connectionInfoPort int /// A 16-bit unsigned integer that MUST be set by the client to the port /// on which it is listening as a server-role peer, for use with the retrieval protocol. ///
hash byte The HoHoDk value of the segment.
return INITIAL_OFFER_MESSAGE
        public INITIAL_OFFER_MESSAGE CreateInitialOfferMessage(
            int connectionInfoPort,
            byte[] hash)
        {
            if (hash == null)
            {
                if (this.logger != null)
                {
                    this.logger.AddWarning("Please specify the Segment ID under test to the param \"hash\".");
                }

                throw new ArgumentNullException("hash", "Please specify the Segment ID under test to the param \"hash\".");
            }

            MESSAGE_HEADER header;

            // MajorVersion (1 byte):  The major part of the version, which MUST be 0x01.
            // MinorVersion (1 byte):  The minor part of the version, which MUST be 0x00.
            // Padding (4 bytes):  The value of this field is indeterminate and MUST be ignored on processing
            header.MajorVersion = 1;
            header.MinorVersion = 0;
            header.Padding = new byte[4];
            header.MsgType = PCHC_MESSAGE_TYPE.INITIAL_OFFER_MESSAGE;

            CONNECTION_INFORMATION connectionInfo;

            // Padding (6 bytes):  The value of this field is indeterminated and MUST be ignored on processing.
            // Port (2 bytes): A 16-bit unsigned integer that MUST be set by the client to the port on
            // which it is listening as a server-role peer, for use with the retrieval protocol.
            connectionInfo.Port = (ushort)connectionInfoPort;
            connectionInfo.Padding = new byte[6];

            INITIAL_OFFER_MESSAGE initialOfferMessage;

            initialOfferMessage.MsgHeader = header;
            initialOfferMessage.Hash = hash;
            initialOfferMessage.ConnectionInfo = connectionInfo;

            return initialOfferMessage;
        }

Usage Example

        public void HostedCacheServer_PchcServer_MessageHeader_TypeInvalid()
        {
            CheckApplicability();

            PCHCClient pchcClient = new PCHCClient(
                    TransferProtocol.HTTPS,
                    testConfig.HostedCacheServerComputerName,
                    testConfig.HostedCacheServerHTTPSListenPort,
                    PchcConsts.HttpsUrl,
                    testConfig.DomainName,
                    testConfig.UserName,
                    testConfig.UserPassword);

            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Send message with invalid message type to hosted cache server");

            var initialOffer = pchcClient.CreateInitialOfferMessage(
                testConfig.ClientContentRetrievalListenPort,
                new byte[0]);

            initialOffer.MsgHeader.MsgType = (PCHC_MESSAGE_TYPE)0xFEFE;

            bool passed = false;
            try
            {
                pchcClient.SendInitialOfferMessage(initialOffer);
            }
            catch
            {
                passed = true;
            }

            BaseTestSite.Assert.IsTrue(passed, "Hosted cache server should drop message with invalid message type");
        }
All Usage Examples Of Microsoft.Protocols.TestTools.StackSdk.BranchCache.Pchc.PCHCClient::CreateInitialOfferMessage