|
| 1 | +// Copyright 2022 ESRI |
| 2 | +// |
| 3 | +// All rights reserved under the copyright laws of the United States |
| 4 | +// and applicable international laws, treaties, and conventions. |
| 5 | +// |
| 6 | +// You may freely redistribute and use this sample code, with or |
| 7 | +// without modification, provided you include the original copyright |
| 8 | +// notice and use restrictions. |
| 9 | +// |
| 10 | +// See the use restrictions at <your Enterprise SDK install location>/userestrictions.txt. |
| 11 | +// |
| 12 | + |
| 13 | +using System; |
| 14 | +using System.Collections.Generic; |
| 15 | +using System.Linq; |
| 16 | +using System.Text; |
| 17 | +using System.Collections.Specialized; |
| 18 | +using System.Runtime.InteropServices; |
| 19 | +using ESRI.ArcGIS.esriSystem; |
| 20 | +using ESRI.ArcGIS.Server; |
| 21 | +using ESRI.ArcGIS.Geometry; |
| 22 | +using ESRI.ArcGIS.Geodatabase; |
| 23 | +using ESRI.ArcGIS.Carto; |
| 24 | +using ESRI.Server.SOESupport; |
| 25 | +using ESRI.Server.SOESupport.SOI; |
| 26 | + |
| 27 | +//This is SOI template of Enterprise SDK |
| 28 | + |
| 29 | +namespace FilterFeaturesByFieldSOI |
| 30 | +{ |
| 31 | + [ComVisible(true)] |
| 32 | + [Guid("c9eaee50-c440-4b5a-b909-40e52e3f138c")] |
| 33 | + [ClassInterface(ClassInterfaceType.None)] |
| 34 | + [ServerObjectInterceptor("MapServer", |
| 35 | + Description = "", |
| 36 | + DisplayName = ".NET FilterFeaturesByField SOI", |
| 37 | + Properties = "", |
| 38 | + SupportsSharedInstances = true)] |
| 39 | + public class FilterFeaturesByFieldSOI : IServerObjectExtension, IRESTRequestHandler, IWebRequestHandler, IRequestHandler2 |
| 40 | + { |
| 41 | + private string _soiName; |
| 42 | + private IServerObjectHelper _soHelper; |
| 43 | + private RestSOIHelper _restSOIHelper; |
| 44 | + |
| 45 | + public FilterFeaturesByFieldSOI() |
| 46 | + { |
| 47 | + _soiName = this.GetType().Name; |
| 48 | + } |
| 49 | + |
| 50 | + public void Init(IServerObjectHelper pSOH) |
| 51 | + { |
| 52 | + //System.Diagnostics.Debugger.Launch(); |
| 53 | + |
| 54 | + _soHelper = pSOH; |
| 55 | + _restSOIHelper = new RestSOIHelper(pSOH); |
| 56 | + } |
| 57 | + |
| 58 | + public void Shutdown() |
| 59 | + { |
| 60 | + } |
| 61 | + |
| 62 | + #region REST interceptors |
| 63 | + |
| 64 | + public string GetSchema() |
| 65 | + { |
| 66 | + IRESTRequestHandler restRequestHandler = _restSOIHelper.FindRequestHandlerDelegate<IRESTRequestHandler>(); |
| 67 | + if (restRequestHandler == null) |
| 68 | + return null; |
| 69 | + |
| 70 | + return restRequestHandler.GetSchema(); |
| 71 | + } |
| 72 | + |
| 73 | + public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName, |
| 74 | + string operationInput, string outputFormat, string requestProperties, out string responseProperties) |
| 75 | + { |
| 76 | + responseProperties = null; |
| 77 | + |
| 78 | + // Find the correct delegate to forward the request too |
| 79 | + IRESTRequestHandler restRequestHandler = _restSOIHelper.FindRequestHandlerDelegate<IRESTRequestHandler>(); |
| 80 | + if (restRequestHandler == null) |
| 81 | + return null; |
| 82 | + |
| 83 | + if (operationName == "export" || operationName == "identify" || operationName == "find") |
| 84 | + { |
| 85 | + var joOperationInput = new JsonObject(operationInput); |
| 86 | + var operationInputToJsonTest = joOperationInput.ToJson(); |
| 87 | + |
| 88 | + if (joOperationInput.Exists("layerDefs")) |
| 89 | + joOperationInput.Delete("layerDefs"); |
| 90 | + |
| 91 | + var joLayerDefsFilter = new JsonObject(); |
| 92 | + // Filter the features by the POP attribute field. |
| 93 | + joLayerDefsFilter.AddString("0", "POP > 500000"); |
| 94 | + joOperationInput.AddJsonObject("layerDefs", joLayerDefsFilter); |
| 95 | + |
| 96 | + operationInput = joOperationInput.ToJson(); |
| 97 | + } |
| 98 | + |
| 99 | + return restRequestHandler.HandleRESTRequest( |
| 100 | + Capabilities, resourceName, operationName, operationInput, |
| 101 | + outputFormat, requestProperties, out responseProperties); |
| 102 | + } |
| 103 | + |
| 104 | + private JsonObject CreateACircle() |
| 105 | + { |
| 106 | + string circleJs = "{\"spatialReference\":{\"wkid\":4269}, \"curveRings\": [[[-102, 41],{\"a\":[[-102, 41], [-104, 39], 0, 1]}]]}"; |
| 107 | + IPolygon poly = ESRI.Server.SOESupport.Conversion.ToGeometry(circleJs, esriGeometryType.esriGeometryPolygon) as IPolygon; |
| 108 | + ((IPolycurve)poly).Densify(0.1, 0.1); //Densifying as ToJsonObject() can't jsonify any curves |
| 109 | + return ESRI.Server.SOESupport.Conversion.ToJsonObject(poly, true); |
| 110 | + } |
| 111 | + |
| 112 | + #endregion |
| 113 | + |
| 114 | + #region SOAP interceptors |
| 115 | + public byte[] HandleBinaryRequest(ref byte[] request) |
| 116 | + { |
| 117 | + IRequestHandler requestHandler = _restSOIHelper.FindRequestHandlerDelegate<IRequestHandler>(); |
| 118 | + if (requestHandler != null) |
| 119 | + { |
| 120 | + return requestHandler.HandleBinaryRequest(request); |
| 121 | + } |
| 122 | + |
| 123 | + //Insert error response here. |
| 124 | + return null; |
| 125 | + } |
| 126 | + |
| 127 | + public string HandleStringRequest(string Capabilities, string request) |
| 128 | + { |
| 129 | + IRequestHandler requestHandler = _restSOIHelper.FindRequestHandlerDelegate<IRequestHandler>(); |
| 130 | + if (requestHandler != null) |
| 131 | + { |
| 132 | + return requestHandler.HandleStringRequest(Capabilities, request); |
| 133 | + } |
| 134 | + |
| 135 | + //Insert error response here. |
| 136 | + return null; |
| 137 | + } |
| 138 | + |
| 139 | + public byte[] HandleBinaryRequest2(string Capabilities, ref byte[] request) |
| 140 | + { |
| 141 | + IRequestHandler2 requestHandler = _restSOIHelper.FindRequestHandlerDelegate<IRequestHandler2>(); |
| 142 | + if (requestHandler != null) |
| 143 | + { |
| 144 | + return requestHandler.HandleBinaryRequest2(Capabilities, request); |
| 145 | + } |
| 146 | + |
| 147 | + //Insert error response here. |
| 148 | + return null; |
| 149 | + } |
| 150 | + #endregion |
| 151 | + |
| 152 | + #region OGC interceptors |
| 153 | + public byte[] HandleStringWebRequest(esriHttpMethod httpMethod, string requestURL, string queryString, string Capabilities, string requestData, out string responseContentType, out esriWebResponseDataType respDataType) |
| 154 | + { |
| 155 | + IWebRequestHandler webRequestHandler = _restSOIHelper.FindRequestHandlerDelegate<IWebRequestHandler>(); |
| 156 | + if (webRequestHandler != null) |
| 157 | + { |
| 158 | + return webRequestHandler.HandleStringWebRequest( |
| 159 | + httpMethod, requestURL, queryString, Capabilities, requestData, out responseContentType, out respDataType); |
| 160 | + } |
| 161 | + |
| 162 | + responseContentType = null; |
| 163 | + respDataType = esriWebResponseDataType.esriWRDTPayload; |
| 164 | + //Insert error response here. |
| 165 | + return null; |
| 166 | + } |
| 167 | + #endregion |
| 168 | + } |
| 169 | +} |
0 commit comments