Exemplo n.º 1
0
        virtual public ICalendarComponent Build(string objectName, bool uninitialized)
        {
            Type type = null;

            // Determine the type of component to build.
            switch (objectName.ToUpper())
            {
            // FIXME: implement
            case Components.ALARM:
                type = typeof(Alarm);
                break;

            case Components.EVENT:
                type = typeof(Event);
                break;

            //case FREEBUSY: return new FreeBusy();
            case Components.JOURNAL:
                type = typeof(Journal);
                break;

            case Components.TIMEZONE:
                type = typeof(iCalTimeZone);
                break;

            case Components.TODO:
                type = typeof(Todo);
                break;

            case Components.DAYLIGHT:
            case Components.STANDARD:
                type = typeof(iCalTimeZoneInfo);
                break;

            default:
                type = typeof(CalendarComponent);
                break;
            }

            ICalendarComponent c = null;

            if (uninitialized)
            {
                // Create a new, uninitialized object (i.e. no constructor has been called).
                c = SerializationUtil.GetUninitializedObject(type) as ICalendarComponent;
            }
            else
            {
                // Create a new, initialized object.
                c = Activator.CreateInstance(type) as ICalendarComponent;
            }

            if (c != null)
            {
                // Assign the name of this component.
                c.Name = objectName.ToUpper();
            }

            return(c);
        }
Exemplo n.º 2
0
        public override object Deserialize(TextReader tr)
        {
            if (tr != null)
            {
                // Normalize the text before parsing it
                tr = TextUtil.Normalize(tr, SerializationContext);

                // Create a lexer for our text stream
                iCalLexer  lexer  = new iCalLexer(tr);
                iCalParser parser = new iCalParser(lexer);

                // Get our serialization context
                ISerializationContext ctx = SerializationContext;

                // Get a serializer factory from our serialization services
                ISerializerFactory sf = GetService <ISerializerFactory>();

                // Get a calendar component factory from our serialization services
                ICalendarComponentFactory cf = GetService <ICalendarComponentFactory>();

                // Parse the component!
                ICalendarComponent component = parser.component(ctx, sf, cf, null);

                // Close our text stream
                tr.Close();

                // Return the parsed component
                return(component);
            }
            return(null);
        }
        /// <summary>
        ///     Apply the time-filter to the VFREEBUSY components.
        ///     A VFREEBUSY component overlaps a given time range if the condition for the
        ///     corresponding component state specified in the table (pg66 RFC 4791) is satisfied.
        /// </summary>
        /// <param name="component">THe VTODO</param>
        /// <param name="start">The start time of the filter</param>
        /// <param name="end">The end datetime of the filter</param>
        /// <returns>True if pass the filter, false otherwise.</returns>
        private static bool ApplyTimeFilterToVFREEBUSY(this ICalendarComponent component, DateTime start, DateTime end)
        {
            var DTSTART = component.GetComponentProperty("DTSTART") == null
                ? DateTime.MinValue
                : ((IValue <DateTime>)component.GetComponentProperty("DTSTART")).Value;
            var DTEND = component.GetComponentProperty("DTEND") == null
                ? DateTime.MaxValue
                : ((IValue <DateTime>)component.GetComponentProperty("DTEND")).Value;

            //VFREEBUSY has both the DTSTART and DTEND properties? Y
            // VFREEBUSY has the FREEBUSY property? *
            if (DTSTART != DateTime.MinValue && DTEND != DateTime.MaxValue)
            {
                return(start <= DTEND && end > DTSTART);
            }

            //VFREEBUSY has both the DTSTART and DTEND properties? N
            // VFREEBUSY has the FREEBUSY property? Y
            if (component.MultipleValuesProperties.ContainsKey("FREEBUSY"))
            {
                //take the freebusy properties
                var freeBProp = component.MultipleValuesProperties["FREEBUSY"]
                                .Select(x => ((IValue <Period>)x).Value);

                if (freeBProp.Any(period => start < period.End.Value && end > period.Start.Value))
                {
                    return(true);
                }
            }

            //VFREEBUSY has both the DTSTART and DTEND properties? N
            // VFREEBUSY has the FREEBUSY property? N
            return(false);
        }
