internal Object GetValue() { if (HasParent) { ParentMeasure parent = (ParentMeasure)Plugin.Measures[ParentID]; double countItem = 0; if (parent.Name == "mGcal" && parent.lastEvents != null) { countItem = parent.lastEvents.Count; } else if (parent.lastMessages != null) { countItem = parent.lastMessages.Count; } else { return(""); } if (countItem > ndx) { try { object value = null; if (parent.Name == "mGcal") { GCalEvent ge = parent.lastEvents[ndx]; value = Tools.getObjectProperty(ge, property); if (value == null) { return(""); } if (value is DateTime) { DateTime dt = (DateTime)value; if (Tools.IsToday(dt)) { return(dt.ToString(todayDateFormat)); } else if (Tools.IsInWeek(dt)) { return(dt.ToString(weekDateFormat)); } else { return(dt.ToString(dateFormat)); } } else if (value is Boolean) { return(((Boolean)value) ? "1" : "0"); // See Update } else { return(value.ToString()); } } else { GMessage gm = parent.lastMessages[ndx]; if (this.property == "EmailDate") { return(gm.EmailDate.ToShortDateString() + " " + gm.EmailDate.ToShortTimeString()); } else { value = Tools.getObjectProperty(gm, property); return(value.ToString()); } } } catch (Exception e) { API.Log(API.LogType.Error, "RainGoo.dll: Exception : " + e.Message); } } } // API.Log(API.LogType.Warning, "RainGoo.dll: Cannot get value with index [" + ndx + "] and property [" + property + "]"); return(""); }
internal Boolean UpdateEvents() { try { long now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; if (now - lastUpdate < MIN_INTERVAL) { #if DEBUG API.Log(API.LogType.Notice, "RainGoo.dll: Calendar update interval too short !"); #endif return(false); } List <GCalEvent> events = null; if (googleClientId == null || googleClientId == "" || googleClientId == "#GoogleAccountID#" || googleClientSecret == null || googleClientSecret == "" || googleClientSecret == "#GoogleAccountSecret#" || googleUserName == null || googleUserName == "" || googleUserName == "#GmailUserName#" || calUrls.Count == 0 || calUrls[0] == null || calUrls[0] == "" || calUrls[0] == "#Calendar1#") { events = new List <GCalEvent>(); if (googleClientId == null || googleClientId == "" || googleClientId == "#GoogleAccountID#" || googleClientSecret == null || googleClientSecret == "" || googleClientSecret == "#GoogleAccountSecret#") { GCalEvent fakeEvent = new GCalEvent(); fakeEvent.Start = DateTime.Now; fakeEvent.IsAllDay = true; fakeEvent.End = DateTime.Now; fakeEvent.Link = "https://console.cloud.google.com"; fakeEvent.Title = "No google ID/Secret provided"; fakeEvent.Id = "fake123456"; fakeEvent.HexaColor = "000000"; fakeEvent.HexaColorCal = "000000"; events.Add(fakeEvent); } if (googleUserName == null || googleUserName == "" || googleUserName == "#GmailUserName#") { GCalEvent fakeEvent = new GCalEvent(); fakeEvent.Start = DateTime.Now; fakeEvent.IsAllDay = true; fakeEvent.End = DateTime.Now; fakeEvent.Link = "https://console.cloud.google.com"; fakeEvent.Title = "No Calendar user name provided"; fakeEvent.Id = "fake123456"; fakeEvent.HexaColor = "000000"; fakeEvent.HexaColorCal = "000000"; events.Add(fakeEvent); } if (calUrls.Count == 0 || calUrls[0] == null || calUrls[0] == "" || calUrls[0] == "#Calendar1#") { GCalEvent fakeEvent = new GCalEvent(); fakeEvent.Start = DateTime.Now; fakeEvent.IsAllDay = true; fakeEvent.End = DateTime.Now; fakeEvent.Link = "https://console.cloud.google.com"; fakeEvent.Title = "No Calendar provided"; fakeEvent.Id = "fake123456"; fakeEvent.HexaColor = "000000"; fakeEvent.HexaColorCal = "000000"; events.Add(fakeEvent); } } else { events = new List <GCalEvent>(); GCalAPI gcal = new GCalAPI(googleClientId, googleClientSecret, googleUserName); #if DEBUG API.Log(API.LogType.Notice, "RainGoo.dll: About to read events..."); #endif for (int i = 0; i < calUrls.Count; i++) { String calUrl = calUrls[i]; #if DEBUG API.Log(API.LogType.Notice, "RainGoo.dll: Retrieving calendar [" + calUrl + "]"); #endif List <GCalEvent> e = gcal.GetEvents(calUrl, DateTime.Now, DateTime.Now.AddDays(Limit2Xdays), max); foreach (GCalEvent ge in e) { ge.Data.Add("CalId", (i + 1).ToString()); } events.AddRange(e); } events.Sort(); } if (events.Count > max) { events.RemoveRange(max, (events.Count - max)); } // Generates include files if (!String.IsNullOrEmpty(calendarPath)) { Tools.GenerateIncFile(events.Count , Path.Combine(calendarPath, "TMeasures.inc") , Path.Combine(calendarPath, "Measures.inc")); Tools.GenerateIncFile(events.Count , Path.Combine(calendarPath, "TMeters.inc") , Path.Combine(calendarPath, "Meters.inc")); } lastUpdate = now; lastEvents = events; return(true); } catch (Exception e) { API.Log(API.LogType.Error, "RainGoo.dll: Cannot update events : " + e.Message); } return(false); }