Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Client.Core/JobStorrage/JobStorrageManager.cs @ 1352

Last change on this file since 1352 was 1340, checked in by kgrading, 16 years ago

Code Review changes (#522)

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.JobStorrage {
12  public class JobStorrageManager {
13   
14    private static List<JobStorrageInfo> storedJobsList = new List<JobStorrageInfo>();
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      JobStorrageInfo info = new JobStorrageInfo { 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.GetInstance().Info("JobStorrageManager", "Job " + info.JobID + " stored on the harddisc");
31      }
32      catch (Exception e) {
33        //Todo: Change to logging.exception!
34        Console.WriteLine(e);
35      }       
36    }
37
38    public static void CheckAndSubmitJobsFromDisc() {
39      for(int index=storedJobsList.Count; index > 0; index--) {
40        if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin && (storedJobsList[index-1].ServerIP == WcfService.Instance.ServerIP && storedJobsList[index-1].ServerPort == WcfService.Instance.ServerPort)) {
41          String filename = storedJobsList[index-1].ServerIP + "." + storedJobsList[index-1].ServerPort + "." + storedJobsList[index-1].JobID.ToString();
42          Logging.GetInstance().Info("JobStorrageManager", "Sending stored job " + storedJobsList[index-1].JobID + " to the server");
43          byte[] job = File.ReadAllBytes(path + filename + ".dat");
44         
45          //Todo: ask server first if he really wants the job...
46          ResponseResultReceived res = WcfService.Instance.SendStoredJobResultsSync(ConfigManager.Instance.GetClientInfo().ClientId, storedJobsList[index-1].JobID, job, 1.00, null, true);
47          //TODO: has to be fixed from server side
48          //if (res.Success == true) {
49          Logging.GetInstance().Info("JobStorrageManager", "Sending of job " + storedJobsList[index - 1].JobID + " done"); 
50          storedJobsList.Remove(storedJobsList[index - 1]);
51          File.Delete(path + filename + ".dat");
52           
53       //   }
54        }
55      }
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.