Beispiel #1
0
 public bool CheckUpdateQuantityParameters(SortedDictionary <string, string> parameters, out int num_iid, out int quantity, out int type, out string result)
 {
     num_iid  = 0;
     quantity = 0;
     type     = 1;
     if (!OpenApiHelper.CheckSystemParameters(parameters, this.site.AppKey, out result))
     {
         return(false);
     }
     if (!int.TryParse(parameters["num_iid"], out num_iid))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "num_iid");
         return(false);
     }
     if (!int.TryParse(parameters["quantity"], out quantity))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "quantity");
         return(false);
     }
     if (!int.TryParse(parameters["type"], out type))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "type");
         return(false);
     }
     return(true);
 }
Beispiel #2
0
 private bool CheckChangLogisticsParameters(SortedDictionary <string, string> parameters, ref string result)
 {
     if (!OpenApiHelper.CheckSystemParameters(parameters, this.site.AppKey, out result))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["tid"])))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Missing_Required_Arguments, "tid");
         return(false);
     }
     if (string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["company_name"])))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Missing_Required_Arguments, "company_name");
         return(false);
     }
     if (!ExpressHelper.IsExitExpress(DataHelper.CleanSearchString(parameters["company_name"])))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Company_not_Exists, "company_name");
         return(false);
     }
     if (string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["out_sid"])))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Missing_Required_Arguments, "out_sid");
         return(false);
     }
     if (DataHelper.CleanSearchString(parameters["out_sid"]).Length > 20)
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Out_Sid_Too_Long, "out_sid");
         return(false);
     }
     return(true);
 }
Beispiel #3
0
        public void TestMethod1()
        {
            var apiHelper = new OpenApiHelper(@"c:\temp\keap_swagger.json");
            var tags      = apiHelper.GetTagNames();

            foreach (var tag in tags)
            {
            }
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sortedParams = OpenApiHelper.GetSortedParams(this.Context);
            string result = string.Empty;

            this.UpdateProductQuantity(sortedParams, ref result);
            base.Response.ContentType = "text/json";
            base.Response.Write(result);
            base.Response.End();
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sortedParams = OpenApiHelper.GetSortedParams(this.Context);
            string results = string.Empty;

            this.GetIncrementSoldTrades(sortedParams, ref results);
            base.Response.ContentType = "text/json";
            base.Response.Write(results);
            base.Response.End();
        }
Beispiel #6
0
 private static OpenApiOperation CreateOperation(
     SwaggerAggregateRoute aggregateRoute,
     IEnumerable <RouteDocs> routesDocs,
     Response response) => new OpenApiOperation()
 {
     Tags        = GetTags(routesDocs),
     Summary     = GetSummary(routesDocs),
     Description = GetDescription(aggregateRoute, routesDocs),
     Responses   = OpenApiHelper.Responses(response),
     Parameters  = GetParameters(routesDocs)
 };
Beispiel #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sortedParams = OpenApiHelper.GetSortedParams(this.Context);
            string results = string.Empty;

            this.GetSoldTrades(sortedParams, ref results);
            base.Response.ContentType = "text/json";
            Globals.Debuglog(base.Request.Url.ToString() + "||" + Globals.SubStr(results, 200, "------------结束"), "_DebugERP.txt");
            base.Response.Write(results);
            base.Response.End();
        }
Beispiel #8
0
 private bool CheckTradesParameters(SortedDictionary <string, string> parameters, ref string results)
 {
     if (!OpenApiHelper.CheckSystemParameters(parameters, this.site.AppKey, out results))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["tid"])))
     {
         results = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Missing_Required_Arguments, "tid");
         return(false);
     }
     return(true);
 }
Beispiel #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddJsonOptions(o => o.SerializerSettings.DateFormatString = "yyyy-MM-dd");

            services.AddOpenApiDocument(OpenApiHelper.GetOpenApiDocumentSettings());

            services.AddCors();

            services.RegisterServiceDependencies();
            services.RegisterInfrastructureDependencies(Configuration);
        }
