コード例 #1
0
        public static List <ProtoSpecModule> GetModuleList(bool isConsole)
        {
            try
            {
#if DEBUG
                string protoSpecDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\..\\..\\server-new\\doc\\通讯协议"));
#else
                string protoSpecDir = Path.Combine(Environment.CurrentDirectory, "server-new\\doc\\通讯协议");
#endif
                protoSpecDir = FixPath(protoSpecDir);

                List <ProtoSpecModule> moduleList = new List <ProtoSpecModule>();

                string protocol = null;

                string[] files = Directory.GetFiles(protoSpecDir);

                foreach (string file in files)
                {
                    if (Path.GetFileNameWithoutExtension(file) == "Readme")
                    {
                        continue;
                    }

                    protocol += File.ReadAllText(file, Encoding.UTF8);
                }

                ProtoSpecParser parser = new ProtoSpecParser(protocol, 0);

                ProtoSpecDocument document = parser.Parse();

                foreach (ProtoSpecModule module in document.Modules)
                {
                    moduleList.Add(module);
                }

                return(moduleList);
            }
            catch (Exception ex)
            {
                Error(ex.Message);
            }

            return(null);
        }
コード例 #2
0
        //private Dictionary<string, ProtoSpecAction> actionDict = null;

        public void ParseProtoSpec(bool reload)
        {
            if (isProtoSpecParsed && reload != true)
            {
                return;
            }

            try
            {
//				actionDict = new Dictionary<string, ProtoSpecAction>();

                                #if DEBUG
                string protoSpecDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\..\\..\\server-new\\doc\\通讯协议"));
                                #else
                string protoSpecDir = Path.Combine(Environment.CurrentDirectory, "server-new\\doc\\通讯协议");
                                #endif

                treeView1.Nodes.Clear();

                string protocol = null;

                string[] files = Directory.GetFiles(protoSpecDir);

                foreach (string file in files)
                {
                    if (Path.GetFileNameWithoutExtension(file) == "Readme")
                    {
                        continue;
                    }

                    protocol += File.ReadAllText(file, Encoding.UTF8);
                }

                ProtoSpecParser parser = new ProtoSpecParser(protocol, 0);

                ProtoSpecDocument document = parser.Parse();

                foreach (ProtoSpecModule module in document.Modules)
                {
                    TreeNode moduleNode = treeView1.Nodes.Add(module.Name + " = " + module.ModuleId);

                    foreach (ProtoSpecAction action in module.Actions)
                    {
                        TreeNode actionNode = moduleNode.Nodes.Add(action.Name + " = " + action.ActionId);

                        actionNode.Tag = action;
                        actionNode.ContextMenuStrip = contextMenuStrip1;

                        //actionDict.Add(actionNode.FullPath, action);

                        TreeNode inputNode = actionNode.Nodes.Add("in");

                        ProtoSpecSubsetTree(module, action, inputNode, action.Input);

                        TreeNode outputNode = actionNode.Nodes.Add("out");

                        ProtoSpecSubsetTree(module, action, outputNode, action.Output);
                    }
                }

                protoSpecDocument = document;

                isProtoSpecParsed = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }