예제 #1
0
 public void Dispose()
 {
     if (this.descriptor != null)
     {
         this.descriptor = null;
     }
 }
        public override void Dispose()
        {
            this.newLineStr = "";

            this.reader = "";
            if (this.descriptor != null)
            {
                this.descriptor = null;
            }
        }
        public override bool Generate(
            TableDescriptor descriptor, string reader,
            string outputDir, NewLineType newLineType)
        {
            this.descriptor = descriptor;
            this.reader     = reader;

            if (newLineType == NewLineType.Dos)
            {
                this.newLineStr = "\r\n";
            }
            else
            {
                this.newLineStr = "\n";
            }

            for (int i = 0; i < this.descriptor.GlobalStructs.Count; ++i)
            {
                TableDescriptor.StructDef def =
                    this.descriptor.GlobalStructs[i];

                string filePath = Path.Combine(
                    outputDir, def.Name + ".cs");
                string fileContent = GenerateGlobalStructFile(def);
                try {
                    File.WriteAllText(filePath, fileContent);
                } catch (Exception e) {
                    Console.Error.WriteLine(string.Format(
                                                "error: write file {0} failed: {1}",
                                                filePath, e.Message));
                    return(false);
                }
            }

            for (int i = 0; i < this.descriptor.Tables.Count; ++i)
            {
                TableDescriptor.TableDef def = this.descriptor.Tables[i];

                string filePath = Path.Combine(
                    outputDir, def.Name + ".cs");
                string fileContent = GenerateTableFile(def);
                try {
                    File.WriteAllText(filePath, fileContent);
                } catch (Exception e) {
                    Console.Error.WriteLine(string.Format(
                                                "error: write file {0} failed: {1}",
                                                filePath, e.Message));
                    return(false);
                }
            }

            return(true);
        }
예제 #4
0
 public abstract bool Generate(
     TableDescriptor descriptor, string reader,
     string outputDir, NewLineType newLineType);
예제 #5
0
        public bool Parse(string defineFilePath)
        {
            this.descriptor = new TableDescriptor();

            XDocument xmlDoc = null;

            try {
                this.descriptor.FilePath = Path.GetFullPath(defineFilePath);
                xmlDoc = XDocument.Load(
                    this.descriptor.FilePath, LoadOptions.SetLineInfo);
            } catch (Exception e) {
                Console.Error.WriteLine(string.Format(
                                            "error: can not load define file `{0}`: {1}",
                                            defineFilePath, e.Message));
                return(false);
            }

            // check root node name
            if (xmlDoc.Root.Name != "define")
            {
                PrintLineError(xmlDoc.Root,
                               "root node must be `define` node");
                return(false);
            }

            // parse readers
            {
                IEnumerator <XElement> iter = xmlDoc.XPathSelectElements(
                    "/define/reader").GetEnumerator();
                while (iter.MoveNext())
                {
                    XElement element = iter.Current;

                    if (AddReaderDef(element) == false)
                    {
                        return(false);
                    }
                }
            }

            // parse global structs
            {
                IEnumerator <XElement> iter = xmlDoc.XPathSelectElements(
                    "/define/struct").GetEnumerator();
                while (iter.MoveNext())
                {
                    XElement element = iter.Current;

                    if (AddStructDef(null, element) == false)
                    {
                        return(false);
                    }
                }
            }

            // parse tables
            {
                IEnumerator <XElement> iter = xmlDoc.XPathSelectElements(
                    "/define/table").GetEnumerator();
                while (iter.MoveNext())
                {
                    XElement element = iter.Current;

                    if (AddTableDef(element) == false)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }