public FilteredCalendarObjectList(ICalendarObject attached)
 {
     Attached               = attached;
     m_Items                = new List <T>();
     attached.ChildAdded   += new EventHandler <ObjectEventArgs <ICalendarObject> >(m_Attached_ChildAdded);
     attached.ChildRemoved += new EventHandler <ObjectEventArgs <ICalendarObject> >(m_Attached_ChildRemoved);
 }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="component"></param>
        public virtual void AddItem(ICalendarObject component)
        {
            var prop = component as IComponentProperty;

            if (prop == null)
            {
                throw new ArgumentException("THe value should be an IComponentProperty");
            }
            if (prop.Name == "RRULE" || prop.Name == "ATTENDEE" || prop.Name == "FREEBUSY")
            {
                if (MultipleValuesProperties.ContainsKey(prop.Name))
                {
                    MultipleValuesProperties[prop.Name].Add(prop);
                }
                else
                {
                    MultipleValuesProperties[prop.Name] = new List <IComponentProperty>()
                    {
                        prop
                    }
                };
            }
            else
            {
                Properties.Add(prop.Name, prop);
            }
        }
Beispiel #3
0
        //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
                });
            }
        }
 protected void OnChildRemoved(ICalendarObject child)
 {
     if (ChildRemoved != null)
     {
         ChildRemoved(this, new ObjectEventArgs <ICalendarObject>(child));
     }
 }
Beispiel #5
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();
     }
 }
 public virtual void SetParent(ICalendarObject parent)
 {
     foreach (var parameter in this)
     {
         parameter.Parent = parent;
     }
 }
Beispiel #7
0
        public override object Deserialize(TextReader tr)
        {
            if (tr != null)
            {
                string value = tr.ReadToEnd();

                ICalendarObject co = SerializationContext.Peek() as ICalendarObject;
                if (co != null)
                {
                    EncodableDataType dt = new EncodableDataType();
                    dt.AssociatedObject = co;
                    value = Decode(dt, value);
                }

                value = TextUtil.Normalize(value, SerializationContext).ReadToEnd();

                try
                {
                    Uri uri = new Uri(value);
                    return(uri);
                }
                catch
                {
                }
            }
            return(null);
        }
        public override object Deserialize(TextReader tr)
        {
            string value = tr.ReadToEnd();

            try
            {
                ICalendarObject obj = SerializationContext.Peek() as ICalendarObject;
                if (obj != null)
                {
                    // Decode the value, if necessary!
                    EncodableDataType dt = new EncodableDataType();
                    dt.AssociatedObject = obj;
                    value = Decode(dt, value);
                }

                int i;
                if (Int32.TryParse(value, out i))
                {
                    return(i);
                }
            }
            catch {}

            return(value);
        }
Beispiel #9
0
        /// <summary>
        ///     Add a CalendarComponent property to the object.
        /// </summary>
        /// <param name="component">The calendarProperty to be added.</param>
        public virtual void AddItem(ICalendarObject component)
        {
            var prop = component as IComponentProperty;

            if (prop == null)
            {
                throw new ArgumentException("THe value should be an IComponentProperty");
            }

            //TODO:this properties should implement other interface to indentify that may contains
            //multiples values, this way is gonna be simpler this verification, among other things

            //check if the property is already in the object. If it is then put it in the
            //multiple property list.
            if (Properties.ContainsKey(prop.Name))
            {
                MultipleValuesProperties[prop.Name] = new List <IComponentProperty> {
                    prop, Properties[prop.Name]
                };
                Properties.Remove(prop.Name);
            }
            else if (MultipleValuesProperties.ContainsKey(prop.Name))
            {
                MultipleValuesProperties[prop.Name].Add(prop);
            }
            else
            {
                Properties.Add(prop.Name, prop);
            }
        }
        public CalendarPropertyList(ICalendarObject parent, bool caseInsensitive)
        {
            m_Parent = parent;

            ItemAdded   += new EventHandler <ObjectEventArgs <ICalendarProperty, int> >(CalendarPropertyList_ItemAdded);
            ItemRemoved += new EventHandler <ObjectEventArgs <ICalendarProperty, int> >(CalendarPropertyList_ItemRemoved);
        }
 public CalendarPropertyList(ICalendarObject parent, bool caseInsensitive)
 {
     _mParent          = parent;
     _mCaseInsensitive = caseInsensitive;
     ItemAdded        += CalendarPropertyList_ItemAdded;
     ItemRemoved      += CalendarPropertyList_ItemRemoved;
 }
 public AssociatedCalendarParameterList(ICalendarParameterList list, ICalendarObject parent, ICalendarParameterListContainer container) :
     this(parent, container)
 {
     if (list != null)
     {
         if (m_AssociatedContainer != null &&
             m_AssociatedContainer.Parameters != null)
         {
             foreach (ICalendarParameter p in list)
             {
                 if (!m_AssociatedContainer.Parameters.Contains(p))
                 {
                     m_AssociatedContainer.Parameters.Add(p);
                 }
             }
         }
         else
         {
             foreach (ICalendarParameter p in list)
             {
                 m_Parameters.Add(p);
             }
         }
     }
 }
 static public void AssociateItem(object item, ICalendarObject objectToAssociate)
 {
     if (item is ICalendarDataType)
         ((ICalendarDataType)item).AssociatedObject = objectToAssociate;
     else if (item is ICalendarObject)
         ((ICalendarObject)item).Parent = objectToAssociate;
 }
