コード例 #1
0
ファイル: cmdSampleDocument.cs プロジェクト: mff-uk/xcase
        public override void Execute(object parameter)
        {
            XmlSchemaTranslator translator = new XmlSchemaTranslator();
            string schema = translator.Translate((PSMDiagram)ActiveDiagramView.Diagram);

            XMLSchemaWindow.Show(MainWindow.dockManager, (PSMDiagram)ActiveDiagramView.Diagram, schema, translator.Log);
        }
コード例 #2
0
ファイル: StartupManager.cs プロジェクト: mff-uk/xcase
        /// <summary>
        /// Exports the xml schema into a file.
        /// </summary>
        /// <param name="diagram">The exported diagram.</param>
        /// <param name="path">The file path.</param>
        private static void ExportXsd(Diagram diagram, string path)
        {
            Console.Write("Exporting diagram {0} to {1}.... ", diagram.Caption, path);
            if (translator == null)
            {
                // show start dialog of translation
                StartTranslation st = new StartTranslation();
                DialogResult     dr = st.ShowDialog();
                if (dr != DialogResult.OK)
                {
                    return;
                }

                Configuration config = new Configuration();
                if (!st.isDefConfigChecked())
                {
                    config.Load(st.getConfigFileName());
                }

                if (config == null)
                {
                    return;
                }

                translator = new XmlSchemaTranslator(config, "projectA"); // todo: ...
            }
            string xsdString = translator.Translate((PSMDiagram)diagram);

            xsdString = xsdString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>",
                                          "<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            File.WriteAllText(path, xsdString, Encoding.UTF8);
            Console.WriteLine("OK");
        }
コード例 #3
0
ファイル: StartupManager.cs プロジェクト: mff-uk/xcase
        /// <summary>
        /// Exports the xml schema into a file.
        /// </summary>
        /// <param name="diagram">The exported diagram.</param>
        /// <param name="path">The file path.</param>
        private static void ExportXsd(Diagram diagram, string path)
        {
            Console.Write("Exporting diagram {0} to {1}.... ", diagram.Caption, path);
            if (translator == null)
            {
                translator = new XmlSchemaTranslator();
            }
            string xsdString = translator.Translate((PSMDiagram)diagram);

            xsdString = xsdString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>",
                                          "<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            File.WriteAllText(path, xsdString, Encoding.UTF8);
            Console.WriteLine("OK");
        }
コード例 #4
0
        public override void Execute(object parameter)
        {
            // todo: uncomment the next statement to run a test
            //Test(); return;

            PSMDiagram diagram = (PSMDiagram)ActiveDiagramView.Diagram;

            if (diagram.Roots.Count < 1)
            {
                MessageBox.Show("PSM diagram is empty. Nothing to translate.", "XCase Warning");
                return;
            }

            // show dialog starting translation
            StartTranslation st = new StartTranslation();
            DialogResult     dr = st.ShowDialog();

            if (dr != DialogResult.OK)
            {
                return;
            }

            Configuration config = new Configuration();

            if (!st.isDefConfigChecked())
            {
                config.Load(st.getConfigFileName());
            }

            if (config == null)
            {
                return;
            }

            // get short name of current project
            string projectName = getProjectName();

            // call XML Schema translation
            XmlSchemaTranslator translator = new XmlSchemaTranslator(config, projectName);
            string resultMessage           = translator.Translate(diagram);

            if (resultMessage.Equals("ok"))
            {
                // get results and display them in nice window
                Dictionary <string, string> schemas = translator.getResults();
                XMLSchemaWindow.Show(MainWindow.dockManager, (PSMDiagram)ActiveDiagramView.Diagram, schemas, translator.Log);
            }
        }
コード例 #5
0
ファイル: ProjectTranslator.cs プロジェクト: mff-uk/xcase
        /// <summary>
        ///
        /// </summary>
        /// <param name="targetDirectory">Directory where schemas are saved. When left to null, project's direcotry is used</param>
        public void SaveSchemas(string targetDirectory)
        {
            if (string.IsNullOrEmpty(targetDirectory))
            {
                targetDirectory = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(Project.FilePath));
            }

            SchemaFiles.Clear();
            foreach (PSMDiagram psmDiagram in Project.PSMDiagrams)
            {
                XmlSchemaTranslator t = new XmlSchemaTranslator();
                string schema         = t.Translate(psmDiagram);
                schema = schema.Replace("utf-16", "utf-8");
                string targetPath = string.Format("{0}\\{1}.xsd", targetDirectory, psmDiagram.Caption);
                File.WriteAllText(targetPath, schema, System.Text.Encoding.UTF8);
                SchemaFiles[psmDiagram] = targetPath;
            }
        }
コード例 #6
0
        // TODO: for testing purposes only
        // This function calls translation of active PSM diagram into XML Schema schemas.
        // It stores resulting schemas (.xsd files) to the path specified by diOutput parameter.
        private void GenerateXsd(Configuration config, DirectoryInfo diOutput)
        {
            // get short name of current project
            string projectName = getProjectName();

            // call XML Schema translation
            XmlSchemaTranslator translator = new XmlSchemaTranslator(config, projectName);
            string resultMessage           = translator.Translate((PSMDiagram)ActiveDiagramView.Diagram);

            if (resultMessage.Equals("ok"))
            {
                // get results and store them into the output directory
                Dictionary <string, string> schemas = translator.getResults();
                foreach (string fileName in schemas.Keys)
                {
                    File.WriteAllText(diOutput.FullName + "/" + fileName, schemas[fileName], System.Text.Encoding.UTF8);
                }
            }
        }
