Beispiel #1
0
        public Ribbon1()
        {
#if false
connectToServer:
            var webQuery = Environment.GetEnvironmentVariable(_envVarServer);
            var provider = new XmlSchemaProvider(webQuery);

            try
            {
                schema = provider.GetInstance();
            }
            catch (WebException)
            {
                var result = MessageBox.Show("Не удаётся подключиться к серверу мониторинга проектов.\nПроверьте подключение и войдите в систему",
                                             "Уведомление", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);

                if (result == DialogResult.Retry)
                {
                    goto connectToServer;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //schema = SchemeWork.CreateSchema();
#endif
        }
Beispiel #2
0
        private static void FillSchema()
        {
connectToServer:
            var webQuery = Environment.GetEnvironmentVariable("officeaddinserver");
            //webQuery = "http://localhost:25000/monitoring/get.schema.aspx";
            var provider = new XmlSchemaProvider(webQuery);

            try
            {
                Schema = provider.GetInstance();
            }
            catch (WebException)
            {
                var result = System.Windows.Forms.MessageBox.Show("Не удаётся подключиться к серверу мониторинга проектов.",
                                                                  "Уведомление",
                                                                  System.Windows.Forms.MessageBoxButtons.RetryCancel,
                                                                  System.Windows.Forms.MessageBoxIcon.Warning);

                if (result == System.Windows.Forms.DialogResult.Retry)
                {
                    goto connectToServer;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
 public XmlSchemaProvider Schema(
     [ArgRequired, ArgExistingFile, ArgDescription("Full path to xsd file to validate.")] string schema)
 {
     try
     {
         var schemaProvider = new XmlSchemaProvider(schema);
         Console.Write("Schema:\t{0} [v{1}] ({2})  ", schemaProvider.NamespaceUri, schemaProvider.SchemaVersion, schemaProvider.Path);
         ColorConsole.Ok();
         return(schemaProvider);
     }
     catch (XmlSchemaException e)
     {
         Console.WriteLine("File: {0}", schema);
         Console.Write("-> ");
         ColorConsole.Error(e.Message);
         Console.WriteLine($"-> At line {e.LineNumber}, pos {e.LinePosition}");
         return(null);
     }
     catch (XmlException e)
     {
         Console.WriteLine("File: {0}", schema);
         Console.Write("-> ");
         ColorConsole.Error(e.Message);
         return(null);
     }
 }
Beispiel #4
0
        public void Merge(string xsdFileWithOtherIncludedOrLinkedXsdFiles, string outputFilePath, XmlSchemaMergeSettings settings = null)
        {
            if (settings == null)
            {
                settings = XmlSchemaMergeSettings.Default;
            }

            var schemaProvider = new XmlSchemaProvider(xsdFileWithOtherIncludedOrLinkedXsdFiles);

            if (settings.SetSchemaVersion == null)
            {
                settings.SetSchemaVersion = new Version(schemaProvider.SchemaVersion.Major, schemaProvider.SchemaVersion.Minor, schemaProvider.SchemaVersion.Build + 1);
            }

            if (string.IsNullOrEmpty(outputFilePath))
            {
                outputFilePath = $"{Path.GetDirectoryName(schemaProvider.Path)}{Path.DirectorySeparatorChar}{Path.GetFileNameWithoutExtension(schemaProvider.Path)}_{settings.SetSchemaVersion}.xsd";
            }

            var mode = settings.OverwriteExisting ? FileMode.Create : FileMode.CreateNew;

            using (var file = new FileStream(outputFilePath, mode, FileAccess.Write))
            {
                Merge(schemaProvider.CompiledSchema, file, settings);
            }
        }
        public void Xml(
            [ArgRequired, ArgExistingFile, ArgDescription("Full path to xml file to validate.")] string file,
            [ArgExistingFile, ArgDescription("If schema is given, that schema file is used. Otherwise an inline (schemaLocation) is searched.")] string schema,
            [ArgExistingFile, ArgDescription("If schematron is given, that xslt file is used to do schematron validation.")] string schematron
            )
        {
            XmlSchemaProvider xmlSchemaProvider = null;

            if (!string.IsNullOrEmpty(schema))
            {
                Console.Write("Using ");
                xmlSchemaProvider = Schema(schema);
            }

#if NET461
            XsltFileProvider xsltFileProvider = null;
            if (!string.IsNullOrEmpty(schematron))
            {
                Console.Write("Using: ");
                xsltFileProvider = Schematron(schematron);
            }
#endif

            Console.Write($"Validating xml:\t{file}  ");

            var validateionResult = xmlSchemaProvider != null
                ? new XmlSchemaValidator(xmlSchemaProvider).Validate(file)
                : new XmlValidator().Validate(file);

            if (validateionResult.WarningCount > 0 || validateionResult.ErrorCount > 0)
            {
                Console.WriteLine();
                foreach (var warning in validateionResult.Warnings)
                {
                    Console.Write("-> ");
                    ColorConsole.Warning(warning);
                }

                foreach (var error in validateionResult.Errors)
                {
                    Console.Write("-> ");
                    ColorConsole.Error(error);
                }
            }
            else
            {
#if NET461
                if (xsltFileProvider != null)
                {
                    var saxonResult = new SaxonValidator(xsltFileProvider).Validate(file);
                }
#endif
                ColorConsole.Ok();
            }
        }