private static void ProgressOcrResultAsync(ThreadModel model) { try { object ocrResult = null; ////Call Get OCR result //var client = new HttpClient(); //var queryString = HttpUtility.ParseQueryString(string.Empty); //// Request headers //client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}"); //var uri = "https://westcentralus.api.cognitive.microsoft.com/vision/v3.1/read/analyzeResults/{operationId}?" + queryString; //ocrResult = await client.GetAsync(uri); model.Response.Status = (int)HttpStatusCode.OK; model.Response.Message = "Successed"; model.Response.Data = ocrResult; model.Event.Set(); //Common.WriteLog(model); } catch (Exception ex) { //log Ex } finally { int availableThreads = Semaphore.Release(); } }
/// <summary> /// adding new request to queue /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool AddThreadRequest(ThreadModel model) { if (!ConcurrentDictionary.TryAdd(model.Name, model)) { return(false); } ConcurrentQueue.Enqueue(model.Name); QueueEvent.Set(); return(true); }
/// <summary> /// function process request /// </summary> /// <param name="model"></param> private static void ProgressAsync(ThreadModel model) { try { string operationId = string.Empty; ////Call Read Ocr result //var client = new HttpClient(); //var queryString = HttpUtility.ParseQueryString(string.Empty); //// Request headers //client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}"); //// Request parameters //queryString["language"] = "{string}"; //var uri = "https://westcentralus.api.cognitive.microsoft.com/vision/v3.1/read/analyze?" + queryString; //HttpResponseMessage response; //// Request body //byte[] byteData = Encoding.UTF8.GetBytes("{body}"); //using (var content = new ByteArrayContent(byteData)) //{ // content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); // response = await client.PostAsync(uri, content); //} //if (response.StatusCode == HttpStatusCode.Accepted // && response.Headers.TryGetValues("Operation-Location", out var headerValues)) //{ // operationId = headerValues.ToArray()[0]; //} //Then update state response model.OperationId = operationId; ConcurrentDictionary[model.Name] = model; //Common.WriteLog(model); } catch (Exception ex) { Console.WriteLine($"Error {model.Number}-------------------- {ex.Message}"); //Log ex } finally { int availableThreads = Semaphore.Release(); Console.WriteLine($" ---> AvailableThreads:{availableThreads} || Queue:{ConcurrentQueue.Count()} || Dictiondary:{ConcurrentDictionary.Count()}"); } }