예제 #1
0
 public Property(ContentLine cl) : base(cl.Parent)
 {
     this.Name = cl.Name;
     this.Value = cl.Value;
     foreach (DictionaryEntry de in cl.Parameters)
         this.Parameters[de.Key] = de.Value;
 }
예제 #2
0
 public Property(ContentLine cl) : base(cl.Parent)
 {
     this.Name  = cl.Name;
     this.Value = cl.Value;
     foreach (DictionaryEntry de in cl.Parameters)
     {
         this.Parameters[de.Key] = de.Value;
     }
 }
예제 #3
0
 public Property(ContentLine cl) : base(cl.Parent)
 {
     this.Name  = cl.Name;
     this.Value = cl.Value;
     foreach (Parameter p in cl.Parameters)
     {
         AddParameter(p);
     }
 }
예제 #4
0
        public override void SetContentLineValue(ContentLine cl)
        {
            base.SetContentLineValue(cl);

            if (cl.Name == "UID")
            {
                Text text = new Text();
                text.ContentLine = cl;
                UID = text.Value;
            }
        }
예제 #5
0
        /// <summary>
        /// For iCalendar components, automatically finds and retrieves fields that
        /// match the field specified in the <see cref="ContentLine"/>, and sets
        /// their value.
        /// <example>
        /// For example, if a public DTStart field exists in the specified component,
        /// (i.e. <c>public Date_Time DTStart;</c>)
        /// and a content line of <c>DTSTART;TZID=US-Eastern:20060830T090000</c> is
        /// encountered, this method will automatically set the value of the
        /// DTStart field to Aug. 30, 2006, 9:00 AM in the US-Eastern TimeZone.
        /// </example>
        /// <note>
        ///     It should not be necessary to invoke this method manually as it
        ///     is handled automatically during the iCalendar parsing.
        /// </note>
        /// </summary>
        /// <param name="cl">The <see cref="ContentLine"/> to process.</param>
        virtual public void SetContentLineValue(ContentLine cl)
        {
            if (cl.Name != null)
            {
                string name = cl.Name;
                Type   type = GetType();

                // Remove X- from the property name, since
                // non-standard properties are named like
                // everything else, but also have the NonstandardAttribute
                // attached.
                if (name.StartsWith("X-"))
                {
                    name = name.Remove(0, 2);
                }

                // Replace invalid characters
                name = name.Replace("-", "_");

                //
                // Find the public field that matches the name of our content line (ignoring case)
                //
                FieldInfo    field    = type.GetField(name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Static);
                PropertyInfo property = null;

                if (field == null)
                {
                    property = type.GetProperty(name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Static);
                }

                if (field != null ||
                    property != null)
                {
                    // Get the field/property's value
                    object value = field == null?property.GetValue(this, null) : field.GetValue(this);

                    Type     itemType       = field == null ? property.PropertyType : field.FieldType;
                    object[] itemAttributes = field == null?property.GetCustomAttributes(true) : field.GetCustomAttributes(true);

                    Type elementType = itemType.IsArray ? itemType.GetElementType() : itemType;

                    // If it's an iCalDataType, or an array of iCalDataType, then let's fill it!
                    if (itemType.IsSubclassOf(typeof(iCalDataType)) ||
                        (itemType.IsArray && itemType.GetElementType().IsSubclassOf(typeof(iCalDataType))))
                    {
                        iCalDataType icdt = null;
                        if (!itemType.IsArray)
                        {
                            icdt = (iCalDataType)value;
                        }
                        if (icdt == null)
                        {
                            icdt = (iCalDataType)Activator.CreateInstance(elementType);
                        }

                        // Assign custom attributes for the specific field
                        icdt.Attributes = itemAttributes;

                        // Set the content line for the object.  On most objects, this
                        // triggers the object to parse the content line with Parse().
                        icdt.ContentLine = cl;

                        // It's an array, let's add an item to the end
                        if (itemType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                            {
                                arr.AddRange((ICollection)value);
                            }
                            arr.Add(icdt);
                            if (field != null)
                            {
                                field.SetValue(this, arr.ToArray(elementType));
                            }
                            else
                            {
                                property.SetValue(this, arr.ToArray(elementType), null);
                            }
                        }
                        // Otherwise, set the value directly!
                        else
                        {
                            if (field != null)
                            {
                                field.SetValue(this, icdt);
                            }
                            else
                            {
                                property.SetValue(this, icdt, null);
                            }
                        }
                    }
                    else
                    {
                        FieldInfo minValue = itemType.GetField("MinValue");
                        object    minVal   = (minValue != null) ? minValue.GetValue(null) : null;

                        if (itemType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                            {
                                arr.AddRange((ICollection)value);
                            }
                            arr.Add(cl.Value);

                            if (field != null)
                            {
                                field.SetValue(this, arr.ToArray(elementType));
                            }
                            else
                            {
                                property.SetValue(this, arr.ToArray(elementType), null);
                            }
                        }
                        // Always assign enum values
                        else if (itemType.IsEnum)
                        {
                            if (field != null)
                            {
                                field.SetValue(this, Enum.Parse(itemType, cl.Value.Replace("-", "_")));
                            }
                            else
                            {
                                property.SetValue(this, Enum.Parse(itemType, cl.Value.Replace("-", "_")), null);
                            }
                        }
                        // Otherwise, set the value directly!
                        else if (value == null || value.Equals(minVal))
                        {
                            if (field != null)
                            {
                                field.SetValue(this, cl.Value);
                            }
                            else
                            {
                                property.SetValue(this, cl.Value, null);
                            }
                        }
                        else
                        {
                            ; // FIXME: throw single-value exception, if "strict" parsing is enabled
                        }
                    }
                }
                else
                {
                    // This is a non-standard property.  Let's load it into memory,
                    // So we can serialize it later
                    Property p = new Property(cl);
                    p.AddToParent();
                }
            }
        }
