Beispiel #1
0
        /// <summary>
        /// Adds an <see cref="iCalObject"/>-based component to the
        /// appropriate collection.  Currently, the iCalendar component
        /// supports the following components:
        ///     <list type="bullet">
        ///         <item><see cref="DDay.iCal.Components.Event"/></item>
        ///         <item><see cref="DDay.iCal.Components.FreeBusy"/></item>
        ///         <item><see cref="DDay.iCal.Components.Journal"/></item>
        ///         <item><see cref="DDay.iCal.Components.TimeZone"/></item>
        ///         <item><see cref="DDay.iCal.Components.Todo"/></item>
        ///     </list>
        /// </summary>
        /// <param name="child"></param>
        public override void AddChild(iCalObject child)
        {
            base.AddChild(child);
            child.Parent = this;

            if (child is UniqueComponent)
            {
                UniqueComponents.Add((UniqueComponent)child);
            }

            Type type = child.GetType();

            if (type == typeof(Event) || type.IsSubclassOf(typeof(Event)))
            {
                Events.Add((Event)child);
            }
            else if (type == typeof(FreeBusy) || type.IsSubclassOf(typeof(FreeBusy)))
            {
                FreeBusy.Add((FreeBusy)child);
            }
            else if (type == typeof(Journal) || type.IsSubclassOf(typeof(Journal)))
            {
                Journals.Add((Journal)child);
            }
            else if (type == typeof(iCalTimeZone) || type.IsSubclassOf(typeof(iCalTimeZone)))
            {
                TimeZones.Add((iCalTimeZone)child);
            }
            else if (type == typeof(Todo) || type.IsSubclassOf(typeof(Todo)))
            {
                Todos.Add((Todo)child);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Removes an <see cref="iCalObject"/>-based component from all
        /// of the collections that this object may be contained in within
        /// the iCalendar.
        /// </summary>
        /// <param name="child"></param>
        public override void RemoveChild(iCalObject child)
        {
            base.RemoveChild(child);

            if (child is UniqueComponent)
            {
                UniqueComponents.Remove((UniqueComponent)child);
            }

            Type type = child.GetType();

            if (type == typeof(Event) || type.IsSubclassOf(typeof(Event)))
            {
                Events.Remove((Event)child);
            }
            else if (type == typeof(FreeBusy) || type.IsSubclassOf(typeof(FreeBusy)))
            {
                FreeBusy.Remove((FreeBusy)child);
            }
            else if (type == typeof(Journal) || type.IsSubclassOf(typeof(Journal)))
            {
                Journals.Remove((Journal)child);
            }
            else if (type == typeof(DDay.iCal.Components.TimeZone) || type.IsSubclassOf(typeof(DDay.iCal.Components.TimeZone)))
            {
                TimeZones.Remove((DDay.iCal.Components.TimeZone)child);
            }
            else if (type == typeof(Todo) || type.IsSubclassOf(typeof(Todo)))
            {
                Todos.Remove((Todo)child);
            }
        }
Beispiel #3
0
 public void Dispose()
 {
     Children.Clear();
     Events.Clear();
     FreeBusy.Clear();
     Journals.Clear();
     Todos.Clear();
     TimeZones.Clear();
     UniqueComponents.Clear();
 }
Beispiel #4
0
 protected bool Equals(Calendar other)
 {
     return(string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) &&
            UniqueComponents.SequenceEqual(other.UniqueComponents) &&
            Events.SequenceEqual(other.Events) &&
            Todos.SequenceEqual(other.Todos) &&
            Journals.SequenceEqual(other.Journals) &&
            FreeBusy.SequenceEqual(other.FreeBusy) &&
            TimeZones.SequenceEqual(other.TimeZones));
 }
Beispiel #5
0
        virtual public void MergeWith(IMergeable obj)
        {
            IICalendar c = obj as IICalendar;

            if (c != null)
            {
                if (Name == null)
                {
                    Name = c.Name;
                }

                Method    = c.Method;
                Version   = c.Version;
                ProductID = c.ProductID;
                Scale     = c.Scale;

                foreach (ICalendarProperty p in c.Properties)
                {
                    if (!Properties.ContainsKey(p.Name))
                    {
                        Properties.Add(p.Copy <ICalendarProperty>());
                    }
                }
                foreach (ICalendarObject child in c.Children)
                {
                    if (child is IUniqueComponent)
                    {
                        if (!UniqueComponents.ContainsKey(((IUniqueComponent)child).UID))
                        {
                            AddChild(child.Copy <ICalendarObject>());
                        }
                    }
                    else if (child is ITimeZone)
                    {
                        ITimeZone tz = GetTimeZone(((ITimeZone)child).TZID);
                        if (tz == null)
                        {
                            AddChild(child.Copy <ICalendarObject>());
                        }
                    }
                    else
                    {
                        AddChild(child.Copy <ICalendarObject>());
                    }
                }
            }
        }
Beispiel #6
0
        public override bool Equals(object obj)
        {
            IICalendar iCal = obj as iCalendar;

            if (iCal != null)
            {
                bool isEqual =
                    object.Equals(Version, iCal.Version) &&
                    object.Equals(ProductID, iCal.ProductID) &&
                    object.Equals(Scale, iCal.Scale) &&
                    object.Equals(Method, iCal.Method) &&
                    (
                        (UniqueComponents == null && iCal.UniqueComponents == null) ||
                        (UniqueComponents != null && iCal.UniqueComponents != null && object.Equals(UniqueComponents.Count, iCal.UniqueComponents.Count))
                    );

                if (isEqual)
                {
                    if (UniqueComponents.Count != iCal.UniqueComponents.Count)
                    {
                        return(false);
                    }

                    IEnumerator <IUniqueComponent> e1 = UniqueComponents.GetEnumerator();
                    IEnumerator <IUniqueComponent> e2 = iCal.UniqueComponents.GetEnumerator();
                    while (e1.MoveNext())
                    {
                        if (!e2.MoveNext())
                        {
                            return(false);
                        }
                        if (!object.Equals(e1.Current, e2.Current))
                        {
                            return(false);
                        }
                    }
                    return(!e2.MoveNext());
                }
                return(false);
            }
            return(base.Equals(obj));
        }
Beispiel #7
0
        public virtual void MergeWith(IMergeable obj)
        {
            var c = obj as Calendar;

            if (c == null)
            {
                return;
            }

            if (Name == null)
            {
                Name = c.Name;
            }

            Method    = c.Method;
            Version   = c.Version;
            ProductId = c.ProductId;
            Scale     = c.Scale;

            foreach (var p in c.Properties.Where(p => !Properties.ContainsKey(p.Name)))
            {
                Properties.Add(p);
            }

            foreach (var child in c.Children)
            {
                if (child is IUniqueComponent)
                {
                    if (!UniqueComponents.ContainsKey(((IUniqueComponent)child).Uid))
                    {
                        this.AddChild(child);
                    }
                }
                else
                {
                    this.AddChild(child);
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Resolves each UID in the UniqueComponents list
        /// to a valid UID.  When the UIDs are updated, each
        /// UniqueComponentList that contains the UniqueComponent
        /// will be updated as well.
        /// </summary>
        public override void OnLoad(EventArgs e)
        {
            UniqueComponents.ResolveUIDs();

            base.OnLoad(e);
        }