using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Linq; using System.Windows.Forms; using HeuristicLab.OKB.Client; using HeuristicLab.MainForm; namespace HeuristicLab.OKB.AlgorithmHost { [ViewAttribute("AlgorithmContainer View")] [Content(typeof(AlgorithmContainer), true)] public partial class AlgorithmContainerView : ParameterizedNamedItemContainerView { private Mapping resultMapping; public AlgorithmContainerView() { resultMapping = new Mapping(); InitializeComponent(); } public new AlgorithmContainer Content { get { return (AlgorithmContainer)base.Content; } set { base.Content = value; } } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { resultMapping.Map = null; } else { resultMapping.Map = Content.ResultMapping; resultMappingView.Content = resultMapping; } } private DataTable backgroundLoadedResults = null; protected override void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { backgroundWorker.ReportProgress(0); var client = ClientFactory.Create(); int count; DataTable results = client.PrepareDataTable(out count, "Result"); results.BeginLoadData(); DataTable newRows; do { newRows = client.GetNextRows(100); results.Merge(newRows); } while (newRows != null && newRows.Rows.Count > 0); client.FinishFetchingRows(); client.Close(); results.EndLoadData(); backgroundLoadedResults = results; base.backgroundWorker_DoWork(sender, e); } protected override void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { base.backgroundWorker_RunWorkerCompleted(sender, e); resultMappingView.Enabled = false; if (backgroundLoadedParameters != null) { resultMapping.Values.Clear(); resultMapping.Values.Add(null); resultMapping.Values.AddRange(backgroundLoadedResults.Rows.Cast().Select(r => (string)r["Name"])); resultMappingView.Enabled = true; } } private void stripButton_Click(object sender, EventArgs e) { Content.Strip(); this.Enabled = false; } } }