Example #1
0
 public override string SerializeToString()
 {
     if (m_Binary.Uri != null)
     {
         ISerializable serializer = SerializerFactory.Create(m_Binary.Uri);
         return(serializer.SerializeToString());
     }
     else
     {
         return(Convert.ToBase64String(m_Binary.Data));
     }
 }
Example #2
0
        public override string SerializeToString()
        {
            string value = string.Empty;

            ISerializable serializer = SerializerFactory.Create(m_Period.StartTime);

            if (serializer != null)
            {
                value += serializer.SerializeToString();
            }

            value += "/";

            serializer = SerializerFactory.Create(m_Period.Duration);
            if (serializer != null)
            {
                value += serializer.SerializeToString();
            }

            return(value);
        }
Example #3
0
 public override string SerializeToString()
 {
     if (m_Binary.Uri != null)
     {
         ISerializable serializer = SerializerFactory.Create(m_Binary.Uri);
         return(serializer.SerializeToString());
     }
     else
     {
         UTF8Encoding encoding = new UTF8Encoding();
         return(Encode(encoding.GetString(m_Binary.Data)));
     }
 }
Example #4
0
        public override string SerializeToString()
        {
            List <string> values = new List <string>();

            foreach (object obj in m_RDate.Items)
            {
                ISerializable serializer = SerializerFactory.Create(obj);
                if (serializer != null)
                {
                    values.Add(serializer.SerializeToString());
                }
            }

            return(string.Join(",", values.ToArray()));
        }
Example #5
0
 public override string SerializeToString()
 {
     if (m_Binary.Uri != null)
     {
         ISerializable serializer = SerializerFactory.Create(m_Binary.Uri);
         return(serializer.SerializeToString());
     }
     else
     {
         // NOTE: fixed a bug pointed out by Tony Dubey that caused binary data
         // to be converted to a UTF8 string before being serialized into
         // a BASE64 char array (which caused data loss).
         return(Encode(m_Binary.Data));
     }
 }
