Esempio n. 1
0
        private Status PerformSchemaCheck(CheckOptions c, TextWriter writer)
        {
            Status            ret       = Status.Ok;
            XmlReaderSettings rSettings = new XmlReaderSettings();

            foreach (var schemaFile in c.GetSchemas())
            {
                try
                {
                    var ns = GetSchemaNamespace(schemaFile);
                    rSettings.Schemas.Add(ns, schemaFile.FullName);
                }
                catch (XmlSchemaException ex)
                {
                    writer.WriteLine($"XSD\t{schemaFile}\tSchema error: {ex.Message} at line {ex.LineNumber}, position {ex.LinePosition}.");
                    ret |= Status.XsdSchemaError;
                }
                catch (Exception ex)
                {
                    writer.WriteLine($"XSD\t{schemaFile}\tSchema error: {ex.Message}.");
                    ret |= Status.XsdSchemaError;
                }
            }
            return(ret);
        }
Esempio n. 2
0
        public static Status Run(CheckOptions opts, TextWriter writer = null)
        {
            if (writer == null)
            {
                writer = Console.Out;
            }
            writer.WriteLine("=== ids-tool - checking IDS files.");

            Status retvalue = Status.Ok;

            // if no check is required than check default
            if (
                opts.InputSource == null
                )
            {
                opts.CheckSchemaDefinition = true;
                writer.WriteLine("Performing default checks.");
            }
            else
            {
                List <string> checks = new List <string>();
                if (opts.InputSource != null)
                {
                    checks.Add("XML content");
                }
                if (opts.CheckSchemaDefinition)
                {
                    checks.Add("Xsd schemas correctness");
                }
                writer.WriteLine($"Checking: {string.Join(", ", checks.ToArray())}.");
            }

            // start checking
            if (opts.CheckSchemaDefinition)
            {
                retvalue |= opts.PerformSchemaCheck(opts, writer);
            }

            if (Directory.Exists(opts.InputSource))
            {
                writer.WriteLine("");
                var t = new DirectoryInfo(opts.InputSource);
                opts.ResolvedSource = t;
                var ret = ProcessExamplesFolder(t, new CheckInfo(opts, writer));
                writer.WriteLine($"\r\nCompleted with status: {ret}.");
                return(ret);
            }
            if (File.Exists(opts.InputSource))
            {
                writer.WriteLine("");
                var t = new FileInfo(opts.InputSource);
                opts.ResolvedSource = t;
                var ret = ProcessSingleFile(t, new CheckInfo(opts, writer));
                writer.WriteLine($"\r\nCompleted with status: {ret}.");
                return(ret);
            }
            writer.WriteError($"Error: Invalid input source '{opts.InputSource}'");
            return(Status.NotFoundError);
        }
Esempio n. 3
0
 public CheckInfo(CheckOptions opts, TextWriter writer)
 {
     Options = opts;
     Writer  = writer;
     if (Writer is StringWriter)
     {
         Verbose = true;
     }
 }