示例#1
0
        private void Menu_WbApi_Click(object sender, EventArgs e)
        {
            doctype = "WebApi";
            OpenFIle.Multiselect = false;
            OpenFIle.Filter      = "WebApi-json(*.json)|*.json";
            OpenFIle.ShowDialog();
            if (string.IsNullOrEmpty(OpenFIle.FileName))
            {
                MessageBox.Show("未选择文件!");
            }
            else
            {
                string jsonFilePath         = OpenFIle.FileName;
                string jsonContent          = UtilityHelper.ReadFileContent(jsonFilePath);
                List <ApiSeetingModel> Apis = JsonConvert.DeserializeObject <List <ApiSeetingModel> >(jsonContent);
                if (ApiDoc == null || ApiDoc.PageCount == 0)
                {
                    MessageBox.Show("尚未创建相关Api文档,无法进行配置参数导入!");
                }
                else
                {
                    //文档追加表格
                    Section tablesection = ApiDoc.Sections[0];
                    int     n            = 0;
                    foreach (var m in Apis)
                    {
                        n++;
                        Paragraph paragraph = tablesection.AddParagraph();
                        //Paragraph paragraph = tablesection.Paragraphs[0];
                        NewLine(tablesection, paragraph);
                        paragraph.AppendText($"{n}.{m.ApiName}");
                        paragraph.ApplyStyle(BuiltinStyle.Heading2);
                        string[] tableTitle = { "名称", "类型", "长度", "必填", "说明" };
                        NewLine(tablesection, paragraph);
                        //Api描述信息
                        AddText(tablesection, paragraph, "Api名称", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, m.ApiName, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                        //更新时间
                        AddText(tablesection, paragraph, "更新时间", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, m.ApiUpdateTime, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                        //功能介绍
                        AddText(tablesection, paragraph, "功能介绍", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, m.ApiDesc, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                        //Url
                        AddText(tablesection, paragraph, "Url", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, m.Url, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                        //请求方式
                        AddText(tablesection, paragraph, "请求方式", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, m.Method, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                        //编码规范
                        AddText(tablesection, paragraph, "编码规范", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, m.Encoding, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                        //公共请求消息头/消息头(Header)
                        AddText(tablesection, paragraph, "公共请求消息头/消息头(Header)", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, m.RequestHeader, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                        //公共响应消息头/公共响应头域
                        AddText(tablesection, paragraph, "公共响应消息头/公共响应头域", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, m.ResponseHeader, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                        //新增请求头Table
                        AddText(tablesection, paragraph, "额外的请求头", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddTable(tablesection, paragraph, tableTitle, m.RequestExtraHeader);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                        //新增BodyTable
                        AddText(tablesection, paragraph, "Body", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddTable(tablesection, paragraph, tableTitle, m.RequestBodyJson);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                        //新增响应参数Table
                        AddText(tablesection, paragraph, "响应参数", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddTable(tablesection, paragraph, tableTitle, m.ResponseResult);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                    }


                    if (!string.IsNullOrEmpty(CreateDocFile))
                    {
                        //如果未创建其他Api文档,则在程序运行目录下创建文件
                        ApiDoc.SaveToFile(CreateDocFile, FileFormat.Doc);
                        MessageBox.Show("导入成功");
                    }
                    else
                    {
                        //如果未创建其他Api文档,则在程序运行目录下创建文件
                        ApiDoc.SaveToFile($"{DateTime.Now.ToString("yyyyMMddHHmm")}.docx", FileFormat.Doc);
                        MessageBox.Show("导入成功");
                    }
                }
            }
        }
示例#2
0
        private void Menu_Sdk_Click(object sender, EventArgs e)
        {
            doctype = "Sdk";
            OpenFIle.Multiselect = false;
            OpenFIle.Filter      = "Sdk-json文件(*.json)|*.json";
            OpenFIle.ShowDialog();
            if (string.IsNullOrEmpty(OpenFIle.FileName))
            {
                MessageBox.Show("未选择任何Json配置文件");
            }
            else
            {
                if (ApiDoc == null)
                {
                    MessageBox.Show("尚未创建相关Api文档,无法进行配置参数导入!");
                }
                else
                {
                    string jsonFilePath = OpenFIle.FileName;
                    string jsonContent  = UtilityHelper.ReadFileContent(jsonFilePath);
                    List <SdkSettingModel> sdkSettings = JsonConvert.DeserializeObject <List <SdkSettingModel> >(jsonContent);
                    //文档追加表格
                    Section tablesection = ApiDoc.Sections[0];
                    int     n            = 0;
                    foreach (var s in sdkSettings)
                    {
                        n++;
                        Paragraph paragraph = tablesection.AddParagraph();
                        NewLine(tablesection, paragraph);
                        paragraph.AppendText($"{n}.{s.FuncChineseName}");
                        paragraph.ApplyStyle(BuiltinStyle.Heading2);
                        string[] tableTitle = { "名称", "类型", "长度", "必填", "说明" };
                        NewLine(tablesection, paragraph);
                        //函数位置
                        AddText(tablesection, paragraph, "函数位置", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, s.FuncPosition, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);

                        AddText(tablesection, paragraph, "方法名称", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, s.FuncName, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);

                        AddText(tablesection, paragraph, "方法备注", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, s.FuncDesc, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);

                        AddText(tablesection, paragraph, "传入形参", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddTable(tablesection, paragraph, tableTitle, s.InputParams);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);

                        AddText(tablesection, paragraph, "返回结果类型", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, s.ReturnType, FontStyleName);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);

                        AddText(tablesection, paragraph, "返回结果", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddTable(tablesection, paragraph, tableTitle, s.OutParams);
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);

                        AddText(tablesection, paragraph, "备注", TitleStyleName);
                        NewLine(tablesection, paragraph);
                        AddText(tablesection, paragraph, s.ReturnParamsDesc, FontStyleName);
                        //首行缩进
                        paragraph.Format.FirstLineIndent = 30;
                        NewLine(tablesection, paragraph);
                        NewLine(tablesection, paragraph);
                    }
                }
                if (!string.IsNullOrEmpty(CreateDocFile))
                {
                    //如果未创建其他Api文档,则在程序运行目录下创建文件
                    ApiDoc.SaveToFile(CreateDocFile, FileFormat.Doc);
                    MessageBox.Show("导入成功");
                }
                else
                {
                    //如果未创建其他Api文档,则在程序运行目录下创建文件
                    ApiDoc.SaveToFile($"{DateTime.Now.ToString("yyyyMMddHHmm")}.docx", FileFormat.Doc);
                    MessageBox.Show("导入成功");
                }
            }
        }
示例#3
0
 private void LoadFile()
 {
     FileName = OpenFIle.ReadFileName(_dialogService);
     _eventAggregator.GetEvent <LoadFileEvent>().Publish(FileName);
 }