Esempio n. 1
0
        /// <summary>
        /// Load definition section only, for import defined types.
        /// </summary>
        /// <param name="filePath">BinX file to load definitions from</param>
        /// <param name="definitions">Reference to the Definitions class to hold the imported definitions</param>
        public static void loadDefinitions(string filePath, ref DefinitionsNode definitions)
        {
            bool bBinxDoc = false;

            try
            {
                XmlTextReader reader = new XmlTextReader(filePath);
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (bBinxDoc)
                        {
                            if (reader.LocalName.Equals(sDefinitions))
                            {
                                //<definitions>
                                loadDefinitions(reader, ref definitions);
                            }
                        }
                        else if (reader.LocalName.Equals(sBinx))
                        {
                            bBinxDoc = true;
                        }
                    }
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Bad XML file");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Load definition section only, for import defined types.
 /// </summary>
 /// <param name="filePath">BinX file to load definitions from</param>
 /// <param name="definitions">Reference to the Definitions class to hold the imported definitions</param>
 public static void loadDefinitions(string filePath, ref DefinitionsNode definitions)
 {
     bool bBinxDoc = false;
     try
     {
         XmlTextReader reader = new XmlTextReader(filePath);
         while (reader.Read())
         {
             if (reader.NodeType == XmlNodeType.Element)
             {
                 if (bBinxDoc)
                 {
                     if (reader.LocalName.Equals(sDefinitions))
                     {
                         //<definitions>
                         loadDefinitions(reader, ref definitions);
                     }
                 }
                 else if (reader.LocalName.Equals(sBinx))
                 {
                     bBinxDoc = true;
                 }
             }
         }
         reader.Close();
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message, "Bad XML file");
     }
 }
Esempio n. 3
0
 public Document(string sFilePath)
 {
     this.filePath_ = sFilePath;
     dataTypes_     = new DataTypes();
     definitions_   = new DefinitionsNode();
     dataset_       = new DatasetNode();
 }
Esempio n. 4
0
 public Document(string sFilePath)
 {
     this.filePath_ = sFilePath;
     dataTypes_ = new DataTypes();
     definitions_ = new DefinitionsNode();
     dataset_ = new DatasetNode();
 }
Esempio n. 5
0
        /// <summary>
        /// Use parser to load a BinX document and merge all definitions from it. Note there may be duplicate type names after merge.
        /// </summary>
        /// <param name="filepath"></param>
        public void import(string filepath)
        {
            DefinitionsNode exdefs = new DefinitionsNode();

            Parser.loadDefinitions(filepath, ref exdefs);

            foreach (DefineTypeNode tp in exdefs.getDefinitions())
            {
                definitions_.Add(tp);
            }
//			definitions_.AddRange(exdefs.getDefinitions());
        }
Esempio n. 6
0
        /// <summary>
        /// Clear all data elements and create an empty document.
        /// </summary>
        /// <param name="root"></param>
        public void initializeTree(TreeNode root)
        {
            root.Nodes.Clear();
            document_.clear();
            //add definitions section node
            DefinitionsNode dn = document_.getDefinitions();

            root.Nodes.Add(new DataNode(dn));
            DatasetNode dsn = document_.getDataset();

            root.Nodes.Add(new DataNode(dsn));
            root.ExpandAll();
        }
Esempio n. 7
0
        private static string typeNameJustDefined;              //used to check reference to itself

        /// <summary>
        /// Internal validator to validate the BinX grammar and usage. It is used after opening and saving a BinX document. A error window
        /// is popped up with error and warning messages listed for reference.
        /// </summary>
        /// <param name="defset"></param>
        /// <param name="dataset"></param>
        public static void validate(DefinitionsNode defset, DatasetNode dataset)
        {
            ArrayList report = new ArrayList();
            Hashtable defs   = new Hashtable();

            //check definition section
            foreach (DefineTypeNode dt in defset.getDefinitions())
            {
                string sTypeName = dt.getTypeName();
                //check duplicate type definitions
                if (defs.Contains(sTypeName))
                {
                    report.Add("Error: duplicate type name '" + sTypeName + "' at '" + dt.toNodeText() + "'.");
                }
                else
                {
                    defs.Add(sTypeName, sTypeName);
                }
                //check defineType content
                typeNameJustDefined = sTypeName;
                checkComplexType(dt.getBaseType(), defs, report);
            }
            typeNameJustDefined = null;
            if (dataset != null)
            {
                //check dataset section
                if (dataset.getBinaryFileName() == null || dataset.getBinaryFileName().Length < 1)
                {
                    report.Add("Warning: dataset has no binary file attached.");
                }
                if (dataset.getDataset().Count <= 0)
                {
                    report.Add("Warning: dataset has no element.");
                }
                Hashtable varNames = new Hashtable();
                foreach (AbstractNode an in dataset.getDataset())
                {
                    //check for duplicate varNames
                    checkVarNames(an, varNames, report);
                    checkUseType(an, defs, report);
                }
            }
            //show report if any
            if (report.Count > 0)
            {
                formErrors = new FormErrors();
                formErrors.addMessages(report);
                formErrors.Show();
            }
        }
