public HttpResponseMessage QueriesLeftToday(ResponseFormat?format = null) { var guid = Request.GetToken(); MorpherCacheObject cacheObject = null; if (guid == null) { cacheObject = _apiThrottler.GetQueryLimit(Request.GetClientIp()); if (cacheObject == null) { return(Request.CreateResponse( HttpStatusCode.OK, new ServiceErrorMessage(new IpBlockedException()), format)); } } else { cacheObject = _apiThrottler.GetQueryLimit(guid.Value); if (cacheObject == null) { return(Request.CreateResponse( HttpStatusCode.OK, new ServiceErrorMessage(new TokenNotFoundException()), format)); } } return(Request.CreateResponse(HttpStatusCode.OK, Math.Max(cacheObject.QueriesLeft, 0), format)); }
internal QueryOptions(ResponseFormat? format, int? top, string select, string filter) { Format = format; Top = top; Select = select; Filter = filter; }
public HttpResponseMessage DeclensionList( [FromBody] string text, [FromUri] General.Data.DeclensionFlags?flags = null, [FromUri] ResponseFormat?format = null) { if (string.IsNullOrWhiteSpace(text)) { throw new RequiredParameterIsNotSpecifiedException(nameof(text)); } var words = text.Split('\n'); Func <string, General.Data.DeclensionFlags?, Data.DeclensionResult> inflector = (s, f) => { var result = _morpher.Declension(s, f); _resultTrimmer.Trim(result, Request.GetToken()); return(result); }; return(format == ResponseFormat.Json ? Request.CreateResponse( HttpStatusCode.OK, DeclensionListResultJson.InflectList(inflector, words, flags), ResponseFormat.Json) : Request.CreateResponse( HttpStatusCode.OK, DeclensionListResultXml.InflectList(inflector, words, flags), ResponseFormat.Xml)); }
public HttpResponseMessage AdjectiveGenders(string s, ResponseFormat?format = null) { if (string.IsNullOrWhiteSpace(s)) { throw new RequiredParameterIsNotSpecifiedException(nameof(s)); } Data.AdjectiveGenders adjectives = _analyzer.AdjectiveGenders(s); return(Request.CreateResponse(HttpStatusCode.OK, adjectives, format)); }
public HttpResponseMessage UserDictDelete(string s, ResponseFormat?format = null) { if (string.IsNullOrWhiteSpace(s)) { throw new RequiredParameterIsNotSpecifiedException(nameof(s)); } bool found = _exceptionDictionary.Remove(s); return(Request.CreateResponse(HttpStatusCode.OK, found, format)); }
public HttpResponseMessage Accentizer([FromBody] string text, [FromUri] ResponseFormat?format = null) { if (string.IsNullOrWhiteSpace(text)) { throw new RequiredParameterIsNotSpecifiedException(nameof(text)); } string accentized = _analyzer.Accentizer(text); return(Request.CreateResponse(HttpStatusCode.OK, accentized, format)); }
public HttpResponseMessage Spell(decimal n, string unit, ResponseFormat?format = null) { if (string.IsNullOrWhiteSpace(unit)) { throw new RequiredParameterIsNotSpecifiedException(nameof(unit)); } NumberSpelling numberSpelling = _analyzer.Spell(n, unit); return(Request.CreateResponse(HttpStatusCode.OK, numberSpelling, format)); }
public HttpResponseMessage Spell(decimal n, string unit, ResponseFormat?format = null) { if (string.IsNullOrWhiteSpace(unit)) { throw new RequiredParameterIsNotSpecifiedException(nameof(unit)); } var s = _analyzer.Spell(n, unit); _resultTrimmer.Trim(s, Request.GetToken()); return(Request.CreateResponse(HttpStatusCode.OK, s, format)); }
public static HttpResponseMessage CreateResponse <T>( this HttpRequestMessage message, HttpStatusCode statusCode, T value, ResponseFormat?format) { switch (format) { case ResponseFormat.Json: return(message.CreateResponse(statusCode, value, JsonMediaTypeFormatter)); case ResponseFormat.Xml: return(message.CreateResponse(statusCode, value, XmlMediaTypeFormatter)); default: return(message.Headers.Accept.ToString() == "application/json" ? message.CreateResponse(statusCode, value, JsonMediaTypeFormatter) : message.CreateResponse(statusCode, value, XmlMediaTypeFormatter)); } }
public HttpResponseMessage Declension(string s, General.Data.DeclensionFlags?flags = null, ResponseFormat?format = null) { if (string.IsNullOrWhiteSpace(s)) { throw new RequiredParameterIsNotSpecifiedException(nameof(s)); } if (this.Request.GetQueryString("flags") != null && flags == null) { throw new InvalidFlagsException(); } Data.DeclensionResult declensionResult = _analyzer.Declension(s, flags); _resultTrimmer.Trim(declensionResult, Request.GetToken()); return(Request.CreateResponse(HttpStatusCode.OK, declensionResult, format)); }
public HttpResponseMessage UserDictGetAll(ResponseFormat?format = null) { var result = _exceptionDictionary.GetAll(); return(Request.CreateResponse(HttpStatusCode.OK, result, format)); }
internal HttpMessage AddInsertEntityRequest(MultipartContent changeset, string table, int?timeout, string requestId, ResponseFormat?responsePreference, IDictionary <string, object> tableEntityProperties, QueryOptions queryOptions) { var message = CreateInsertEntityRequest(table, timeout, requestId, responsePreference, tableEntityProperties, queryOptions); changeset.AddContent(new RequestRequestContent(message.Request)); return(message); }
internal HttpMessage CreateBatchRequest(MultipartContent content, string requestId, ResponseFormat?responsePreference) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Post; var uri = new RawRequestUriBuilder(); uri.AppendRaw(url, false); uri.AppendPath("/$batch", false); request.Uri = uri; request.Headers.Add("x-ms-version", version); if (requestId != null) { request.Headers.Add("x-ms-client-request-id", requestId); } request.Headers.Add("DataServiceVersion", "3.0"); if (responsePreference != null) { request.Headers.Add("Prefer", responsePreference.Value.ToString()); } request.Content = content; content.ApplyToRequest(request); return(message); }
internal void AddInsertEntityRequest(MultipartContent changeset, string table, int?timeout, string requestId, ResponseFormat?responsePreference, IDictionary <string, object> tableEntityProperties, QueryOptions queryOptions) { var message = CreateInsertEntityRequest(table, timeout, requestId, responsePreference, tableEntityProperties, queryOptions); changeset.Add(new RequestRequestContent(message.Request), new Dictionary <string, string> { { HttpHeader.Names.ContentType, ApplicationHttp }, { CteHeaderName, Binary } }); }
public virtual Response <TableResponse> Create(TableProperties tableProperties, string requestId = null, ResponseFormat?responsePreference = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("TableInternalClient.Create"); scope.Start(); try { return(RestClient.Create(tableProperties, requestId, responsePreference, queryOptions, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <IReadOnlyDictionary <string, object> > InsertEntity(string table, int?timeout = null, string requestId = null, ResponseFormat?responsePreference = null, IDictionary <string, object> tableEntityProperties = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("TableInternalClient.InsertEntity"); scope.Start(); try { return(RestClient.InsertEntity(table, timeout, requestId, responsePreference, tableEntityProperties, queryOptions, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }