- Timestamp:
- 05/29/09 15:14:32 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Client.Core/3.2/JobStorage/JobStorageManager.cs
r1775 r1959 10 10 using System.Xml.Serialization; 11 11 using System.Diagnostics; 12 using System.Xml; 12 13 13 14 namespace HeuristicLab.Hive.Client.Core.JobStorage { … … 15 16 16 17 private static List<JobStorageInfo> storedJobsList = new List<JobStorageInfo>(); 17 //Todo: execution path 18 //Todo: Choose a better directory name 19 private static String path = "C:\\Program Files\\HeuristicLab 3.0\\plugins\\Hive.Client.Jobs\\"; 18 19 private static String path = System.IO.Directory.GetCurrentDirectory()+"\\plugins\\Hive.Client.Jobs\\"; 20 20 21 21 public static void PersistObjectToDisc(String serverIP, long serverPort, Guid jobId, byte[] job) { 22 22 String filename = serverIP + "." + serverPort + "." + jobId.ToString(); 23 23 JobStorageInfo info = new JobStorageInfo { JobID = jobId, ServerIP = serverIP, ServerPort = serverPort, TimeFinished = DateTime.Now }; 24 25 if (!Directory.Exists(path)) 26 Directory.CreateDirectory(path); 27 24 28 25 Stream jobstream = null; 29 26 try { 30 27 jobstream = File.Create(path + filename + ".dat"); 31 28 jobstream.Write(job, 0, job.Length); 32 storedJobsList.Add(info); 33 Debug.WriteLine("Job " + info.JobID + " stored on the harddisc"); 34 //Logging.Instance.Info("JobStorageManager", "Job " + info.JobID + " stored on the harddisc"); 29 storedJobsList.Add(info); 30 Logging.Instance.Info("JobStorageManager", "Job " + info.JobID + " stored on the harddisc"); 35 31 } 36 32 catch (Exception e) { … … 49 45 for(int index=storedJobsList.Count; index > 0; index--) { 50 46 if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin && (storedJobsList[index-1].ServerIP == WcfService.Instance.ServerIP && storedJobsList[index-1].ServerPort == WcfService.Instance.ServerPort)) { 51 String filename = storedJobsList[index-1].ServerIP + "." + storedJobsList[index-1].ServerPort + "." + storedJobsList[index-1].JobID.ToString(); 52 Debug.WriteLine("Sending stored job " + storedJobsList[index - 1].JobID + " to the server"); 53 //Logging.Instance.Info("JobStorrageManager", "Sending stored job " + storedJobsList[index - 1].JobID + " to the server"); 47 String filename = storedJobsList[index-1].ServerIP + "." + storedJobsList[index-1].ServerPort + "." + storedJobsList[index-1].JobID.ToString(); 48 Logging.Instance.Info("JobStorrageManager", "Sending stored job " + storedJobsList[index - 1].JobID + " to the server"); 54 49 byte[] job = File.ReadAllBytes(path + filename + ".dat"); 50 51 if (WcfService.Instance.IsJobStillNeeded(storedJobsList[index - 1].JobID).StatusMessage == ApplicationConstants.RESPONSE_COMMUNICATOR_SEND_JOBRESULT) { 52 ResponseResultReceived res = WcfService.Instance.SendStoredJobResultsSync(ConfigManager.Instance.GetClientInfo().Id, storedJobsList[index - 1].JobID, job, 1.00, null, true); 53 if (!res.Success) 54 Logging.Instance.Error("JobStorageManager", "sending of job failed: " + res.StatusMessage); 55 else 56 Logging.Instance.Info("JobStorrageManager", "Sending of job " + storedJobsList[index - 1].JobID + " done"); 57 } 58 ClientStatusInfo.JobsProcessed++; 59 55 60 56 //Todo: ask server first if he really wants the job...57 ResponseResultReceived res = WcfService.Instance.SendStoredJobResultsSync(ConfigManager.Instance.GetClientInfo().Id, storedJobsList[index-1].JobID, job, 1.00, null, true);58 ClientStatusInfo.JobsProcessed++;59 //TODO: has to be fixed from server side60 //if (res.Success == true) {61 Debug.WriteLine("Sending of job " + storedJobsList[index - 1].JobID + " done");62 //Logging.Instance.Info("JobStorrageManager", "Sending of job " + storedJobsList[index - 1].JobID + " done");63 61 64 62 storedJobsList.Remove(storedJobsList[index - 1]); 65 File.Delete(path + filename + ".dat"); 66 67 // } 63 File.Delete(path + filename + ".dat"); 68 64 } 69 65 } … … 76 72 writer.Close(); 77 73 } 74 75 static JobStorageManager() { 76 Logging.Instance.Info("JobStorrageManager", "Restoring Joblist from Harddisk"); 77 if (!Directory.Exists(path)) 78 Directory.CreateDirectory(path); 79 80 XmlSerializer serializer = new XmlSerializer(typeof(List<JobStorageInfo>)); 81 if(File.Exists(Path.Combine(path ,"list.xml"))) { 82 try { 83 FileStream stream = new FileStream(Path.Combine(path, "list.xml"), FileMode.Open); 84 XmlTextReader reader = new XmlTextReader(stream); 85 storedJobsList = (List<JobStorageInfo>)serializer.Deserialize(reader); 86 Logging.Instance.Info("JobStorrageManager", "Loaded " + storedJobsList.Count + " Elements"); 87 } 88 catch (Exception e) { 89 Logging.Instance.Error("JobStorrageManager", "Exception while loading the Stored Job List", e); 90 } 91 } else { 92 Logging.Instance.Info("JobStorrageManager", "no stored jobs on harddisk, starting new list"); 93 storedJobsList = new List<JobStorageInfo>(); 94 } 95 } 78 96 79 97 }
Note: See TracChangeset
for help on using the changeset viewer.