Esempio n. 8
0
        private static string typeNameJustDefined; //used to check reference to itself

        #endregion Fields

        #region Methods

        /// <summary>
        /// Internal validator to validate the BinX grammar and usage. It is used after opening and saving a BinX document. A error window 
        /// is popped up with error and warning messages listed for reference.
        /// </summary>
        /// <param name="defset"></param>
        /// <param name="dataset"></param>
        public static void validate(DefinitionsNode defset, DatasetNode dataset)
        {
            ArrayList report = new ArrayList();
            Hashtable defs = new Hashtable();
            //check definition section
            foreach (DefineTypeNode dt in defset.getDefinitions())
            {
                string sTypeName = dt.getTypeName();
                //check duplicate type definitions
                if (defs.Contains(sTypeName))
                {
                    report.Add("Error: duplicate type name '" + sTypeName + "' at '" + dt.toNodeText() + "'.");
                }
                else
                {
                    defs.Add(sTypeName, sTypeName);
                }
                //check defineType content
                typeNameJustDefined = sTypeName;
                checkComplexType(dt.getBaseType(), defs, report);
            }
            typeNameJustDefined = null;
            if (dataset != null)
            {
                //check dataset section
                if (dataset.getBinaryFileName() == null || dataset.getBinaryFileName().Length < 1)
                {
                    report.Add("Warning: dataset has no binary file attached.");
                }
                if (dataset.getDataset().Count <= 0)
                {
                    report.Add("Warning: dataset has no element.");
                }
                Hashtable varNames = new Hashtable();
                foreach (AbstractNode an in dataset.getDataset())
                {
                    //check for duplicate varNames
                    checkVarNames(an, varNames, report);
                    checkUseType(an, defs, report);
                }
            }
            //show report if any
            if (report.Count > 0)
            {
                formErrors = new FormErrors();
                formErrors.addMessages(report);
                formErrors.Show();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Load definitions section.
        /// </summary>
        /// <param name="reader"></param>
        protected static void loadDefinitions(XmlTextReader reader, ref DefinitionsNode definitions)
        {
            DefineTypeNode ut = null;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.LocalName.Equals("defineType"))
                    {
                        string sTypename = reader.GetAttribute("typeName");
                        ut = new DefineTypeNode(sTypename);
                    }
                    else if (reader.LocalName.Equals("struct") && ut != null)
                    {
                        ut.setBaseType(LoadStruct(reader));
                    }
                    else if (reader.LocalName.Equals("union") && ut != null)
                    {
                        ut.setBaseType(LoadUnion(reader));
                    }
                    else if (reader.LocalName.StartsWith("array") && ut != null)
                    {
                        ut.setBaseType(LoadArray(reader));
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName.Equals("defineType") && ut != null)
                    {
                        definitions.addChild(ut);
                        ut = null;
                    }
                    else if (reader.LocalName.Equals(sDefinitions))
                    {
                        return;
                    }
                }
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Load definitions section.
 /// </summary>
 /// <param name="reader"></param>
 protected static void loadDefinitions(XmlTextReader reader, ref DefinitionsNode definitions)
 {
     DefineTypeNode ut = null;
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.Element)
         {
             if (reader.LocalName.Equals("defineType"))
             {
                 string sTypename = reader.GetAttribute("typeName");
                 ut = new DefineTypeNode(sTypename);
             }
             else if (reader.LocalName.Equals("struct") && ut!=null)
             {
                 ut.setBaseType( LoadStruct(reader) );
             }
             else if (reader.LocalName.Equals("union") && ut!=null)
             {
                 ut.setBaseType( LoadUnion(reader) );
             }
             else if (reader.LocalName.StartsWith("array") && ut!=null)
             {
                 ut.setBaseType( LoadArray(reader) );
             }
         }
         else if (reader.NodeType == XmlNodeType.EndElement)
         {
             if (reader.LocalName.Equals("defineType") && ut!=null)
             {
                 definitions.addChild(ut);
                 ut = null;
             }
             else if (reader.LocalName.Equals(sDefinitions))
             {
                 return;
             }
         }
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Use parser to load a BinX document and merge all definitions from it. Note there may be duplicate type names after merge.
        /// </summary>
        /// <param name="filepath"></param>
        public void import(string filepath)
        {
            DefinitionsNode exdefs = new DefinitionsNode();
            Parser.loadDefinitions(filepath, ref exdefs);

            foreach (DefineTypeNode tp in exdefs.getDefinitions())
            {
                definitions_.Add(tp);
            }
            //			definitions_.AddRange(exdefs.getDefinitions());
        }
Esempio n. 12
0
 public Document()
 {
     dataTypes_ = new DataTypes();
     definitions_ = new DefinitionsNode();
     dataset_ = new DatasetNode();
 }
Esempio n. 13
0
 public Document()
 {
     dataTypes_   = new DataTypes();
     definitions_ = new DefinitionsNode();
     dataset_     = new DatasetNode();
 }