Beispiel #10
0
 public bool CheckProductParameters(System.Collections.Generic.SortedDictionary <string, string> parameters, out int num_iid, out string result)
 {
     num_iid = 0;
     if (!OpenApiHelper.CheckSystemParameters(parameters, this.site.AppKey, out result))
     {
         return(false);
     }
     if (!int.TryParse(parameters["num_iid"], out num_iid))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "num_iid");
         return(false);
     }
     return(true);
 }
Beispiel #11
0
 public bool CheckUpdateApproveStatusParameters(System.Collections.Generic.SortedDictionary <string, string> parameters, out int num_iid, out string status, out string result)
 {
     num_iid = 0;
     status  = string.Empty;
     if (!OpenApiHelper.CheckSystemParameters(parameters, this.site.AppKey, out result))
     {
         return(false);
     }
     if (!int.TryParse(parameters["num_iid"], out num_iid))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "num_iid");
         return(false);
     }
     status = DataHelper.CleanSearchString(parameters["approve_status"]);
     if (status != "On_Sale" && status != "Un_Sale" && status != "In_Stock")
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Product_Status_is_Invalid, "approve_status");
         return(false);
     }
     return(true);
 }
        private bool CheckUpdateTradeMemoParameters(SortedDictionary <string, string> parameters, out int flag, ref string result)
        {
            flag = 0;
            if (!OpenApiHelper.CheckSystemParameters(parameters, this.site.AppKey, out result))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["tid"])))
            {
                result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Missing_Required_Arguments, "tid");
                return(false);
            }
            if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["flag"])))
            {
                if (!int.TryParse(DataHelper.CleanSearchString(parameters["flag"]), out flag))
                {
                    result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "flag");
                    return(false);
                }
                if ((flag < 1) || (flag > 6))
                {
                    result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Trade_Flag_Too_Long, "flag");
                    return(false);
                }
            }
            if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["memo"])) && (DataHelper.CleanSearchString(parameters["memo"]).Length > 300))
            {
                result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Trade_Memo_Too_Long, "memo");
                return(false);
            }
            Regex regex = new Regex("^(?!_)(?!.*?_$)(?!-)(?!.*?-$)[a-zA-Z0-9._一-龥-]+$");

            if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["memo"])) && !regex.IsMatch(DataHelper.CleanSearchString(parameters["memo"])))
            {
                result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "memo");
                return(false);
            }
            return(true);
        }
Beispiel #13
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            System.Collections.Generic.SortedDictionary <string, string> sortedParams = OpenApiHelper.GetSortedParams(this.Context);
            string empty = string.Empty;

            this.UpdateProductApproveStatus(sortedParams, ref empty);
            base.Response.ContentType = "text/json";
            base.Response.Write(empty);
            base.Response.End();
        }
