/// <summary>
        /// Gets the free/busy status appointment information for User2 (as specified in ptfconfig) through testUserName's account.
        /// </summary>
        /// <param name="testUserName">The user who gets the free/busy status information.</param>
        /// <param name="password">The testUserName's password.</param>
        /// <returns>
        /// <para>"0": means "FreeBusy", which indicates brief information about the appointments on the calendar;</para>
        /// <para>"1": means "Detailed", which indicates detailed information about the appointments on the calendar;</para>
        /// <para>"2": means the appointment free/busy information can't be viewed or error occurs, which indicates the user has no permission to get information about the appointments on the calendar;</para>
        /// </returns>
        public string GetUserFreeBusyStatus(string testUserName, string password)
        {
            // Use the specified user for the web service client authentication
            string domain = Common.GetConfigurationPropertyValue("Domain", this.Site);

            this.availability.Credentials = new NetworkCredential(testUserName, password, domain);

            GetUserAvailabilityRequestType availabilityRequest = new GetUserAvailabilityRequestType();

            SerializableTimeZone timezone = new SerializableTimeZone()
            {
                Bias         = 480,
                StandardTime = new SerializableTimeZoneTime()
                {
                    Bias = 0, Time = "02:00:00", DayOrder = 5, Month = 10, DayOfWeek = "Sunday"
                },
                DaylightTime = new SerializableTimeZoneTime()
                {
                    Bias = -60, Time = "02:00:00", DayOrder = 1, Month = 4, DayOfWeek = "Sunday"
                }
            };

            availabilityRequest.TimeZone = timezone;

            // Specifies the mailbox to query for availability information.
            string       user         = Common.GetConfigurationPropertyValue("User2Name", this.Site);
            EmailAddress emailAddress = new EmailAddress()
            {
                Address = string.IsNullOrEmpty(user) ? string.Empty : user + "@" + domain
            };

            MailboxData mailboxData = new MailboxData()
            {
                Email        = emailAddress,
                AttendeeType = MeetingAttendeeType.Organizer,
            };

            availabilityRequest.MailboxDataArray = new MailboxData[] { mailboxData };

            // Identify the time to compare free/busy information.
            FreeBusyViewOptionsType freeBusyViewOptions = new FreeBusyViewOptionsType()
            {
                TimeWindow = new Duration()
                {
                    StartTime = DateTime.Now, EndTime = DateTime.Now.AddHours(3)
                },
                RequestedView          = FreeBusyViewType.Detailed,
                RequestedViewSpecified = true
            };

            availabilityRequest.FreeBusyViewOptions = freeBusyViewOptions;

            GetUserAvailabilityResponseType availabilityInfo = null;

            try
            {
                availabilityInfo = this.availability.GetUserAvailability(availabilityRequest);
            }
            catch (SoapException exception)
            {
                Site.Assert.Fail("Error occurs when getting free/busy status: {0}", exception.Message);
            }

            string freeBusyStatus = "3";

            FreeBusyResponseType[] freeBusyArray = availabilityInfo.FreeBusyResponseArray;
            if (freeBusyArray != null)
            {
                foreach (FreeBusyResponseType freeBusy in freeBusyArray)
                {
                    ResponseClassType responseClass = freeBusy.ResponseMessage.ResponseClass;
                    if (responseClass == ResponseClassType.Success)
                    {
                        // If the response FreeBusyViewType value is FreeBusy or Detailed, the freeBusyStatus is Detailed.
                        // If all the response FreeBusyViewType values are FreeBusy, the freeBusyStatus is FreeBusy;
                        if (freeBusy.FreeBusyView.FreeBusyViewType == FreeBusyViewType.Detailed)
                        {
                            freeBusyStatus = "1";
                        }
                        else if (freeBusy.FreeBusyView.FreeBusyViewType == FreeBusyViewType.FreeBusy)
                        {
                            if (freeBusyStatus != "1")
                            {
                                freeBusyStatus = "0";
                            }
                        }
                    }
                    else if (responseClass == ResponseClassType.Error)
                    {
                        if (freeBusy.ResponseMessage.ResponseCode == ResponseCodeType.ErrorNoFreeBusyAccess)
                        {
                            return("2");
                        }
                        else
                        {
                            Site.Assert.Fail("Error occurs when getting free/busy status. ErrorCode: {0}; ErrorMessage: {1}.", freeBusy.ResponseMessage.ResponseCode, freeBusy.ResponseMessage.MessageText);
                        }
                    }
                }
            }

            return(freeBusyStatus);
        }
