public async Task <UploadOutputResult> UploadOutputAsync(int inputId, OutputContent outputContent) { using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.UserAgent.Add(UserAgent); httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); var query = $"inputId={inputId}" + $"&email={UrlEncoder.Default.Encode(_configuration.GetValue<string>("BatchClient:Email"))}"; var response = await httpClient.PostAsJsonAsync(BaseUrl + $"api/Batch/UploadOutput?{query}", outputContent); if (!response.IsSuccessStatusCode) { if (response.StatusCode == HttpStatusCode.BadRequest || response.StatusCode == HttpStatusCode.NotFound || response.StatusCode == HttpStatusCode.Forbidden) { var errorMessage = await response.Content.ReadAsStringAsync(); throw new HttpRequestException($"{(int) response.StatusCode} {response.StatusCode.ToString()}: {errorMessage}"); } response.EnsureSuccessStatusCode(); } return(JsonConvert.DeserializeObject <UploadOutputResult>(await response.Content.ReadAsStringAsync())); } }
public OutputContent GetContent(ICacheProvider cacheProvider) { var upgraded = false; _lock.EnterUpgradeableReadLock(); try { // check the cache first var cachedValue = cacheProvider.Get <OutputContent>(GetCacheKeyFor(RequestFor)); if (cachedValue == null) { _lock.EnterWriteLock(); upgraded = true; var content = this.Select(f => f.GetContent(cacheProvider)); var minificationProvider = MinificationRegistry.Get(ResourceType); Log.WriteLine("Combining content for '{0}'", RequestFor); // Combine all of the files into one string var minifiedContent = minificationProvider.Combine(content.Select(x => x.Content)); cachedValue = new OutputContent { Content = minifiedContent, ContentHash = minifiedContent.HashArray(), AllowClientCaching = ContainsPlaceHolder || CacheFor.HasValue, CacheFor = CacheFor, ContentType = minificationProvider.GetContentType(RequestFor), LastModifiedDate = content.Max(x => x.LastModifiedDate) }; cacheProvider.Add(GetCacheKeyFor(RequestFor), cachedValue, GetDependencies()); } return(cachedValue); } finally { if (upgraded) { _lock.ExitWriteLock(); } _lock.ExitUpgradeableReadLock(); } }
public IHttpActionResult Post(InputParameter input) { if (input == null) { return(BadRequest()); } try { var score = _parseService.ParseToScore(input.value); OutputContent content = new OutputContent(score); return(Ok(content)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public static extern UInt32 LPR_ControlContent(ref OutputContent pContent);
public OutputContent GetContent(ICacheProvider cacheProvider, Mode mode) { var upgraded = false; _lock.EnterUpgradeableReadLock(); try { // check the cache first var returnValue = cacheProvider.Get <OutputContent>(GetCacheKeyFor(VirtualPath, mode)); if (returnValue == null) { Log.WriteLine("Generating Content For '{0}'", VirtualPath); _lock.EnterWriteLock(); upgraded = true; byte[] rejuicedValue = null; var file = new FileInfo(PhysicalPath); // clear existing dependencies _dependencies.Clear(); var minificationProvider = MinificationRegistry.Get(ResourceType); var notFound = false; try { var fileBytes = File.ReadAllBytes(PhysicalPath); if (fileBytes.Length > 2 && fileBytes[0] == 0xEF && fileBytes[1] == 0xBB && fileBytes[2] == 0xBF) { fileBytes = fileBytes.Skip(3).ToArray(); } rejuicedValue = FileTransformationPipeline.TransformInputFile(this, fileBytes); } catch (IOException) { } // Combined value var combinedValue = new OutputContent { Content = rejuicedValue, ContentHash = rejuicedValue.HashArray(), AllowClientCaching = false, ContentType = ResourceType == ResourceType.Css ? "text/css" : "text/javascript", LastModifiedDate = file.LastWriteTimeUtc }; var dependencies = GetDependencies(); cacheProvider.Add(GetCacheKeyFor(VirtualPath, Mode.Combine), combinedValue, dependencies); returnValue = combinedValue; if (Mode == Mode.Minify && !notFound) { Log.WriteLine("Minifying Content For '{0}'", VirtualPath); // Minified value byte[] minifiedContent = null; try { minifiedContent = minificationProvider.Minify(rejuicedValue); } catch (Exception e) { // Yes, catching Exception is bad. However, anyone can plug in their own minification provider // and throw any exception they want. We want to make sure that exceptions thrown by rejuicer // have the filename inside them. So we just wrap the exception here & throw the wrapped exception. throw new InvalidOperationException(string.Format("Encountered exception trying minify invalid JavaScript for file '{0}'.", VirtualPath), e); } var minifiedValue = new OutputContent { Content = minifiedContent, ContentHash = minifiedContent.HashArray(), AllowClientCaching = false, ContentType = ResourceType == ResourceType.Css ? "text/css" : "text/javascript", LastModifiedDate = file.LastWriteTimeUtc }; cacheProvider.Add(GetCacheKeyFor(VirtualPath, mode), minifiedValue, dependencies); returnValue = minifiedValue; } } return(returnValue); } finally { if (upgraded) { _lock.ExitWriteLock(); } _lock.ExitUpgradeableReadLock(); } }