Example #6
0
        public override void Serialize(Stream stream, Encoding encoding)
        {
            // Open the component
            byte[] open = encoding.GetBytes("BEGIN:" + m_component.Name + "\r\n");
            stream.Write(open, 0, open.Length);

            // Get a list of fields
            List <FieldInfo> fields = new List <FieldInfo>(m_component.GetType().GetFields());

            // Alphabetize the list of fields we just obtained
            fields.Sort(new FieldAlphabetizer());

            // Iterate through each field and attempt to serialize it
            foreach (FieldInfo field in fields)
            {
                // Make sure the field isn't marked as "NotSerialized"
                if (field.GetCustomAttributes(typeof(NotSerialized), true).Length == 0)
                {
                    object obj = field.GetValue(m_component);
                    if (obj is iCalObject)
                    {
                        iCalObject ico = (iCalObject)obj;
                        if (ico.Name == null)
                        {
                            ico.Name = field.Name.ToUpper().Replace("_", "-");
                        }
                    }

                    // Create a serializer for the object
                    ISerializable serializer = SerializerFactory.Create(obj);

                    // Check to see if the property matches its default value.
                    // If so, we don't even need to serialize it, as it is
                    // already at its default value.
                    object   defaultValue = null;
                    object[] dvAttrs      = field.GetCustomAttributes(typeof(DefaultValueAttribute), true);
                    if (dvAttrs.Length > 0)
                    {
                        defaultValue = ((DefaultValueAttribute)dvAttrs[0]).Value;
                    }

                    // To continue, the default value must either not be set,
                    // or it must not match the actual value of the item.
                    if (defaultValue == null ||
                        (serializer != null && !serializer.SerializeToString().Equals(defaultValue.ToString() + "\r\n")))
                    {
                        // FIXME: enum values cannot name themselves; we need to do it for them.
                        // For this to happen, we probably need to wrap enum values into a
                        // class that inherits from iCalObject.
                        if (field.FieldType.IsEnum)
                        {
                            byte[] data = encoding.GetBytes(field.Name.ToUpper().Replace("_", "-") + ":");
                            stream.Write(data, 0, data.Length);
                        }

                        // Actually serialize the object
                        if (serializer != null)
                        {
                            serializer.Serialize(stream, encoding);
                        }
                    }
                }
            }

            // If any extra serialization is necessary, do it now
            base.Serialize(stream, encoding);

            // Close the component
            byte[] close = encoding.GetBytes("END:" + m_component.Name + "\r\n");
            stream.Write(close, 0, close.Length);
        }
        public override void Serialize(Stream stream, Encoding encoding)
        {
            // Open the component
            byte[] open = encoding.GetBytes("BEGIN:" + Component.Name + "\r\n");
            stream.Write(open, 0, open.Length);

            // Get a list of fields and properties
            List <object> items = this.FieldsAndProperties;

            // Alphabetize the list of fields & properties we just obtained
            items.Sort(new FieldPropertyAlphabetizer());

            // Iterate through each item and attempt to serialize it
            foreach (object item in items)
            {
                FieldInfo    field     = null;
                PropertyInfo prop      = null;
                Type         itemType  = null;
                string       itemName  = null;
                object[]     itemAttrs = null;

                if (item is FieldInfo)
                {
                    field    = (FieldInfo)item;
                    itemType = field.FieldType;
                    itemName = field.Name;
                }
                else
                {
                    prop     = (PropertyInfo)item;
                    itemType = prop.PropertyType;
                    itemName = prop.Name;
                }

                // Get attributes that are attached to each item
                itemAttrs = (field != null) ? field.GetCustomAttributes(true) : prop.GetCustomAttributes(true);

                // Get the item's value
                object obj = (field == null) ? prop.GetValue(Component, null) : field.GetValue(Component);

                // Adjust the items' name to be iCal-compliant
                if (obj is iCalObject)
                {
                    iCalObject ico = (iCalObject)obj;
                    if (ico.Name == null)
                    {
                        ico.Name = itemName.ToUpper().Replace("_", "-");
                    }

                    // If the property is non-standard, then replace
                    // it with an X-name
                    if (!ico.Name.StartsWith("X-"))
                    {
                        foreach (object attr in itemAttrs)
                        {
                            if (attr is NonstandardAttribute)
                            {
                                ico.Name = "X-" + ico.Name;
                                break;
                            }
                        }
                    }
                }

                // Retrieve custom attributes for this field/property
                if (obj is iCalDataType)
                {
                    ((iCalDataType)obj).Attributes = itemAttrs;
                }

                // Get the default value of the object, if available
                object defaultValue = null;
                foreach (Attribute a in itemAttrs)
                {
                    if (a is DefaultValueAttribute)
                    {
                        defaultValue = ((DefaultValueAttribute)a).Value;
                    }
                }

                // Create a serializer for the object
                ISerializable serializer = SerializerFactory.Create(obj);

                // To continue, the default value must either not be set,
                // or it must not match the actual value of the item.
                if (defaultValue == null ||
                    (serializer != null && !serializer.SerializeToString().Equals(defaultValue.ToString())))
                {
                    // FIXME: enum values cannot name themselves; we need to do it for them.
                    // For this to happen, we probably need to wrap enum values into a
                    // class that inherits from iCalObject.
                    if (itemType.IsEnum)
                    {
                        byte[] data = encoding.GetBytes(itemName.ToUpper().Replace("_", "-") + ":");
                        stream.Write(data, 0, data.Length);
                    }

                    // Actually serialize the object
                    if (serializer != null)
                    {
                        serializer.Serialize(stream, encoding);
                    }
                }
            }

            // If any extra serialization is necessary, do it now
            base.Serialize(stream, encoding);

            // Close the component
            byte[] close = encoding.GetBytes("END:" + Component.Name + "\r\n");
            stream.Write(close, 0, close.Length);
        }