Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/23/10 10:50:26 (14 years ago)
Author:
kgrading
Message:

implemented the server on the client, using push & force push, added refresh buttons, added auto calender methods that traverse the tree... (#908)

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  
    3636
    3737    public void SetUptimeCalendar(List<Appointment> appointments) {
    38       UptimeManager.Instance.Appointments = appointments;
     38      UptimeManager.Instance.SetAppointments(true, false, appointments);
    3939    }
    4040
    4141    public List<Appointment> GetUptimeCalendar() {
    42       return UptimeManager.Instance.Appointments;
     42      return UptimeManager.Instance.AppContainer.Appointments;
    4343    }
    4444
  • trunk/sources/HeuristicLab.Hive.Client.Core/3.2/ConfigurationManager/UptimeManager.cs

    r2025 r3203  
    77using System.IO;
    88using HeuristicLab.Hive.Client.Common;
     9using HeuristicLab.Hive.Contracts.BusinessObjects;
     10using HeuristicLab.Hive.Contracts;
    911
    1012namespace HeuristicLab.Hive.Client.Core.ConfigurationManager {
    1113  public class UptimeManager {
    1214
    13     private List<Appointment> appointments = null;
    14     public List<Appointment> Appointments {
     15    private AppointmentContainer _appContainer = null;
     16    public AppointmentContainer AppContainer {
    1517      get {
    16         if (appointments == null)
     18        if (_appContainer == null)
    1719          RestoreFromHDD();
    18         return appointments;
     20        return _appContainer;
    1921      }
    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\\";
    2626
    2727    private static UptimeManager instance = null;
     
    3636
    3737    private void PersistToHDD() {
    38       XmlSerializer s = new XmlSerializer(typeof(List<Appointment>));
     38      XmlSerializer s = new XmlSerializer(typeof(AppointmentContainer));
    3939      if (!Directory.Exists(path))
    4040        Directory.CreateDirectory(path);
     
    4242      try {
    4343        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) {
    4647        Logging.Instance.Error(this.ToString(), "Persistance of the Calendar failed!", e);
    47       } finally {
    48         if(w!=null)
     48      }
     49      finally {
     50        if (w != null)
    4951          w.Close();
    5052      }
     
    5254
    5355    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"))) {
    5658        TextReader r = null;
    57        
     59
    5860        try {
    5961          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) {
    6266          Logging.Instance.Error(this.ToString(), "Deserialization of Calendar failed", e);
    6367          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();
    6874        }
    6975      } else {
    70         Appointments = new List<Appointment>();
     76        _appContainer = new AppointmentContainer();
    7177      }
    7278    }
    7379
    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);
    80113    }
    81114  }
  • trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs

    r3022 r3203  
    8888        wcfService.SetIPAndPort(cc.IPAdress, cc.Port);
    8989
    90       if (UptimeManager.Instance.isOnline())
     90      if (!UptimeManager.Instance.CalendarAvailable || UptimeManager.Instance.IsOnline())
    9191        wcfService.Connect();
    9292
     
    191191          break;
    192192
     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;
    193206
    194207        //Hard shutdown of the client
     
    263276      Logging.Instance.Info(this.ToString(), "END: Sended snapshot sync");
    264277      //Uptime Limit reached, now is a good time to destroy this jobs.
    265       if (!UptimeManager.Instance.isOnline()) {
     278      if (!UptimeManager.Instance.IsOnline()) {
    266279        KillAppDomain(jId);
    267280        //Still anything running?
     
    381394    /// <param name="e"></param>
    382395    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      }
    386415    }
    387416
  • trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Heartbeat.cs

    r3011 r3203  
    8989      TimeSpan span = DateTime.Now - lastFullHour;
    9090      if (span.TotalSeconds < (Interval/1000)) {
    91         if (UptimeManager.Instance.isOnline()) {
     91        if (UptimeManager.Instance.IsOnline() && UptimeManager.Instance.CalendarAvailable) {
    9292          //That's quiet simple: Just reconnect and you're good for new jobs
    9393          if (wcfService.ConnState != NetworkEnum.WcfConnState.Loggedin) {
  • trunk/sources/HeuristicLab.Hive.Client.Core/3.2/HeuristicLab.Hive.Client.Core-3.2.csproj

    r3022 r3203  
    9696    <Compile Include="ClientConsoleService\TransferObjects\JobStatus.cs" />
    9797    <Compile Include="ClientConsoleService\TransferObjects\StatusCommons.cs" />
     98    <Compile Include="ConfigurationManager\AppointmentContainer.cs" />
    9899    <Compile Include="ConfigurationManager\ClientStatusInfo.cs" />
    99100    <Compile Include="ConfigurationManager\ConfigManager.cs" />
Note: See TracChangeset for help on using the changeset viewer.