예제 #1
0
 public Document(string sFilePath)
 {
     this.filePath_ = sFilePath;
     dataTypes_ = new DataTypes();
     definitions_ = new DefinitionsNode();
     dataset_ = new DatasetNode();
 }
예제 #2
0
 public Document(string sFilePath)
 {
     this.filePath_ = sFilePath;
     dataTypes_     = new DataTypes();
     definitions_   = new DefinitionsNode();
     dataset_       = new DatasetNode();
 }
예제 #3
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();
        }
예제 #4
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();
            }
        }
예제 #5
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();
            }
        }
예제 #6
0
파일: Parser.cs 프로젝트: tedwen/binxeditor
 /// <summary>
 /// Load dataset section from BinX document.
 /// </summary>
 /// <param name="reader"></param>
 protected static void loadDataset(XmlTextReader reader, ref DatasetNode dataset)
 {
     dataset.setBinaryFileName(reader.GetAttribute("src"));
     dataset.setBigEndian(reader.GetAttribute("byteOrder").Equals("bigEndian"));
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.Element)
         {
             AbstractNode it = ParseNode(reader);
             dataset.addChild(it);
         }
         else if (reader.NodeType == XmlNodeType.EndElement)
         {
             if (reader.LocalName.Equals("dataset"))
             {
                 return;
             }
         }
     }
 }
예제 #7
0
파일: Parser.cs 프로젝트: tedwen/binxeditor
        /// <summary>
        /// Parse a BinX document from a file and save extracted definitions and data elements in the given containers.
        /// </summary>
        /// <param name="filePath">File path and name to parse</param>
        /// <param name="definitions">Container object reference for definitions</param>
        /// <param name="dataset">Container object reference for dataset elements</param>
        /// <returns>true if successful</returns>
        public static bool load(string filePath, ref DefinitionsNode definitions, ref DatasetNode dataset)
        {
            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(sDataset))
                            {
                                //<dataset>
                                loadDataset(reader, ref dataset);
                            }
                        }
                        else if (reader.LocalName.Equals(sBinx))
                        {
                            bBinxDoc = true;
                        }
                    }
                }
                reader.Close();
                return(true);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Bad XML file");
                return(false);
            }
        }
예제 #8
0
파일: Parser.cs 프로젝트: tedwen/binxeditor
 /// <summary>
 /// Parse a BinX document from a file and save extracted definitions and data elements in the given containers.
 /// </summary>
 /// <param name="filePath">File path and name to parse</param>
 /// <param name="definitions">Container object reference for definitions</param>
 /// <param name="dataset">Container object reference for dataset elements</param>
 /// <returns>true if successful</returns>
 public static bool load(string filePath, ref DefinitionsNode definitions, ref DatasetNode dataset)
 {
     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(sDataset))
                     {
                         //<dataset>
                         loadDataset(reader, ref dataset);
                     }
                 }
                 else if (reader.LocalName.Equals(sBinx))
                 {
                     bBinxDoc = true;
                 }
             }
         }
         reader.Close();
         return true;
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message, "Bad XML file");
         return false;
     }
 }
예제 #9
0
파일: Parser.cs 프로젝트: tedwen/binxeditor
 /// <summary>
 /// Load dataset section from BinX document.
 /// </summary>
 /// <param name="reader"></param>
 protected static void loadDataset(XmlTextReader reader, ref DatasetNode dataset)
 {
     dataset.setBinaryFileName(reader.GetAttribute("src"));
     dataset.setBigEndian(reader.GetAttribute("byteOrder").Equals("bigEndian"));
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.Element)
         {
             AbstractNode it = ParseNode(reader);
             dataset.addChild(it);
         }
         else if (reader.NodeType==XmlNodeType.EndElement)
         {
             if (reader.LocalName.Equals("dataset"))
             {
                 return;
             }
         }
     }
 }
예제 #10
0
 public Document()
 {
     dataTypes_ = new DataTypes();
     definitions_ = new DefinitionsNode();
     dataset_ = new DatasetNode();
 }
예제 #11
0
 public Document()
 {
     dataTypes_   = new DataTypes();
     definitions_ = new DefinitionsNode();
     dataset_     = new DatasetNode();
 }