/// <summary> /// Update restart buttons visibility and ableness based on the overall result /// </summary> /// <param name="result"></param> private void UpdateRestartButtons(OverallResult result) { bool areButtonsEnabled = false; switch (result) { case OverallResult.None: areButtonsEnabled = false; break; case OverallResult.NoItemsFound: areButtonsEnabled = false; break; case OverallResult.ItemsFoundAndRemoved: areButtonsEnabled = true; break; case OverallResult.ItemsFoundButNotRemoved: areButtonsEnabled = false; break; case OverallResult.Error: areButtonsEnabled = false; break; default: break; } this.RestartLaterButton.Visible = areButtonsEnabled; this.RestartLaterButton.Enabled = areButtonsEnabled; this.RestartNowButton.Visible = areButtonsEnabled; this.RestartNowButton.Enabled = areButtonsEnabled; }
/// <summary> /// Translate an overall result into what the end user will see as the result /// </summary> /// <param name="result"></param> private void UpdateOverallStatusLabel(OverallResult result) { var stringTable = Localizer.Get(); string newText = string.Empty; switch (result) { case OverallResult.None: goto case OverallResult.Error; case OverallResult.NoItemsFound: newText = stringTable.OverallStatusNotOnSystem; break; case OverallResult.ItemsFoundAndRemoved: newText = stringTable.OverallStatusAppRemoved; break; case OverallResult.ItemsFoundButNotRemoved: goto case OverallResult.Error; case OverallResult.Error: newText = stringTable.OverallStatusError; break; default: break; } this.OverallResultLabel.Text = newText; }
public static async Task Run( [BlobTrigger("raw-images/{name}", Connection = Constants.StoreConnectionName)] Stream myBlob, string name, [Queue("failure", Connection = Constants.StoreConnectionName)] CloudQueue failureQueue, [Queue("facesdetected", Connection = Constants.StoreConnectionName)] CloudQueue facesDetectedQueue, [Table("status", Connection = Constants.StoreConnectionName)] CloudTable statusTable, TraceWriter log ) { log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes"); var response = await CallFaceApiToDetectFaces(myBlob); if (response.StatusCode != HttpStatusCode.OK) { await AddMessageAsync(failureQueue, new Failure(name, response.StatusCode)); return; } string contentString = await response.Content.ReadAsStringAsync(); var faces = JsonConvert.DeserializeObject <Face[]>(contentString); var overallResult = new OverallResult(name, faces.Length, null); TableOperation insertOrMergeIdentificationResult = TableOperation.InsertOrReplace(overallResult); await statusTable.ExecuteAsync(insertOrMergeIdentificationResult); if (faces.Length > 0) { var detectFacesResult = new DetectFacesResult(name, faces.Select(x => x.FaceId).ToArray()); await AddMessageAsync(facesDetectedQueue, detectFacesResult); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, [Table("status", Connection = Constants.StoreConnectionName)] CloudTable statusTable, Binder binder, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); if (req.ContentType != "application/octet-stream" || req.ContentLength == 0) { return(new BadRequestObjectResult("Expected a jpeg image encoded as application/octet-stream")); } var identifier = Guid.NewGuid().ToString(); // add table entry so we can track overall status var overallResult = new OverallResult(identifier, null, null); TableOperation insertIdentificationResult = TableOperation.Insert(overallResult); await statusTable.ExecuteAsync(insertIdentificationResult); // store the image in a blob var bytes = GetImageBytes(req); await WriteImageToBlob(binder, identifier, bytes); return((ActionResult) new OkObjectResult(identifier)); }
private static async Task UpdateOverallStatus( CloudTable statusTable, DetectFacesResult facesResult, KnownFace[] knownFaces) { var overallResult = new OverallResult(facesResult.ImgId, facesResult.FaceIds.Length, knownFaces.Length); TableOperation insertOrMergeIdentificationResult = TableOperation.InsertOrReplace(overallResult); await statusTable.ExecuteAsync(insertOrMergeIdentificationResult); }
/// <summary> /// Prioritizes previous results with a current result to determine which one to keep /// </summary> /// <param name="previous"></param> /// <param name="mostRecent"></param> /// <returns></returns> internal static OverallResult CalculateMergedResult(OverallResult previous, OverallResult mostRecent) { var mostRelevant = previous; if (mostRecent > previous) { mostRelevant = mostRecent; } return(mostRelevant); }
public void TestConstruction04() { var xml = new XmlDocument(); var reader = XmlReader.Create(new StringReader(Resources.TestStrings.XmlOverallResult04)); reader.Read(); var result = new OverallResult(xml.ReadNode(reader)); Assert.IsFalse(result.Success); Assert.AreEqual(new TimeSpan((Int64)(0.064298 * TimeSpan.TicksPerSecond)), result.Duration); Assert.AreEqual("cerr 01\ncerr 02", result.StdErr); Assert.AreEqual(string.Empty, result.StdOut); }
public void TestConstruction02() { var xml = new XmlDocument(); var reader = XmlReader.Create(new StringReader(Resources.TestStrings.XmlOverallResult02)); reader.Read(); var result = new OverallResult(xml.ReadNode(reader)); Assert.IsTrue(result.Success); Assert.AreEqual(new TimeSpan(0), result.Duration); Assert.AreEqual(string.Empty, result.StdErr); Assert.AreEqual(string.Empty, result.StdOut); }
/// <summary> /// Prioritizes previous results with a current result to determine which one to keep /// </summary> /// <param name="previous"></param> /// <param name="mostRecent"></param> /// <returns></returns> private static OverallResult CalculateMergedResult(OverallResult previous, OverallResult mostRecent) { var mostRelevant = previous; if (previous > mostRecent) { mostRelevant = previous; } else { mostRelevant = mostRecent; } return(mostRelevant); }
/// <summary> /// Translates a single removal result into an overall result for displaying to the user /// </summary> /// <param name="fixResult"></param> /// <returns></returns> private static OverallResult CalculateSingleResult(Utilities.FixResult fixResult) { OverallResult result = OverallResult.None; if (fixResult == null || fixResult.DidFail) { result = OverallResult.Error; } else { if (fixResult.DidExist) { result = fixResult.WasRemoved ? OverallResult.ItemsFoundAndRemoved : OverallResult.ItemsFoundButNotRemoved; } else { result = OverallResult.NoItemsFound; } } return(result); }
/// <summary> /// Update restart buttons visibility and ableness based on the overall result /// </summary> /// <param name="result"></param> private void UpdateRestartButtons(OverallResult result) { bool areButtonsEnabled = false; switch (result) { case OverallResult.None: areButtonsEnabled = false; break; case OverallResult.NoItemsFound: areButtonsEnabled = false; break; case OverallResult.ItemsFoundAndRemoved: areButtonsEnabled = true; break; case OverallResult.ItemsFoundButNotRemoved: areButtonsEnabled = false; break; case OverallResult.Error: areButtonsEnabled = false; break; default: break; } this.RestartLaterButton.Visible = areButtonsEnabled; this.RestartLaterButton.Enabled = areButtonsEnabled; this.RestartNowButton.Visible = areButtonsEnabled; this.RestartNowButton.Enabled = areButtonsEnabled; }
/// <summary> /// Translate an overall result into what the end user will see as the result /// </summary> /// <param name="result"></param> private void UpdateOverallStatusLabel(OverallResult result) { var stringTable = Localization.LocalizationManager.Get(); string newText = string.Empty; switch (result) { case OverallResult.None: case OverallResult.ItemsFoundButNotRemoved: case OverallResult.Error: newText = stringTable.OverallStatusError; break; case OverallResult.NoItemsFound: newText = stringTable.OverallStatusNotOnSystem; break; case OverallResult.ItemsFoundAndRemoved: newText = stringTable.OverallStatusAppRemoved; break; default: break; } this.OverallResultLabel.Text = newText; }
/// <summary> /// Prioritizes previous results with a current result to determine which one to keep /// </summary> /// <param name="previous"></param> /// <param name="mostRecent"></param> /// <returns></returns> internal static OverallResult CalculateMergedResult(OverallResult previous, OverallResult mostRecent) { var mostRelevant = previous; if (mostRecent > previous) { mostRelevant = mostRecent; } return mostRelevant; }
private void InitializeBackgroundWorker() { this.MainProgressBar.Value = 5; var backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.DoWork += (sender, e) => { var bgWorker = sender as BackgroundWorker; if (bgWorker != null) { OverallResult overallResult = OverallResult.None; var stringTable = Localizer.Get(); var agents = GetSuperfishRemovalAgents().ToList(); if (agents != null && agents.Any()) { foreach (var agent in agents) { try { double percentageComplete = ((double)(agents.IndexOf(agent) + 1) / (double)agents.Count) * 100; var removalResult = TryToExecuteRemoval(agent); bgWorker.ReportProgress(Convert.ToInt32(percentageComplete), removalResult); overallResult = CalculateSingleResult(removalResult); System.Threading.Thread.Sleep(1000); // Some of the agents perform very quickly. Slow it down to show each step } catch (Exception ex) { Logging.Logger.Log(Logging.LogSeverity.Error, ex.Message); } } } bgWorker.ReportProgress(100, overallResult); System.Threading.Thread.Sleep(500); // Let the user see the final 100% before hiding progress bar } }; backgroundWorker.ProgressChanged += (sender, e) => { if (e != null) { if (e.UserState == null) { this.UpdateOverallStatusLabel(OverallResult.Error); } else { this.MainProgressBar.Value = e.ProgressPercentage; var result = e.UserState as Utilities.FixResult; if (result != null) { this.AddLabelBasedOnIndividualResult(result); } else { var overallStatus = (OverallResult)e.UserState; if (overallStatus != OverallResult.None) { this.UpdateOverallStatusLabel(overallStatus); this.UpdateRestartButtons(overallStatus); } } } } }; backgroundWorker.RunWorkerCompleted += (sender, e) => { this.IsDoingWork = false; this.MainProgressBar.Value = 0; }; backgroundWorker.RunWorkerAsync(); // Start! }
public CustomerResult() { Result = new OverallResult(); }
public async Task MakePurchaseCallAsyncTestAsync() { var model = new PurchaseModel() { Items = new List <ItemModel>() { new ItemModel() { Brand = "cola", Id = 1, Name = "coke", Price = (decimal)1.5, Quantity = 20, TotalPrice = 30 } }, PaymentType = 1 }; var returnobject = new OverallResult <List <Results <ItemModel> > >() { Objects = new List <Results <ItemModel> >() { new Results <ItemModel>() { Exception = null, HttpStatusCode = HttpStatusCode.OK, Result = new ItemModel() { Brand = "cola", Id = 1, Name = "coke", Price = (decimal)1.5, Quantity = 20, TotalPrice = 30 }, Success = true }, new Results <ItemModel>() { Exception = null, HttpStatusCode = HttpStatusCode.OK, Result = new ItemModel() { Brand = "cola", Id = 2, Name = "coke", Price = (decimal)1.5, Quantity = 20, TotalPrice = 30 }, Success = true } }, Success = true }; _requestManger.Setup(e => e.PatchRequest(It.IsAny <string>(), model, It.IsAny <string>())).Returns(Task.FromResult(JsonConvert.SerializeObject(returnobject))); var result = await _purchaseHandler.MakePurchaseCallAsync(model, "it is the token"); result.Objects.Count.Should().Be(2); result.Should().NotBeNull(); }