예제 #1
0
        internal static bool IsMsiInstalled(MachineHealthContainer machineHealthContainer)
        {
            SFDeployerTrace.WriteNoise(StringResources.Info_BPAConflictingInstallations);
            var fabricProductNames = new string[] { "Windows Fabric", "Microsoft Service Fabric", "Microsoft Azure Service Fabric" };

            bool          localMachineFailed = false;
            List <string> machineNamesTemp   = GetMachineNamesIncludingClient(machineHealthContainer.GetHealthyMachineNames());

            Parallel.ForEach(
                machineNamesTemp,
                (string machineName) =>
            {
                bool result = false;
                using (RegistryKey uninstallKeys = GetHklm(machineName).OpenSubKey(DMConstants.UninstallProgramsBaseKey))
                {
                    if (uninstallKeys != null)
                    {
                        Parallel.ForEach(
                            uninstallKeys.GetSubKeyNames(),
                            (string guid) =>
                        {
                            using (RegistryKey uninstallKey = uninstallKeys.OpenSubKey(guid))
                            {
                                string uninstallString = (string)uninstallKey.GetValue("UninstallString", null);
                                if (uninstallString != null)
                                {
                                    string displayNameValue = (string)uninstallKey.GetValue("DisplayName", null);
                                    if (displayNameValue != null)
                                    {
                                        displayNameValue = displayNameValue.Trim();
                                        if (uninstallString.IndexOf("msiexec.exe", StringComparison.OrdinalIgnoreCase) >= 0)
                                        {
                                            foreach (string productName in fabricProductNames)
                                            {
                                                if (string.Equals(displayNameValue, productName, StringComparison.OrdinalIgnoreCase))
                                                {
                                                    SFDeployerTrace.WriteError(StringResources.Error_BPAMsiIsInstalled, displayNameValue, machineName);
                                                    result = true;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        });
                    }
                }

                if (result)
                {
                    if (Helpers.IsLocalIpAddress(machineName))
                    {
                        localMachineFailed = true;
                    }
                    else
                    {
                        machineHealthContainer.MarkMachineAsUnhealthy(machineName);
                    }
                }
            });

            if (localMachineFailed)
            {
                return(true);
            }

            return(!machineHealthContainer.EnoughHealthyMachines());
        }
예제 #2
0
        internal static bool CheckRequiredPorts(MachineHealthContainer machineHealthContainer)
        {
            SFDeployerTrace.WriteNoise(StringResources.Info_BPARequiredPorts);
            int[] requiredPorts = { DMConstants.SmbFileSharePort };
            bool  result        = true;

            foreach (string machineFqdn in machineHealthContainer.GetHealthyMachineNames())
            {
                if (Uri.CheckHostName(machineFqdn) == UriHostNameType.Unknown)
                {
                    result = false;
                    SFDeployerTrace.WriteError(StringResources.Error_BPAMachineNotPingable, machineFqdn);
                }
            }

            if (!result)
            {
                return(false);
            }

            foreach (int port in requiredPorts)
            {
                Parallel.ForEach(
                    machineHealthContainer.GetHealthyMachineNames(),
                    (string machineName) =>
                {
                    result                      = true;
                    IPAddress address           = null;
                    bool isParseableAsIPAddress = IPAddress.TryParse(machineName, out address);

                    if (isParseableAsIPAddress)
                    {
                        if (address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            SFDeployerTrace.WriteNoise("Using IPv4 address for {0}", machineName);
                        }
                        else if (address.AddressFamily == AddressFamily.InterNetworkV6)
                        {
                            SFDeployerTrace.WriteNoise("Using IPv6 address for {0}", machineName);
                        }
                        else
                        {
                            SFDeployerTrace.WriteError(StringResources.Error_BPAPortConnectFailed, machineName, port, "Expected IPv4 or IPv6 address");
                            result = false;
                            return;
                        }

                        try
                        {
                            using (TcpClient client = new TcpClient(address.AddressFamily))
                            {
                                client.Connect(address, port);
                            }
                        }
                        catch (SocketException ex)
                        {
                            SFDeployerTrace.WriteError(StringResources.Error_BPAPortConnectFailed, machineName, port, ex.Message);
                            result = false;
                        }
                    }
                    else
                    {
                        try
                        {
                            using (new TcpClient(machineName, port))
                            {
                                // Intentionally empty.  The constructor already establishes a connection
                            }
                        }
                        catch (SocketException ex)
                        {
                            SFDeployerTrace.WriteError(StringResources.Error_BPAPortConnectFailed, machineName, port, ex.Message);
                            result = false;
                        }
                    }

                    if (!result)
                    {
                        machineHealthContainer.MarkMachineAsUnhealthy(machineName);
                    }
                });
            }

            return(machineHealthContainer.EnoughHealthyMachines());
        }