예제 #1
0
        public void InsertApi(ApiInterfaceInfo info)
        {
            if (info.ActionName == null)
            {
                info.ActionName = string.Empty;
            }
            if (info.ApiName == null)
            {
                info.ApiName = string.Empty;
            }
            if (info.ApiCode == null)
            {
                info.ApiCode = string.Empty;
            }
            if (info.ActionRoute == null)
            {
                info.ActionRoute = string.Empty;
            }
            if (string.IsNullOrEmpty(info.SID))
            {
                info.SID = Guid.NewGuid().ToString("N");
            }


            db.Insert(info);
        }
예제 #2
0
        /// <summary>
        /// generate csharp code
        /// </summary>
        /// <param name="apiData"></param>
        private void GenerateController(ApiInterfaceInfo apiData)
        {
            try
            {
                apiData.Project = this.Project;
                //创建RequestBody
                var razor = new TemplateBuilder <object>(
                    AppDomain.CurrentDomain.BaseDirectory + "/templates/request_body.txt",
                    apiData,
                    Project.Namespace,
                    Project.Version,
                    Path.Combine(apiData.ApiCode, apiData.ActionName, apiData.ActionName + "RequestModel.cs"));
                razor.Render();


                ////创建responseBody
                razor = new TemplateBuilder <object>(
                    AppDomain.CurrentDomain.BaseDirectory + "/templates/response_body.txt",
                    apiData,
                    Project.Namespace,
                    Project.Version,
                    Path.Combine(apiData.ApiCode, apiData.ActionName, apiData.ActionName + "ResponseModel.cs"));
                razor.Render();

                //创建service
                razor = new TemplateBuilder <object>(
                    AppDomain.CurrentDomain.BaseDirectory + "/templates/controller.txt",
                    apiData,
                    Project.Namespace,
                    Project.Version,
                    Path.Combine(apiData.ApiCode, apiData.ActionName, apiData.ActionName + ".cs"));
                razor.Render();


                //创建构造函数
                razor = new TemplateBuilder <object>(
                    AppDomain.CurrentDomain.BaseDirectory + "/templates/constructor.txt",
                    apiData,
                    Project.Namespace,
                    Project.Version,
                    Path.Combine(apiData.ApiCode, apiData.ApiCode + "Controller.cs"));
                razor.Render(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.ToString());
                //Application.Exit();
            }
        }
예제 #3
0
        public void BindData()
        {
            if (this.ApiData != null && this.ApiData.IsResultPaging)
            {
                this.chkPaging.Checked = true;
            }
            else
            {
                this.chkPaging.Checked = false;
            }


            if (this.ApiData == null)
            {
                this.ApiData = new ApiInterfaceInfo();

                this.ApiData.RequestBodys  = new List <RequestBodyInfo>();
                this.ApiData.ResponseBodys = new List <ResponseBodyInfo>();

                this.ApiData.RequestBodys.Add(new RequestBodyInfo());
                this.ApiData.ResponseBodys.Add(new ResponseBodyInfo());
                this.chkBool.Checked = false;
                this.chkInt.Checked  = false;
                this.chkList.Checked = false;
                this.tbActionMethod.SelectedIndex = 0;
            }
            else
            {
                this.tbName.Text       = this.ApiData.ApiName;
                this.chkLogin.Checked  = this.ApiData.IsAuthorize;
                this.tbApiCode.Text    = this.ApiData.ApiCode;
                this.tbActionName.Text = this.ApiData.ActionName;
                if (string.IsNullOrEmpty(this.ApiData.ActionMethod))
                {
                    this.tbActionMethod.SelectedIndex = 0;
                }
                else
                {
                    this.tbActionMethod.SelectedItem = this.ApiData.ActionMethod;
                }
                this.tbRoute.Text = this.ApiData.ActionRoute;

                this.chkBool.Checked   = this.ApiData.IsResultBool;
                this.chkInt.Checked    = this.ApiData.IsResultInt;
                this.chkList.Checked   = this.ApiData.IsList;
                this.chkPaging.Checked = this.ApiData.IsResultPaging;
            }
        }
예제 #4
0
        public FormApi(ProjectInfo project, Form opener, ApiInterfaceInfo apiInterface = null)
        {
            InitializeComponent();
            this.ProjectData = project;
            this.openerForm  = opener;

            if (apiInterface != null)
            {
                this.ApiData = apiInterface;
            }

            this.BindData();

            this.BindRequestBody();

            this.BindResponseBody();
        }
예제 #5
0
        /// <summary>
        /// 删除ApiInterfaceInfo
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int DeleteApi(ApiInterfaceInfo info)
        {
            int rows = 0;

            try
            {
                db.BeginTransaction();

                rows += db.Delete <RequestBodyInfo>("WHERE `RelationSID` = @0", info.SID);
                rows += db.Delete <ResponseBodyInfo>("WHERE `RelationSID` = @0", info.SID);
                rows += db.Delete <ApiInterfaceInfo>("WHERE `SID` = @0", info.SID);

                db.CompleteTransaction();
            }
            catch (Exception e)
            {
                db.AbortTransaction();
            }
            return(rows);
        }
예제 #6
0
 /// <summary>
 /// 更新ApiInterfaceInfo
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 public int SaveApi(ApiInterfaceInfo info)
 {
     return(db.Update(info));
 }