Beispiel #14
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();
		}
Beispiel #15
0
 public override void RemoveChild(ICalendarObject child)
 {
     if (child is IAlarm)
     {
         Alarms.Remove((IAlarm)child);
     }
     base.RemoveChild(child);
 }
Beispiel #16
0
 public override void AddChild(ICalendarObject child)
 {
     if (child is IAlarm)
     {
         Alarms.Add((IAlarm)child);
     }
     base.AddChild(child);
 }
        public CalendarParameterList(ICalendarObject parent, bool caseInsensitive)
        {
            m_Parent          = parent;
            m_CaseInsensitive = caseInsensitive;

            ItemAdded   += new EventHandler <ObjectEventArgs <ICalendarParameter> >(CalendarParameterList_ItemAdded);
            ItemRemoved += new EventHandler <ObjectEventArgs <ICalendarParameter> >(CalendarParameterList_ItemRemoved);
        }
Beispiel #18
0
 /// <summary>
 /// Copies values from the target object to the
 /// current object.
 /// </summary>
 virtual public void CopyFrom(ICopyable obj)
 {
     if (obj is ICalendarDataType)
     {
         ICalendarDataType dt = (ICalendarDataType)obj;
         _AssociatedObject = dt.AssociatedObject;
         _Parameters       = new AssociatedCalendarParameterList(dt.Parameters, _AssociatedObject, _AssociatedObject as ICalendarParameterListContainer);
     }
 }
 /// <summary>
 /// Removes a child at the given index in the children list.
 /// </summary>
 /// <param name="index"></param>
 virtual public void RemoveChildAt(int index)
 {
     if (index >= 0 && index < _Children.Count)
     {
         ICalendarObject child = _Children[index];
         _Children.RemoveAt(index);
         OnChildRemoved(child);
     }
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="CalendarParameterList" /> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="caseInsensitive">
        ///     if set to <c>true</c> [case insensitive].
        /// </param>
        public CalendarParameterList(ICalendarObject parent, bool caseInsensitive)
        {
            _parent          = parent;
            _caseInsensitive = caseInsensitive;


            ItemAdded   += OnParameterAdded;
            ItemRemoved += OnParameterRemoved;
        }
 /// <summary>
 /// Removed an <see cref="iCalObject"/>-based object from the <see cref="Children"/>
 /// collection.
 /// </summary>
 /// <param name="child"></param>
 virtual public void RemoveChild(ICalendarObject child)
 {
     if (_Children.Contains(child))
     {
         _Children.Remove(child);
         child.Parent = null;
         OnChildRemoved(child);
     }
 }
Beispiel #22
0
        /// <summary>
        /// Parse the string that contain a calendar defines
        /// under the protocol RFC 5545. Builds an instance
        /// of VCalendar with its components, properties..
        /// </summary>
        /// <param name="calendarString">The calendar to parse.</param>
        /// <returns>An instance of VCalendar.</returns>
        public static VCalendar Parse(string calendarString)
        {
            var             calCompFactory  = new CalendarComponentFactory();
            var             compPropFactory = new ComponentPropertyFactory();
            var             name            = "";
            var             value           = "";
            var             parameters      = new List <PropertyParameter>();
            ICalendarObject calComponent    = null;
            ICalendarObject compProperty    = null;
            var             objStack        = new Stack <ICalendarObject>();
            Type            type            = null;
            var             lines           = Parser.CalendarReader(calendarString);

            foreach (var line in lines)
            {
                if (!Parser.CalendarParser(line, out name, out parameters, out value))
                {
                    continue;
                }
                switch (name)
                {
                case "BEGIN":


                    ///if the component is vcalendar then create is
                    /// if not then call the factory to get the object
                    /// that name.
                    calComponent = value == "VCALENDAR" ? new VCalendar() : calCompFactory.CreateIntance(value);
                    objStack.Push(calComponent);
                    continue;

                case "END":
                    var endedObject = objStack.Pop();
                    //if the last object in the stack is an VCalendar then
                    //is the end of the parsing
                    var vCalendar = endedObject as VCalendar;
                    if (vCalendar != null)
                    {
                        return(vCalendar);
                    }

                    ///if the object is not a VCalendar means
                    /// that should be added to his father that
                    /// is the first in the stack
                    ((IAggregator)objStack.Peek()).AddItem(endedObject);
                    continue;
                }
                ///creates an instance of a property
                compProperty = compPropFactory.CreateIntance(name, name);

                var topObj = objStack.Peek();
                ((IAggregator)topObj).AddItem(((IDeserialize)compProperty).Deserialize(value, parameters));
            }

            throw new ArgumentException("The calendar file MUST contain at least an element.");
        }
 /// <summary>
 /// Copies values from the target object to the
 /// current object.
 /// </summary>
 virtual public void CopyFrom(ICopyable obj)
 {
     if (obj is ICalendarDataType)
     {
         ICalendarDataType dt = (ICalendarDataType)obj;
         _AssociatedObject = dt.AssociatedObject;
         _Proxy.SetParent(_AssociatedObject);
         _Proxy.SetProxiedObject(dt.Parameters);
     }
 }
        public override bool Equals(object obj)
        {
            ICalendarObject o = obj as ICalendarObject;

            if (o != null)
            {
                return(object.Equals(o.Name, Name));
            }
            return(base.Equals(obj));
        }
Beispiel #25
0
 /// <summary>
 /// If component is VAlarm type the add it to Alarms
 /// if not is a property and call the base
 /// </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);
 }
