private async Task PostAndWriteResultAsync(string argument) { this._cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = this._cancellationTokenSource.Token; try { cancellationToken.ThrowIfCancellationRequested(); this._pluginInterface.Framework.Gui.Chat.Print("Calculating..."); var byteArrayContent = new ByteArrayContent(JsonSerializer.SerializeToUtf8Bytes(new { numbers = argument })); byteArrayContent.Headers.ContentType = MediaTypeHeaderValue; cancellationToken.ThrowIfCancellationRequested(); var(statusCode, bytes) = await this._httpClient.PostAsync(FunctionUri, byteArrayContent, cancellationToken) .ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault switch (statusCode) { case HttpStatusCode.OK: { var results = MessagePackSerializer.Deserialize <V2>(bytes).Result; var maxMean = results.OrderByDescending(x => x.Value.Mean).First().Value.Mean; var maxMedian = results.OrderByDescending(x => x.Value.Median).First().Value.Median; this._pluginInterface.Framework.Gui.Chat.Print( "Line Mean Median Worst "); this._pluginInterface.Framework.Gui.Chat.Print( "------------------------------------------------------"); foreach (var result in results) { var(Mean, Median, (value, probability)) = result.Value; var line = $"{result.Key,-17} {Mean,8:F}{(Mean.Equals(maxMean) ? " *" : " ")} {Median,8:F}{(Median.Equals(maxMedian) ? " *" : " ")} {value,5:D}({probability,3}%)"; this._pluginInterface.Framework.Gui.Chat.Print(line); } break; } case HttpStatusCode.BadRequest: this._pluginInterface.Framework.Gui.Chat.PrintError("Please check your numbers and try again."); break; default: this._pluginInterface.Framework.Gui.Chat.Print("Server error. Please try later."); break; } } catch (OperationCanceledException) { this._pluginInterface.Framework.Gui.Chat.Print("Cancelled."); } finally { this._cancellationTokenSource.Dispose(); this._cancellationTokenSource = null; } }
/// <summary> /// Returns true if IngredientObjectNutrients instances are equal /// </summary> /// <param name="other">Instance of IngredientObjectNutrients to be compared</param> /// <returns>Boolean</returns> public bool Equals(IngredientObjectNutrients other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Name == other.Name || Name != null && Name.Equals(other.Name) ) && ( Per100g == other.Per100g || Per100g != null && Per100g.Equals(other.Per100g) ) && ( MeasurementUnit == other.MeasurementUnit || MeasurementUnit != null && MeasurementUnit.Equals(other.MeasurementUnit) ) && ( Min == other.Min || Min != null && Min.Equals(other.Min) ) && ( Max == other.Max || Max != null && Max.Equals(other.Max) ) && ( Median == other.Median || Median != null && Median.Equals(other.Median) ) && ( Rank == other.Rank || Rank != null && Rank.Equals(other.Rank) ) && ( DataPoints == other.DataPoints || DataPoints != null && DataPoints.Equals(other.DataPoints) ) && ( Footnote == other.Footnote || Footnote != null && Footnote.Equals(other.Footnote) ) && ( Description == other.Description || Description != null && Description.Equals(other.Description) )); }