Beispiel #14
0
 private bool CheckIncrementSoldTradesParameters(System.Collections.Generic.SortedDictionary <string, string> parameters, out System.DateTime start_modified, out System.DateTime end_modified, out string status, out int page_no, out int page_size, ref string result)
 {
     start_modified = System.DateTime.Now;
     end_modified   = System.DateTime.Now;
     page_size      = 10;
     page_no        = 1;
     status         = DataHelper.CleanSearchString(parameters["status"]);
     if (!OpenApiHelper.CheckSystemParameters(parameters, this.site.AppKey, out result))
     {
         return(false);
     }
     if (!string.IsNullOrWhiteSpace(status) && status != "WAIT_BUYER_PAY" && status != "WAIT_SELLER_SEND_GOODS " && status != "WAIT_BUYER_CONFIRM_GOODS" && status != "TRADE_CLOSED" && status != "TRADE_FINISHED")
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Trade_Status_is_Invalid, "status");
         return(false);
     }
     if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_size"])) && !int.TryParse(parameters["page_size"].ToString(), out page_size))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "page_size");
         return(false);
     }
     if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_size"])) && (page_size <= 0 || page_size > 100))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Page_Size_Too_Long, "page_size");
         return(false);
     }
     if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_no"])) && !int.TryParse(parameters["page_no"].ToString(), out page_no))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "page_no");
         return(false);
     }
     if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_no"])) && page_no <= 0)
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Page_Size_Too_Long, "page_no");
         return(false);
     }
     if (string.IsNullOrEmpty(parameters["start_modified"]))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Missing_Required_Arguments, "start_modified");
         return(false);
     }
     if (!OpenApiHelper.IsDate(parameters["start_modified"]))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Invalid_Timestamp, "start_modified");
         return(false);
     }
     System.DateTime.TryParse(parameters["start_modified"], out start_modified);
     if (start_modified > System.DateTime.Now)
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_Start_Now, "start_modified and currenttime");
         return(false);
     }
     if (string.IsNullOrEmpty(parameters["end_modified"]))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Missing_Required_Arguments, "end_modified");
         return(false);
     }
     if (!OpenApiHelper.IsDate(parameters["end_modified"]))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Invalid_Timestamp, "end_modified");
         return(false);
     }
     System.DateTime.TryParse(parameters["end_modified"], out end_modified);
     if (start_modified > end_modified)
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_Start_End, "start_modified and end_modified");
         return(false);
     }
     if ((end_modified - start_modified).TotalDays > 1.0)
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_StartModified_AND_EndModified, "start_modified and end_modified");
         return(false);
     }
     if (end_modified > System.DateTime.Now)
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_End_Now, "end_modified and currenttime");
         return(false);
     }
     return(true);
 }
Beispiel #15
0
 public bool CheckSoldProductsParameters(System.Collections.Generic.SortedDictionary <string, string> parameters, out System.DateTime?start_modified, out System.DateTime?end_modified, out string status, out int page_no, out int page_size, out string result)
 {
     start_modified = null;
     end_modified   = null;
     status         = string.Empty;
     page_no        = 1;
     page_size      = 10;
     if (!OpenApiHelper.CheckSystemParameters(parameters, this.site.AppKey, out result))
     {
         return(false);
     }
     status = DataHelper.CleanSearchString(parameters["approve_status"]);
     if (!string.IsNullOrWhiteSpace(status) && status != "On_Sale" && status != "Un_Sale" && status != "In_Stock")
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Product_Status_is_Invalid, "approve_status");
         return(false);
     }
     if (!string.IsNullOrEmpty(parameters["start_modified"]) && !OpenApiHelper.IsDate(parameters["start_modified"]))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Invalid_Timestamp, "start_modified");
         return(false);
     }
     if (!string.IsNullOrEmpty(parameters["end_modified"]) && !OpenApiHelper.IsDate(parameters["end_modified"]))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Invalid_Timestamp, "end_modified");
         return(false);
     }
     if (!string.IsNullOrEmpty(parameters["start_modified"]))
     {
         System.DateTime dateTime;
         System.DateTime.TryParse(parameters["start_modified"], out dateTime);
         start_modified = new System.DateTime?(dateTime);
         if (dateTime > System.DateTime.Now)
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_Start_Now, "start_modified and currenttime");
             return(false);
         }
         if (!string.IsNullOrEmpty(parameters["end_modified"]))
         {
             System.DateTime dateTime2;
             System.DateTime.TryParse(parameters["end_modified"], out dateTime2);
             end_modified = new System.DateTime?(dateTime2);
             if (dateTime > dateTime2)
             {
                 result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_Start_End, "start_modified and end_created");
                 return(false);
             }
             if (dateTime2 > System.DateTime.Now)
             {
                 result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_End_Now, "end_modified and currenttime");
                 return(false);
             }
         }
     }
     else if (!string.IsNullOrEmpty(parameters["end_modified"]))
     {
         System.DateTime dateTime2;
         System.DateTime.TryParse(parameters["end_modified"], out dateTime2);
         if (dateTime2 > System.DateTime.Now)
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_End_Now, "end_modified and currenttime");
             return(false);
         }
     }
     if (!string.IsNullOrEmpty(parameters["order_by"]))
     {
         if (parameters["order_by"].Split(new char[]
         {
             ':'
         }).Length != 2)
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Invalid_Format, "order_by");
             return(false);
         }
         string[] array = parameters["order_by"].Split(new char[]
         {
             ':'
         });
         string text = DataHelper.CleanSearchString(array[0]);
         string a    = DataHelper.CleanSearchString(array[1]);
         if (string.IsNullOrEmpty(text))
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Invalid_Format, "order_by");
             return(false);
         }
         if (text != "display_sequence" || text != "create_time" || text != "sold_quantity")
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Invalid_Format, "order_by");
             return(false);
         }
         if (a != "desc" || a != "asc")
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Invalid_Format, "order_by");
             return(false);
         }
     }
     if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_size"])) && !int.TryParse(parameters["page_size"].ToString(), out page_size))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "page_size");
         return(false);
     }
     if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_size"])) && (page_size <= 0 || page_size > 100))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Page_Size_Too_Long, "page_size");
         return(false);
     }
     if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_no"])) && !int.TryParse(parameters["page_no"].ToString(), out page_no))
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "page_no");
         return(false);
     }
     if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_no"])) && page_no <= 0)
     {
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Page_Size_Too_Long, "page_no");
         return(false);
     }
     return(true);
 }
