Esempio n. 1
0
        /// <summary>
        /// Validates a project file against the given schema.  If no schema is given, validates
        /// against the default schema
        /// </summary>
        /// <param name="projectFile">Path of the file to validate.</param>
        /// <param name="schemaFile">Can be null.</param>
        /// <param name="binPath">Path to the framework directory where the default schema for
        /// this ToolsVersion can be found.</param>
        /// <returns>True if the project was successfully validated against the given schema, false otherwise</returns>
        internal static void VerifyProjectSchema
        (
            string projectFile,
            string schemaFile,
            string binPath
        )
        {
            ErrorUtilities.VerifyThrowArgumentNull(projectFile, "projectFile");
            ErrorUtilities.VerifyThrowArgumentNull(binPath, "binPath");

            if ((schemaFile == null) || (schemaFile.Length == 0))
            {
                schemaFile = Path.Combine(binPath, "net.r_eg.IeXod.xsd");
            }

            if (FileSystems.Default.FileExists(schemaFile))
            {
                // Print the schema file we're using, particularly since it can vary
                // according to the toolset being used
                Console.WriteLine(AssemblyResources.GetString("SchemaFileLocation"), schemaFile);
            }
            else
            {
                // If we've gotten to this point, there is no schema to validate against -- just exit.
                InitializationException.Throw
                (
                    ResourceUtilities.FormatResourceStringStripCodeAndKeyword("SchemaNotFoundErrorWithFile", schemaFile),
                    null /* No associated command line switch */
                );
            }

            ProjectSchemaValidationHandler validationHandler = new ProjectSchemaValidationHandler();

            validationHandler.VerifyProjectSchema(projectFile, schemaFile);
        }
Esempio n. 2
0
 /// <summary>
 /// Given the parameters passed in, builds an error message and throws an
 /// InitializationException with that message.
 /// </summary>
 private static void ThrowInitializationExceptionWithResource
 (
     string projectFile,
     int fileLine,
     int fileEndLine,
     int fileColumn,
     int fileEndColumn,
     string resourceName,
     params object[] args
 )
 {
     InitializationException.Throw
     (
         BuildStringFromResource
         (
             projectFile,
             fileLine,
             fileEndLine,
             fileColumn,
             fileEndColumn,
             resourceName,
             args
         ),
         null      /* No associated command line switch */
     );
 }
Esempio n. 3
0
        /// <summary>
        /// Throws the exception if the specified condition is not met.
        /// </summary>
        internal static void VerifyThrow(bool condition, string messageResourceName, string invalidSwitch, params object[] args)
        {
            if (!condition)
            {
                string errorMessage = AssemblyResources.GetString(messageResourceName);

                ErrorUtilities.VerifyThrow(errorMessage != null, "The resource string must exist.");

                errorMessage = ResourceUtilities.FormatString(errorMessage, args);

                InitializationException.Throw(errorMessage, invalidSwitch);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Throws an exception if any errors were found while parsing the command-line.
 /// </summary>
 internal void ThrowErrors()
 {
     if (HaveErrors())
     {
         if (_isParameterError)
         {
             InitializationException.Throw(_errorMessage, _badCommandLineArg, _innerException, false);
         }
         else
         {
             CommandLineSwitchException.Throw(_errorMessage, _badCommandLineArg);
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Throws the exception using the given exception context.
        /// </summary>
        /// <param name="messageResourceName"></param>
        /// <param name="invalidSwitch"></param>
        /// <param name="e"></param>
        /// <param name="showStackTrace"></param>
        internal static void Throw(string messageResourceName, string invalidSwitch, Exception e, bool showStackTrace)
        {
            string errorMessage = AssemblyResources.GetString(messageResourceName);

            ErrorUtilities.VerifyThrow(errorMessage != null, "The resource string must exist.");

            if (showStackTrace && e != null)
            {
                errorMessage += Environment.NewLine + e.ToString();
            }
            else
            {
                // the exception message can contain a format item i.e. "{0}" to hold the given exception's message
                errorMessage = ResourceUtilities.FormatString(errorMessage, ((e == null) ? String.Empty : e.Message));
            }

            InitializationException.Throw(errorMessage, invalidSwitch);
        }