コード例 #1
0
        // This function check whether dotnet exe exists in %PATH% on IOT device.
        // It will read %PATH% from registry and expand %systemroot% if found
        // Currently it doesn't support expanding other variables.
        internal static bool IsDotNetExeInPath(MachineHealthContainer machineHealthContainer)
        {
            bool result = true;

            Parallel.ForEach(
                machineHealthContainer.GetHealthyMachineNames(),
                (string machineName) =>
            {
                // Currently we only need to check for IOTCore environment
                if (StandaloneUtility.IsIOTCore(machineName))
                {
                    string remotePath       = string.Empty;
                    string remoteSystemRoot = string.Empty;

                    // Read %Path% variable
                    using (RegistryKey regKey = StandaloneUtility.GetHklm(machineName))
                    {
                        RegistryKey envKey = regKey.OpenSubKey(DMConstants.EnvironmentRegKeyPath);
                        if (envKey != null)
                        {
                            remotePath = (string)envKey.GetValue(DMConstants.Path, string.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames);
                        }

                        RegistryKey versionKey = regKey.OpenSubKey(DMConstants.IOTCurrentVersionRegKeyPath);
                        if (versionKey != null)
                        {
                            remoteSystemRoot = (string)versionKey.GetValue(DMConstants.SystemRoot, string.Empty);
                        }
                    }

                    bool found     = false;
                    string[] paths = remotePath.Split(';');
                    foreach (string path in paths)
                    {
                        // Replace %SystemRoot%
                        string absolutePath  = Regex.Replace(path, "%SYSTEMROOT%", remoteSystemRoot, RegexOptions.IgnoreCase);
                        absolutePath         = Path.Combine(absolutePath, "dotnet.exe");
                        string dotNetExePath = Helpers.GetRemotePathIfNotLocalMachine(absolutePath, machineName);
                        if (File.Exists(dotNetExePath))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        result = false;
                    }
                }
            });

            return(result);
        }