NAnt.Core.FrameworkInfo.Validate C# (CSharp) Method

Validate() private method

private Validate ( ) : void
return void
        internal void Validate()
        {
            if (_status == InitStatus.Valid) {
                return;
            }

            Init();

            // reset status to avoid status check in properties from getting
            // triggered
            _status = InitStatus.Initialized;

            try {
                // verify if framework directory is configured, and indirectly
                // check if it exists
                if (FrameworkDirectory == null) {
                    throw new ArgumentException("The \"frameworkdirectory\" " +
                        "attribute does not exist, or has no value.");
                }

                // verify if framework assembly directory is configured, and
                // indirectly check if it exists
                if (FrameworkAssemblyDirectory == null) {
                    throw new ArgumentException("The \"frameworkassemblydirectory\" " +
                        "attribute does not exist, or has no value.");
                }

                // verify if version is configured
                if (Version == null) {
                    throw new ArgumentException("The \"version\" attribute " +
                        "does not exist, or has no value.");
                }

                // verify if clrversion is configured
                if (ClrVersion == null) {
                    throw new ArgumentException("The \"clrversion\" attribute " +
                        "does not exist, or has no value.");
                }

                // mark framework valid
                _status = InitStatus.Valid;
            } catch (Exception ex) {
                _status = InitStatus.Invalid;
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    "{0} ({1}) is not installed, or not correctly configured.",
                    Description, Name), Location.UnknownLocation, ex);
            }
        }

Usage Example

        private FrameworkInfo ConfigureRuntimeFramework()
        {
            ArrayList candidates = new ArrayList();

            // determine the framework family name
            string frameworkFamily = PlatformHelper.IsMono ? "mono" : "net";
            // determine the version of the current runtime framework
            Version frameworkClrVersion = new Version(Environment.Version.ToString(3));

            // determine which framework configuration matches the host CLR
            foreach (FrameworkInfo framework in Project.Frameworks)
            {
                if (framework.Family != frameworkFamily)
                {
                    continue;
                }
                if (framework.ClrVersion != frameworkClrVersion)
                {
                    continue;
                }
                candidates.Add(framework);
            }

            FrameworkInfo selected = null;

            for (int i = 0; i < candidates.Count; i++)
            {
                FrameworkInfo current = (FrameworkInfo)candidates[i];
                try {
                    // validate
                    current.Validate();
                    selected = current;
                    if (selected.SdkDirectory != null)
                    {
                        // if we found a matching framework with a valid
                        // SDK, then skip further candidates
                        break;
                    }
                } catch {
                    // only rethrow exception if we haven't yet found a valid
                    // framework and we're dealing with the last candidate
                    if (selected == null && i == (candidates.Count - 1))
                    {
                        throw;
                    }
                }
            }

            if (selected == null)
            {
                // information about the current runtime framework should
                // be added to the NAnt configuration file
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       ResourceUtils.GetString("NA1062"), frameworkFamily,
                                                       frameworkClrVersion.ToString()));
            }

            return(selected);
        }
All Usage Examples Of NAnt.Core.FrameworkInfo::Validate