Exemplo n.º 4
0
        public override string SerializeToString(object obj)
        {
            ICalendarComponent c = obj as ICalendarComponent;

            if (c != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(TextUtil.WrapLines("BEGIN:" + c.Name.ToUpper()));

                // Get a serializer factory
                ISerializerFactory sf = GetService <ISerializerFactory>();

                // Sort the calendar properties in alphabetical order before
                // serializing them!
                List <ICalendarProperty> properties = new List <ICalendarProperty>(c.Properties);

                // FIXME: remove this try/catch
                try
                {
                    properties.Sort(PropertySorter);
                }
                catch (Exception e)
                {
                    throw;
                }

                // Serialize properties
                foreach (ICalendarProperty p in properties)
                {
                    // Get a serializer for each property.
                    IStringSerializer serializer = sf.Build(p.GetType(), SerializationContext) as IStringSerializer;
                    if (serializer != null)
                    {
                        sb.Append(serializer.SerializeToString(p));
                    }
                }

                // Serialize child objects
                if (sf != null)
                {
                    foreach (ICalendarObject child in c.Children)
                    {
                        // Get a serializer for each child object.
                        IStringSerializer serializer = sf.Build(child.GetType(), SerializationContext) as IStringSerializer;
                        if (serializer != null)
                        {
                            sb.Append(serializer.SerializeToString(child));
                        }
                    }
                }

                sb.Append(TextUtil.WrapLines("END:" + c.Name.ToUpper()));
                return(sb.ToString());
            }
            return(null);
        }
Exemplo n.º 5
0
        static public ICalendarComponent LoadFromStream(TextReader textReader)
        {
            string text = textReader.ReadToEnd();

            textReader.Close();

            byte[]             memoryBlock   = Encoding.UTF8.GetBytes(text);
            MemoryStream       ms            = new MemoryStream(memoryBlock);
            ICalendarComponent iCalComponent = LoadFromStream(ms, Encoding.UTF8);

            ms.Dispose();
            return(iCalComponent);
        }