Example #2
0
        /// <summary>
        /// Construct a transport response based on the received SealedMessageType instance (from SMD, SIMD or SMR).
        /// </summary>
        /// <param name="sealedMessage">The SMD, SMR, SIMD or TRD SealedMessageType instance to create a transport response for.</param>
        /// <param name="sourceOrganisation">The organisation generating the response.</param>
        /// <param name="deliveryResponseClass">The type of response.</param>
        /// <param name="deliveryResponseCode">The response code.</param>
        /// <param name="deliveryResponseMessage">Message containing more details on the response.</param>
        /// <param name="transportResponseTime">The time of the response.</param>
        /// <param name="responseId">A unique ID to identify the response.</param>
        /// <param name="isFinal">A value to indicate if the transport response is the final response.</param>
        /// <param name="otherTransportMetadata">Additional metadata to be included.</param>
        /// <param name="payloadDecryptionCertificate">The certificate to decrypt the sealed message encrypted payload with (the digest value of the message is obtained from the decrypted payload).</param>
        /// <returns>The TransportResponseType instance.</returns>
        public static TransportResponseType GetTransportResponse(
            CommonSealedMessageType sealedMessage,
            string sourceOrganisation,
            ResponseClassType deliveryResponseClass,
            string deliveryResponseCode,
            string deliveryResponseMessage,
            DateTime transportResponseTime,
            string responseId,
            bool isFinal,
            List <OtherTransportMetadataEntryType> otherTransportMetadata,
            X509Certificate2 payloadDecryptionCertificate)
        {
            // Validate sealedMessage
            Validation.ValidateArgumentRequired("sealedMessage", sealedMessage);
            Validation.ValidateArgumentRequired("sealedMessage.EncryptedPayload", sealedMessage.EncryptedPayload);
            Validation.ValidateArgumentRequired("sealedMessage.InvocationId", sealedMessage.InvocationId);
            Validation.ValidateArgumentRequired("sealedMessage.ReceiverOrganisation", sealedMessage.ReceiverOrganisation);
            Validation.ValidateArgumentRequired("sealedMessage.SenderOrganisation", sealedMessage.SenderOrganisation);
            Validation.ValidateArgumentRequired("sealedMessage.ServiceCategory", sealedMessage.ServiceCategory);

            Validation.ValidateArgumentRequired("sourceOrganisation", sourceOrganisation);
            Validation.ValidateArgumentRequired("deliveryResponseCode", deliveryResponseCode);
            Validation.ValidateArgumentRequired("deliveryResponseMessage", deliveryResponseMessage);
            Validation.ValidateArgumentRequired("responseId", responseId);

            Validation.ValidateArgumentRequired("payloadDecryptionCertificate", payloadDecryptionCertificate);

            // deliveryResponseClass isn't validated as it is an enum and there is no option to omit it.

            TransportResponseType tr = new TransportResponseType();

            tr.deliveryResponse = new DeliveryResponseType();

            tr.deliveryResponse.responseClass = deliveryResponseClass;
            tr.deliveryResponse.responseCode  = deliveryResponseCode;
            tr.deliveryResponse.message       = deliveryResponseMessage;
            tr.final = isFinal;

            if (deliveryResponseClass == ResponseClassType.Success)
            {
                XmlDocument    encryptedPayload = sealedMessage.EncryptedPayload.SerializeToXml("encryptedPayload");
                XmlDocument    signedPayload    = encryptedPayload.XspDecrypt(payloadDecryptionCertificate);
                IList <byte[]> digestValues     = signedPayload.XspGetDigestValues();

                tr.deliveryResponse.digestValue = digestValues[0];
            }

            tr.metadata = new TransportResponseMetadataType();
            tr.metadata.transportResponseTime = transportResponseTime.ToUniversalTime();
            tr.metadata.responseId            = responseId;
            tr.metadata.sourceOrganisation    = sourceOrganisation;
            tr.metadata.serviceCategory       = sealedMessage.ServiceCategory;
            tr.metadata.invocationId          = sealedMessage.InvocationId;
            tr.metadata.receiverOrganisation  = sealedMessage.ReceiverOrganisation;
            tr.metadata.senderOrganisation    = sealedMessage.SenderOrganisation;

            if (otherTransportMetadata != null && otherTransportMetadata.Count > 0)
            {
                tr.metadata.otherTransportMetadata = otherTransportMetadata.ToArray();
            }

            return(tr);
        }