- Timestamp:
- 07/18/14 13:44:53 (10 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HiveStatistics/sources/HeuristicLab.Optimizer/3.3/StartPage.cs
r11203 r11205 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.IO; 24 25 using System.Linq; … … 34 35 [View("Start Page")] 35 36 public partial class StartPage : HeuristicLab.MainForm.WindowsForms.View { 37 private const string StandardProblemsGroupName = "Standard Problems"; 38 private const string DataAnalysisGroupName = "Data Analysis"; 39 private const string ScriptsGroupName = "Scripts"; 40 private const string UncategorizedGroupName = "Uncategorized"; 41 private const string SampleNamePrefix = "HeuristicLab.Optimizer.Documents."; 42 private const string SampleNameSuffix = ".hl"; 43 44 private readonly Dictionary<ListViewGroup, List<string>> groupLookup = new Dictionary<ListViewGroup, List<string>>(); 45 private readonly ListViewGroup standardProblemsGroup = new ListViewGroup(StandardProblemsGroupName); 46 private readonly ListViewGroup dataAnalysisGroup = new ListViewGroup(DataAnalysisGroupName); 47 private readonly ListViewGroup scriptsGroup = new ListViewGroup(ScriptsGroupName); 48 private readonly ListViewGroup uncategorizedGroup = new ListViewGroup(UncategorizedGroupName); 49 50 private IProgress progress; 51 36 52 public StartPage() { 37 53 InitializeComponent(); … … 49 65 using (Stream stream = assembly.GetManifestResourceStream(typeof(StartPage), "Documents.FirstSteps.rtf")) 50 66 firstStepsRichTextBox.LoadFile(stream, RichTextBoxStreamType.RichText); 51 } 52 catch (Exception) { } 67 } catch (Exception) { } 53 68 54 69 samplesListView.Enabled = false; 70 samplesListView.Groups.Add(standardProblemsGroup); 71 samplesListView.Groups.Add(dataAnalysisGroup); 72 samplesListView.Groups.Add(scriptsGroup); 73 samplesListView.Groups.Add(uncategorizedGroup); 74 FillGroupLookup(); 75 55 76 showStartPageCheckBox.Checked = Properties.Settings.Default.ShowStartPage; 56 77 … … 67 88 68 89 private void LoadSamples(object state) { 69 Assembly assembly = Assembly.GetExecutingAssembly(); 70 var samples = assembly.GetManifestResourceNames().Where(x => x.EndsWith(".hl")); 71 int count = samples.Count(); 90 progress = MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(samplesListView, "Loading..."); 91 try { 92 var assembly = Assembly.GetExecutingAssembly(); 93 var samples = assembly.GetManifestResourceNames().Where(x => x.EndsWith(SampleNameSuffix)); 94 int count = samples.Count(); 95 96 foreach (var entry in groupLookup) { 97 var group = entry.Key; 98 var sampleList = entry.Value; 99 foreach (var sampleName in sampleList) { 100 string resourceName = SampleNamePrefix + sampleName + SampleNameSuffix; 101 LoadSample(resourceName, assembly, group, count); 102 } 103 } 104 105 var categorizedSamples = groupLookup.Select(x => x.Value).SelectMany(x => x).Select(x => SampleNamePrefix + x + SampleNameSuffix); 106 var uncategorizedSamples = samples.Except(categorizedSamples); 107 108 foreach (var resourceName in uncategorizedSamples) { 109 LoadSample(resourceName, assembly, uncategorizedGroup, count); 110 } 111 112 OnAllSamplesLoaded(); 113 } finally { 114 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(samplesListView); 115 } 116 } 117 118 private void LoadSample(string name, Assembly assembly, ListViewGroup group, int count) { 72 119 string path = Path.GetTempFileName(); 73 74 foreach (string name in samples) { 75 try { 76 using (Stream stream = assembly.GetManifestResourceStream(name)) { 77 WriteStreamToTempFile(stream, path); 78 INamedItem item = XmlParser.Deserialize<INamedItem>(path); 79 OnSampleLoaded(item, loadingProgressBar.Maximum / count); 80 } 81 } 82 catch (Exception) { } 83 } 84 OnAllSamplesLoaded(); 85 } 86 private void OnSampleLoaded(INamedItem sample, int progress) { 120 try { 121 using (var stream = assembly.GetManifestResourceStream(name)) { 122 WriteStreamToTempFile(stream, path); // create a file in a temporary folder (persistence cannot load these files directly from the stream) 123 var item = XmlParser.Deserialize<INamedItem>(path); 124 OnSampleLoaded(item, group, 1.0 / count); 125 } 126 } catch (Exception) { 127 } finally { 128 if (File.Exists(path)) { 129 File.Delete(path); // make sure we remove the temporary file 130 } 131 } 132 } 133 134 private void FillGroupLookup() { 135 var standardProblems = new List<string> { "ES_Griewank", "GA_TSP", "GA_VRP", "GE_ArtificialAnt", 136 "IslandGA_TSP", "LS_Knapsack", "PSO_Schwefel", "RAPGA_JSSP", 137 "SA_Rastrigin", "SGP_SantaFe","GP_Multiplexer", "SS_VRP", "TS_TSP", "TS_VRP", "VNS_TSP" 138 }; 139 groupLookup[standardProblemsGroup] = standardProblems; 140 var dataAnalysisProblems = new List<string> { "SGP_SymbClass", "SGP_SymbReg", "OSGP_TimeSeries", "GE_SymbReg", "GPR" }; 141 groupLookup[dataAnalysisGroup] = dataAnalysisProblems; 142 var scripts = new List<string> { "GA_QAP_Script", "GUI_Automation_Script", "OSGA_Rastrigin_Script" }; 143 groupLookup[scriptsGroup] = scripts; 144 } 145 146 private void OnSampleLoaded(INamedItem sample, ListViewGroup group, double progress) { 87 147 if (InvokeRequired) 88 Invoke(new Action<INamedItem, int>(OnSampleLoaded), sample, progress);148 Invoke(new Action<INamedItem, ListViewGroup, double>(OnSampleLoaded), sample, group, progress); 89 149 else { 90 ListViewItem item = new ListViewItem(new string[] { sample.Name, sample.Description } );150 ListViewItem item = new ListViewItem(new string[] { sample.Name, sample.Description }, group); 91 151 item.ToolTipText = sample.ItemName + ": " + sample.ItemDescription; 92 152 samplesListView.SmallImageList.Images.Add(sample.ItemImage); … … 94 154 item.Tag = sample; 95 155 samplesListView.Items.Add(item); 96 loadingProgressBar.Value += progress;156 this.progress.ProgressValue += progress; 97 157 } 98 158 } … … 106 166 samplesListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 107 167 } 108 loadingPanel.Visible = false;109 168 } 110 169 } … … 115 174 116 175 private void samplesListView_DoubleClick(object sender, EventArgs e) { 117 if (samplesListView.SelectedItems.Count == 1) 118 MainFormManager.MainForm.ShowContent((IContent)((IItem)samplesListView.SelectedItems[0].Tag).Clone()); 176 if (samplesListView.SelectedItems.Count == 1) { 177 var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>(); 178 try { 179 mainForm.SetWaitCursor(); 180 mainForm.ShowContent((IContent)((IItem)samplesListView.SelectedItems[0].Tag).Clone()); 181 } finally { 182 mainForm.ResetWaitCursor(); 183 } 184 185 } 119 186 } 120 187 private void samplesListView_ItemDrag(object sender, ItemDragEventArgs e) { … … 134 201 private void WriteStreamToTempFile(Stream stream, string path) { 135 202 using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) { 136 int cnt = 0; 137 byte[] buffer = new byte[32 * 1024]; 138 while ((cnt = stream.Read(buffer, 0, buffer.Length)) != 0) 139 output.Write(buffer, 0, cnt); 203 stream.CopyTo(output); 140 204 } 141 205 }
Note: See TracChangeset
for help on using the changeset viewer.