Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Client.Core/JobStorage/JobStorageManager.cs @ 1371

Last change on this file since 1371 was 1371, checked in by kgrading, 15 years ago

renamed the getLogger method (#529)

File size: 2.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
6using HeuristicLab.Hive.Client.Common;
7using HeuristicLab.Hive.Client.Communication;
8using HeuristicLab.Hive.Client.Core.ConfigurationManager;
9using HeuristicLab.Hive.Contracts;
10
11namespace 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   
19    public static void PersistObjectToDisc(String serverIP, long serverPort, long jobId, byte[] job) {
20      String filename = serverIP + "." + serverPort + "." + jobId.ToString();
21
22      JobStorageInfo info = new JobStorageInfo { JobID = jobId, ServerIP = serverIP, ServerPort = serverPort, TimeFinished = DateTime.Now };
23     
24      //Todo: Filestream won't be closed if exception occurs
25      try {
26        Stream jobstream = File.Create(path + filename + ".dat");
27        jobstream.Write(job, 0, job.Length);
28        storedJobsList.Add(info);
29        jobstream.Close();
30        Logging.Instance.Info("JobStorageManager", "Job " + info.JobID + " stored on the harddisc");
31      }
32      catch (Exception e) {
33        Logging.Instance.Error("JobStorageManager", "Exception: ", e);
34      }       
35    }
36
37    public static void CheckAndSubmitJobsFromDisc() {
38      for(int index=storedJobsList.Count; index > 0; index--) {
39        if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin && (storedJobsList[index-1].ServerIP == WcfService.Instance.ServerIP && storedJobsList[index-1].ServerPort == WcfService.Instance.ServerPort)) {
40          String filename = storedJobsList[index-1].ServerIP + "." + storedJobsList[index-1].ServerPort + "." + storedJobsList[index-1].JobID.ToString();
41          Logging.Instance.Info("JobStorrageManager", "Sending stored job " + storedJobsList[index - 1].JobID + " to the server");
42          byte[] job = File.ReadAllBytes(path + filename + ".dat");
43         
44          //Todo: ask server first if he really wants the job...
45          ResponseResultReceived res = WcfService.Instance.SendStoredJobResultsSync(ConfigManager.Instance.GetClientInfo().ClientId, storedJobsList[index-1].JobID, job, 1.00, null, true);
46          //TODO: has to be fixed from server side
47          //if (res.Success == true) {
48          Logging.Instance.Info("JobStorrageManager", "Sending of job " + storedJobsList[index - 1].JobID + " done"); 
49          storedJobsList.Remove(storedJobsList[index - 1]);
50          File.Delete(path + filename + ".dat");
51           
52       //   }
53        }
54      }
55    }
56  }
57}
Note: See TracBrowser for help on using the repository browser.