예제 #6
0
	public void contentline(
		iCalObject o
	) //throws RecognitionException, TokenStreamException
{
		
		
		ContentLine c = new ContentLine(o);
		string n;
		string v;
		
		
		n=name();
		c.Name = n;
		{    // ( ... )*
			for (;;)
			{
				if ((LA(1)==SEMICOLON))
				{
					match(SEMICOLON);
					{
						switch ( LA(1) )
						{
						case IANA_TOKEN:
						{
							param(c);
							break;
						}
						case X_NAME:
						{
							xparam(c);
							break;
						}
						default:
						{
							throw new NoViableAltException(LT(1), getFilename());
						}
						 }
					}
				}
				else
				{
					goto _loop50_breakloop;
				}
				
			}
_loop50_breakloop:			;
		}    // ( ... )*
		match(COLON);
		v=value();
		c.Value = v; DDay.iCal.Serialization.iCalendar.Components.ContentLineSerializer.DeserializeToObject(c, o);
		match(CRLF);
	}
예제 #7
0
        /// <summary>
        /// For iCalendar components, automatically finds and retrieves fields that
        /// match the field specified in the <see cref="ContentLine"/>, and sets
        /// their value.
        /// <example>
        /// For example, if a public DTStart field exists in the specified component,
        /// (i.e. <c>public Date_Time DTStart;</c>)
        /// and a content line of <c>DTSTART;TZID=US-Eastern:20060830T090000</c> is
        /// encountered, this method will automatically set the value of the
        /// DTStart field to Aug. 30, 2006, 9:00 AM in the US-Eastern TimeZone.
        /// </example>
        /// <note>
        ///     It should not be necessary to invoke this method manually as it
        ///     is handled automatically during the iCalendar parsing.
        /// </note>
        /// </summary>
        /// <param name="cl">The <see cref="ContentLine"/> to process.</param>
        /// <param name="obj">The <see cref="iCalObject"/> to assign information to.</param>
        static public void DeserializeToObject(ContentLine cl, iCalObject obj)
        {
            if (cl.Name != null)
            {
                string name = cl.Name;
                Type type = obj.GetType();

                // Remove X- from the property name, since
                // non-standard properties are named like
                // everything else, but also have the NonstandardAttribute
                // attached.
                if (name.StartsWith("X-"))
                    name = name.Remove(0, 2);

                // Replace invalid characters
                name = name.Replace("-", "_");

                //
                // Find the public field that matches the name of our content line (ignoring case)
                //
                FieldInfo field = type.GetField(name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Static);
                PropertyInfo property = null;

                if (field == null)
                    property = type.GetProperty(name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Static);

                if (field != null ||
                    property != null)
                {
                    // Get the field/property's value
                    object value = field == null ? property.GetValue(obj, null) : field.GetValue(obj);
                    Type itemType = field == null ? property.PropertyType : field.FieldType;
                    object[] itemAttributes = field == null ? property.GetCustomAttributes(true) : field.GetCustomAttributes(true);

                    Type elementType = itemType.IsArray ? itemType.GetElementType() : itemType;

                    // If it's an iCalDataType, or an array of iCalDataType, then let's fill it!
                    if (itemType.IsSubclassOf(typeof(iCalDataType)) ||
                        (itemType.IsArray && itemType.GetElementType().IsSubclassOf(typeof(iCalDataType))))
                    {
                        iCalDataType icdt = null;
                        if (!itemType.IsArray)
                            icdt = (iCalDataType)value;
                        if (icdt == null)
                            icdt = (iCalDataType)Activator.CreateInstance(elementType);

                        // Assign custom attributes for the specific field
                        icdt.Attributes = itemAttributes;

                        // Set the content line for the object.                        
                        icdt.ContentLine = cl;

                        // It's an array, let's add an item to the end
                        if (itemType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                                arr.AddRange((ICollection)value);
                            arr.Add(icdt);
                            if (field != null)
                                field.SetValue(obj, arr.ToArray(elementType));
                            else
                                property.SetValue(obj, arr.ToArray(elementType), null);
                        }
                        // Otherwise, set the value directly!
                        else
                        {
                            if (field != null)
                                field.SetValue(obj, icdt);
                            else property.SetValue(obj, icdt, null);
                        }
                    }
                    else
                    {
                        FieldInfo minValue = itemType.GetField("MinValue");
                        object minVal = (minValue != null) ? minValue.GetValue(null) : null;

                        if (itemType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                                arr.AddRange((ICollection)value);
                            arr.Add(cl.Value);

                            if (field != null)
                                field.SetValue(obj, arr.ToArray(elementType));
                            else property.SetValue(obj, arr.ToArray(elementType), null);
                        }
                        // Always assign enum values
                        else if (itemType.IsEnum)
                        {
                            if (field != null)
                                field.SetValue(obj, Enum.Parse(itemType, cl.Value.Replace("-", "_")));
                            else property.SetValue(obj, Enum.Parse(itemType, cl.Value.Replace("-", "_")), null);
                        }
                        // Otherwise, set the value directly!
                        else if (value == null || value.Equals(minVal))
                        {
                            if (field != null)
                                field.SetValue(obj, cl.Value);
                            else property.SetValue(obj, cl.Value, null);
                        }
                        else ;// FIXME: throw single-value exception, if "strict" parsing is enabled
                    }
                }
                else
                {
                    // This is a non-standard property.  Let's load it into memory,
                    // So we can serialize it later
                    Property p = new Property(cl);
                    p.AddToParent();
                }
            }
        }
