Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1449 was 1449, checked in by svonolfe, 15 years ago

Refactored DAL (now using GUIDs as IDs instead of longs) (#527)

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, Guid 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      Stream jobstream = null;
25      try {
26        jobstream = File.Create(path + filename + ".dat");
27        jobstream.Write(job, 0, job.Length);
28        storedJobsList.Add(info);
29        Logging.Instance.Info("JobStorageManager", "Job " + info.JobID + " stored on the harddisc");
30      }
31      catch (Exception e) {
32        Logging.Instance.Error("JobStorageManager", "Exception: ", e);
33      }
34      finally {
35        if(jobstream!=null)
36          jobstream.Close();
37      }
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();
44          Logging.Instance.Info("JobStorrageManager", "Sending stored job " + storedJobsList[index - 1].JobID + " to the server");
45          byte[] job = File.ReadAllBytes(path + filename + ".dat");
46         
47          //Todo: ask server first if he really wants the job...
48          ResponseResultReceived res = WcfService.Instance.SendStoredJobResultsSync(ConfigManager.Instance.GetClientInfo().Id, storedJobsList[index-1].JobID, job, 1.00, null, true);
49          //TODO: has to be fixed from server side
50          //if (res.Success == true) {
51          Logging.Instance.Info("JobStorrageManager", "Sending of job " + storedJobsList[index - 1].JobID + " done"); 
52          storedJobsList.Remove(storedJobsList[index - 1]);
53          File.Delete(path + filename + ".dat");
54           
55       //   }
56        }
57      }
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.