public void Deserialize(System.IO.TextReader rdr, Serializer serializer) { string name, value; var parameters = new XNameValueCollection(); while (rdr.Property(out name, out value, parameters) && !string.IsNullOrEmpty(name)) { switch (name) { case "BEGIN": var detail = serializer.GetService <TimeZoneDetail>(); detail.Type = value; detail.Calendar = Calendar; detail.Deserialize(rdr, serializer); Add(detail); break; case "END": if (value == "VTIMEZONE") { return; } break; } } }
public void Deserialize(System.IO.TextReader rdr, Serializer serializer) { string name, value; var parameters = new XNameValueCollection(); while (rdr.Property(out name, out value, parameters) && !string.IsNullOrEmpty(name)) { switch (name.ToUpper()) { case "TZID": ID = value; break; case "TZNAME": Name = value; break; case "DTSTART": Start = value.ToDateTime(); break; case "RRULE": var rule = serializer.GetService <Recurrence>(); rule.Deserialize(value, parameters); Recurrences.Add(rule); break; case "TZOFFSETFROM": OffsetFrom = value.ToOffset(); break; case "TZOFFSETTO": OffsetTo = value.ToOffset(); break; case "END": return; } } }
public override string ToString() { var parameters = new XNameValueCollection(); if (Count != null) { parameters["COUNT"] = Count.ToString(); } if (Interval != null) { parameters["INTERVAL"] = Interval.ToString(); } if (Frequency != null) { parameters["FREQ"] = Frequency.Value.ToString().ToUpper(); } if (Until != null) { parameters["UNTIL"] = Common.FormatDate(Until.Value); } if (ByMonth != null) { parameters["BYMONTH"] = ByMonth.ToString(); } if (ByMonthDay != null) { parameters["BYMONTHDAY"] = ByMonthDay.ToString(); } if (ByDay != null && ByDay.Length > 0) { parameters["BYDAY"] = string.Join(",", ByDay); } return(Common.FormatParameters(parameters).TrimStart(';')); }
public void Deserialize(string value, XNameValueCollection parameters) { Count = parameters["COUNT"].ToInt(); Interval = parameters["INTERVAL"].ToInt(); Frequency = parameters["FREQ"].ToEnum <Frequencies>(); Until = parameters["UNTIL"].ToDateTime(); ByMonth = parameters["BYMONTH"].ToInt(); ByMonthDay = parameters["BYMONTHDAY"].ToInt(); ByDay = parameters["BYDAY"].SplitEscaped().ToArray(); }
public void Deserialize(string value, XNameValueCollection parameters) { Email = value.Substring(value.IndexOf(':') + 1); Name = parameters["CN"]; SentBy = parameters["SENT-BY"]; if (!string.IsNullOrEmpty(SentBy)) { SentBy = SentBy.Substring(SentBy.IndexOf(':') + 1); } Directory = parameters["DIR"]; }
public XNameValueCollection GetParameters() { var values = new XNameValueCollection(); if (DateTime != null) { values["VALUE"] = "DATE-TIME"; } if (DateTime == null && Related != Relateds.Start) { values["RELATED"] = Related.ToString().ToUpper(); } return(values); }
internal static string FormatParameters(XNameValueCollection parameters) { if (parameters == null || parameters.Count == 0) { return(string.Empty); } var sb = new StringBuilder(); foreach (var key in parameters.AllKeys) { sb.AppendFormat(";{0}={1}", key, ParamEncode(parameters[key])); } return(sb.ToString()); }
public void Deserialize(string value, XNameValueCollection parameters) { if (string.Equals(parameters["VALUE"], "DATE-TIME", StringComparison.OrdinalIgnoreCase)) { DateTime = value.ToDateTime(); } else { Relateds related; if (System.Enum.TryParse <Relateds>(parameters["RELATED"], true, out related)) { Related = related; } var duration = TimeSpan.Zero; var neg = false; var num = ""; foreach (var c in value.ToUpper()) { if (char.IsDigit(c)) { num += c; } else { switch (c) { case '-': neg = true; continue; case 'W': duration = duration.Add(TimeSpan.FromDays((num.ToInt() ?? 0) * 7)); break; case 'D': duration = duration.Add(TimeSpan.FromDays(num.ToInt() ?? 0)); break; case 'H': duration = duration.Add(TimeSpan.FromHours(num.ToInt() ?? 0)); break; case 'M': duration = duration.Add(TimeSpan.FromMinutes(num.ToInt() ?? 0)); break; case 'S': duration = duration.Add(TimeSpan.FromSeconds(num.ToInt() ?? 0)); break; } num = string.Empty; } } Duration = neg ? -duration : duration; } }
public void Deserialize(System.IO.TextReader rdr, Serializer serializer) { string name, value; var parameters = new XNameValueCollection(); while (rdr.Property(out name, out value, parameters) && !string.IsNullOrEmpty(name)) { switch (name) { case "ACTION": Action = getAlarmActions(value); break; case "DESCRIPTION": Description = value; break; case "TRIGGER": CalDavTrigger = serializer.GetService <Trigger>(); CalDavTrigger.Deserialize(value, parameters); break; } } }
public XNameValueCollection GetParameters() { var values = new XNameValueCollection(); if (!string.IsNullOrEmpty(Name)) { values["CN"] = Name; } if (!string.IsNullOrEmpty(Directory)) { values["DIR"] = Directory; } if (!string.IsNullOrEmpty(SentBy)) { values["SENT-BY"] = SentBy; } return(values); }
public void Deserialize(System.IO.TextReader rdr, Serializer serializer) { string name, value; var parameters = new XNameValueCollection(); while (rdr.Property(out name, out value, parameters) && !string.IsNullOrEmpty(name)) { switch (name.ToUpper()) { case "UID": UID = value; break; case "ORGANIZER": Organizer = new Contact(); Organizer.Deserialize(value, parameters); break; case "SEQUENCE": Sequence = value.ToInt(); break; case "LAST-MODIFIED": LastModified = value.ToDateTime(); break; case "DTSTART": LastModified = value.ToDateTime(); break; case "DTEND": LastModified = value.ToDateTime(); break; case "DTSTAMP": DTSTAMP = value.ToDateTime(); break; case "FREEBUSY": var parts = value.Split('/'); Details.Add(new DateTimeRange { From = parts.FirstOrDefault().ToDateTime(), To = parts.ElementAtOrDefault(1).ToDateTime() }); break; case "END": return; default: Properties.Add(new NameValuePairWithParameters(name, value, parameters)); break; } } }
public void Deserialize(System.IO.TextReader rdr, Serializer serializer) { string name, value; var parameters = new XNameValueCollection(); while (rdr.Property(out name, out value, parameters) && !string.IsNullOrEmpty(name)) { switch (name.ToUpper()) { case "BEGIN": if (value == "VCALENDAR") { var e = serializer.GetService <Calendar>(); e.Deserialize(rdr, serializer); this.Add(e); } break; } } }
public void Deserialize(System.IO.TextReader rdr, Serializer serializer) { string name, value; var parameters = new XNameValueCollection(); while (rdr.Property(out name, out value, parameters) && !string.IsNullOrEmpty(name)) { switch (name.ToUpper()) { case "UID": UID = value; break; case "DTSTAMP": DTSTAMP = value.ToDateTime(); break; case "DTSTART": Start = value.ToDateTime(); break; case "DUE": Due = value.ToDateTime(); break; case "SUMMARY": Summary = value; break; case "CLASS": Class = value.ToEnum <Classes>(); break; case "CATEGORIES": Categories = value.SplitEscaped().ToList(); break; case "PRIORITY": Priority = value.ToInt(); break; case "STATUS": Status = value.ToEnum <Statuses>(); break; case "LAST-MODIFIED": LastModified = value.ToDateTime(); break; case "COMPLETED": Completed = value.ToDateTime(); break; case "SEQUENCE": Sequence = value.ToInt(); break; case "END": return; default: Properties.Add(new NameValuePairWithParameters(name, value, parameters)); break; } } }
public void Deserialize(System.IO.TextReader rdr, Serializer serializer) { string name, value; var parameters = new XNameValueCollection(); while (rdr.Property(out name, out value, parameters) && !string.IsNullOrEmpty(name)) { switch (name.ToUpper()) { case "CLASS": Class = value.ToEnum <Classes>(); break; case "STATUS": Status = value.ToEnum <Statuses>(); break; case "UID": UID = value; break; case "ORGANIZER": Organizer = new Contact(); Organizer.Deserialize(value, parameters); break; case "CATEGORIES": Categories = value.SplitEscaped().ToList(); break; case "DESCRIPTION": Description = value; break; case "SEQUENCE": Sequence = value.ToInt(); break; case "LAST-MODIFIED": LastModified = value.ToDateTime(); break; case "DTSTAMP": DTSTAMP = value.ToDateTime(); break; case "END": return; default: Properties.Add(new NameValuePairWithParameters(name, value, parameters)); break; } } }
public virtual void Deserialize(System.IO.TextReader rdr, Serializer serializer = null) { if (serializer == null) { serializer = new Serializer(); } string name, value; var parameters = new XNameValueCollection(); while (rdr.Property(out name, out value, parameters) && !string.IsNullOrEmpty(name)) { switch (name.ToUpper()) { case "BEGIN": switch (value) { case "VEVENT": var e = serializer.GetService <Event>(); e.Calendar = this; Events.Add(e); e.Deserialize(rdr, serializer); break; case "VTIMEZONE": var tz = serializer.GetService <TimeZone>(); tz.Calendar = this; TimeZones.Add(tz); tz.Deserialize(rdr, serializer); break; case "VTODO": var td = serializer.GetService <ToDo>(); td.Calendar = this; ToDos.Add(td); td.Deserialize(rdr, serializer); break; case "VFREEBUSY": var fb = serializer.GetService <FreeBusy>(); fb.Calendar = this; FreeBusy.Add(fb); fb.Deserialize(rdr, serializer); break; case "VJOURNAL": var jn = serializer.GetService <JournalEntry>(); jn.Calendar = this; JournalEntries.Add(jn); jn.Deserialize(rdr, serializer); break; } break; case "CALSCALE": Scale = value; break; case "VERSION": Version = value; break; case "PRODID": ProdID = value; break; case "END": if (value == "VCALENDAR") { return; } break; default: Properties.Add(new NameValuePairWithParameters(name, value, parameters)); break; } } }
internal static bool Property(this System.IO.TextReader rdr, out string name, out string value, XNameValueCollection parameters) { var line = rdr.ReadLine(); var oline = line; value = name = null; if (line == null) { return(false); } int peek; while ((peek = rdr.Peek()) == 9 || peek == 32) { line += rdr.ReadLine().Substring(1); } if (parameters != null) { parameters.Clear(); } var i = 0; var separators = new[] { ':', ';', '=' }; string part, paramValue; char sep; while (line.Length > 0) { i = line.IndexOfAny(separators); if (i == -1) { value = line; return(true); } sep = line[i]; part = line.Substring(0, i); line = line.Substring(i + 1); if (name == null) { name = part; } else if (sep == ':') { value = line; return(true); } else if (sep == '=') { if (line.Length > 1 && line[0] == '"') { paramValue = line.Substring(1, line.IndexOf('"', 1) - 1); line = line.Substring(paramValue.Length + 2); if (line.Length > 0 && line[0] == ';') { line = line.Substring(1); } } else { i = line.IndexOfAny(separators); if (i == -1) { i = line.Length; } paramValue = line.Substring(0, i); line = line.Substring((int)Math.Min(line.Length, paramValue.Length + 1)); } paramValue = paramValue.Replace("=3D", "=").Replace("\\;", ";"); parameters[part] = paramValue; } } return(true); }
internal static void Property(this System.IO.TextWriter wrtr, string name, string value, bool encoded = false, XNameValueCollection parameters = null) { if (value == null) { return; } value = name.ToUpper() + FormatParameters(parameters) + ":" + (encoded ? value : PropertyEncode(value)); while (value.Length > 75) { wrtr.WriteLine(value.Substring(0, 75)); value = "\t" + value.Substring(75); } if (value.Length > 0) { wrtr.WriteLine(value); } }
public NameValuePairWithParameters(string name, string val, XNameValueCollection parameters) { Name = name; Value = val; Parameters = parameters; }
public void Deserialize(System.IO.TextReader rdr, Serializer serializer) { string name, value; var parameters = new XNameValueCollection(); while (rdr.Property(out name, out value, parameters) && !string.IsNullOrEmpty(name)) { switch (name.ToUpper()) { case "BEGIN": switch (value) { case "VALARM": var a = serializer.GetService <Alarm>(); a.Deserialize(rdr, serializer); Alarms.Add(a); break; } break; case "ATTENDEE": var contact = new Contact(); contact.Deserialize(value, parameters); Attendees.Add(contact); break; case "CATEGORIES": Categories = value.SplitEscaped().ToList(); break; case "CLASS": Class = value.ToEnum <Classes>(); break; case "CREATED": Created = value.ToDateTime(); break; case "DESCRIPTION": Description = value; break; case "DTEND": End = value.ToDateTime(); break; case "DTSTAMP": DTSTAMP = value.ToDateTime().GetValueOrDefault(); break; case "DTSTART": Start = value.ToDateTime(); break; case "LAST-MODIFIED": LastModified = value.ToDateTime(); break; case "LOCATION": Location = value; break; case "ORGANIZER": Organizer = serializer.GetService <Contact>(); Organizer.Deserialize(value, parameters); break; case "PRIORITY": Priority = value.ToInt(); break; case "SEQUENCE": Sequence = value.ToInt(); break; case "STATUS": Status = value.ToEnum <Statuses>(); break; case "SUMMARY": Summary = value; break; case "TRANSP": Transparency = value; break; case "UID": UID = value; break; case "URL": Url = value.ToUri(); break; case "ATTACH": var attach = value.ToUri(); if (attach != null) { Attachments.Add(attach); } break; case "RRULE": var rule = serializer.GetService <Recurrence>(); rule.Deserialize(null, parameters); Recurrences.Add(rule); break; case "END": return; default: Properties.Add(new NameValuePairWithParameters(name, value, parameters)); break; } } IsAllDay = Start == End; }