Esempio n. 1
0
        private void CopySchema(string source, string destDir, List <String> files)
        {
            if (files.Contains(source))
            {
                return;
            }
            files.Add(source);

            // Copy to output
            lblStatus.Text = String.Format("Copy '{0}'->'{1}\\{0}'", Path.GetFileName(source), destDir);
            Application.DoEvents();
            File.Copy(source, Path.Combine(destDir, Path.GetFileName(source)), true);

            // Copy dependencies
            Stream fs = null;

            try
            {
                fs = File.OpenRead(source);
                XmlSchema xsd = XmlSchema.Read(fs, new ValidationEventHandler(delegate(object o, ValidationEventArgs e1)
                {
                    System.Diagnostics.Trace.WriteLine(e1.Message);
                }));
                fs.Close();

                // Process includes
                foreach (object xsi in xsd.Includes)
                {
                    if (xsi is XmlSchemaInclude)
                    {
                        CopySchema(Path.Combine(Path.GetDirectoryName(source), (xsi as XmlSchemaInclude).SchemaLocation), destDir, files);
                    }
                    else if (xsi is XmlSchemaImport &&
                             (xsi as XmlSchemaImport).SchemaLocation != null)
                    {
                        CopySchema(Path.Combine(Path.GetDirectoryName(source), (xsi as XmlSchemaImport).SchemaLocation), destDir, files);
                    }
                }
            }
            catch (Exception ex)
            {
                frmErrorDialog dlg = new frmErrorDialog();
                dlg.Message = ex.Message;
                dlg.Details = ex.ToString();
                dlg.ShowDialog();
                return;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Load an XmlSchemaSet object
        /// </summary>
        private MohawkCollege.EHR.Util.SimpleXSD.XmlSchemaSet LoadSchemaSet(string fileName)
        {
            List <KeyValuePair <String, XmlSeverityType> > parseErrors = new List <KeyValuePair <String, XmlSeverityType> >();

            MohawkCollege.EHR.Util.SimpleXSD.XmlSchemaSet retVal = new MohawkCollege.EHR.Util.SimpleXSD.XmlSchemaSet();
            retVal.Loading += new XmlSchemaLoadingHandler(retVal_Loading);
            // Read
            retVal.Add(fileName);
            retVal.Load();

            // Any parsing errors or warnings?
            if (parseErrors.Count > 0)
            {
                frmErrorDialog dlg = new frmErrorDialog();
                dlg.Message = String.Format(CultureInfo.CurrentCulture, "Encountered '{0}' warnings and errors processing schema '{1}'...", parseErrors.Count, Path.GetFileName(fileName));
                foreach (KeyValuePair <String, XmlSeverityType> kv in parseErrors)
                {
                    dlg.Details += String.Format("{0}: {1}\r\n", kv.Value, kv.Key);
                }
                dlg.ShowDialog();
            }

            return(retVal);
        }
Esempio n. 3
0
        public void Compare()
        {
            this.Cursor = Cursors.AppStarting;

            try
            {
                Status = new KeyValuePair <string, int>("Comparing schemas...", 0);

                // The main diff tree
                DiffBuilder builder = new DiffBuilder();
                builder.Comparing += new XmlSchemaLoadingHandler(delegate(object sender, float perc)
                {
                    if (StatusChanged != null)
                    {
                        StatusChanged(this, new StatusChangedEventArgs()
                        {
                            Text = "Comparing schemas...", Progress = (int)(perc * 100)
                        });
                    }
                });
                schemaSet1 = LoadSchemaSet(schema1);
                schemaSet2 = LoadSchemaSet(schema2);
                DiffTree differenceTree = builder.BuildTree(schemaSet1, schemaSet2);

                // SEt the initial schema elemnts
                schemaObjectA.SchemaObject = schemaSet1.Elements[0];
                schemaObjectB.SchemaObject = schemaSet2.Elements[0];
                schemaObjectA.Title        = schema1;
                schemaObjectB.Title        = schema2;

                // Draw the difference tree
                trvOverview.Nodes.Clear();

                // Add the nodes
                TreeNode node = trvOverview.Nodes.Add("root", "Comparison Summary", "root", "root");
                node.Tag = differenceTree;
                ShowDiffTreeNodes(differenceTree.Nodes, node, "/");
                //trvOverview.Nodes[0].Expand();

                Status = new KeyValuePair <string, int>("Comparison Complete...", 100);

                if (differenceTree.CountDifferences() == 0)
                {
                    throw new NoDifferenceException();
                }
            }
            catch (NoDifferenceException e)
            {
                Status = new KeyValuePair <string, int>("Identical schemas encountered.", 0);

                if (MessageBox.Show(
                        String.Format("The schemas '{0}' and '{1}' are identical in structure. Do you still want to see the summary?", schema1, schema2),
                        "Identical Schemas", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.No)
                {
                    throw;
                }
            }
            catch (Exception e)
            {
                frmErrorDialog dlg = new frmErrorDialog();
                dlg.Message = "Could not complete comparison";
                dlg.Details = e.ToString();
                dlg.ShowDialog();
                Status = new KeyValuePair <string, int>("Error occured", 0);
                throw;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }