public static SyncObject[] AllSyncObjects() { XmlNodeList nodeList = db.Doc.SelectNodes("/db/" + SyncTag); int count = nodeList.Count; SyncObject[] allSyncObjects = new SyncObject[count]; for (int i = 0; i < count; i++) { XmlNode node = nodeList[i]; SyncObject obj = new SyncObject(); XmlAttributeCollection attribs = node.Attributes; obj.ReferenceID = attribs[XmlDatabase.IdAttribute].Value; obj.ModifyDate = DateTime.Parse(attribs[ModifyDateAttribute].Value); obj.SyncType = (SyncType)int.Parse(attribs[SyncTypeAttribute].Value); obj.Url = attribs.GetValue(UrlAttribute, UrlAttributeDefault); obj.OldUrl = attribs.GetValue(OldUrlAttribute, OldUrlAttributeDefault); allSyncObjects[i] = obj; } return(allSyncObjects); }
public static SyncObject GetSyncObject(string id) { if (id == null) { return(null); } XmlNode node = db.Doc.GetElementById(id); if (node == null) { return(null); } SyncObject obj = new SyncObject(); XmlAttributeCollection attribs = node.Attributes; obj.ReferenceID = id; obj.ModifyDate = DateTime.Parse(attribs[ModifyDateAttribute].Value); obj.SyncType = (SyncType)int.Parse(attribs[SyncTypeAttribute].Value); obj.Url = attribs.GetValue(UrlAttribute, UrlAttributeDefault); obj.OldUrl = attribs.GetValue(OldUrlAttribute, OldUrlAttributeDefault); return(obj); }
public static Contact GetContact(string id) { XmlElement element = db.Doc.GetElementById(id); if (element == null) { return(null); } XmlAttributeCollection attribs = element.Attributes; Contact contact = new Contact(false); contact.ID = id; contact.RawName = attribs[NameAttribute].Value; contact.RawWork = attribs[WorkAttribute].Value; contact.RawEmail = attribs[EmailAttribute].Value; contact.RawWebsite = attribs[WebSiteAttribute].Value; contact.RawIM = attribs[IMAttribute].Value; contact.RawPhone = attribs[PhoneAttribute].Value; contact.RawAddress = attribs[AddressAttribute].Value; contact.RawSpecialDate = attribs.GetValue(DateAttribute, DateAttributeDefault); contact.RawTile = attribs[TileAttribute].Value; contact.ReadOnly = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value); contact.Private = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value); contact.Gender = (Gender)byte.Parse(attribs.GetValue(GenderAttribute, GenderAttributeDefault)); return(contact); }
/// <summary> /// Get all contacts. /// </summary> public static IEnumerable <Contact> GetContacts() { XmlNodeList contacts = db.Doc.SelectNodes("/db/" + ContactTag); foreach (XmlNode node in contacts) { // // <c /> // XmlAttributeCollection attribs = node.Attributes; Contact c = new Contact(false); c.ID = attribs[XmlDatabase.IdAttribute].Value; c.RawName = attribs[NameAttribute].Value; c.RawWork = attribs[WorkAttribute].Value; c.RawEmail = attribs[EmailAttribute].Value; c.RawWebsite = attribs[WebSiteAttribute].Value; c.RawIM = attribs[IMAttribute].Value; c.RawPhone = attribs[PhoneAttribute].Value; c.RawAddress = attribs[AddressAttribute].Value; c.RawSpecialDate = attribs.GetValue(DateAttribute, DateAttributeDefault); c.RawTile = attribs[TileAttribute].Value; c.ReadOnly = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value); c.Private = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value); yield return(c); } }
/// <summary> /// Gets all Appointments that are enabled and have reminders set within one day. /// </summary> /// <returns></returns> private static Reminder[] ActiveAppointments() { XmlDocument db = AppointmentDatabase.Database.Doc; XmlNodeList elements = db.GetElementsByTagName(AppointmentDatabase.AppointmentTag); int count = elements.Count; if (count > 0) { DateTime now = DateTime.Now; Reminder[] reminders = new Reminder[count]; int actualsize = 0; for (int i = 0; i < count; i++) { XmlNode current = elements[i]; XmlAttributeCollection attribs = current.Attributes; XmlAttribute repeatId = attribs[AppointmentDatabase.RepeatIdAttribute]; TimeSpan reminder; XmlNode baseRecurring = null; if (repeatId != null) { // Get the recurring event this appointment is based off of. baseRecurring = AppointmentDatabase.Database.Doc.GetElementById(repeatId.Value); reminder = TimeSpan.Parse(AppointmentDatabase.GetAttribute(AppointmentDatabase.ReminderAttribute, attribs, baseRecurring.Attributes, AppointmentDatabase.ReminderAttributeDefault)); } else { reminder = TimeSpan.Parse(attribs.GetValue(AppointmentDatabase.ReminderAttribute, AppointmentDatabase.ReminderAttributeDefault)); } if (reminder != TimeSpan.FromSeconds(-1)) { if (current.ParentNode.ParentNode.Name != AppointmentDatabase.RecurringAppointmentTag) { // This is a standard (non-recurring) appointment DateTime start; DateTime end; bool allday; if (repeatId != null) { start = FormatHelpers.ParseDateTime(AppointmentDatabase.GetAttribute(AppointmentDatabase.StartDateAttribute, attribs, baseRecurring.Attributes, null)); end = FormatHelpers.ParseDateTime(AppointmentDatabase.GetAttribute(AppointmentDatabase.EndDateAttribute, attribs, baseRecurring.Attributes, null)); allday = FormatHelpers.ParseBool(AppointmentDatabase.GetAttribute(AppointmentDatabase.AllDayAttribute, attribs, baseRecurring.Attributes, AppointmentDatabase.AllDayAttributeDefault)); } else { start = FormatHelpers.ParseDateTime(attribs[AppointmentDatabase.StartDateAttribute].Value); end = FormatHelpers.ParseDateTime(attribs[AppointmentDatabase.EndDateAttribute].Value); allday = FormatHelpers.ParseBool(attribs.GetValue(AppointmentDatabase.AllDayAttribute, AppointmentDatabase.AllDayAttributeDefault)); } if (allday) { start = start.Date; end = end.Date; } DateTime ring; try { ring = start - reminder; } catch { ring = start; } // We only want to queue up to one day's worth of appointments. if (ring < now.AddDays(1)) { Reminder r = new Reminder(); r.ReminderType = ReminderType.Appointment; r.ID = attribs[XmlDatabase.IdAttribute].Value; r.EventStartDate = start; r.EventEndDate = end; r.AlertStartTime = ring; r.AlertEndTime = end; reminders[actualsize++] = r; } } else { // This is a recurring appointment DateTime start = FormatHelpers.ParseDateTime(attribs[AppointmentDatabase.StartDateAttribute].Value); DateTime end = FormatHelpers.ParseDateTime(attribs[AppointmentDatabase.EndDateAttribute].Value); bool allday = FormatHelpers.ParseBool(attribs.GetValue(AppointmentDatabase.AllDayAttribute, AppointmentDatabase.AllDayAttributeDefault)); Appointment appt = new Appointment(false); appt.ID = attribs[XmlDatabase.IdAttribute].Value; appt.StartDate = start; appt.EndDate = end; appt.AllDay = allday; appt.Reminder = reminder; appt.IsRepeating = true; Recurrence recurrence = new Recurrence(); recurrence.Type = (RepeatType)int.Parse(attribs[AppointmentDatabase.RepeatTypeAttribute].Value); recurrence.Day = attribs[AppointmentDatabase.RepeatDayAttribute].Value; recurrence.Week = int.Parse(attribs[AppointmentDatabase.RepeatWeekAttribute].Value); recurrence.Month = int.Parse(attribs[AppointmentDatabase.RepeatMonthAttribute].Value); recurrence.Year = int.Parse(attribs[AppointmentDatabase.RepeatYearAttribute].Value); recurrence.End = (RepeatEnd)int.Parse(attribs[AppointmentDatabase.RepeatEndAttribute].Value); recurrence.EndDate = FormatHelpers.ParseShortDateTime(attribs[AppointmentDatabase.RepeatEndDateAttribute].Value); recurrence.EndCount = int.Parse(attribs[AppointmentDatabase.RepeatEndCountAttribute].Value); appt.Recurrence = recurrence; if (attribs[AppointmentDatabase.RepeatIdAttribute] != null) { appt.RepeatID = attribs[AppointmentDatabase.RepeatIdAttribute].Value; } DateTime d = now.Add((allday ? TimeSpan.Zero : start.TimeOfDay) - reminder); bool add = false; if (appt.OccursOnDate(d)) { add = true; appt.RepresentingDate = d.Date; } else if (appt.OccursOnDate(d.AddDays(1))) { add = true; appt.RepresentingDate = d.AddDays(1).Date; } if (add) { // Check to see if there is another event on this date. Appointment[] events = AppointmentDatabase.GetAppointments(appt.RepresentingDate, false); if (events != null) { foreach (Appointment each in events) { if (each.RepeatID == appt.ID) { each.RepresentingDate = appt.RepresentingDate; appt = each; break; } } } if (appt.Reminder == TimeSpan.FromSeconds(-1)) { continue; } Reminder r = new Reminder(); r.ReminderType = ReminderType.Appointment; r.ID = appt.ID; r.EventStartDate = appt.RepresentingDate.Add(appt.StartDate.TimeOfDay); r.EventEndDate = appt.RepresentingDate.Add(appt.EndDate - appt.StartDate); r.AlertStartTime = appt.AllDay ? appt.RepresentingDate.Subtract(appt.Reminder) : appt.RepresentingDate.Add(appt.StartDate.TimeOfDay).Subtract(appt.Reminder); // TODO: 11Mar2014 Check to make sure this works. r.AlertEndTime = appt.AllDay ? appt.RepresentingDate.AddDays(1) : appt.RepresentingDate.Add(appt.EndDate.TimeOfDay); reminders[actualsize++] = r; } } } } // Trim array to size. Array.Resize(ref reminders, actualsize); return(reminders); } return(new Reminder[0]); }