/// <summary>
        /// Converts the date time to universal date time string.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>String representation of DateTime.</returns>
        internal string ConvertDateTimeToUniversalDateTimeString(DateTime value)
        {
            DateTime dateTime;

            switch (value.Kind)
            {
            case DateTimeKind.Unspecified:
                dateTime = EwsUtilities.ConvertTime(
                    value,
                    this.TimeZone,
                    TimeZoneInfo.Utc);

                break;

            case DateTimeKind.Local:
                dateTime = EwsUtilities.ConvertTime(
                    value,
                    TimeZoneInfo.Local,
                    TimeZoneInfo.Utc);

                break;

            default:
                // The date is already in UTC, no need to convert it.
                dateTime = value;

                break;
            }
            return(dateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture));
        }
        /// <summary>
        /// Converts the universal date time string to local date time.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>DateTime</returns>
        internal DateTime?ConvertUniversalDateTimeStringToLocalDateTime(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }
            else
            {
                // Assume an unbiased date/time is in UTC. Convert to UTC otherwise.
                DateTime dateTime = DateTime.Parse(
                    value,
                    CultureInfo.InvariantCulture,
                    DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);

                if (this.TimeZone == TimeZoneInfo.Utc)
                {
                    // This returns a DateTime with Kind.Utc
                    return(dateTime);
                }
                else
                {
                    DateTime localTime = EwsUtilities.ConvertTime(
                        dateTime,
                        TimeZoneInfo.Utc,
                        this.TimeZone);

                    if (EwsUtilities.IsLocalTimeZone(this.TimeZone))
                    {
                        // This returns a DateTime with Kind.Local
                        return(new DateTime(localTime.Ticks, DateTimeKind.Local));
                    }
                    else
                    {
                        // This returns a DateTime with Kind.Unspecified
                        return(localTime);
                    }
                }
            }
        }
        /// <summary>
        /// Scopes the date time property to the appropriate time zone, if necessary.
        /// </summary>
        /// <param name="service">The service emitting the request.</param>
        /// <param name="dateTime">The date time.</param>
        /// <param name="propertyBag">The property bag.</param>
        /// <param name="isUpdateOperation">Indicates whether the scoping is to be performed in the context of an update operation.</param>
        /// <returns>The converted DateTime.</returns>
        internal virtual DateTime ScopeToTimeZone(
            ExchangeServiceBase service,
            DateTime dateTime,
            PropertyBag propertyBag,
            bool isUpdateOperation)
        {
            try
            {
                DateTime convertedDateTime = EwsUtilities.ConvertTime(
                    dateTime,
                    service.TimeZone,
                    TimeZoneInfo.Utc);

                return(new DateTime(convertedDateTime.Ticks, DateTimeKind.Utc));
            }
            catch (TimeZoneConversionException e)
            {
                throw new PropertyException(
                          string.Format(Strings.InvalidDateTime, dateTime),
                          this.Name,
                          e);
            }
        }
        /// <summary>
        /// Scopes the date time property to the appropriate time zone, if necessary.
        /// </summary>
        /// <param name="service">The service emitting the request.</param>
        /// <param name="dateTime">The date time.</param>
        /// <param name="propertyBag">The property bag.</param>
        /// <param name="isUpdateOperation">Indicates whether the scoping is to be performed in the context of an update operation.</param>
        /// <returns>The converted DateTime.</returns>
        internal override DateTime ScopeToTimeZone(
            ExchangeServiceBase service,
            DateTime dateTime,
            PropertyBag propertyBag,
            bool isUpdateOperation)
        {
            if (!propertyBag.Owner.GetIsCustomDateTimeScopingRequired())
            {
                // Most item types do not require a custom scoping mechanism. For those item types,
                // use the default scoping mechanism.
                return(base.ScopeToTimeZone(
                           service,
                           dateTime,
                           propertyBag,
                           isUpdateOperation));
            }
            else
            {
                // Appointment, however, requires a custom scoping mechanism which is based on an
                // associated time zone property.
                PropertyDefinition timeZoneProperty      = this.GetTimeZoneProperty(service.RequestedServerVersion);
                object             timeZonePropertyValue = null;

                bool timeZonePropertyIsSet = propertyBag.TryGetProperty(timeZoneProperty, out timeZonePropertyValue);

                if (timeZonePropertyValue != null && propertyBag.IsPropertyUpdated(timeZoneProperty))
                {
                    // If we have the associated time zone property handy and if it has been updated locally,
                    // then we scope the date time to that time zone.
                    try
                    {
                        DateTime convertedDateTime = EwsUtilities.ConvertTime(
                            dateTime,
                            (TimeZoneInfo)timeZonePropertyValue,
                            TimeZoneInfo.Utc);

                        // This is necessary to stamp the date/time with the Local kind.
                        return(new DateTime(convertedDateTime.Ticks, DateTimeKind.Utc));
                    }
                    catch (TimeZoneConversionException e)
                    {
                        throw new PropertyException(
                                  string.Format(Strings.InvalidDateTime, dateTime),
                                  this.Name,
                                  e);
                    }
                }
                else
                {
                    if (isUpdateOperation)
                    {
                        // In an update operation, what we do depends on what version of EWS
                        // we are targeting.
                        if (service.RequestedServerVersion == ExchangeVersion.Exchange2007_SP1)
                        {
                            // For Exchange 2007 SP1, we still need to scope to the service's time zone.
                            return(base.ScopeToTimeZone(
                                       service,
                                       dateTime,
                                       propertyBag,
                                       isUpdateOperation));
                        }
                        else
                        {
                            // Otherwise, we let the server scope to the appropriate time zone.
                            return(dateTime);
                        }
                    }
                    else
                    {
                        // In a Create operation, always scope to the service's time zone.
                        return(base.ScopeToTimeZone(
                                   service,
                                   dateTime,
                                   propertyBag,
                                   isUpdateOperation));
                    }
                }
            }
        }