Beispiel #16
0
 private bool CheckSoldTradesParameters(SortedDictionary <string, string> parameters, out DateTime?start_time, out DateTime?end_time, out string status, out int page_no, out int page_size, ref string result)
 {
     start_time = new DateTime?();
     end_time   = new DateTime?();
     page_size  = 10;
     page_no    = 1;
     status     = DataHelper.CleanSearchString(parameters["status"]);
     if (OpenApiHelper.CheckSystemParameters(parameters, this.site.AppKey, out result))
     {
         DateTime time2;
         if (!string.IsNullOrEmpty(parameters["start_created"]) && !OpenApiHelper.IsDate(parameters["start_created"]))
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Invalid_Timestamp, "start_created");
             return(false);
         }
         if (!string.IsNullOrEmpty(parameters["end_created"]) && !OpenApiHelper.IsDate(parameters["end_created"]))
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Invalid_Timestamp, "end_created");
             return(false);
         }
         if (!string.IsNullOrEmpty(parameters["start_created"]))
         {
             DateTime time;
             DateTime.TryParse(parameters["start_created"], out time);
             start_time = new DateTime?(time);
             if (time > DateTime.Now)
             {
                 result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_Start_Now, "start_created and currenttime");
                 return(false);
             }
             if (!string.IsNullOrEmpty(parameters["end_created"]))
             {
                 DateTime.TryParse(parameters["end_created"], out time2);
                 end_time = new DateTime?(time2);
                 if (time > time2)
                 {
                     result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_Start_End, "start_created and end_created");
                     return(false);
                 }
                 if (time2 > DateTime.Now)
                 {
                     result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_End_Now, "end_created and currenttime");
                     return(false);
                 }
             }
         }
         else if (!string.IsNullOrEmpty(parameters["end_created"]))
         {
             DateTime.TryParse(parameters["end_created"], out time2);
             if (time2 > DateTime.Now)
             {
                 result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Time_End_Now, "end_created and currenttime");
                 return(false);
             }
         }
         if (((!string.IsNullOrWhiteSpace(status) && (status != "WAIT_BUYER_PAY")) && ((status != "WAIT_SELLER_SEND_GOODS") && (status != "WAIT_BUYER_CONFIRM_GOODS"))) && ((status != "TRADE_CLOSED") && (status != "TRADE_FINISHED")))
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Trade_Status_is_Invalid, "status");
             return(false);
         }
         if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_no"])) && !int.TryParse(parameters["page_no"].ToString(), out page_no))
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "page_no");
             return(false);
         }
         if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_no"])) && (page_no <= 0))
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Page_Size_Too_Long, "page_no");
             return(false);
         }
         if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_size"])) && !int.TryParse(parameters["page_size"].ToString(), out page_size))
         {
             result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Parameters_Format_Error, "page_size");
             return(false);
         }
         if (string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_size"])) || ((page_size > 0) && (page_size <= 100)))
         {
             return(true);
         }
         result = OpenApiErrorMessage.ShowErrorMsg(OpenApiErrorCode.Page_Size_Too_Long, "page_size");
     }
     return(false);
 }
