Пример #1
0
        public override void ProcessDirective(string directiveName, IDictionary<string, string> arguments)
        {
            base.ProcessDirective(directiveName, arguments);
            try
            {
                if (!arguments.ContainsKey(NameParameterName))
                {
                    DirectiveProcessorException e = new DirectiveProcessorException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            "{0} is a required parameter for the {1} directive",
                            NameParameterName,
                            this.DirectiveName));
                    e.Source = Host.TemplateFile;
                    throw e;
                }

                this.References.Add(this.GetTempAssemblyName(arguments[NameParameterName]));
            }
            catch (DirectiveProcessorException e)
            {
                // Report expected errors without the call stack
                CompilerError error = new CompilerError();
                error.ErrorText = e.Message;
                error.FileName = e.Source;
                this.Errors.Add(error);
            }
        }
Пример #2
0
        /// <summary>
        /// Resolves assembly reference to an absolute path name.
        /// </summary>
        /// <param name="assemblyName">An assembly reference.</param>
        /// <returns>An absolute path to the assembly.</returns>
        private string ResolveAssemblyReference(string assemblyName)
        {
            string assemblyPath = assemblyName;

            // Try to resolve assembly name as relative path first
            try
            {
                assemblyPath = Host.ResolvePath(assemblyName);
                if (File.Exists(assemblyPath))
                {
                    return assemblyPath;
                }
            }
            catch (FileNotFoundException)
            {
            }

            // Try to resolve assembly name
            try
            {
                assemblyPath = Host.ResolveAssemblyReference(assemblyName);
                if (File.Exists(assemblyPath))
                {
                    return assemblyPath;
                }
            }
            catch (FileNotFoundException)
            {
            }
            catch (FileLoadException)
            {
            }

            DirectiveProcessorException directiveProcessorException = new DirectiveProcessorException(
                string.Format(
                    CultureInfo.CurrentCulture,
                    "{0} directive: Assembly '{1}' resolved as '{2}' could not be found.",
                    this.DirectiveName,
                    assemblyName,
                    assemblyPath));
            directiveProcessorException.Source = Host.TemplateFile;
            throw directiveProcessorException;
        }
Пример #3
0
        private XmlSchema ReadSchema(string filePath)
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.XmlResolver = null;
            settings.CloseInput = false;

            using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            using (XmlReader reader = XmlReader.Create(stream, settings))
            {
                this.schemaValidationErrors = false;
                try
                {
                    XmlSchema schema = XmlSchema.Read(reader, this.ValidationErrorHandler);
                    if (this.schemaValidationErrors)
                    {
                        // TODO: Does this ever execute?
                        DirectiveProcessorException e = new DirectiveProcessorException(
                            string.Format(
                                CultureInfo.CurrentCulture,
                                "schema '{0}' contains validation errors",
                                filePath));
                        e.Source = filePath;
                        throw e;
                    }

                    schema.SourceUri = filePath;
                    return schema;
                }
                catch (XmlException e)
                {
                    DirectiveProcessorException directiveException = new DirectiveProcessorException(e.Message, e);
                    directiveException.Source = filePath;
                    throw directiveException;
                }
            }
        }
Пример #4
0
        public override void ProcessDirective(string directiveName, IDictionary<string, string> arguments)
        {
            base.ProcessDirective(directiveName, arguments);
            try
            {
                // Extract files directive parameter
                if (!arguments.ContainsKey(FileParameterName))
                {
                    DirectiveProcessorException e = new DirectiveProcessorException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            "{0} is a required parameter for the {1} directive",
                            XsdProcessor.FileParameterName,
                            this.DirectiveName));
                    e.Source = Host.TemplateFile;
                    throw e;
                }

                this.ProcessDirectiveCore(arguments[FileParameterName]);
            }
            catch (DirectiveProcessorException e)
            {
                CompilerError error = new CompilerError();
                error.ErrorText = e.Message;
                error.FileName = e.Source;
                this.Errors.Add(error);
            }
        }
Пример #5
0
        /// <summary>
        /// Resolves relative file path.
        /// </summary>
        /// <param name="basePath">File path of the main file.</param>
        /// <param name="relativePath">Relative path to referred file.</param>
        /// <returns>Absolute path.</returns>
        private static string ResolvePath(string basePath, string relativePath)
        {
            string baseDirectory = Path.GetDirectoryName(basePath);
            string filePath = NormalizePath(Path.Combine(baseDirectory, relativePath));

            if (!File.Exists(filePath))
            {
                DirectiveProcessorException e = new DirectiveProcessorException(
                    string.Format(CultureInfo.CurrentCulture, "File doesn't exist: {0}", filePath));
                e.Source = basePath;
                throw e;
            }

            return filePath;
        }