Beispiel #26
0
        /// <summary>
        /// Creates a typed object that is a direct child of the iCalendar itself.  Generally,
        /// you would invoke this method to create an Event, Todo, Journal, TimeZone, FreeBusy,
        /// or other base component type.
        /// </summary>
        /// <example>
        /// To create an event, use the following:
        /// <code>
        /// IICalendar iCal = new iCalendar();
        ///
        /// Event evt = iCal.Create&lt;Event&gt;();
        /// </code>
        ///
        /// This creates the event, and adds it to the Events list of the iCalendar.
        /// </example>
        /// <typeparam name="T">The type of object to create</typeparam>
        /// <returns>An object of the type specified</returns>
        public T Create <T>() where T : ICalendarComponent
        {
            ICalendarObject obj = Activator.CreateInstance(typeof(T)) as ICalendarObject;

            if (obj is T)
            {
                this.AddChild(obj);
                return((T)obj);
            }
            return(default(T));
        }
Beispiel #27
0
 public static void AssociateItem(object item, ICalendarObject objectToAssociate)
 {
     if (item is ICalendarDataType)
     {
         ((ICalendarDataType)item).AssociatedObject = objectToAssociate;
     }
     else if (item is ICalendarObject)
     {
         ((ICalendarObject)item).Parent = objectToAssociate;
     }
 }
        /// <summary>
        ///     Copies values from the target object to the
        ///     current object.
        /// </summary>
        /// <param name="obj"></param>
        public virtual void CopyFrom(ICopyable obj)
        {
            var calendarDataType = obj as ICalendarDataType;

            if (calendarDataType != null)
            {
                ICalendarDataType dt = calendarDataType;
                AssociatedObjectMember = dt.AssociatedObject;
                _proxy.SetParent(AssociatedObjectMember);
                _proxy.SetProxiedObject(dt.Parameters);
            }
        }
        private void WriteObject(ICalendarObject calendarObject)
        {
            // Get a serializer for each child object.
            var serializer = _serializerFactory.Build(
                calendarObject.GetType(),
                SerializationContext) as IStringSerializer;

            if (serializer != null)
            {
                _writer.Write(serializer.SerializeToString(calendarObject));
            }
        }
