private bool DetectVersionInfo(BranchCacheDetector detector)
        {
            logWriter.AddLog(LogLevel.Warning, "===== Fetch Version Info =====");

            try
            {
                detectionInfo.VersionInformation = detector.FetchVersionInfo(detectionInfo);
            }
            catch (Exception ex)
            {
                logWriter.AddLog(LogLevel.Warning, "Failed", false, LogStyle.StepFailed);
                logWriter.AddLineToLog(LogLevel.Information);
                logWriter.AddLog(LogLevel.Information, string.Format("FetchVersionInfo failed, reason: {0}", ex.Message));
                logWriter.AddLog(LogLevel.Error, string.Format("Detect version info failed. Cannot do further detection.", ex.Message));
            }

            logWriter.AddLog(LogLevel.Warning, "Finished", false, LogStyle.StepPassed);
            logWriter.AddLineToLog(LogLevel.Information);

            if (detectionInfo.VersionInformation != null)
            {
                logWriter.AddLog(LogLevel.Information, "Target SUT Share Info:");
                logWriter.AddLog(LogLevel.Information, string.Format("Content Information SUT supported: {0}", detectionInfo.VersionInformation));
                logWriter.AddLineToLog(LogLevel.Information);
            }
            return(true);
        }
 private void DetectPlatform(BranchCacheDetector detector)
 {
     logWriter.AddLog(LogLevel.Warning, "===== Detect SUT Platform and Useraccounts =====");
     detector.FetchPlatform(detectionInfo);
     logWriter.AddLog(LogLevel.Warning, "Finished", false, LogStyle.StepPassed);
     logWriter.AddLineToLog(LogLevel.Information);
 }
        private bool DetectLocalNetworkInfo(BranchCacheDetector detector)
        {
            logWriter.AddLog(LogLevel.Warning, "===== Fetch Network Info =====");

            try
            {
                detectionInfo.ContentServerNetworkInformation = detector.FetchLocalNetworkInfo(detectionInfo);
                if (!string.IsNullOrEmpty(detectionInfo.HostedCacheServerName))
                {
                    detectionInfo.HostedCacheServerNetworkInfo = detector.FetchLocalNetworkInfo(detectionInfo);
                }
            }
            catch (Exception ex)
            {
                logWriter.AddLog(LogLevel.Warning, "Failed", false, LogStyle.StepFailed);
                logWriter.AddLineToLog(LogLevel.Information);
                logWriter.AddLog(LogLevel.Error, string.Format("Detect network info failed: {0} \r\nPlease check Target SUT", ex.Message));
            }

            if (detectionInfo.ContentServerNetworkInformation == null ||
                (!string.IsNullOrEmpty(detectionInfo.HostedCacheServerName) && detectionInfo.HostedCacheServerNetworkInfo == null))
            {
                logWriter.AddLog(LogLevel.Warning, "Failed", false, LogStyle.StepFailed);
                logWriter.AddLineToLog(LogLevel.Information);
                return(false);
            }

            logWriter.AddLog(LogLevel.Warning, "Finished", false, LogStyle.StepPassed);
            logWriter.AddLineToLog(LogLevel.Information);

            logWriter.AddLog(LogLevel.Information, "ContentServer Network Info:");
            logWriter.AddLog(LogLevel.Information, "Available IP Address:");
            foreach (var item in detectionInfo.ContentServerNetworkInformation.SUTIpList)
            {
                logWriter.AddLog(LogLevel.Information, "\t" + item.ToString());
            }
            logWriter.AddLineToLog(LogLevel.Information);

            if (!string.IsNullOrEmpty(detectionInfo.HostedCacheServerName))
            {
                logWriter.AddLog(LogLevel.Information, "HostedCacheServer Network Info:");
                logWriter.AddLog(LogLevel.Information, "Available IP Address:");

                foreach (var item in detectionInfo.HostedCacheServerNetworkInfo.SUTIpList)
                {
                    logWriter.AddLog(LogLevel.Information, "\t" + item.ToString());
                }
                logWriter.AddLineToLog(LogLevel.Information);
            }

            logWriter.AddLog(LogLevel.Information, "Local Test Driver Network Info:");
            logWriter.AddLog(LogLevel.Information, "Available IP Address:");
            foreach (var item in detectionInfo.ContentServerNetworkInformation.LocalIpList)
            {
                logWriter.AddLog(LogLevel.Information, "\t" + item.ToString());
            }
            logWriter.AddLineToLog(LogLevel.Information);

            return(true);
        }
        private bool PingSUT(BranchCacheDetector detector)
        {
            logWriter.AddLog(LogLevel.Warning, "===== Ping Target SUT =====");

            try
            {
                detectionInfo.ContentServerNetworkInformation = detector.PingTargetSUT(detector.ContentServerName);
                if (!string.IsNullOrEmpty(detector.HostedCacheServerName))
                {
                    detectionInfo.HostedCacheServerNetworkInfo = detector.PingTargetSUT(detector.HostedCacheServerName);
                }
            }
            catch (Exception ex)
            {
                logWriter.AddLog(LogLevel.Warning, "Failed", false, LogStyle.StepFailed);
                throw new Exception(ex.Message);
            }

            if (detectionInfo.ContentServerNetworkInformation.SUTIpList.Count == 0 ||
                !string.IsNullOrEmpty(detectionInfo.HostedCacheServerName) && detectionInfo.HostedCacheServerNetworkInfo.SUTIpList.Count == 0)
            {
                logWriter.AddLog(LogLevel.Warning, "Failed", false, LogStyle.StepFailed);
                return(false);
            }

            logWriter.AddLog(LogLevel.Warning, "Success", false, LogStyle.StepPassed);
            logWriter.AddLineToLog(LogLevel.Information);
            return(true);
        }
        /// <summary>
        /// Run property autodetection.
        /// </summary>
        /// <returns>Return true if the function is succeeded.</returns>
        public bool RunDetection()
        {
            logWriter.AddLog(LogLevel.Warning, "===== Start detecting =====", false);
            BranchCacheDetector detector = new BranchCacheDetector(
                logWriter,
                detectionInfo.ContentServerName,
                detectionInfo.HostedCacheServerName,
                new AccountCredential(detectionInfo.Domain, detectionInfo.UserName, detectionInfo.Password),
                SecurityPackageType.Negotiate);

            try
            {
                //Terminate the whole detection if any exception happens in the following processes
                if (!PingSUT(detector))
                {
                    return(false);
                }

                if (!DetectLocalNetworkInfo(detector))
                {
                    return(false);
                }

                if (!CheckUsernamePassword(detector))
                {
                    return(false);
                }

                //Do not interrupt auto-detection
                //Even if detect platform failed
                DetectPlatform(detector);

                if (!DetectShareInfo(detector))
                {
                    return(false);
                }

                if (!DetectVersionInfo(detector))
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                //PTM will catch this exception and display to the user with message box.
                throw new Exception(string.Format("Failed to do auto detection with exception {0}.", ex.Message), ex);
            }
            finally
            {
                CleanUpAfterDetection(detector.ClientList);
            }

            logWriter.AddLog(LogLevel.Warning, "===== End detecting =====");
            return(true);
        }
        private bool CheckUsernamePassword(BranchCacheDetector detector)
        {
            logWriter.AddLog(LogLevel.Warning, "===== Check the Credential =====");

            try
            {
                detector.CheckUsernamePassword(detectionInfo);
            }
            catch (Exception ex)
            {
                logWriter.AddLog(LogLevel.Warning, "Failed", false, LogStyle.StepFailed);
                logWriter.AddLineToLog(LogLevel.Information);
                logWriter.AddLog(LogLevel.Error, string.Format("The User cannot log on:{0} \r\nPlease check the credential", ex.Message));
            }

            logWriter.AddLog(LogLevel.Warning, "Finished", false, LogStyle.StepPassed);
            logWriter.AddLineToLog(LogLevel.Information);

            return(true);
        }