Changeset 2021 for trunk/sources
- Timestamp:
- 06/05/09 13:29:18 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Client.Core/3.2/ConfigurationManager/UptimeManager.cs
r2011 r2021 6 6 using System.Xml.Serialization; 7 7 using System.IO; 8 using HeuristicLab.Hive.Client.Common; 8 9 9 10 namespace HeuristicLab.Hive.Client.Core.ConfigurationManager { 10 11 public class UptimeManager { 11 12 12 public List<Appointment> Appointments { get; set; } 13 private List<Appointment> appointments = null; 14 public List<Appointment> Appointments { 15 get { 16 if (appointments == null) 17 RestoreFromHDD(); 18 return appointments; 19 } 20 set { 21 appointments = value; 22 PersistToHDD(); 23 } 24 } 13 25 private static String path = System.IO.Directory.GetCurrentDirectory()+"\\plugins\\Hive.Client.Jobs\\"; 14 26 … … 25 37 private void PersistToHDD() { 26 38 XmlSerializer s = new XmlSerializer(typeof(List<Appointment>)); 27 using (TextWriter w = new StreamWriter(path + "calendar.xml")) { 39 if (!Directory.Exists(path)) 40 Directory.CreateDirectory(path); 41 TextWriter w = null; 42 try { 43 w = new StreamWriter(path + "calendar.xml"); 28 44 s.Serialize(w, Appointments); 45 } catch(Exception e) { 46 Logging.Instance.Error(this.ToString(), "Persistance of the Calendar failed!", e); 47 } finally { 48 if(w!=null) 49 w.Close(); 29 50 } 30 51 } … … 32 53 private void RestoreFromHDD() { 33 54 XmlSerializer s = new XmlSerializer(typeof(List<Appointment>)); 34 using (TextReader r = new StreamReader(path + "calendar.xml")) { 35 Appointments = (List<Appointment>)s.Deserialize(r); 36 } 55 if(File.Exists(Path.Combine(path, "calendar.xml"))) { 56 TextReader r = null; 57 58 try { 59 r = new StreamReader(path + "calendar.xml"); 60 Appointments = (List<Appointment>)s.Deserialize(r); 61 } catch (Exception e) { 62 Logging.Instance.Error(this.ToString(), "Deserialization of Calendar failed", e); 63 Logging.Instance.Info(this.ToString(), "Starting with a new one"); 64 appointments = new List<Appointment>(); 65 } finally { 66 if(r!=null) 67 r.Close(); 68 } 69 } else { 70 Appointments = new List<Appointment>(); 71 } 37 72 } 38 73
Note: See TracChangeset
for help on using the changeset viewer.