Esempio n. 1
0
        /// <summary>
        /// Given a set of task parameters from the UsingTask and from the task invocation, generate a dictionary that combines the two, or throws if the merge
        /// is impossible (we shouldn't ever get to this point if it is ...)
        /// </summary>
        private static IDictionary <string, string> MergeTaskFactoryParameterSets(IDictionary <string, string> factoryIdentityParameters, IDictionary <string, string> taskIdentityParameters)
        {
            IDictionary <string, string> mergedParameters = null;
            string mergedRuntime      = null;
            string mergedArchitecture = null;

            if (factoryIdentityParameters == null || factoryIdentityParameters.Count == 0)
            {
                mergedParameters = new Dictionary <string, string>(taskIdentityParameters, StringComparer.OrdinalIgnoreCase);
            }
            else if (taskIdentityParameters == null || taskIdentityParameters.Count == 0)
            {
                mergedParameters = new Dictionary <string, string>(factoryIdentityParameters, StringComparer.OrdinalIgnoreCase);
            }

            if (mergedParameters != null)
            {
                mergedParameters.TryGetValue(XMakeAttributes.runtime, out mergedRuntime);
                mergedParameters.TryGetValue(XMakeAttributes.architecture, out mergedArchitecture);

                mergedParameters[XMakeAttributes.runtime]      = XMakeAttributes.GetExplicitMSBuildRuntime(mergedRuntime);
                mergedParameters[XMakeAttributes.architecture] = XMakeAttributes.GetExplicitMSBuildArchitecture(mergedArchitecture);
            }
            else
            {
                string taskRuntime           = null;
                string taskArchitecture      = null;
                string usingTaskRuntime      = null;
                string usingTaskArchitecture = null;

                mergedParameters = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

                taskIdentityParameters.TryGetValue(XMakeAttributes.runtime, out taskRuntime);
                factoryIdentityParameters.TryGetValue(XMakeAttributes.runtime, out usingTaskRuntime);

                if (!XMakeAttributes.TryMergeRuntimeValues(taskRuntime, usingTaskRuntime, out mergedRuntime))
                {
                    ErrorUtilities.ThrowInternalError("How did we get two runtime values that were unmergeable?");
                }
                else
                {
                    mergedParameters.Add(XMakeAttributes.runtime, mergedRuntime);
                }

                taskIdentityParameters.TryGetValue(XMakeAttributes.architecture, out taskArchitecture);
                factoryIdentityParameters.TryGetValue(XMakeAttributes.architecture, out usingTaskArchitecture);

                if (!XMakeAttributes.TryMergeArchitectureValues(taskArchitecture, usingTaskArchitecture, out mergedArchitecture))
                {
                    ErrorUtilities.ThrowInternalError("How did we get two runtime values that were unmergeable?");
                }
                else
                {
                    mergedParameters.Add(XMakeAttributes.architecture, mergedArchitecture);
                }
            }

            return(mergedParameters);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns true if a task host exists that can service the requested runtime and architecture
        /// values, and false otherwise.
        /// </summary>
        internal static bool DoesTaskHostExist(string runtime, string architecture)
        {
            if (runtime != null)
            {
                runtime = runtime.Trim();
            }

            if (architecture != null)
            {
                architecture = architecture.Trim();
            }

            if (!XMakeAttributes.IsValidMSBuildRuntimeValue(runtime))
            {
                ErrorUtilities.ThrowArgument("InvalidTaskHostFactoryParameter", runtime, "Runtime", XMakeAttributes.MSBuildRuntimeValues.clr2, XMakeAttributes.MSBuildRuntimeValues.clr4, XMakeAttributes.MSBuildRuntimeValues.currentRuntime, XMakeAttributes.MSBuildRuntimeValues.any);
            }

            if (!XMakeAttributes.IsValidMSBuildArchitectureValue(architecture))
            {
                ErrorUtilities.ThrowArgument("InvalidTaskHostFactoryParameter", architecture, "Architecture", XMakeAttributes.MSBuildArchitectureValues.x86, XMakeAttributes.MSBuildArchitectureValues.x64, XMakeAttributes.MSBuildArchitectureValues.currentArchitecture, XMakeAttributes.MSBuildArchitectureValues.any);
            }

            runtime      = XMakeAttributes.GetExplicitMSBuildRuntime(runtime);
            architecture = XMakeAttributes.GetExplicitMSBuildArchitecture(architecture);

            IDictionary <string, string> parameters = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            parameters.Add(XMakeAttributes.runtime, runtime);
            parameters.Add(XMakeAttributes.architecture, architecture);

            TaskHostContext desiredContext   = CommunicationsUtilities.GetTaskHostContext(parameters);
            string          taskHostLocation = NodeProviderOutOfProcTaskHost.GetMSBuildLocationFromHostContext(desiredContext);

            if (taskHostLocation != null && FileUtilities.FileExistsNoThrow(taskHostLocation))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns true if the provided set of task host parameters matches the current process,
        /// and false otherwise.
        /// </summary>
        private static bool TaskHostParametersMatchCurrentProcess(IDictionary <string, string> mergedParameters)
        {
            if (mergedParameters == null || mergedParameters.Count == 0)
            {
                // We don't care, so they match by default.
                return(true);
            }

            string runtime;

            if (mergedParameters.TryGetValue(XMakeAttributes.runtime, out runtime))
            {
                string currentRuntime = XMakeAttributes.GetExplicitMSBuildRuntime(XMakeAttributes.MSBuildRuntimeValues.currentRuntime);

                if (!currentRuntime.Equals(XMakeAttributes.GetExplicitMSBuildRuntime(runtime), StringComparison.OrdinalIgnoreCase))
                {
                    // runtime doesn't match
                    return(false);
                }
            }

            string architecture;

            if (mergedParameters.TryGetValue(XMakeAttributes.architecture, out architecture))
            {
                string currentArchitecture = XMakeAttributes.GetCurrentMSBuildArchitecture();

                if (!currentArchitecture.Equals(XMakeAttributes.GetExplicitMSBuildArchitecture(architecture), StringComparison.OrdinalIgnoreCase))
                {
                    // architecture doesn't match
                    return(false);
                }
            }

            // if it doesn't not match, then it matches
            return(true);
        }