Beispiel #17
0
 public bool CheckSoldProductsParameters(SortedDictionary <string, string> parameters, out DateTime?start_modified, out DateTime?end_modified, out string status, out int page_no, out int page_size, out string result)
 {
     start_modified = new DateTime?();
     end_modified   = new DateTime?();
     status         = string.Empty;
     page_no        = 1;
     page_size      = 10;
     if (!OpenApiHelper.CheckSystemParameters(parameters, this.site.AppKey, out result))
     {
         return(false);
     }
     status = DataHelper.CleanSearchString(parameters["approve_status"]);
     if (!string.IsNullOrWhiteSpace(status) && status != "On_Sale" && (status != "Un_Sale" && status != "In_Stock"))
     {
         result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Product_Status_is_Invalid, "approve_status");
         return(false);
     }
     else if (!string.IsNullOrEmpty(parameters["start_modified"]) && !OpenApiHelper.IsDate(parameters["start_modified"]))
     {
         result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Invalid_Timestamp, "start_modified");
         return(false);
     }
     else if (!string.IsNullOrEmpty(parameters["end_modified"]) && !OpenApiHelper.IsDate(parameters["end_modified"]))
     {
         result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Invalid_Timestamp, "end_modified");
         return(false);
     }
     else
     {
         if (!string.IsNullOrEmpty(parameters["start_modified"]))
         {
             DateTime result1;
             DateTime.TryParse(parameters["start_modified"], out result1);
             start_modified = new DateTime?(result1);
             if (result1 > DateTime.Now)
             {
                 result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Time_Start_Now, "start_modified and currenttime");
                 return(false);
             }
             else if (!string.IsNullOrEmpty(parameters["end_modified"]))
             {
                 DateTime result2;
                 DateTime.TryParse(parameters["end_modified"], out result2);
                 end_modified = new DateTime?(result2);
                 if (result1 > result2)
                 {
                     result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Time_Start_End, "start_modified and end_created");
                     return(false);
                 }
                 else if (result2 > DateTime.Now)
                 {
                     result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Time_End_Now, "end_modified and currenttime");
                     return(false);
                 }
             }
         }
         else if (!string.IsNullOrEmpty(parameters["end_modified"]))
         {
             DateTime result1;
             DateTime.TryParse(parameters["end_modified"], out result1);
             if (result1 > DateTime.Now)
             {
                 result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Time_End_Now, "end_modified and currenttime");
                 return(false);
             }
         }
         if (!string.IsNullOrEmpty(parameters["order_by"]))
         {
             if (parameters["order_by"].Split(':').Length != 2)
             {
                 result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Invalid_Format, "order_by");
                 return(false);
             }
             else
             {
                 string[] strArray = parameters["order_by"].Split(':');
                 string   str1     = DataHelper.CleanSearchString(strArray[0]);
                 string   str2     = DataHelper.CleanSearchString(strArray[1]);
                 if (string.IsNullOrEmpty(str1))
                 {
                     result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Invalid_Format, "order_by");
                     return(false);
                 }
                 else if (str1 != "display_sequence" || str1 != "create_time" || str1 != "sold_quantity")
                 {
                     result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Invalid_Format, "order_by");
                     return(false);
                 }
                 else if (str2 != "desc" || str2 != "asc")
                 {
                     result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Invalid_Format, "order_by");
                     return(false);
                 }
             }
         }
         if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_size"])) && !int.TryParse(((object)parameters["page_size"]).ToString(), out page_size))
         {
             result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Parameters_Format_Error, "page_size");
             return(false);
         }
         else if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_size"])) && (page_size <= 0 || page_size > 100))
         {
             result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Page_Size_Too_Long, "page_size");
             return(false);
         }
         else if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_no"])) && !int.TryParse(((object)parameters["page_no"]).ToString(), out page_no))
         {
             result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Parameters_Format_Error, "page_no");
             return(false);
         }
         else
         {
             if (string.IsNullOrEmpty(DataHelper.CleanSearchString(parameters["page_no"])) || page_no > 0)
             {
                 return(true);
             }
             result = OpenApiErrorMessage.ShowErrorMsg((Enum)OpenApiErrorCode.Page_Size_Too_Long, "page_no");
             return(false);
         }
     }
 }
