- Timestamp:
- 02/14/11 18:23:37 (13 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveExperimentClient.cs
r5404 r5458 38 38 using HeuristicLab.PluginInfrastructure; 39 39 using System.IO; 40 using System.Configuration; 41 using System.Reflection; 42 using HeuristicLab.PluginInfrastructure.Manager; 40 43 41 44 /// <summary> … … 76 79 } 77 80 78 private string resource Ids;79 public string Resource Ids {80 get { return resource Ids; }81 private string resourceNames; 82 public string ResourceNames { 83 get { return resourceNames; } 81 84 set { 82 if (resource Ids != value) {83 resource Ids = value;84 OnResource IdsChanged();85 if (resourceNames != value) { 86 resourceNames = value; 87 OnResourceNamesChanged(); 85 88 } 86 89 } … … 117 120 public IEnumerable<Plugin> OnlinePlugins { 118 121 get { return onlinePlugins; } 119 set { onlinePlugins = value; } 122 set { onlinePlugins = value; } 120 123 } 121 124 … … 131 134 set { useLocalPlugins = value; } 132 135 } 133 134 public HiveExperimentClient() : base(itemName, itemDescription) {135 // TODO //this.ResourceIds = HeuristicLab.Hive.Experiment.Properties.Settings.Default.ResourceIds;136 this.Resource Ids = "HEAL";136 137 public HiveExperimentClient() 138 : base(itemName, itemDescription) { 139 this.ResourceNames = "HEAL"; 137 140 this.log = new Log(); 138 141 InitTimer(); 139 142 } 140 public HiveExperimentClient(DT.HiveExperiment hiveExperimentDto) : this() { 143 public HiveExperimentClient(DT.HiveExperiment hiveExperimentDto) 144 : this() { 141 145 UpdateFromDto(hiveExperimentDto); 142 146 } 143 147 protected HiveExperimentClient(HiveExperimentClient original, Cloner cloner) 144 148 : base(original, cloner) { 145 this.Resource Ids = original.resourceIds;149 this.ResourceNames = original.resourceNames; 146 150 this.ExecutionState = original.executionState; 147 151 this.ExecutionTime = original.executionTime; … … 158 162 this.Name = hiveExperimentDto.Name; 159 163 this.Description = hiveExperimentDto.Description; 160 // TODO: this.ResourceIds = hiveExperimentDto.ResourceIds;164 this.ResourceNames = hiveExperimentDto.ResourceNames; 161 165 this.rootJobId = hiveExperimentDto.RootJobId; 162 166 } … … 167 171 Name = this.Name, 168 172 Description = this.Description, 169 //ResourceIds = this.ResourceIds,173 ResourceNames = this.ResourceNames, 170 174 RootJobId = this.rootJobId 171 175 }; … … 227 231 228 232 public void Prepare() { 229 // do nothing 233 this.timer.Stop(); 234 this.ExecutionState = Core.ExecutionState.Prepared; 235 this.ExecutionTime = TimeSpan.Zero; 230 236 } 231 237 232 238 public void Start() { 233 239 OnStarted(); 234 ExecutionTime = new TimeSpan();240 ExecutionTime = TimeSpan.Zero; 235 241 lastUpdateTime = DateTime.Now; 236 242 this.ExecutionState = Core.ExecutionState.Started; … … 246 252 IsProgressing = true; 247 253 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) { 248 IEnumerable<string> groups = ToResourceIdList(this.ResourceIds); 254 IEnumerable<string> resourceNames = ToResourceNameList(this.ResourceNames); 255 var resourceIds = new List<Guid>(); 256 foreach (var resourceName in resourceNames) { 257 Guid resourceId = service.Obj.GetResourceId(resourceName); 258 if (resourceId == Guid.Empty) { 259 throw new ResourceNotFoundException(string.Format("Could not find the resource '{0}'", resourceName)); 260 } 261 resourceIds.Add(resourceId); 262 } 263 249 264 this.HiveJob.SetIndexInParentOptimizerList(null); 250 265 … … 255 270 this.OnlinePlugins = service.Obj.GetPlugins(); 256 271 this.AlreadyUploadedPlugins = new List<Plugin>(); 272 Plugin configFilePlugin = UploadConfigurationFile(service.Obj); 273 this.alreadyUploadedPlugins.Add(configFilePlugin); 257 274 258 275 this.progress.Status = "Uploading jobs..."; 259 UploadJobWithChildren(service.Obj, this.HiveJob, null, groups, ref jobCount, totalJobCount);276 UploadJobWithChildren(service.Obj, this.HiveJob, null, resourceIds, ref jobCount, totalJobCount, configFilePlugin.Id); 260 277 this.rootJobId = this.HiveJob.Job.Id; 261 278 LogMessage("Finished sending jobs to hive"); … … 272 289 catch (Exception e) { 273 290 OnExceptionOccured(e); 291 this.Prepare(); 274 292 } 275 293 finally { 276 294 IsProgressing = false; 277 295 } 296 } 297 298 /// <summary> 299 /// Uploads the local configuration file as plugin 300 /// </summary> 301 private static Plugin UploadConfigurationFile(IHiveService service) { 302 string exeFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HeuristicLab 3.3.exe"); 303 string configFileName = ConfigurationManager.OpenExeConfiguration(exeFilePath).FilePath; 304 305 Plugin configPlugin = new Plugin() { 306 Name = "Configuration", 307 IsLocal = true, 308 Version = new Version() 309 }; 310 PluginData configFile = new PluginData() { 311 FileName = configFileName, 312 Data = File.ReadAllBytes(configFileName) 313 }; 314 configPlugin.Id = service.AddPlugin(configPlugin, new List<PluginData> { configFile }); 315 return configPlugin; 278 316 } 279 317 … … 286 324 /// <param name="parentHiveJob">shall be null if its the root job</param> 287 325 /// <param name="groups"></param> 288 private void UploadJobWithChildren(IHiveService service, HiveJob hiveJob, HiveJob parentHiveJob, IEnumerable< string> groups, ref int jobCount, int totalJobCount) {326 private void UploadJobWithChildren(IHiveService service, HiveJob hiveJob, HiveJob parentHiveJob, IEnumerable<Guid> groups, ref int jobCount, int totalJobCount, Guid configPluginId) { 289 327 jobCount++; 290 328 this.progress.Status = string.Format("Serializing job {0} of {1}", jobCount, totalJobCount); … … 301 339 302 340 hiveJob.Job.PluginsNeededIds = GetPluginDependencies(service, onlinePlugins, alreadyUploadedPlugins, plugins, useLocalPlugins); 341 hiveJob.Job.PluginsNeededIds.Add(configPluginId); 303 342 304 343 this.progress.Status = string.Format("Uploading job {0} of {1} ({2} kb)", jobCount, totalJobCount, jobData.Data.Count() / 1024); … … 306 345 307 346 if (parentHiveJob != null) { 308 //response = service.AddChildJob(parentHiveJob.Job.Id, serializedJob);309 347 hiveJob.Job.Id = service.AddChildJob(parentHiveJob.Job.Id, hiveJob.Job, jobData); 310 348 } else { 311 // response = service.AddJobWithGroupStrings(serializedJob, groups); 312 hiveJob.Job.Id = service.AddJob(hiveJob.Job, jobData, null); // todo: use ResourceIds 349 hiveJob.Job.Id = service.AddJob(hiveJob.Job, jobData, groups); 313 350 } 314 351 … … 316 353 317 354 foreach (HiveJob child in hiveJob.ChildHiveJobs) { 318 UploadJobWithChildren(service, child, hiveJob, groups, ref jobCount, totalJobCount );319 } 320 } 321 355 UploadJobWithChildren(service, child, hiveJob, groups, ref jobCount, totalJobCount, configPluginId); 356 } 357 } 358 322 359 /// <summary> 323 360 /// Converts a string which can contain Ids separated by ';' to a enumerable 324 361 /// </summary> 325 private IEnumerable<string> ToResource IdList(string resourceGroups) {362 private IEnumerable<string> ToResourceNameList(string resourceGroups) { 326 363 if (!string.IsNullOrEmpty(resourceGroups)) { 327 return resource Ids.Split(';');364 return resourceNames.Split(';'); 328 365 } else { 329 366 return new List<string>(); … … 395 432 } 396 433 397 public event EventHandler Resource IdsChanged;398 protected virtual void OnResource IdsChanged() {399 EventHandler handler = Resource IdsChanged;434 public event EventHandler ResourceNamesChanged; 435 protected virtual void OnResourceNamesChanged() { 436 EventHandler handler = ResourceNamesChanged; 400 437 if (handler != null) handler(this, EventArgs.Empty); 401 438 } … … 649 686 } 650 687 } 651 #endregion 688 #endregion 652 689 653 690 #region Plugin Management -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/HeuristicLab.Clients.Hive-3.4.csproj
r5457 r5458 102 102 </Reference> 103 103 <Reference Include="System" /> 104 <Reference Include="System.Configuration" /> 104 105 <Reference Include="System.Core" /> 105 106 <Reference Include="System.Drawing" /> … … 118 119 <Compile Include="Exceptions\OptimizerNotFoundException.cs" /> 119 120 <Compile Include="ExperimentManager\PluginClient.cs" /> 121 <Compile Include="Exceptions\ResourceNotFoundException.cs" /> 120 122 <Compile Include="IServiceLocator.cs" /> 121 123 <Compile Include="Jobs\OptimizerJob.cs" />
Note: See TracChangeset
for help on using the changeset viewer.