| | |
| | | using System; |
| | | using MoonExp.cs; |
| | | using Newtonsoft.Json.Converters; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Web.Http; |
| | | using System.Web.Http.Hosting; |
| | | |
| | | namespace MoonExp |
| | | { |
| | |
| | | { |
| | | public static void Register(HttpConfiguration config) |
| | | { |
| | | // Web API configuration and services |
| | | |
| | | // Web API routes |
| | | config.MapHttpAttributeRoutes(); |
| | | |
| | | //config.Routes.MapHttpRoute( |
| | | // name: "TerraApi", |
| | | // routeTemplate: "{controller}/3d/terrain", |
| | | // defaults: new { controller = "Terra" } |
| | | //); |
| | | |
| | | // {controller}/{id} |
| | | config.Routes.MapHttpRoute( |
| | | name: "DefaultApi", |
| | | routeTemplate: "api/{controller}/{id}", |
| | | routeTemplate: "{controller}/{action}/{id}", |
| | | defaults: new { id = RouteParameter.Optional } |
| | | ); |
| | | |
| | | // æ³¨åæ©å±ä¸»æºç¼åPolicy |
| | | GlobalConfiguration.Configuration.Services.Replace(typeof(IHostBufferPolicySelector), new NoBufferPolicySelector()); |
| | | |
| | | // å±è½è¿åXMLæ ¼å¼ |
| | | GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); |
| | | |
| | | // è§£å³webapiå¨ multipart/form-data æ æ³æ å°å®ä½ç±»ï¼HttpContext.Request.Files.Count |
| | | //GlobalConfiguration.Configuration.Formatters.Add(new FormMultipartEncodedMediaTypeFormatter()); |
| | | |
| | | // ä¿®æ¹æ¥ææ ¼å¼ |
| | | IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); |
| | | timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; |
| | | GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(timeConverter); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using MoonExp.cs; |
| | | using MoonExp.Models; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Net.Http; |
| | | using System.Web.Http; |
| | | |
| | | namespace MoonExp.Controllers |
| | | { |
| | | public class ExportController : ApiController |
| | | { |
| | | [HttpGet] |
| | | public string Test() |
| | | { |
| | | return DateTime.Now.ToString("yyyyy-MM-dd HH:mm:ss"); |
| | | } |
| | | |
| | | [HttpPost] |
| | | public ResponseMsg<string> Start([FromBody]ExportArgs args) |
| | | { |
| | | try |
| | | { |
| | | if (args == null || |
| | | string.IsNullOrWhiteSpace(args.layers) || |
| | | string.IsNullOrWhiteSpace(args.token) || |
| | | (args.xmin == 0 && args.ymin == 0 && args.xmax == 0 && args.ymax == 0)) |
| | | { |
| | | return ResponseMsg<string>.fail("åæ°ä¸å®æ´"); |
| | | } |
| | | |
| | | if (!ExportUtil.VerifyToken(args.token)) |
| | | { |
| | | return ResponseMsg<string>.fail("ä»¤çæ æ"); |
| | | } |
| | | |
| | | string err = null; |
| | | string imgPath = ExportUtil.Generate(args, ref err); |
| | | if (string.IsNullOrEmpty(imgPath)) |
| | | { |
| | | return ResponseMsg<string>.fail(null == err ? "çæå¤±è´¥" : err); |
| | | } |
| | | |
| | | return ResponseMsg<string>.success("æå", imgPath); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); |
| | | return ResponseMsg<string>.fail(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | <RootNamespace>MoonExp</RootNamespace> |
| | | <AssemblyName>MoonExp</AssemblyName> |
| | | <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> |
| | | <UseIISExpress>true</UseIISExpress> |
| | | <UseIISExpress>false</UseIISExpress> |
| | | <IISExpressSSLPort /> |
| | | <IISExpressAnonymousAuthentication /> |
| | | <IISExpressWindowsAuthentication /> |
| | |
| | | </Reference> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <Content Include="export.html" /> |
| | | <Content Include="Global.asax" /> |
| | | <Content Include="Web.config" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <Compile Include="App_Start\WebApiConfig.cs" /> |
| | | <Compile Include="Controllers\ExportController.cs" /> |
| | | <Compile Include="cs\ExportUtil.cs" /> |
| | | <Compile Include="cs\LogOut.cs" /> |
| | | <Compile Include="cs\NoBufferPolicySelector.cs" /> |
| | | <Compile Include="cs\PostgreHelper.cs" /> |
| | | <Compile Include="Global.asax.cs"> |
| | | <DependentUpon>Global.asax</DependentUpon> |
| | |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <Folder Include="App_Data\" /> |
| | | <Folder Include="Controllers\" /> |
| | | </ItemGroup> |
| | | <PropertyGroup> |
| | | <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> |
| | |
| | | <WebProjectProperties> |
| | | <UseIIS>True</UseIIS> |
| | | <AutoAssignPort>True</AutoAssignPort> |
| | | <DevelopmentServerPort>0</DevelopmentServerPort> |
| | | <DevelopmentServerPort>1062</DevelopmentServerPort> |
| | | <DevelopmentServerVPath>/</DevelopmentServerVPath> |
| | | <IISUrl>http://localhost:1380/</IISUrl> |
| | | <IISUrl>http://localhost/MoonExp</IISUrl> |
| | | <NTLMAuthentication>False</NTLMAuthentication> |
| | | <UseCustomServer>False</UseCustomServer> |
| | | <CustomServerUrl> |
| | |
| | | </appSettings> |
| | | <system.web> |
| | | <compilation debug="true" targetFramework="4.5.2" /> |
| | | <httpRuntime targetFramework="4.5.2" /> |
| | | <!-- maxRequestLengthæ¯ä¸ä¼ æä»¶æ¶æå¤§size(å使¯KB,é»è®¤å¼æ¯4096kb)ï¼executionTimeoutæ¯è¯·æ±session(å使¯ç§,é»è®¤å¼æ¯110s) --> |
| | | <httpRuntime maxRequestLength="2147483647" executionTimeout="8640000"/> |
| | | <pages controlRenderingCompatibilityVersion="4.0"/> |
| | | </system.web> |
| | | <system.webServer> |
| | | <security> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Net.Http; |
| | | using System.Web; |
| | | using System.Web.Http.WebHost; |
| | | |
| | | namespace MoonExp.cs |
| | | { |
| | | public class NoBufferPolicySelector : WebHostBufferPolicySelector |
| | | { |
| | | public override bool UseBufferedInputStream(object hostContext) |
| | | { |
| | | var context = hostContext as HttpContextBase; |
| | | |
| | | if (context != null) |
| | | { |
| | | if (context.Request.HttpMethod == HttpMethod.Post.ToString() && context.Request.ContentLength > 102400) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <!DOCTYPE html> |
| | | <html xmlns="http://www.w3.org/1999/xhtml"> |
| | | <head> |
| | | <title>MoonExp</title> |
| | | <meta http-equiv="Expires" content="0" /> |
| | | <meta http-equiv="Cache" content="no-cache" /> |
| | | <meta http-equiv="Pragma" content="no-cache" /> |
| | | <meta http-equiv="Cache-control" content="no-cache" /> |
| | | <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> |
| | | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| | | <script src="js/jquery.1.12.4.js"></script> |
| | | <script> |
| | | var token = "384d7382-ea48-400b-bc92-58cb2b28bcbc"; |
| | | |
| | | $(function () { |
| | | $("#token").html(token); |
| | | }); |
| | | |
| | | // Ajax |
| | | function ajax(url, type, data, dataType, contentType, fn) { |
| | | $.ajax({ |
| | | url: url, |
| | | type: type, |
| | | data: data, |
| | | dataType: dataType || "json", // htmlãjsonãjsonpãscriptãtext |
| | | contentType: contentType || "application/json", // "application/x-www-form-urlencoded" |
| | | success: function (data) { |
| | | fn(data); |
| | | }, |
| | | error: function (e) { |
| | | console.error(e); |
| | | fn(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // åºå¾-1 |
| | | function exportMap1() { |
| | | var page = $("#selectPage").find("option:selected").text(); |
| | | var data = { |
| | | token: token, |
| | | title: "管éåºç¡å¤§æ°æ®å¹³å°ï¼DW1-01ï¼", |
| | | pageSize: page, |
| | | province: "æ²³åç", |
| | | scale: "1ï¼5ä¸", |
| | | resolution: "5ç±³", |
| | | date: "2022.11.09", |
| | | layers: "m_hydraulic_protection,m_marker,m_pipeline,m_sitepoint,m_valvehousepoint,m_crossing,é«å¾·ç¢é", |
| | | rotation: 0, |
| | | xmin: 103.394023, |
| | | ymin: 30.690466, |
| | | ymax: 37.871048, |
| | | xmax: 112.534648 |
| | | }; |
| | | |
| | | ajax("Export/Start", "POST", JSON.stringify(data), null, null, function (rs) { |
| | | alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result); |
| | | console.log(rs); |
| | | }); |
| | | } |
| | | |
| | | // åºå¾-2 |
| | | function exportMap2() { |
| | | var page = $("#selectPage").find("option:selected").text(); |
| | | var data = { |
| | | token: token, |
| | | title: "管éåºç¡å¤§æ°æ®å¹³å°ï¼DW1-02ï¼", |
| | | pageSize: page, |
| | | province: "å±±ä¸ç", |
| | | scale: "1ï¼1ä¸", |
| | | resolution: "2ç±³", |
| | | date: "2022.11.10", |
| | | layers: "bs_project,th_strategic_channel,m_hydraulic_protection,m_marker,m_pipeline,m_sitepoint,m_valvehousepoint,m_crossing,é«å¾·å½±å", |
| | | rotation: 0, |
| | | xmin: 103.394023, |
| | | ymin: 30.690466, |
| | | ymax: 37.871048, |
| | | xmax: 112.534648 |
| | | }; |
| | | |
| | | ajax("Export/Start", "POST", JSON.stringify(data), null, null, function (rs) { |
| | | alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result); |
| | | console.log(rs); |
| | | }); |
| | | } |
| | | </script> |
| | | </head> |
| | | <body> |
| | | <h2>Toeknï¼<span id="token" style="font-size: 14px;"></span></h2> |
| | | <select id="selectPage"> |
| | | <option>A0</option> |
| | | <option>A1</option> |
| | | <option>A2</option> |
| | | <option>A3</option> |
| | | <option selected="selected">A4</option> |
| | | </select> |
| | | <input type="button" value="åºå¾-1" onclick="exportMap1()" /> |
| | | <input type="button" value="åºå¾-2" onclick="exportMap2()" /> |
| | | <br /><br /> |
| | | </body> |
| | | </html> |