private void AddProgressView(string progressMessage) { var mainForm = MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>(); mainForm.AddOperationProgressToView(this, progressMessage); progressViewCreated = true; }
private void RebuildDataTableAsync() { string resultName = (string)dataTableComboBox.SelectedItem; if (string.IsNullOrEmpty(resultName)) { return; } string rowName = (string)dataRowComboBox.SelectedItem; var task = Task.Factory.StartNew(() => { sem.Wait(); progress = MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Calculating values..."); RebuildDataTable(resultName, rowName); }); task.ContinueWith((t) => { MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); ErrorHandling.ShowErrorDialog("An error occured while calculating values. ", t.Exception); sem.Release(); }, TaskContinuationOptions.OnlyOnFaulted); task.ContinueWith((t) => { MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); sem.Release(); }, TaskContinuationOptions.OnlyOnRanToCompletion); }
private void LoadSamples(object state) { progress = MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(samplesListView, "Loading..."); try { var assembly = Assembly.GetExecutingAssembly(); var samples = assembly.GetManifestResourceNames().Where(x => x.EndsWith(SampleNameSuffix)); int count = samples.Count(); foreach (var entry in groupLookup) { var group = entry.Key; var sampleList = entry.Value; foreach (var sampleName in sampleList) { string resourceName = SampleNamePrefix + sampleName + SampleNameSuffix; LoadSample(resourceName, assembly, group, count); } } var categorizedSamples = groupLookup.Select(x => x.Value).SelectMany(x => x).Select(x => SampleNamePrefix + x + SampleNameSuffix); var uncategorizedSamples = samples.Except(categorizedSamples); foreach (var resourceName in uncategorizedSamples) { LoadSample(resourceName, assembly, uncategorizedGroup, count); } OnAllSamplesLoaded(); } finally { MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(samplesListView); } }
private void UploadAsync() { var message = "Uploading runs to OKB..."; IProgress progress = MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message); double count = dataGridView.Rows.Count; int i = 0; foreach (DataGridViewRow row in dataGridView.Rows) { i++; if (!Convert.ToBoolean(row.Cells[UploadColumn.Name].Value)) { continue; } selectedAlgorithm = algorithms.FirstOrDefault(x => x.Name == row.Cells[OKBAlgorithmColumn.Name].Value.ToString()); selectedProblem = problems.FirstOrDefault(x => x.Name == row.Cells[OKBProblemColumn.Name].Value.ToString()); if (selectedAlgorithm == null || selectedProblem == null) { throw new ArgumentException("Can't retrieve the algorithm/problem to upload"); } OKBRun run = new OKBRun(selectedAlgorithm.Id, selectedProblem.Id, row.Tag as IRun, UserInformation.Instance.User.Id); run.Store(); progress.ProgressValue = ((double)i) / count; } MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); ClearRuns(); }
private void progress_ProgressStateChanged(object sender, EventArgs e) { if (progress.ProgressState != ProgressState.Started) { MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromContent(content); progress.ProgressStateChanged -= progress_ProgressStateChanged; } }
private void CalculateValuesAsync(string groupName) { CalculateAllGroupsTest(); CalculateNormalityTest(); CalculatePairwiseTest(groupName); MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); }
protected override void DeregisterContentEvents() { base.DeregisterContentEvents(); Content.ModelChanged -= Content_Changed; Content.ProblemDataChanged -= Content_Changed; treeChart.Repainted -= treeChart_Repainted; MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(grpSimplify, false); }
protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.ModelChanged += Content_Changed; Content.ProblemDataChanged += Content_Changed; treeChart.Repainted += treeChart_Repainted; MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress); }
private void DeleteHiveJobsAsync(object items) { MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Deleting job..."); foreach (RefreshableJob item in (List <RefreshableJob>)items) { Content.Remove(item); } MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); }
private void btnUpload_Click(object sender, EventArgs e) { var task = System.Threading.Tasks.Task.Factory.StartNew(UploadAsync); task.ContinueWith((t) => { MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); PluginInfrastructure.ErrorHandling.ShowErrorDialog("An exception occured while uploading the runs to the OKB.", t.Exception); }, TaskContinuationOptions.OnlyOnFaulted); }
private void RunCreationClient_Refreshed(object sender, EventArgs e) { if (InvokeRequired) { Invoke((Action <object, EventArgs>)RunCreationClient_Refreshed, sender, e); return; } MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); refreshing = false; SetEnabledStateOfControls(); }
public void Close(CloseReason closeReason) { MainForm mainform = MainFormManager.GetMainForm <MainForm>(); Form form = mainform.GetForm(this); if (form != null) { this.IsShown = false; mainform.CloseView(this, closeReason); } }
private void RemoveProgressView() { if (!progressViewCreated) { return; } var mainForm = MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>(); mainForm.RemoveOperationProgressFromView(this); progressViewCreated = false; }
public void FinishProgressView() { if (InvokeRequired) { Invoke(new Action(FinishProgressView)); } else { MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); } }
private void RunCreationClient_Refreshing(object sender, EventArgs e) { if (InvokeRequired) { Invoke((Action <object, EventArgs>)RunCreationClient_Refreshing, sender, e); return; } var message = "Refreshing algorithms and problems..."; MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message); refreshing = true; SetEnabledStateOfControls(); }
public void StartProgressView() { if (InvokeRequired) { Invoke(new Action(StartProgressView)); } else { var message = "Downloading resources. Please be patient."; MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message); } }
private void samplesListView_DoubleClick(object sender, EventArgs e) { if (samplesListView.SelectedItems.Count == 1) { var mainForm = MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>(); try { mainForm.SetWaitCursor(); mainForm.ShowContent((IContent)((IItem)samplesListView.SelectedItems[0].Tag).Clone()); } finally { mainForm.ResetWaitCursor(); } } }
private void CalculatePairwise(string groupName) { if (groupName == null) { return; } if (!VerifyDataLength(false)) { return; } MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating..."); Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName)); }
public new void Show() { MainForm mainform = MainFormManager.GetMainForm <MainForm>(); bool firstTimeShown = mainform.GetForm(this) == null; this.IsShown = true; mainform.ShowView(this); if (firstTimeShown) { Form form = mainform.GetForm(this); form.FormClosed += new FormClosedEventHandler(OnClosedHelper); form.FormClosing += new FormClosingEventHandler(OnClosingHelper); } this.OnShown(new ViewShownEventArgs(this, firstTimeShown)); }
protected override void itemsListView_DragDrop(object sender, DragEventArgs e) { if (e.Effect != DragDropEffects.Copy) { return; } IDataAnalysisProblemData problemData = null; var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); if (dropData is IDataAnalysisProblemData) { problemData = (IDataAnalysisProblemData)dropData; } else if (dropData is IDataAnalysisProblem) { problemData = ((IDataAnalysisProblem)dropData).ProblemData; } else if (dropData is IValueParameter) { var param = (IValueParameter)dropData; problemData = param.Value as DataAnalysisProblemData; } if (problemData == null) { return; } problemData = (IDataAnalysisProblemData)problemData.Clone(); try { problemData.AdjustProblemDataProperties(Content.ProblemData); Content.ProblemData = problemData; if (!Content.Name.EndsWith(" with changed problemData")) { Content.Name += " with changed problemData"; } Content.Filename = string.Empty; MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().UpdateTitle(); } catch (InvalidOperationException invalidOperationException) { ErrorHandling.ShowErrorDialog(this, invalidOperationException); } catch (ArgumentException argumentException) { ErrorHandling.ShowErrorDialog(this, argumentException); } }
private void exportButton_Click(object sender, EventArgs e) { var exporter = new SymbolicDiscriminantFunctionClassificationSolutionExcelExporter(); exportFileDialog.Filter = exporter.FileTypeFilter; if (exportFileDialog.ShowDialog(this) == DialogResult.OK) { var name = exportFileDialog.FileName; using (BackgroundWorker bg = new BackgroundWorker()) { MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Exportion solution to " + name + "."); bg.DoWork += (o, a) => exporter.Export(Content, name); bg.RunWorkerCompleted += (o, a) => MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); bg.RunWorkerAsync(); } } }
private static void SavingCompleted(IStorableContent content, Exception error) { try { if (error != null) { throw error; } MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().UpdateTitle(); } catch (OperationCanceledException) { // do nothing if canceled } catch (Exception ex) { ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot save file.", ex); } finally { Progress.Hide(content); MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().ResetAppStartingCursor(); } }
protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.RefreshAutomaticallyChanged += new EventHandler(Content_RefreshAutomaticallyChanged); Content.JobChanged += new EventHandler(Content_HiveExperimentChanged); Content.IsControllableChanged += new EventHandler(Content_IsControllableChanged); Content.JobStatisticsChanged += new EventHandler(Content_JobStatisticsChanged); Content.ExceptionOccured += new EventHandler <EventArgs <Exception> >(Content_ExceptionOccured); Content.StateLogListChanged += new EventHandler(Content_StateLogListChanged); Content.HiveTasksChanged += new EventHandler(Content_HiveTasksChanged); Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged); Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged); Content.Loaded += new EventHandler(Content_Loaded); Content.TaskReceived += new EventHandler(Content_TaskReceived); MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, Content.Progress); }
private void CalculateValues() { if (!VerifyDataLength(true)) { return; } if (data != null && data.All(x => x != null)) { MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>() .AddOperationProgressToView(this, "Calculating..."); string curItem = (string)groupCompComboBox.SelectedItem; Task.Factory.StartNew(() => CalculateValuesAsync(curItem)); } }
public static void SaveAs(IContentView view) { IStorableContent content = view.Content as IStorableContent; if (!view.Locked && content != null) { if (saveFileDialog == null) { saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Save Item"; saveFileDialog.DefaultExt = "hl"; saveFileDialog.Filter = "Uncompressed HeuristicLab Files|*.hl|HeuristicLab Files|*.hl|All Files|*.*"; saveFileDialog.FilterIndex = 2; } INamedItem namedItem = content as INamedItem; string suggestedFileName = string.Empty; if (!string.IsNullOrEmpty(content.Filename)) { suggestedFileName = content.Filename; } else if (namedItem != null) { suggestedFileName = namedItem.Name; } else { suggestedFileName = "Item"; } saveFileDialog.FileName = suggestedFileName; if (saveFileDialog.ShowDialog() == DialogResult.OK) { MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().SetAppStartingCursor(); SetSaveOperationProgressInContentViews(content, true, saveFileDialog.FileName); if (saveFileDialog.FilterIndex == 1) { ContentManager.SaveAsync(content, saveFileDialog.FileName, false, SavingCompleted); } else { ContentManager.SaveAsync(content, saveFileDialog.FileName, true, SavingCompleted); } } } }
private static void SetSaveOperationProgressInContentViews(IStorableContent content, bool showProgress, string fileName = null) { HeuristicLab.MainForm.WindowsForms.MainForm mainForm = MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>(); #region Mono Compatibility // removed the InvokeRequired check because of Mono mainForm.Invoke((Action) delegate { if (showProgress) { mainForm.AddOperationProgressToContent(content, string.Format("Saving to file \"{0}\"...", Path.GetFileName(fileName ?? content.Filename))); } else { mainForm.RemoveOperationProgressFromContent(content); } }); #endregion }
private void addLineToChart_Click(object sender, EventArgs e) { MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Adding fitted lines to charts..."); string resultName = (string)dataTableComboBox.SelectedItem; string rowName = (string)dataRowComboBox.SelectedItem; var task = Task.Factory.StartNew(() => AddLineToChart(resultName, rowName)); task.ContinueWith((t) => { MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); ErrorHandling.ShowErrorDialog("An error occured while adding lines to charts. ", t.Exception); }, TaskContinuationOptions.OnlyOnFaulted); task.ContinueWith((t) => { MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); }, TaskContinuationOptions.OnlyOnRanToCompletion); }
private static void Save(IContentView view) { IStorableContent content = view.Content as IStorableContent; if (!view.Locked && content != null) { if (string.IsNullOrEmpty(content.Filename)) { SaveAs(view); } else { MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().SetAppStartingCursor(); SetSaveOperationProgressInContentViews(content, true); ContentManager.SaveAsync(content, content.Filename, true, SavingCompleted); } } }
private void DeleteHiveJobs(EventArgs e) { if (itemsListView.SelectedItems.Count > 0) { List <RefreshableJob> items = new List <RefreshableJob>(); foreach (ListViewItem item in itemsListView.SelectedItems) { items.Add((RefreshableJob)item.Tag); } var task = System.Threading.Tasks.Task.Factory.StartNew(DeleteHiveJobsAsync, items); task.ContinueWith((t) => { MainFormManager.GetMainForm <HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); ErrorHandling.ShowErrorDialog("An error occured while deleting the job. ", t.Exception); }, TaskContinuationOptions.OnlyOnFaulted); task.ContinueWith((t) => { itemsListView.Invoke(new Action(() => itemsListView.SelectedItems.Clear())); }, TaskContinuationOptions.OnlyOnRanToCompletion); } }
public override void Execute() { IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; content = activeView.Content as IItem; //IOptimizer and IExecutables need some special care if (content is IOptimizer) { ((IOptimizer)content).Runs.Clear(); } if (content is IExecutable) { IExecutable exec = content as IExecutable; if (exec.ExecutionState != ExecutionState.Prepared) { exec.Prepare(); } } HiveClient.Instance.Refresh(); ItemTask hiveTask = ItemTask.GetItemTaskForItem(content); HiveTask task = hiveTask.CreateHiveTask(); RefreshableJob rJob = new RefreshableJob(); rJob.Job.Name = content.ToString(); rJob.HiveTasks.Add(task); task.ItemTask.ComputeInParallel = content is Experiment || content is BatchRun; progress = MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().AddOperationProgressToContent(this.content, "Uploading to Hive..."); rJob.Progress = progress; progress.ProgressStateChanged += progress_ProgressStateChanged; HiveClient.StartJob(new Action <Exception>(HandleEx), rJob, new CancellationToken()); }