[1364] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.IO;
|
---|
| 6 | using HeuristicLab.Hive.Client.Common;
|
---|
| 7 | using HeuristicLab.Hive.Client.Communication;
|
---|
| 8 | using HeuristicLab.Hive.Client.Core.ConfigurationManager;
|
---|
| 9 | using HeuristicLab.Hive.Contracts;
|
---|
| 10 |
|
---|
| 11 | namespace HeuristicLab.Hive.Client.Core.JobStorage {
|
---|
| 12 | public class JobStorageManager {
|
---|
| 13 |
|
---|
| 14 | private static List<JobStorageInfo> storedJobsList = new List<JobStorageInfo>();
|
---|
| 15 | //Todo: execution path
|
---|
| 16 | //Todo: Choose a better directory name
|
---|
| 17 | private static String path = "C:\\Program Files\\HeuristicLab 3.0\\plugins\\jobStorrage\\";
|
---|
| 18 |
|
---|
[1449] | 19 | public static void PersistObjectToDisc(String serverIP, long serverPort, Guid jobId, byte[] job) {
|
---|
[1364] | 20 | String filename = serverIP + "." + serverPort + "." + jobId.ToString();
|
---|
| 21 |
|
---|
| 22 | JobStorageInfo info = new JobStorageInfo { JobID = jobId, ServerIP = serverIP, ServerPort = serverPort, TimeFinished = DateTime.Now };
|
---|
[1379] | 23 |
|
---|
| 24 | Stream jobstream = null;
|
---|
[1364] | 25 | try {
|
---|
[1379] | 26 | jobstream = File.Create(path + filename + ".dat");
|
---|
[1364] | 27 | jobstream.Write(job, 0, job.Length);
|
---|
| 28 | storedJobsList.Add(info);
|
---|
[1371] | 29 | Logging.Instance.Info("JobStorageManager", "Job " + info.JobID + " stored on the harddisc");
|
---|
[1364] | 30 | }
|
---|
| 31 | catch (Exception e) {
|
---|
[1371] | 32 | Logging.Instance.Error("JobStorageManager", "Exception: ", e);
|
---|
[1379] | 33 | }
|
---|
| 34 | finally {
|
---|
| 35 | if(jobstream!=null)
|
---|
| 36 | jobstream.Close();
|
---|
| 37 | }
|
---|
[1364] | 38 | }
|
---|
| 39 |
|
---|
| 40 | public static void CheckAndSubmitJobsFromDisc() {
|
---|
| 41 | for(int index=storedJobsList.Count; index > 0; index--) {
|
---|
| 42 | if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin && (storedJobsList[index-1].ServerIP == WcfService.Instance.ServerIP && storedJobsList[index-1].ServerPort == WcfService.Instance.ServerPort)) {
|
---|
| 43 | String filename = storedJobsList[index-1].ServerIP + "." + storedJobsList[index-1].ServerPort + "." + storedJobsList[index-1].JobID.ToString();
|
---|
[1371] | 44 | Logging.Instance.Info("JobStorrageManager", "Sending stored job " + storedJobsList[index - 1].JobID + " to the server");
|
---|
[1364] | 45 | byte[] job = File.ReadAllBytes(path + filename + ".dat");
|
---|
| 46 |
|
---|
| 47 | //Todo: ask server first if he really wants the job...
|
---|
[1449] | 48 | ResponseResultReceived res = WcfService.Instance.SendStoredJobResultsSync(ConfigManager.Instance.GetClientInfo().Id, storedJobsList[index-1].JobID, job, 1.00, null, true);
|
---|
[1364] | 49 | //TODO: has to be fixed from server side
|
---|
| 50 | //if (res.Success == true) {
|
---|
[1371] | 51 | Logging.Instance.Info("JobStorrageManager", "Sending of job " + storedJobsList[index - 1].JobID + " done");
|
---|
[1364] | 52 | storedJobsList.Remove(storedJobsList[index - 1]);
|
---|
| 53 | File.Delete(path + filename + ".dat");
|
---|
| 54 |
|
---|
| 55 | // }
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | }
|
---|