Beispiel #18
0
        private static Func <HttpRequest, HttpResponse, RouteData, Task> GetOpenApiJson(List <ServiceHandlerConfigurationInstance> serviceInstanceConfigurations, OpenApiInfo info = null) => async(req, resp, route) =>
        {
            resp.ContentType = "application/json; charset=utf-8";

            var xmlDocumentationFiles = new Dictionary <Assembly, OpenApiXmlDocumentationFile>();
            //ComponentsJsonConverter.XmlDocumentationFiles = xmlDocumentationFiles; // This is a little dirty, but it is a good way to get this into the converter

            if (info == null)
            {
                info = new OpenApiInfo();
            }
            var openApiInfo = new OpenApiInformation {
                Info = info
            };

            foreach (var serviceInstanceConfig in serviceInstanceConfigurations)
            {
                var interfaces = serviceInstanceConfig.ServiceType.GetInterfaces();
                if (interfaces.Length < 1)
                {
                    throw new NotSupportedException(Resources.HostedServiceRequiresAnInterface);
                }

                if (!xmlDocumentationFiles.ContainsKey(interfaces[0].Assembly))
                {
                    xmlDocumentationFiles.Add(interfaces[0].Assembly, new OpenApiXmlDocumentationFile(interfaces[0].Assembly));
                }

                // If we do not have a version number yet, we use the first interface to see if that can give us a version number
                if (string.IsNullOrEmpty(info.Version))
                {
                    info.Version = interfaces[0].Assembly?.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion;
                }

                var tag = new OpenApiTag {
                    Name = serviceInstanceConfig.ServiceType.Name
                };
                tag.Description  = OpenApiHelper.GetDescription(serviceInstanceConfig.ServiceType, interfaces[0], xmlDocumentationFiles);
                tag.ExternalDocs = OpenApiHelper.GetExternalDocs(serviceInstanceConfig.ServiceType, interfaces[0]);
                openApiInfo.Tags.Add(tag);

                var methods = serviceInstanceConfig.ServiceType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.DeclaredOnly);
                foreach (var method in methods)
                {
                    var interfaceMethod = interfaces[0].GetMethod(method.Name);
                    if (interfaceMethod == null)
                    {
                        continue;                          // Should never happen, but doesn't hurt to check
                    }
                    var restAttribute = GetRestAttribute(interfaceMethod);
                    if (restAttribute == null)
                    {
                        continue;                        // This should never happen since GetRestAttribute() above returns a default attribute if none is attached
                    }
                    var httpVerb = restAttribute.Method.ToString().ToLowerInvariant();
                    var pathInfo = new OpenApiPathInfo(restAttribute.Method.ToString(), httpVerb, method.Name, method);

                    // Get method summary and description
                    pathInfo.Verbs[pathInfo.Verbs.Keys.First()].Summary     = OpenApiHelper.GetSummary(interfaceMethod, interfaces[0], xmlDocumentationFiles);
                    pathInfo.Verbs[pathInfo.Verbs.Keys.First()].Description = OpenApiHelper.GetDescription(interfaceMethod, interfaces[0], xmlDocumentationFiles);

                    pathInfo.Tags.Add(new OpenApiTag {
                        Name = serviceInstanceConfig.ServiceType.Name
                    });

                    pathInfo.ReturnType = interfaceMethod.ReturnType;
                    var returnTypeOpenApiString = OpenApiHelper.GetOpenApiType(interfaceMethod.ReturnType);
                    if (string.IsNullOrEmpty(returnTypeOpenApiString)) // If it isn't a simple type (which it really shouldn't be, based on our usage patterns), we add the component definition (schema)
                    {
                        var obsolete          = false;
                        var obsoleteReason    = string.Empty;
                        var obsoleteAttribute = interfaceMethod.GetCustomAttribute <ObsoleteAttribute>();
                        if (obsoleteAttribute != null)
                        {
                            obsolete = true;
                            if (!string.IsNullOrEmpty(obsoleteAttribute.Message))
                            {
                                obsoleteReason = obsoleteAttribute.Message.Trim();
                            }
                        }
                        OpenApiHelper.AddTypeToComponents(openApiInfo, interfaceMethod.ReturnType, obsolete, obsoleteReason, xmlDocumentationFiles);
                        pathInfo.Obsolete       = obsolete;
                        pathInfo.ObsoleteReason = obsoleteReason;
                    }

                    if (httpVerb == "get")
                    {
                        // Get operations do not have a payload/body, so everything must be coming in from the URL
                        OpenApiHelper.ExtractOpenApiParameters(interfaceMethod, pathInfo, xmlDocumentationFiles);
                    }
                    else
                    {
                        var methodParameters = interfaceMethod.GetParameters();
                        foreach (var parameter in methodParameters) // Should always be a single parameter
                        {
                            var obsolete2          = false;
                            var obsoleteReason2    = string.Empty;
                            var obsoleteAttribute2 = parameter.GetCustomAttribute <ObsoleteAttribute>();
                            if (obsoleteAttribute2 != null)
                            {
                                obsolete2 = true;
                                if (!string.IsNullOrEmpty(obsoleteAttribute2.Message))
                                {
                                    obsoleteReason2 = obsoleteAttribute2.Message.Trim();
                                }
                            }
                            OpenApiHelper.AddTypeToComponents(openApiInfo, parameter.ParameterType, obsolete2, obsoleteReason2, xmlDocumentationFiles);
                        }
                        OpenApiHelper.ExtractOpenApiParameters(interfaceMethod, pathInfo, xmlDocumentationFiles);
                        if (methodParameters.Length > 0)
                        {
                            pathInfo.Payload = new OpenApiPayload {
                                Type = methodParameters[0].ParameterType
                            };
                            pathInfo.Payload.Description = OpenApiHelper.GetDescription(methodParameters[0].ParameterType, xmlDocumentationFiles);
                            if (string.IsNullOrEmpty(pathInfo.Payload.Description))
                            {
                                pathInfo.Payload.Description = OpenApiHelper.GetSummary(methodParameters[0].ParameterType, xmlDocumentationFiles);
                            }
                        }
                    }

                    var definedRoute = restAttribute.Route != null ? restAttribute.Route : restAttribute.Name == null ? $"{method.Name}" : $"{restAttribute.Name}";
                    var fullRoute    = string.IsNullOrEmpty(definedRoute) ? $"{serviceInstanceConfig.RouteBasePath}" : $"{serviceInstanceConfig.RouteBasePath}/{definedRoute}";
                    var fullRouteKey = $"{httpVerb}::{fullRoute}";

                    if (!openApiInfo.Paths.ContainsKey(fullRouteKey))
                    {
                        openApiInfo.Paths.Add(fullRouteKey, pathInfo);
                    }
                    else
                    {
                        throw new Exception($"Duplicate path/route in service definition.{Environment.NewLine}Route: {fullRoute}");
                    }
                }
            }

            resp.ContentType = "application/json; charset=utf-8";
            var options = new System.Text.Json.JsonSerializerOptions {
                PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase
            };
            await System.Text.Json.JsonSerializer.SerializeAsync(resp.Body, openApiInfo, typeof(OpenApiInformation), options);
        };
Beispiel #19
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            System.Collections.Generic.SortedDictionary <string, string> sortedParams = OpenApiHelper.GetSortedParams(this.Context);
            string empty = string.Empty;

            this.ChangLogistics(sortedParams, ref empty);
            base.Response.ContentType = "text/json";
            Globals.Debuglog(base.Request.Url.ToString() + "||" + Globals.SubStr(empty, 200, "------------结束"), "_DebugERP.txt");
            base.Response.Write(empty);
            base.Response.End();
        }