protected override IConfigurable PrepareDataObject()
        {
            ADMapiVirtualDirectory admapiVirtualDirectory = (ADMapiVirtualDirectory)base.PrepareDataObject();

            if (base.HasErrors)
            {
                return(null);
            }
            bool flag  = admapiVirtualDirectory.ExternalUrl != null && !string.IsNullOrEmpty(admapiVirtualDirectory.ExternalUrl.ToString());
            bool flag2 = admapiVirtualDirectory.InternalUrl != null && !string.IsNullOrEmpty(admapiVirtualDirectory.InternalUrl.ToString());

            if (!flag && !flag2)
            {
                base.WriteError(new ArgumentException(Strings.ErrorMapiVirtualDirectoryMustSpecifyEitherInternalOrExternalUrl), ErrorCategory.InvalidArgument, admapiVirtualDirectory.Identity);
                return(null);
            }
            if (flag)
            {
                admapiVirtualDirectory.ExternalUrl = new Uri(string.Format("https://{0}/mapi", admapiVirtualDirectory.ExternalUrl.Host));
            }
            if (flag2)
            {
                admapiVirtualDirectory.InternalUrl = new Uri(string.Format("https://{0}/mapi", admapiVirtualDirectory.InternalUrl.Host));
            }
            if (this.IISAuthenticationMethods == null)
            {
                this.IISAuthenticationMethods = admapiVirtualDirectory.IISAuthenticationMethods;
            }
            else
            {
                admapiVirtualDirectory.IISAuthenticationMethods = this.IISAuthenticationMethods;
            }
            if (admapiVirtualDirectory.IISAuthenticationMethods == null)
            {
                base.WriteError(new ArgumentException(Strings.ErrorMapiVirtualDirectoryMustSpecifyIISAuthenticationMethods), ErrorCategory.InvalidArgument, admapiVirtualDirectory.Identity);
                return(null);
            }
            if (this.applyDefaults && !SetMapiVirtualDirectory.IsLocalServer(admapiVirtualDirectory))
            {
                base.WriteError(new ArgumentException(Strings.ErrorMapiVirtualDirectoryMustBeLocalServerToReset), ErrorCategory.InvalidArgument, admapiVirtualDirectory.Identity);
                return(null);
            }
            this.metabasePath = admapiVirtualDirectory.MetabasePath;
            return(admapiVirtualDirectory);
        }
        private static bool IsLocalServer(ADMapiVirtualDirectory dataObject)
        {
            string hostName = IisUtility.GetHostName(dataObject.MetabasePath);

            if (string.IsNullOrEmpty(hostName))
            {
                return(false);
            }
            string localComputerFqdn = NativeHelpers.GetLocalComputerFqdn(false);

            if (hostName.IndexOf('.') != -1)
            {
                return(hostName.Equals(localComputerFqdn, StringComparison.InvariantCultureIgnoreCase));
            }
            string value = SetMapiVirtualDirectory.ServerShortName(localComputerFqdn);
            string text  = SetMapiVirtualDirectory.ServerShortName(hostName);

            return(text.Equals(value, StringComparison.InvariantCultureIgnoreCase));
        }