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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  }
Note: See TracChangeset for help on using the changeset viewer.