Exemplo n.º 6
0
        public static void CompareComponents(ICalendarComponent cb1, ICalendarComponent cb2)
        {
            foreach (var p1 in cb1.Properties)
            {
                var isMatch = false;
                foreach (var p2 in cb2.Properties.AllOf(p1.Name))
                {
                    try
                    {
                        Assert.AreEqual(p1, p2, "The properties '" + p1.Name + "' are not equal.");
                        if (p1.Value is IComparable)
                        {
                            if (((IComparable)p1.Value).CompareTo(p2.Value) != 0)
                            {
                                continue;
                            }
                        }
                        else if (p1.Value is IEnumerable)
                        {
                            CompareEnumerables((IEnumerable)p1.Value, (IEnumerable)p2.Value, p1.Name);
                        }
                        else
                        {
                            Assert.AreEqual(p1.Value, p2.Value, "The '" + p1.Name + "' property values are not equal.");
                        }

                        isMatch = true;
                        break;
                    }
                    catch { }
                }

                Assert.IsTrue(isMatch, "Could not find a matching property - " + p1.Name + ":" + (p1.Value?.ToString() ?? string.Empty));
            }

            Assert.AreEqual(cb1.Children.Count, cb2.Children.Count, "The number of children are not equal.");
            for (var i = 0; i < cb1.Children.Count; i++)
            {
                var child1 = cb1.Children[i] as ICalendarComponent;
                var child2 = cb2.Children[i] as ICalendarComponent;
                if (child1 != null && child2 != null)
                {
                    CompareComponents(child1, child2);
                }
                else
                {
                    Assert.AreEqual(child1, child2, "The child objects are not equal.");
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkbenchViewModel"/> class.
        /// </summary>
        /// <param name="host">The host.</param>
        public WorkbenchViewModel()
            : base()
        {
            PluginContext.Host.UserConnected += (sender, e) => this.component = PluginContext.ComponentFactory.GetInstance<ICalendarComponent>();

            this.DateToDisplay = DateTime.Today;
            this.DayAppointments = new AppointmentCollection();

            this.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == "DateToDisplay")
                    this.RefreshCalendar();
            };
        }
 /// <summary>
 ///     The filters have to be applied in an specific component, property
 ///     or param of a property. This method go deep in the calCOmponents following the
 ///     treeStructure of the filter till it get the component where to apply the filter.
 /// </summary>
 /// <param name="container">The container of the components.</param>
 /// <param name="treeStructure">The IXMLTree where is the filter.</param>
 /// <param name="filter">Return The XmlTreeStructure node that contains the filter.</param>
 /// <param name="component">The final component where to apply the filter.</param>
 /// <returns>True if found the component, false otherwise.</returns>
 public static bool ComponentSeeker(this ICalendarComponentsContainer container,
                                    IXMLTreeStructure treeStructure, out IXMLTreeStructure filter, out ICalendarComponent component)
 {
     filter    = null;
     component = null;
     while (true)
     {
         ICalendarComponent comp     = null;
         IXMLTreeStructure  compNode = null;
         treeStructure.GetChildAtAnyLevel("comp-filter", out compNode);
         if (compNode == null)
         {
             //if the filter doesn't has a child with comp-filter name
             //and the name of the current container is the same
             if (((ICalendarObject)container).Name == treeStructure.Attributes["name"])
             {
                 filter    = treeStructure;
                 component = container as ICalendarComponent;
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         var compName = compNode.Attributes["name"];
         //if the container doesn't has a calComponent with the desired compName
         //then return false
         if (!container.CalendarComponents.ContainsKey(compName))
         {
             return(false);
         }
         //take the comp with the desired name
         comp = container.CalendarComponents[compName].First();
         var componentsContainer = comp as ICalendarComponentsContainer;
         //if the the filter has more components and the container has more calendarComp
         //then go deeper
         if (componentsContainer != null && compNode.Children.Any(x => x.NodeName == "comp-filter"))
         {
             container     = componentsContainer;
             treeStructure = compNode;
             continue;
         }
         //if not then apply the filter in the comp
         component = comp;
         filter    = compNode;
         return(true);
     }
 }
Exemplo n.º 9
0
        public override void CopyFrom(ICopyable obj)
        {
            base.CopyFrom(obj);

            ICalendarComponent c = obj as ICalendarComponent;

            if (c != null)
            {
                Properties.Clear();
                foreach (ICalendarProperty p in c.Properties)
                {
                    Properties.Add(p.Copy <ICalendarProperty>());
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkbenchViewModel"/> class.
        /// </summary>
        /// <param name="host">The host.</param>
        public WorkbenchViewModel()
            : base()
        {
            PluginContext.Host.UserConnected += (sender, e) => this.component = PluginContext.ComponentFactory.GetInstance <ICalendarComponent>();

            this.DateToDisplay   = DateTime.Today;
            this.DayAppointments = new AppointmentCollection();

            this.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == "DateToDisplay")
                {
                    this.RefreshCalendar();
                }
            };
        }
Exemplo n.º 11
0
        private void WriteComponent(ICalendarComponent component, XmlWriter writer)
        {
            writer.WriteStartElement(component.Name.ToLowerInvariant(), xCalWriter.iCalendar20Namespace);

            if (component.Properties.Any())
            {
                writer.WriteStartElement("properties", xCalWriter.iCalendar20Namespace);
                foreach (var property in component.Properties)
                {
                    writer.WriteStartElement(property.Name.ToLowerInvariant(), xCalWriter.iCalendar20Namespace);
                    if (property.Parameters.Any())
                    {
                        writer.WriteStartElement("parameters", xCalWriter.iCalendar20Namespace);
                        foreach (var paramenter in property.Parameters.Where(p => p.Name != "VALUE"))
                        {
                            writer.WriteStartElement(paramenter.Name.ToLowerInvariant(), xCalWriter.iCalendar20Namespace);
                            WriteValue(paramenter.Value, writer);
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                    }

                    WriteValue(property.Value, writer);



                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }

            var childComponents = component.Children.OfType <ICalendarComponent>();

            if (childComponents.Any())
            {
                writer.WriteStartElement("components", xCalWriter.iCalendar20Namespace);
                foreach (var childComponent in component.Children.OfType <ICalendarComponent>())
                {
                    WriteComponent(childComponent, writer);
                }
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
Exemplo n.º 12
0
        public virtual ICalendarComponent Build(string objectName)
        {
            ICalendarComponent c = null;
            var name             = objectName.ToUpper();

            switch (name)
            {
            case Components.Alarm:
                c = new Alarm();
                break;

            case Components.Event:
                c = new CalendarEvent();
                break;

            case Components.Freebusy:
                c = new FreeBusy();
                break;

            case Components.Journal:
                c = new Journal();
                break;

            case Components.Timezone:
                c = new VTimeZone();
                break;

            case Components.Todo:
                c = new Todo();
                break;

            case Components.Calendar:
                c = new Calendar();
                break;

            default:
                c = new CalendarComponent();
                break;
            }
            c.Name = name;
            return(c);
        }
Exemplo n.º 13
0
        static public void CompareComponents(ICalendarComponent cb1, ICalendarComponent cb2)
        {
            foreach (ICalendarProperty p1 in cb1.Properties)
            {
                bool isMatch = false;
                foreach (ICalendarProperty p2 in cb2.Properties.AllOf(p1.Name))
                {
                    try
                    {
                        Assert.AreEqual(p1, p2, "The properties '" + p1.Name + "' are not equal.");
                        if (p1.Value is IComparable)
                            Assert.AreEqual(0, ((IComparable)p1.Value).CompareTo(p2.Value), "The '" + p1.Name + "' property values do not match.");
                        else if (p1.Value is IEnumerable)
                            CompareEnumerables((IEnumerable)p1.Value, (IEnumerable)p2.Value, p1.Name);
                        else
                            Assert.AreEqual(p1.Value, p2.Value, "The '" + p1.Name + "' property values are not equal.");

                        isMatch = true;
                        break;
                    }
                    catch { }
                }

                // If there was no match, and this is a collection property with no items,
                // then simply ignore it!
                if (!isMatch && p1.Value is ICollection && ((ICollection)p1.Value).Count == 0)
                    continue;
                Assert.IsTrue(isMatch, "Could not find a matching property.");                    
            }

            Assert.AreEqual(cb1.Children.Count, cb2.Children.Count, "The number of children are not equal.");
            for (int i = 0; i < cb1.Children.Count; i++)
            {
                ICalendarComponent child1 = cb1.Children[i] as ICalendarComponent;
                ICalendarComponent child2 = cb2.Children[i] as ICalendarComponent;
                if (child1 != null && child2 != null)
                    CompareComponents(child1, child2);
                else
                    Assert.AreEqual(child1, child2, "The child objects are not equal.");
            }
        }
        static public void CompareComponents(ICalendarComponent cb1, ICalendarComponent cb2)
        {
            foreach (ICalendarProperty p1 in cb1.Properties)
            {
                bool isMatch = false;
                foreach (ICalendarProperty p2 in cb2.Properties.AllOf(p1.Name))
                {
                    try
                    {
                        Assert.AreEqual(p1, p2, "The properties '" + p1.Name + "' are not equal.");
                        if (p1.Value is IComparable)
                            Assert.AreEqual(0, ((IComparable)p1.Value).CompareTo(p2.Value), "The '" + p1.Name + "' property values do not match.");
                        else if (p1.Value is IEnumerable)
                            CompareEnumerables((IEnumerable)p1.Value, (IEnumerable)p2.Value, p1.Name);
                        else
                            Assert.AreEqual(p1.Value, p2.Value, "The '" + p1.Name + "' property values are not equal.");

                        isMatch = true;
                        break;
                    }
                    catch { }
                }

                Assert.IsTrue(isMatch, "Could not find a matching property - " + p1.Name + ":" + (p1.Value != null ? p1.Value.ToString() : string.Empty));                    
            }

            Assert.AreEqual(cb1.Children.Count, cb2.Children.Count, "The number of children are not equal.");
            for (int i = 0; i < cb1.Children.Count; i++)
            {
                ICalendarComponent child1 = cb1.Children[i] as ICalendarComponent;
                ICalendarComponent child2 = cb2.Children[i] as ICalendarComponent;
                if (child1 != null && child2 != null)
                    CompareComponents(child1, child2);
                else
                    Assert.AreEqual(child1, child2, "The child objects are not equal.");
            }
        }
Exemplo n.º 15
0
        private static bool ApplyTimeFilterToVALARM(this ICalendarComponent component, DateTime start, DateTime end)
        {
            //TODO: send the container of the VALARM because the trigger
            // expands the DTSTART
            var trigger = ((Trigger)component.Properties["TRIGGER"]).Value;

            DateTime?triggerTime = null;

            //if the trigger define a trigger-time the use it to compare

            /* if (trigger.PropertyParameters.Any(x => x.Name == "VALUE"))
             *  trigger.PropertyParameters
             *      .FirstOrDefault(x => x.Name == "VALUE").Value.ToDateTime(out triggerTime);*/
            if (triggerTime == null)
            {
                return(false);
            }
            if (start <= triggerTime.Value && end > triggerTime.Value)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 16
0
        /// <summary>
        ///     Apply the time-filter to the VTODOs components.
        ///     A VTODO component overlaps a given time range if the condition for the
        ///     corresponding component state specified in the table (pg64 RFC 4791) is satisfied.
        /// </summary>
        /// <param name="component">The VTODO</param>
        /// <param name="start">The start time of the filter</param>
        /// <param name="end">The end datetime of the filter</param>
        /// <param name="expandedDates">The expaned dts by the RRULEs if any.</param>
        /// <returns>True if pass the filter, false otherwise.</returns>
        private static bool ApplyTimeFilterToVTODO(this ICalendarComponent component, DateTime start, DateTime end,
                                                   IEnumerable <DateTime> expandedDates)
        {
            var DURATION = component.GetComponentProperty("DURATION") == null
                ? null
                : ((IValue <DurationType>)component.GetComponentProperty("DURATION")).Value;
            var DUE = component.GetComponentProperty("DUE") == null
                ? null
                : ((IValue <Due>)component.GetComponentProperty("DUE")).Value;

            var COMPLETED = component.GetComponentProperty("COMPLETED") == null
                ? null
                : ((IValue <Completed>)component.GetComponentProperty("COMPLETED")).Value;

            var CREATED = component.GetComponentProperty("CREATED") == null
                ? null
                : ((IValue <Created>)component.GetComponentProperty("Created")).Value;


            //VTODO has the DTSTART property? Y
            if (expandedDates.Any())
            {
                foreach (var DTSTART in expandedDates)
                {
                    // VTODO has the DURATION property? Y
                    // VTODO has the DUE property? N
                    //  VTODO has the COMPLETED property? *
                    // VTODO has the CREATED property? *
                    if (DURATION != null && DUE == null)
                    {
                        var DTSTARTplusDURATION = DTSTART.AddDuration(DURATION);
                        if (start <= DTSTARTplusDURATION &&
                            (end > DTSTART || end > DTSTARTplusDURATION))
                        {
                            return(true);
                        }
                    }

                    // VTODO has the DURATION property? N
                    // VTODO has the DUE property? Y
                    //  VTODO has the COMPLETED property? *
                    // VTODO has the CREATED property? *
                    else if (DUE != null)
                    {
                        if ((start < DUE.Value || start <= DTSTART) &&
                            (end > DTSTART) || end >= DUE.Value)
                        {
                            return(true);
                        }
                    }

                    // VTODO has the DURATION property? N
                    // VTODO has the DUE property? N
                    //  VTODO has the COMPLETED property? *
                    // VTODO has the CREATED property? *
                    if (DUE == null && DURATION == null)
                    {
                        if (start <= DTSTART && end > DTSTART)
                        {
                            return(true);
                        }
                    }
                }
            }

            //VTODO has the DTSTART property? N
            else
            {
                // VTODO has the DURATION property? N
                // VTODO has the DUE property? Y
                //  VTODO has the COMPLETED property? *
                // VTODO has the CREATED property? *
                if (DUE != null && DURATION == null)
                {
                    if (start < DUE.Value && end >= DUE.Value)
                    {
                        return(true);
                    }
                }

                // VTODO has the DURATION property? N
                // VTODO has the DUE property? N
                //  VTODO has the COMPLETED property? Y
                // VTODO has the CREATED property? Y
                if (COMPLETED != null && CREATED != null)
                {
                    if ((start <= CREATED.Value || start <= COMPLETED.Value) &&
                        end >= CREATED.Value || end >= COMPLETED.Value)
                    {
                        return(true);
                    }
                }

                // VTODO has the DURATION property? N
                // VTODO has the DUE property? N
                //  VTODO has the COMPLETED property? Y
                // VTODO has the CREATED property? N
                else if (COMPLETED != null && CREATED == null)
                {
                    if (start <= COMPLETED.Value && end >= COMPLETED.Value)
                    {
                        return(true);
                    }
                }

                // VTODO has the DURATION property? N
                // VTODO has the DUE property? N
                //  VTODO has the COMPLETED property? N
                // VTODO has the CREATED property? Y
                else if (COMPLETED == null && CREATED != null)
                {
                    if (end > CREATED.Value)
                    {
                        return(true);
                    }
                }
            }
            // VTODO has the DURATION property? N
            // VTODO has the DUE property? N
            //  VTODO has the COMPLETED property? N
            // VTODO has the CREATED property? N
            return(true);
        }
Exemplo n.º 17
0
 public CalendarComponentCompositeList(ICalendarComponent component, string componentName)
 {
     m_Component     = component;
     m_ComponentName = componentName;
 }
Exemplo n.º 18
0
        /// <summary>
        ///     Apply the time-filter to the VEVENT components.
        ///     A VEVENT component overlaps a given time range if the condition for the
        ///     corresponding component state specified in the table (pg64 RFC 4791) is satisfied.
        /// </summary>
        /// <param name="component">THe VTODO</param>
        /// <param name="start">The start time of the filter</param>
        /// <param name="end">The end datetime of the filter</param>
        /// <param name="expandedDates">The expaned dts by the RRULEs if any.</param>
        /// <returns>True if pass the filter, false otherwise.</returns>
        private static bool ApplyTimeFilterToVEVENT(this ICalendarComponent component, DateTime start, DateTime end,
                                                    IEnumerable <DateTime> expandedDates)
        {
            var compEndTimeProp = component.GetComponentProperty("DTEND");

            foreach (var DTSTART in expandedDates)
            {
                //VEVENT has the DTEND property? Y
                // VEVENT has the DURATION property? N
                // DURATION property value is greater than 0 seconds? N
                // DTSTART property is a DATE-TIME value? *
                if (compEndTimeProp != null)
                {
                    var DTEND = ((IValue <DateTime>)compEndTimeProp).Value;
                    if (start < DTEND && end > DTSTART)
                    {
                        return(true);
                    }
                }

                var durationProp = component.GetComponentProperty("DURATION");

                //VEVENT has the DTEND property? N
                // VEVENT has the DURATION property? Y
                if (durationProp != null)
                {
                    var DURATION            = ((IValue <DurationType>)durationProp).Value;
                    var DTSTARTplusDURATION = DTSTART.AddDuration(DURATION);

                    // DURATION property value is greater than 0 seconds? Y
                    // DTSTART property is a DATE-TIME value? *
                    if (DURATION.IsPositive)
                    {
                        if (start < DTSTARTplusDURATION && end > DTSTART)
                        {
                            return(true);
                        }
                    }
                    // DURATION property value is greater than 0 seconds? N
                    // DTSTART property is a DATE-TIME value? *
                    else
                    {
                        if (start <= DTSTART && end > DTSTART)
                        {
                            return(true);
                        }
                    }
                }

                //VEVENT has the DTEND property? N
                // VEVENT has the DURATION property? N
                // DURATION property value is greater than 0 seconds? N
                // DTSTART property is a DATE-TIME value? Y
                if (start <= DTSTART && end > DTSTART)
                {
                    return(true);
                }

                //VEVENT has the DTEND property? N
                // VEVENT has the DURATION property? N
                // DURATION property value is greater than 0 seconds? N
                // DTSTART property is a DATE-TIME value? N
                if (start < DTSTART.AddDays(1) && end > DTSTART)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        /// <summary>
        ///     Apply the given filters to to a property in the cal component.
        /// </summary>
        /// <param name="component">The component where to apply the filters.</param>
        /// <param name="filter">Filters container.</param>
        /// <returns>True if the component pass the filters, false otherwise.</returns>
        private static bool PropertyFilter(this ICalendarComponent component, IXMLTreeStructure filter)
        {
            //take the property where to apply the filter.
            var propName = filter.Attributes["name"];

            //if the comp doesn't has the desired prop return false

            //iterate over the filters, if one is false then
            //returns false

            //this is gonna be use for the ATTENDEE and RRULE
            // properties
            foreach (var propFilter in filter.Children)
            {
                var result = false;
                IComponentProperty        propValue;
                List <IComponentProperty> propMultiValues;
                switch (propFilter.NodeName)
                {
                case "text-match":
                    //have to check this line in each of the cases because the
                    //"is not defined"
                    if (component.Properties.TryGetValue(propName, out propValue))
                    {
                        result = propValue.StringValue.TextMatchFilter(propFilter);
                    }
                    else if (component.MultipleValuesProperties.TryGetValue(propName, out propMultiValues))
                    {
                        result = propMultiValues.Any(x => x.StringValue.TextMatchFilter(propFilter));
                    }

                    if (!result)
                    {
                        return(false);
                    }
                    break;

                case "param-filter":
                    if (component.Properties.TryGetValue(propName, out propValue))
                    {
                        result = propValue.ParamFilter(propFilter);
                    }
                    else if (component.MultipleValuesProperties.TryGetValue(propName, out propMultiValues))
                    {
                        result = propMultiValues.Any(x => x.ParamFilter(propFilter));
                    }
                    if (!result)
                    {
                        return(false);
                    }
                    break;

                case "is-not-defined":
                    //if the component has a single prop with the given na,e
                    // return false
                    if (component.Properties.ContainsKey(propName))
                    {
                        return(false);
                    }
                    //else if contains a multiple property with the given name
                    // returns false
                    if (component.GetMultipleCompProperties(propName) != null)
                    {
                        return(false);
                    }
                    break;

                default:
                    throw new NotImplementedException(
                              $"THe property filter {propFilter.NodeName} is not implemented");
                }
            }
            return(true);
        }
Exemplo n.º 21
0
        /// <summary>
        ///     Apply the time filter to the given component as
        ///     defined in 9.9 CALDAV:time-range XML Element.
        /// </summary>
        /// <param name="component">The component where to apply the filter.</param>
        /// <param name="filter">The filter to apply.</param>
        /// <returns>True if the component pass the filter, false otherwise.</returns>
        private static bool ApplyTimeFilter(this ICalendarComponent component, IXMLTreeStructure filter)
        {
            DateTime?start;
            DateTime?end;

            //get the start and time attributes of the filter.
            if (filter.Attributes.ContainsKey("start"))
            {
                filter.Attributes["start"].ToDateTime(out start);
            }
            else //if not then assign infinite
            {
                start = DateTime.MinValue;
            }

            if (filter.Attributes.ContainsKey("end"))
            {
                filter.Attributes["end"].ToDateTime(out end);
            }
            else //if not then assign -infinite
            {
                end = DateTime.MaxValue;
            }

            //Get the DTSTART of the component.
            var compDTSTART = component.GetComponentProperty("DTSTART") == null
                ? DateTime.MaxValue
                : ((IValue <DateTime>)component.GetComponentProperty("DTSTART")).Value;

            //if the component contains RRULES then expand the dts
            IEnumerable <DateTime> expandedDates = null;

            if (component.MultipleValuesProperties.ContainsKey("RRULE"))
            {
                expandedDates = compDTSTART.ExpandTime(component.GetMultipleCompProperties("RRULE").Select(
                                                           x => ((IValue <Recur>)x).Value).ToList());
            }
            if (expandedDates == null)
            {
                expandedDates = new List <DateTime> {
                    compDTSTART
                }
            }
            ;

            if (component is VEvent)
            {
                return(component.ApplyTimeFilterToVEVENT(start.Value, end.Value, expandedDates));
            }
            if (component is VTodo)
            {
                return(component.ApplyTimeFilterToVTODO(start.Value, end.Value, expandedDates));
            }
            if (component is VJournal)
            {
                throw new NotImplementedException("The doesn't support the VJOURNALs yet.");
            }
            if (component is VFreebusy)
            {
                return(component.ApplyTimeFilterToVFREEBUSY(start.Value, end.Value));
            }
            if (component is VAlarm)
            {
                return(component.ApplyTimeFilterToVALARM(start.Value, end.Value));
            }
            return(false);
        }