Beispiel #30
0
        private static string ToString(ICalendarObject obj)
        {
            var calendar = new CalDav.Calendar();

            calendar.AddItem(obj);
            var serializer = new Serializer();

            using (var str = new System.IO.StringWriter()) {
                serializer.Serialize(str, calendar);
                return(str.ToString());
            }
        }
Beispiel #31
0
        public void Save(ICalendarInfo calendar, ICalendarObject e)
        {
            var filename = System.IO.Path.Combine(_directory, calendar.ID, e.UID + ".ics");
            var ical     = new CalDav.Calendar();

            ical.AddItem(e);
            var serializer = new Serializer();

            using (var file = System.IO.File.Open(filename, System.IO.FileMode.Create))
            {
                serializer.Serialize(file, ical);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="component"></param>
 public virtual void AddItem(ICalendarObject component)
 {
     var prop = component as IComponentProperty;
     if (prop == null)
         throw new ArgumentException("THe value should be an IComponentProperty");
     if (prop.Name == "RRULE" || prop.Name == "ATTENDEE" || prop.Name == "FREEBUSY")
     {
         if(MultipleValuesProperties.ContainsKey(prop.Name))
             MultipleValuesProperties[prop.Name].Add(prop);
         else
             MultipleValuesProperties[prop.Name] = new List<IComponentProperty>() {prop};
     }
     else
         Properties.Add(prop.Name, prop);
 }
        public AssociatedCalendarParameterList(ICalendarObject parent, ICalendarParameterListContainer container)
        {
            m_Parent = parent;
            m_AssociatedContainer = container;

            m_Parameters.ItemAdded   += new EventHandler <ObjectEventArgs <ICalendarParameter> >(Parameters_ItemAdded);
            m_Parameters.ItemRemoved += new EventHandler <ObjectEventArgs <ICalendarParameter> >(Parameters_ItemRemoved);
            if (container != null)
            {
                container.Parameters.ItemAdded   += new EventHandler <ObjectEventArgs <ICalendarParameter> >(Parameters_ItemAdded);
                container.Parameters.ItemRemoved += new EventHandler <ObjectEventArgs <ICalendarParameter> >(Parameters_ItemRemoved);
            }
            ItemAdded   += new EventHandler <ObjectEventArgs <ICalendarParameter> >(CalendarParameterList_ItemAdded);
            ItemRemoved += new EventHandler <ObjectEventArgs <ICalendarParameter> >(CalendarParameterList_ItemRemoved);
        }
        public AssociatedCalendarParameterList(ICalendarObject parent, ICalendarParameterListContainer container)
        {
            m_Parent = parent;
            m_AssociatedContainer = container;

            m_Parameters.ItemAdded += new EventHandler<ObjectEventArgs<ICalendarParameter>>(Parameters_ItemAdded);
            m_Parameters.ItemRemoved += new EventHandler<ObjectEventArgs<ICalendarParameter>>(Parameters_ItemRemoved);
            if (container != null)
            {
                container.Parameters.ItemAdded += new EventHandler<ObjectEventArgs<ICalendarParameter>>(Parameters_ItemAdded);
                container.Parameters.ItemRemoved += new EventHandler<ObjectEventArgs<ICalendarParameter>>(Parameters_ItemRemoved);
            }
            ItemAdded += new EventHandler<ObjectEventArgs<ICalendarParameter>>(CalendarParameterList_ItemAdded);
            ItemRemoved += new EventHandler<ObjectEventArgs<ICalendarParameter>>(CalendarParameterList_ItemRemoved);
        }
Beispiel #35
0
        public override string SerializeToString(object obj)
        {
            if (obj != null)
            {
                ISerializationSettings settings = GetService <ISerializationSettings>();

                List <string> values = new List <string>();
                if (obj is string)
                {
                    // Object to be serialied is a string already
                    values.Add((string)obj);
                }
                else if (obj is IEnumerable)
                {
                    // Object is a list of objects (probably IList<string>).
                    foreach (object child in (IEnumerable)obj)
                    {
                        values.Add(child.ToString());
                    }
                }
                else
                {
                    // Serialize the object as a string.
                    values.Add(obj.ToString());
                }

                ICalendarObject co = SerializationContext.Peek() as ICalendarObject;
                if (co != null)
                {
                    // Encode the string as needed.
                    EncodableDataType dt = new EncodableDataType();
                    dt.AssociatedObject = co;
                    for (int i = 0; i < values.Count; i++)
                    {
                        values[i] = Encode(dt, Escape(values[i]));
                    }

                    return(string.Join(",", values.ToArray()));
                }

                for (int i = 0; i < values.Count; i++)
                {
                    values[i] = Escape(values[i]);
                }
                return(string.Join(",", values.ToArray()));
            }
            return(null);
        }
        protected override IValidationResultCollection ValidateObject(ICalendarObject obj)
        {
            ValidationResultCollection results = new ValidationResultCollection(ResourceManager);
            results.Passed = true;

            ICalendarPropertyListContainer c = obj as ICalendarPropertyListContainer;
            if (c != null)
            {
                List<string> validValues = new List<string>(new string[]
                {
                    "BINARY",
                    "BOOLEAN",
                    "CAL-ADDRESS",
                    "DATE",
                    "DATE-TIME",
                    "DURATION",
                    "FLOAT",
                    "INTEGER",
                    "PERIOD",
                    "RECUR",
                    "TEXT",
                    "TIME",
                    "URI",
                    "UTC-OFFSET"
                });

                foreach (ICalendarProperty p in c.Properties)
                {
                    foreach (ICalendarParameter parm in p.Parameters)
                    {
                        if (parm.Values != null &&
                            parm.Values.Length > 0 &&
                            string.Equals(parm.Name, "VALUE", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (!validValues.Contains(parm.Values[0].ToUpper()))
                                Warning(results, "unknownValueTypeParameterError", p.Line, p.Column, parm.Values[0], string.Join(", ", validValues.ToArray()));
                        }
                    }
                }
            }

            return results;
        }
 public AssociatedCalendarParameterList(ICalendarParameterList list, ICalendarObject parent, ICalendarParameterListContainer container) : 
     this(parent, container)
 {
     if (list != null)
     {
         if (m_AssociatedContainer != null &&
             m_AssociatedContainer.Parameters != null)
         {
             foreach (ICalendarParameter p in list)
             {
                 if (!m_AssociatedContainer.Parameters.Contains(p))
                     m_AssociatedContainer.Parameters.Add(p);
             }
         }
         else
         {
             foreach (ICalendarParameter p in list)
                 m_Parameters.Add(p);
         }
     }
 }
        protected override IValidationResultCollection ValidateObject(ICalendarObject component)
        {
            ValidationResultCollection result = new ValidationResultCollection(ResourceManager, "component");

            if (component is ICalendarComponent)
            {
                switch (component.Name.ToUpper())
                {
                    case "VALARM": // FIXME: VALARM should only be valid within recurring components.
                    case "VEVENT":
                    case "VTODO":
                    case "VJOURNAL":
                    case "VTIMEZONE":
                    case "VFREEBUSY":
                    case "DAYLIGHT":
                    case "STANDARD":
                        break;
                    case "VNOTE":
                        {
                            Warning(result, "vnoteDeprecatedError", component.Line, component.Column);
                        } break;
                    default:
                        {
                            // FIXME: return an ERROR for nonstandard components without an "X-" prefix, and
                            // a WARNING for "X-" components.
                        } break;
                }

                // Validation of children of the component, for subcomponents.
                // This is necessary for DAYLIGHT, STANDARD, and VALARM.
                foreach (ICalendarObject child in component.Children)
                {
                    IValidationResultCollection childResult = ValidateObject(child);
                    if (childResult.Passed != null && childResult.Passed.HasValue && !childResult.Passed.Value)
                        result.Add(childResult);
                }
            }

            return result;
        }
        private void WriteObject(ICalendarObject calendarObject)
        {
            // Get a serializer for each child object.
            var serializer = _serializerFactory.Build(
                calendarObject.GetType(),
                SerializationContext) as IStringSerializer;

            if (serializer != null)
            {
                _writer.Write(serializer.SerializeToString(calendarObject));
            }
        }
Beispiel #40
0
        public void Save(ICalendarInfo calendar, ICalendarObject e, IEnumerable<TimeZone> timeZones)
        {
            var filename = System.IO.Path.Combine(_Directory, calendar.ID, e.UID + ".ics");
            var ical = new CalDav.Calendar();

            ical.AddItem(e);
            foreach (var timezone in timeZones)
            {
                ical.TimeZones.Add(timezone);
            }
            var serializer = new Serializer();
            using (var file = System.IO.File.Open(filename, System.IO.FileMode.Create))
                serializer.Serialize(file, ical);

            //update accordingly the _.ical file
            var calFileName = System.IO.Path.Combine(_Directory, calendar.ID + "\\_.ical");

            var globalIcal = LoadSerializedCalendarFromFileName(calendar.ID, calFileName);
            foreach (var item in ical.Items)
            {
                globalIcal.AddItem(item);
            }
            using (var file = System.IO.File.Open(calFileName, System.IO.FileMode.Open, System.IO.FileAccess.Write))
                serializer.Serialize(file, globalIcal);
        }
Beispiel #41
0
        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;
        }
 protected abstract IValidationResultCollection ValidateObject(ICalendarObject obj);
Beispiel #43
0
	public ICalendarComponent  component(
		
	ISerializationContext ctx,
	ISerializerFactory sf,
	ICalendarComponentFactory cf,
	ICalendarObject o

	) //throws RecognitionException, TokenStreamException
{
		ICalendarComponent c = null;;
		
		IToken  n = null;
		IToken  m = null;
		
		match(BEGIN);
		match(COLON);
		{
			switch ( LA(1) )
			{
			case IANA_TOKEN:
			{
				n = LT(1);
				match(IANA_TOKEN);
				c = cf.Build(n.getText().ToLower(), true);
				break;
			}
			case X_NAME:
			{
				m = LT(1);
				match(X_NAME);
				c = cf.Build(m.getText().ToLower(), true);
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			 }
		}
		
			ISerializationProcessor<ICalendarComponent> processor = ctx.GetService(typeof(ISerializationProcessor<ICalendarComponent>)) as ISerializationProcessor<ICalendarComponent>;
			// Do some pre-processing on the component
			if (processor != null)
				processor.PreDeserialization(c);
		
			SerializationUtil.OnDeserializing(c);
		
			// Push the component onto the serialization context stack
			ctx.Push(c);
		
			if (o != null)
			{
				// Add the component as a child immediately, in case
				// embedded components need to access this component,
				// or the iCalendar itself.
				o.AddChild(c); 
			}
			
			c.Line = n.getLine();
			c.Column = n.getColumn();
		
		{    // ( ... )*
			for (;;)
			{
				if ((LA(1)==CRLF))
				{
					match(CRLF);
				}
				else
				{
					goto _loop16_breakloop;
				}
				
			}
_loop16_breakloop:			;
		}    // ( ... )*
		{    // ( ... )*
			for (;;)
			{
				switch ( LA(1) )
				{
				case IANA_TOKEN:
				case X_NAME:
				{
					property(ctx, c);
					break;
				}
				case BEGIN:
				{
					component(ctx, sf, cf, c);
					break;
				}
				default:
				{
					goto _loop18_breakloop;
				}
				 }
			}
_loop18_breakloop:			;
		}    // ( ... )*
		match(END);
		match(COLON);
		match(IANA_TOKEN);
		{    // ( ... )*
			for (;;)
			{
				if ((LA(1)==CRLF))
				{
					match(CRLF);
				}
				else
				{
					goto _loop20_breakloop;
				}
				
			}
_loop20_breakloop:			;
		}    // ( ... )*
			
			// Do some final processing on the component
			if (processor != null)
				processor.PostDeserialization(c);
		
			// Notify that the component has been loaded
			c.OnLoaded();
			
			SerializationUtil.OnDeserialized(c);
			
			// Pop the component off the serialization context stack
			ctx.Pop();
		
		return c;
	}
 public void Write(ICalendarObject calendarObject)
 {
     Initialize();
     WriteObject(calendarObject);
 }
Beispiel #45
0
		public void Save(ICalendarInfo calendar, ICalendarObject e) {
			var filename = System.IO.Path.Combine(_Directory, calendar.ID, e.UID + ".ics");
			var ical = new CalDav.Calendar();
			ical.AddItem(e);
			var serializer = new Serializer();
			using (var file = System.IO.File.Open(filename, System.IO.FileMode.Create))
				serializer.Serialize(file, ical);
		}
        public Evaluator(ICalendarObject associatedObject)
        {
            m_AssociatedObject = associatedObject;

            Initialize();
        }