Changeset 404 for binary-improvements2/WebServer/src/WebAPI/AbsRestApi.cs
- Timestamp:
- Feb 16, 2023, 3:50:53 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/WebAPI/AbsRestApi.cs
r402 r404 95 95 } 96 96 97 protected void SendErrorResult (RequestContext _context, HttpStatusCode _statusCode, byte[] _jsonInputData = null, string _errorCode = null, Exception _exception = null) {98 PrepareEnvelopedResult (out JsonWriter writer);99 writer.WriteRaw (JsonEmptyData);100 SendEnvelopedResult (_context, ref writer, _statusCode, _jsonInputData, _errorCode, _exception);101 }102 103 97 static AbsRestApi () { 104 98 JsonWriter writer = new JsonWriter (); … … 108 102 } 109 103 104 protected virtual void HandleRestGet (RequestContext _context) { 105 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, null, "Unsupported"); 106 } 107 108 protected virtual void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 109 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, _jsonInputData, "Unsupported"); 110 } 111 112 protected virtual void HandleRestPut (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 113 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, _jsonInputData, "Unsupported"); 114 } 115 116 protected virtual void HandleRestDelete (RequestContext _context) { 117 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, null, "Unsupported"); 118 } 119 120 121 #region Helpers 122 110 123 protected static readonly byte[] JsonEmptyData; 111 124 112 protected void PrepareEnvelopedResult (out JsonWriter _writer) {125 protected static void PrepareEnvelopedResult (out JsonWriter _writer) { 113 126 WebUtils.PrepareEnvelopedResult (out _writer); 114 127 } 115 128 116 protected void SendEnvelopedResult (RequestContext _context, ref JsonWriter _writer, HttpStatusCode _statusCode = HttpStatusCode.OK,129 protected static void SendEnvelopedResult (RequestContext _context, ref JsonWriter _writer, HttpStatusCode _statusCode = HttpStatusCode.OK, 117 130 byte[] _jsonInputData = null, string _errorCode = null, Exception _exception = null) { 118 131 … … 120 133 } 121 134 122 protected bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out int _value) { 135 protected static void SendErrorResult (RequestContext _context, HttpStatusCode _statusCode, byte[] _jsonInputData = null, string _errorCode = null, Exception _exception = null) { 136 PrepareEnvelopedResult (out JsonWriter writer); 137 writer.WriteRaw (JsonEmptyData); 138 SendEnvelopedResult (_context, ref writer, _statusCode, _jsonInputData, _errorCode, _exception); 139 } 140 141 protected static bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out int _value) { 123 142 _value = default; 124 143 … … 139 158 } 140 159 141 protected bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out double _value) {160 protected static bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out double _value) { 142 161 _value = default; 143 162 … … 158 177 } 159 178 160 protected bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out string _value) {179 protected static bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out string _value) { 161 180 _value = default; 162 181 … … 176 195 } 177 196 } 178 179 protected virtual void HandleRestGet (RequestContext _context) { 180 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, null, "Unsupported"); 181 } 182 183 protected virtual void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 184 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, _jsonInputData, "Unsupported"); 185 } 186 187 protected virtual void HandleRestPut (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 188 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, _jsonInputData, "Unsupported"); 189 } 190 191 protected virtual void HandleRestDelete (RequestContext _context) { 192 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, null, "Unsupported"); 193 } 197 198 199 #endregion 194 200 } 195 201 }
Note:
See TracChangeset
for help on using the changeset viewer.