public void DeleteResource(string user, string calendar, IUniqueComponent resource) { var request = WebRequest.Create(new Uri(GetRequestUri(user, calendar), resource.UID + ".ics")); request.Credentials = Credentials; request.Method = "DELETE"; request.ContentType = "text/calendar"; var bytes = WrapResource(resource); SendRequest(request, bytes); }
public void CreateResource(string user, string calendar, IUniqueComponent resource) { var request = WebRequest.Create(new Uri(GetRequestUri(user, calendar), resource.UID + ".ics")); request.Credentials = Credentials; request.Method = "PUT"; request.ContentType = "text/calendar"; request.Headers.Add("If-None-Match: *"); var bytes = WrapResource(resource); SendRequest(request, bytes); }
/// <summary> /// Merges this object with another. /// </summary> /// <param name="obj"></param> public virtual void MergeWith(IMergeable obj) { var c = obj as IICalendar; if (c != null) { if (Name == null) { Name = c.Name; } foreach (ICalendarProperty p in c.Properties) { if (!Properties.ContainsKey(p.Name)) { Properties.Add(p.Copy <ICalendarProperty>( )); } } foreach (ICalendarObject child in c.Children) { var uniqueComponent = child as IUniqueComponent; if (uniqueComponent != null) { IUniqueComponent component = UniqueComponents[uniqueComponent.Uid]; if (component == null) { this.AddChild(uniqueComponent.Copy <ICalendarObject>( )); } } else { var timeZone = child as ITimeZone; if (timeZone != null) { ITimeZone tz = GetTimeZone(timeZone.TzId); if (tz == null) { this.AddChild(timeZone.Copy <ICalendarObject>( )); } } else { this.AddChild(child.Copy <ICalendarObject>( )); } } } } }
public override string SerializeToString(object obj) { IUniqueComponent c = obj as IUniqueComponent; if (c != null) { if (c.DTStamp != null && !c.DTStamp.IsUniversalTime) { // Ensure the DTSTAMP property is in universal time before // it is serialized c.DTStamp = new iCalDateTime(c.DTStamp.UTC); } } return(base.SerializeToString(obj)); }
private byte[] WrapResource(IUniqueComponent resource) { var iCal = new iCalendar(); iCal.UniqueComponents.Add(resource); ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new SerializerFactory(); IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; return Encoding.UTF8.GetBytes(serializer.SerializeToString(iCal)); }
static public IFreeBusy Create(ICalendarObject obj, IFreeBusy freeBusyRequest) { if (obj is IGetOccurrencesTyped) { IGetOccurrencesTyped getOccurrences = (IGetOccurrencesTyped)obj; IList <Occurrence> occurrences = getOccurrences.GetOccurrences <IEvent>(freeBusyRequest.Start, freeBusyRequest.End); List <string> contacts = new List <string>(); bool isFilteredByAttendees = false; if (freeBusyRequest.Attendees != null && freeBusyRequest.Attendees.Count > 0) { isFilteredByAttendees = true; foreach (IAttendee attendee in freeBusyRequest.Attendees) { if (attendee.Value != null) { contacts.Add(attendee.Value.OriginalString.Trim()); } } } IFreeBusy fb = freeBusyRequest.Copy <IFreeBusy>(); fb.UID = new UIDFactory().Build(); fb.Entries.Clear(); fb.DTStamp = iCalDateTime.Now; foreach (Occurrence o in occurrences) { IUniqueComponent uc = o.Source as IUniqueComponent; if (uc != null) { IEvent evt = uc as IEvent; bool accepted = false; FreeBusyStatus type = FreeBusyStatus.Busy; // We only accept events, and only "opaque" events. if (evt != null && evt.Transparency != TransparencyType.Transparent) { accepted = true; } // If the result is filtered by attendees, then // we won't accept it until we find an event // that is being attended by this person. if (accepted && isFilteredByAttendees) { accepted = false; foreach (IAttendee a in uc.Attendees) { if (a.Value != null && contacts.Contains(a.Value.OriginalString.Trim())) { if (a.ParticipationStatus != null) { switch (a.ParticipationStatus.ToUpperInvariant()) { case ParticipationStatus.Tentative: accepted = true; type = FreeBusyStatus.BusyTentative; break; case ParticipationStatus.Accepted: accepted = true; type = FreeBusyStatus.Busy; break; default: break; } } } } } if (accepted) { // If the entry was accepted, add it to our list! fb.Entries.Add(new FreeBusyEntry(o.Period, type)); } } } return(fb); } return(null); }