//OPTIONAL MAY OCCUR MORE THAN ONCE // X-PROP, IANA-PROP #endregion Properties #region Methods /// <summary> /// Add an item to the VCALENDAR. /// The item HAS TO BE either an ComponentProperty or CalendarComponent. /// </summary> /// <param name="calObject">The object to be added.</param> public void AddItem(ICalendarObject calObject) { var calendarProperty = calObject as IComponentProperty; //if the object is a property, add it to the properties container if (calendarProperty != null) { Properties.Add(calendarProperty.Name, calendarProperty); return; } //if is not a property add it to the calendar components container var calComponent = calObject as ICalendarComponent; if (CalendarComponents.ContainsKey(calComponent.Name)) { CalendarComponents[calComponent.Name].Add(calComponent); } else { CalendarComponents.Add(calComponent.Name, new List <ICalendarComponent>(1) { calComponent }); } }
public void Serialize(TextWriter writer) { writer.WriteLine("BEGIN:VCALENDAR"); foreach (var property in Properties.Values) { property.Serialize(writer); } foreach (var component in CalendarComponents.SelectMany(components => components.Value)) { component.Serialize(writer); } writer.WriteLine("END:VCALENDAR"); }
/// <summary> /// Return the string representation of the VCALENDAR object /// with just the given properties and components. /// </summary> /// <param name="calData">Properties and components to print.</param> /// <returns></returns> public string ToString(IXMLTreeStructure calData) { var strBuilder = new StringBuilder(); strBuilder.AppendLine("BEGIN:VCALENDAR"); ///take the first node in the tree that contains VCALENDAR in the /// attr "name" var vCal = calData.Children.Where(x => x.NodeName == "comp"). First(x => x.Attributes.ContainsValue("VCALENDAR")); ///take the name of the properties in VCALENDAR that have to be /// returned var propToReturn = vCal.Children .Where(x => x.NodeName == "prop") .SelectMany(x => x.Attributes.Values); ///take those properties from the VCalendar object foreach (var property in Properties.Values.Where(x => propToReturn.Contains(x.Name))) { strBuilder.Append(property); } ///take the desired calendar component names from the tree var compToReturn = vCal.Children.Where(x => x.NodeName == "comp"). SelectMany(x => x.Attributes.Values); ///take the calendar components from the VCALENDAR object foreach (var component in CalendarComponents.Where(comp => compToReturn.Contains(comp.Key))) { ///take the properties of the current component that are in the /// node of the tree with name = to the current component. var properties = vCal.Children.Where(x => x.NodeName == "comp") .First(x => x.Attributes.ContainsValue(component.Key)) .Children.SelectMany(x => x.Attributes.Values); ///take the string representation of the current cal component /// and all the requested properties strBuilder.Append(component.Value.First().ToString(properties)); } strBuilder.AppendLine("END:VCALENDAR"); return(strBuilder.ToString()); }
/// <summary> /// Add an ICalendarComponent to the event /// or a property. /// </summary> /// <param name="component"></param> public override void AddItem(ICalendarObject component) { var item = component as ICalendarComponent; if (item != null) { if (CalendarComponents.ContainsKey(component.Name)) { CalendarComponents[component.Name].Add(item); } else { CalendarComponents.Add(item.Name, new List <ICalendarComponent>() { item }); } } else { base.AddItem(component); } }
/// <summary> /// Add an item to the VCALENDAR. /// The item SHOULD BE either an iCalendar property /// or ICalendar component. /// </summary> /// <param name="calComponent"></param> public void AddItem(ICalendarObject calComponent) { var prop = calComponent as IComponentProperty; if (prop != null) { Properties.Add(prop.Name, prop); return; } if (CalendarComponents.ContainsKey(calComponent.Name)) { CalendarComponents[calComponent.Name].Add((ICalendarComponent)calComponent); } else { CalendarComponents.Add(calComponent.Name, new List <ICalendarComponent>(1) { (ICalendarComponent)calComponent }); } }
/// <summary> /// Return all the CalendarComponents that match with the given the name. /// </summary> /// <param name="componentName">The name of the CalendarComponent.</param> /// <returns> /// The components with the given name. Null if the VCalendar doesn't contain /// a CalendarComponent with the given name. /// </returns> public IList <ICalendarComponent> GetCalendarComponents(string componentName) { return(CalendarComponents.ContainsKey(componentName) ? CalendarComponents[componentName] : null); }