예제 #8
0
        public override void SetContentLineValue(ContentLine cl)
        {
            base.SetContentLineValue(cl);

            if (cl.Name == "UID")
            {
                Text text = new Text();
                text.ContentLine = cl;
                UID = text.Value;
            }
        }
예제 #9
0
	public void contentline(
		iCalObject o
	) //throws RecognitionException, TokenStreamException
{
		
		
		ContentLine c = new ContentLine(o);
		string n;
		string v;
		
		
		try {      // for error handling
			n=name();
			c.Name = n;
			{    // ( ... )*
				for (;;)
				{
					if ((LA(1)==SEMICOLON))
					{
						match(SEMICOLON);
						param(c);
					}
					else
					{
						goto _loop41_breakloop;
					}
					
				}
_loop41_breakloop:				;
			}    // ( ... )*
			match(COLON);
			v=value();
			c.Value = v; o.SetContentLineValue(c);
			match(CRLF);
		}
		catch (RecognitionException ex)
		{
			reportError(ex);
			recover(ex,tokenSet_4_);
		}
	}
예제 #10
0
	public void contentline(
		iCalObject o
	) //throws RecognitionException, TokenStreamException
{
		
		
		ContentLine c = new ContentLine(o);
		string n;
		string v;
		
		
		n=name();
		c.Name = n;
		{    // ( ... )*
			for (;;)
			{
				if ((LA(1)==SEMICOLON))
				{
					match(SEMICOLON);
					param(c);
				}
				else
				{
					goto _loop41_breakloop;
				}
				
			}
_loop41_breakloop:			;
		}    // ( ... )*
		match(COLON);
		v=value();
		c.Value = v; DDay.iCal.Serialization.iCalendar.Components.ContentLineSerializer.DeserializeToObject(c, o);
		match(CRLF);
	}