예제 #1
0
 public virtual void AddItem(ICalendarObject obj)
 {
     if (obj == null)
     {
         return;
     }
     else if (obj is Event)
     {
         Events.Add((Event)obj);
     }
     else if (obj is ToDo)
     {
         ToDos.Add((ToDo)obj);
     }
     else if (obj is JournalEntry)
     {
         JournalEntries.Add((JournalEntry)obj);
     }
     else if (obj is FreeBusy)
     {
         FreeBusy.Add((FreeBusy)obj);
     }
     else
     {
         throw new InvalidCastException();
     }
 }
예제 #2
0
        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;
                }
            }
        }