コード例 #7
0
ファイル: DocumentValidator.cs プロジェクト: mff-uk/xcase
        public bool ValidateDocument(PSMDiagram diagram, string xmltext)
        {
            XmlSchemaTranslator t      = new XmlSchemaTranslator();
            string       xmlSchemaText = t.Translate(diagram);
            XmlReader    xmlfile       = null;
            XmlReader    schemaReader  = null;
            MemoryStream _msSchemaText = null;

            isValid = true;
            abort   = false;
            try
            {
                byte[] b = Encoding.Unicode.GetBytes(xmlSchemaText);
                _msSchemaText = new MemoryStream(b);
                schemaReader  = new XmlTextReader(_msSchemaText);
                XmlSchema schema = XmlSchema.Read(schemaReader, schemaSettings_ValidationEventHandler);
                schema.TargetNamespace = diagram.Project.Schema.XMLNamespaceOrDefaultNamespace;

                XmlReaderSettings schemaSettings = new XmlReaderSettings();
                schemaSettings.Schemas.Add(schema);
                schemaSettings.ValidationType          = ValidationType.Schema;
                schemaSettings.ValidationEventHandler += schemaSettings_ValidationEventHandler;
                schemaSettings.ValidationFlags        |= XmlSchemaValidationFlags.ReportValidationWarnings;
                try
                {
                    xmlfile = XmlReader.Create(new StringReader(xmltext), schemaSettings);
                }
                catch (XmlSchemaValidationException ex)
                {
                    isValid = false;
                    if (!SilentMode)
                    {
                        MessageBox.Show(string.Format("Validation can not continue - schema is invalid. \r\n\r\n{0}", ex.Message), "Invalid schema", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                    ErrorMessage = string.Format("Validation can not continue - schema is invalid. \r\n\r\n{0}", ex.Message);
                    return(false);
                }

                if (isValid)
                {
                    while (xmlfile.Read() && !abort)
                    {
                    }
                }
            }
            catch (XmlSchemaValidationException ex)
            {
                isValid = false;
                if (!SilentMode)
                {
                    MessageBox.Show(string.Format("{0} \r\n\r\nValidation can not continue.", ex.Message), "Invalid document", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                ErrorMessage = string.Format("{0} \r\n\r\nValidation can not continue.", ex.Message);
            }
            catch (Exception ex)
            {
                isValid = false;
                if (!SilentMode)
                {
                    MessageBox.Show(string.Format("{0} \r\n\r\nValidation can not continue.", ex.Message), "Invalid document", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                ErrorMessage = string.Format("{0} \r\n\r\nValidation can not continue.", ex.Message);
            }
            finally
            {
                if (xmlfile != null)
                {
                    xmlfile.Close();
                }
                if (schemaReader != null)
                {
                    schemaReader.Close();
                }
                if (_msSchemaText != null)
                {
                    _msSchemaText.Dispose();
                }
            }

            if (isValid)
            {
                if (!SilentMode)
                {
                    MessageBox.Show("Document is valid", "Document valid", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }

            return(isValid);
        }
コード例 #8
0
        private void bValidate_Click(object sender, RoutedEventArgs e)
        {
            // show start dialog of translation
            StartTranslation st = new StartTranslation();

            System.Windows.Forms.DialogResult dr = st.ShowDialog();
            if (dr != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            Configuration config = new Configuration();

            if (!st.isDefConfigChecked())
            {
                config.Load(st.getConfigFileName());
            }

            if (config == null)
            {
                return;
            }

            XmlSchemaTranslator t = new XmlSchemaTranslator(config, "projectN");  //todo:...

            string       xmlSchemaText = t.Translate(Diagram);
            XmlReader    xmlfile       = null;
            XmlReader    schemaReader  = null;
            MemoryStream _msSchemaText = null;

            isValid = true;
            abort   = false;
            try
            {
                byte[] b = Encoding.Unicode.GetBytes(xmlSchemaText);
                _msSchemaText = new MemoryStream(b);
                schemaReader  = new XmlTextReader(_msSchemaText);
                XmlSchema schema = XmlSchema.Read(schemaReader, schemaSettings_ValidationEventHandler);
                schema.TargetNamespace = Diagram.Project.Schema.XMLNamespaceOrDefaultNamespace;

                XmlReaderSettings schemaSettings = new XmlReaderSettings();
                schemaSettings.Schemas.Add(schema);
                schemaSettings.ValidationType          = ValidationType.Schema;
                schemaSettings.ValidationEventHandler += schemaSettings_ValidationEventHandler;

                try
                {
                    xmlfile = XmlReader.Create(new StringReader(tbDocument.Text), schemaSettings);
                }
                catch (XmlSchemaValidationException ex)
                {
                    isValid = false;
                    MessageBox.Show(string.Format("Validation can not continue - schema is invalid. \r\n\r\n{0}", ex.Message), "Invalid schema", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                if (isValid)
                {
                    while (xmlfile.Read() && !abort)
                    {
                    }
                }
            }
            catch (XmlSchemaValidationException ex)
            {
                isValid = false;
                MessageBox.Show(string.Format("{0} \r\n\r\nValidation can not continue.", ex.Message), "Invalid document", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            catch (Exception ex)
            {
                isValid = false;
                MessageBox.Show(string.Format("{0} \r\n\r\nValidation can not continue.", ex.Message), "Invalid document", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            finally
            {
                if (xmlfile != null)
                {
                    xmlfile.Close();
                }
                if (schemaReader != null)
                {
                    schemaReader.Close();
                }
                if (_msSchemaText != null)
                {
                    _msSchemaText.Dispose();
                }
            }

            if (isValid)
            {
                MessageBox.Show("Document is valid", "Document valid", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }