Changeset 3203 for trunk/sources/HeuristicLab.Hive.Client.Core
- Timestamp:
- 03/23/10 10:50:26 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Hive.Client.Core/3.2
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Client.Core/3.2/ClientConsoleService/ClientConsoleCommunicator.cs
r2009 r3203 36 36 37 37 public void SetUptimeCalendar(List<Appointment> appointments) { 38 UptimeManager.Instance. Appointments = appointments;38 UptimeManager.Instance.SetAppointments(true, false, appointments); 39 39 } 40 40 41 41 public List<Appointment> GetUptimeCalendar() { 42 return UptimeManager.Instance.App ointments;42 return UptimeManager.Instance.AppContainer.Appointments; 43 43 } 44 44 -
trunk/sources/HeuristicLab.Hive.Client.Core/3.2/ConfigurationManager/UptimeManager.cs
r2025 r3203 7 7 using System.IO; 8 8 using HeuristicLab.Hive.Client.Common; 9 using HeuristicLab.Hive.Contracts.BusinessObjects; 10 using HeuristicLab.Hive.Contracts; 9 11 10 12 namespace HeuristicLab.Hive.Client.Core.ConfigurationManager { 11 13 public class UptimeManager { 12 14 13 private List<Appointment> appointments= null;14 public List<Appointment> Appointments{15 private AppointmentContainer _appContainer = null; 16 public AppointmentContainer AppContainer { 15 17 get { 16 if ( appointments== null)18 if (_appContainer == null) 17 19 RestoreFromHDD(); 18 return appointments;20 return _appContainer; 19 21 } 20 set { 21 appointments = value; 22 PersistToHDD(); 23 } 24 } 25 private static String path = System.IO.Directory.GetCurrentDirectory()+"\\plugins\\Hive.Client.Jobs\\"; 22 } 23 public bool CalendarAvailable { get; set; } 24 25 private static String path = System.IO.Directory.GetCurrentDirectory() + "\\plugins\\Hive.Client.Jobs\\"; 26 26 27 27 private static UptimeManager instance = null; … … 36 36 37 37 private void PersistToHDD() { 38 XmlSerializer s = new XmlSerializer(typeof( List<Appointment>));38 XmlSerializer s = new XmlSerializer(typeof(AppointmentContainer)); 39 39 if (!Directory.Exists(path)) 40 40 Directory.CreateDirectory(path); … … 42 42 try { 43 43 w = new StreamWriter(path + "calendar.xml"); 44 s.Serialize(w, Appointments); 45 } catch(Exception e) { 44 s.Serialize(w, AppContainer); 45 } 46 catch (Exception e) { 46 47 Logging.Instance.Error(this.ToString(), "Persistance of the Calendar failed!", e); 47 } finally { 48 if(w!=null) 48 } 49 finally { 50 if (w != null) 49 51 w.Close(); 50 52 } … … 52 54 53 55 private void RestoreFromHDD() { 54 XmlSerializer s = new XmlSerializer(typeof( List<Appointment>));55 if (File.Exists(Path.Combine(path, "calendar.xml"))) {56 XmlSerializer s = new XmlSerializer(typeof(AppointmentContainer)); 57 if (File.Exists(Path.Combine(path, "calendar.xml"))) { 56 58 TextReader r = null; 57 59 58 60 try { 59 61 r = new StreamReader(path + "calendar.xml"); 60 Appointments = (List<Appointment>)s.Deserialize(r); 61 } catch (Exception e) { 62 _appContainer = (AppointmentContainer)s.Deserialize(r); 63 CalendarAvailable = true; 64 } 65 catch (Exception e) { 62 66 Logging.Instance.Error(this.ToString(), "Deserialization of Calendar failed", e); 63 67 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 _appContainer = new AppointmentContainer(); 69 CalendarAvailable = false; 70 } 71 finally { 72 if (r != null) 73 r.Close(); 68 74 } 69 75 } else { 70 Appointments = new List<Appointment>();76 _appContainer = new AppointmentContainer(); 71 77 } 72 78 } 73 79 74 public bool isOnline() { 75 foreach (Appointment app in Appointments) 76 if ((DateTime.Now >= app.StartDate) && 77 (DateTime.Now <= app.EndDate)) 78 return true; 79 return false; 80 public bool IsOnline() { 81 return AppContainer.Appointments.Any(app => (DateTime.Now >= app.StartDate) && (DateTime.Now <= app.EndDate)); 82 } 83 84 public bool SetAppointments(bool isLocal, bool isForced, IEnumerable<Appointment> appointments) { 85 if (!isForced && !isLocal && AppContainer.IsLocal) 86 return false; 87 88 AppContainer.Appointments = new List<Appointment>(appointments); 89 AppContainer.IsLocal = isLocal; 90 AppContainer.Updated = DateTime.Now; 91 CalendarAvailable = true; 92 93 PersistToHDD(); 94 95 return true; 96 } 97 98 internal bool SetAppointments(bool isLocal, ResponseCalendar response) { 99 IList<Appointment> app = new List<Appointment>(); 100 foreach (AppointmentDto appointmentDto in response.Appointments) { 101 app.Add(new Appointment { 102 AllDayEvent = appointmentDto.AllDayEvent, 103 EndDate = appointmentDto.EndDate, 104 StartDate = appointmentDto.StartDate, 105 Recurring = appointmentDto.Recurring, 106 107 RecurringId = appointmentDto.RecurringId, 108 Locked = true, 109 Subject = "Online", 110 }); 111 } 112 return SetAppointments(isLocal, response.ForceFetch, app); 80 113 } 81 114 } -
trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs
r3022 r3203 88 88 wcfService.SetIPAndPort(cc.IPAdress, cc.Port); 89 89 90 if ( UptimeManager.Instance.isOnline())90 if (!UptimeManager.Instance.CalendarAvailable || UptimeManager.Instance.IsOnline()) 91 91 wcfService.Connect(); 92 92 … … 191 191 break; 192 192 193 //Fetch or Force Fetch Calendar! 194 case MessageContainer.MessageType.FetchOrForceFetchCalendar: 195 ResponseCalendar rescal = wcfService.GetCalendarSync(ConfigManager.Instance.GetClientInfo().Id); 196 if(rescal.Success) { 197 if(!UptimeManager.Instance.SetAppointments(false, rescal)) { 198 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.NotAllowedToFetch); 199 } else { 200 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.Fetched); 201 } 202 } else { 203 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.NotAllowedToFetch); 204 } 205 break; 193 206 194 207 //Hard shutdown of the client … … 263 276 Logging.Instance.Info(this.ToString(), "END: Sended snapshot sync"); 264 277 //Uptime Limit reached, now is a good time to destroy this jobs. 265 if (!UptimeManager.Instance. isOnline()) {278 if (!UptimeManager.Instance.IsOnline()) { 266 279 KillAppDomain(jId); 267 280 //Still anything running? … … 381 394 /// <param name="e"></param> 382 395 void wcfService_Connected(object sender, EventArgs e) { 383 wcfService.LoginSync(ConfigManager.Instance.GetClientInfo()); 384 JobStorageManager.CheckAndSubmitJobsFromDisc(); 385 currentlyFetching = false; 396 if (!UptimeManager.Instance.CalendarAvailable) { 397 ResponseCalendar calres = wcfService.GetCalendarSync(ConfigManager.Instance.GetClientInfo().Id); 398 if(calres.Success) { 399 if (UptimeManager.Instance.SetAppointments(false, calres)) 400 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.Fetched); 401 else 402 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.NotAllowedToFetch); 403 } 404 else { 405 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.NotAllowedToFetch); 406 } 407 } 408 //if the fetching from the server failed - still set the client online... maybe we get 409 //a result within the next few heartbeats 410 if (!UptimeManager.Instance.CalendarAvailable || UptimeManager.Instance.IsOnline()) { 411 wcfService.LoginSync(ConfigManager.Instance.GetClientInfo()); 412 JobStorageManager.CheckAndSubmitJobsFromDisc(); 413 currentlyFetching = false; 414 } 386 415 } 387 416 -
trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Heartbeat.cs
r3011 r3203 89 89 TimeSpan span = DateTime.Now - lastFullHour; 90 90 if (span.TotalSeconds < (Interval/1000)) { 91 if (UptimeManager.Instance. isOnline()) {91 if (UptimeManager.Instance.IsOnline() && UptimeManager.Instance.CalendarAvailable) { 92 92 //That's quiet simple: Just reconnect and you're good for new jobs 93 93 if (wcfService.ConnState != NetworkEnum.WcfConnState.Loggedin) { -
trunk/sources/HeuristicLab.Hive.Client.Core/3.2/HeuristicLab.Hive.Client.Core-3.2.csproj
r3022 r3203 96 96 <Compile Include="ClientConsoleService\TransferObjects\JobStatus.cs" /> 97 97 <Compile Include="ClientConsoleService\TransferObjects\StatusCommons.cs" /> 98 <Compile Include="ConfigurationManager\AppointmentContainer.cs" /> 98 99 <Compile Include="ConfigurationManager\ClientStatusInfo.cs" /> 99 100 <Compile Include="ConfigurationManager\ConfigManager.cs" />
Note: See TracChangeset
for help on using the changeset viewer.