private async void btCacheAll_Click(object sender, EventArgs e) { var labelsToCache = _state.Labels.Where(ProfileFilter).Where(t => !t.HasCache).ToList(); if (labelsToCache.Count == 0) { MessageBox.Show("Nothing to cache"); return; } List <Guid> guids = new List <Guid>(); foreach (var label in labelsToCache) { var job = new CacheLabelJob() { LabelId = label._id, LogName = _controller.State.Info.Name }; guids.Add(job.Id); await ApiBoundary.AddCacheLabelJob(job); } //MessageBox.Show($"Added {labelsToCache.Count} cache jobs, wait and do not click this button again"); JobWaiterForm form = new JobWaiterForm(guids.ToArray()); form.jobWaiter.onAllJobsCompleted += async delegate { await _controller.LoadLabels(); RefreshDataInAdapter(); }; form.Show(); }
private async void btCache_Click(object sender, EventArgs e) { var job = new CacheLabelJob() { LabelId = data._id, LogName = _controller.State.Info.Name }; await ApiBoundary.AddCacheLabelJob(job); JobWaiterForm form = new JobWaiterForm(new Guid[] { job.Id }); form.jobWaiter.onAllJobsCompleted += async delegate { await _controller.LoadLabels(); RaiseOnDataDirty(); }; form.Show(); //MessageBox.Show("Added job, you may continue to work, do not click this button again"); }
public static async Task AddCacheLabelJob(CacheLabelJob job) { var json = JsonConvert.SerializeObject(job); HttpWebRequest wq = WebRequest.CreateHttp(SERVER_PATH + "/jobs/new/cachelabel"); wq.Method = "POST"; var reqStr = await wq.GetRequestStreamAsync(); using (var sw = new StreamWriter(reqStr)) { await sw.WriteAsync(json); sw.Close(); } var res = await wq.GetResponseAsync() as HttpWebResponse; if ((int)res.StatusCode != 200) { MessageBox.Show("error"); } }