示例#1
0
        /// <summary>
        ///     Deserializes the specified tr.
        /// </summary>
        /// <param name="tr">The tr.</param>
        /// <returns></returns>
        public override object Deserialize(TextReader tr)
        {
            string value = tr.ReadToEnd( );

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

                // Remove "-" characters while parsing Enumeration values.
                return(Enum.Parse(_enumType, value.Replace("-", ""), true));
            }
// ReSharper disable EmptyGeneralCatchClause
            catch
// ReSharper restore EmptyGeneralCatchClause
            {
            }

            return(value);
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        ///     Deserializes the specified tr.
        /// </summary>
        /// <param name="tr">The tr.</param>
        /// <returns></returns>
        public override object Deserialize(TextReader tr)
        {
            string value = tr.ReadToEnd( );

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

                int i;
                if (Int32.TryParse(value, out i))
                {
                    return(i);
                }
            }
// ReSharper disable EmptyGeneralCatchClause
            catch
// ReSharper restore EmptyGeneralCatchClause
            {
            }

            return(value);
        }
示例#4
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)
        {
            if (tr != null)
            {
                var value = tr.ReadToEnd();

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

                try
                {
                    var 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);
        }
示例#7
0
        /// <summary>
        ///     Deserializes the specified tr.
        /// </summary>
        /// <param name="tr">The tr.</param>
        /// <returns></returns>
        public override object Deserialize(TextReader tr)
        {
            if (tr != null)
            {
                string value = tr.ReadToEnd( );

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

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

                try
                {
                    var uri = new Uri(value);
                    return(uri);
                }
// ReSharper disable EmptyGeneralCatchClause
                catch
// ReSharper restore EmptyGeneralCatchClause
                {
                }
            }
            return(null);
        }
示例#8
0
        public override object Deserialize(TextReader tr)
        {
            if (tr == null)
            {
                return(null);
            }

            var value = tr.ReadToEnd();

            // NOTE: this can deserialize into an IList<string> or simply a string,
            // depending on the input text.  Anything that uses this serializer should
            // be prepared to receive either a string, or an IList<string>.

            var serializeAsList = false;

            // Determine if we can serialize this property
            // with multiple values per line.
            var co = SerializationContext.Peek() as ICalendarObject;

            if (co is ICalendarProperty)
            {
                serializeAsList = GetService <IDataTypeMapper>().GetPropertyAllowsMultipleValues(co);
            }

            // Try to decode the string
            EncodableDataType dt = null;

            if (co != null)
            {
                dt = new EncodableDataType
                {
                    AssociatedObject = co
                };
            }

            var encodedValues = serializeAsList ? UnescapedCommas.Split(value) : new[] { value };
            var escapedValues = Array.ConvertAll(encodedValues, v => Decode(dt, v));
            var values        = Array.ConvertAll(escapedValues, v => Unescape(v));

            if (co is ICalendarProperty)
            {
                // Determine if our we're supposed to store extra information during
                // the serialization process.  If so, let's store the escaped value.
                var settings = GetService <ISerializationSettings>();
                if (settings != null && settings.StoreExtraSerializationData)
                {
                    // Store the escaped value
                    co.SetService("EscapedValue", escapedValues.Length == 1 ? escapedValues[0] : (object)escapedValues);
                }
            }

            // Return either a single value, or the entire list.
            if (values.Length == 1)
            {
                return(values[0]);
            }
            return(values);
        }
示例#9
0
        /// <summary>
        ///     Serializes to string.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        public override string SerializeToString(object obj)
        {
            if (obj != null)
            {
                GetService <ISerializationSettings>( );

                var values = new List <string>( );

                var item = obj as string;

                if (item != null)
                {
                    // Object to be serialized is a string already
                    values.Add(item);
                }
                else
                {
                    var children = obj as IEnumerable;

                    if (children != null)
                    {
                        // Object is a list of objects (probably IList<string>).
                        values.AddRange(from object child in children
                                        select child.ToString( ));
                    }
                    else
                    {
                        // Serialize the object as a string.
                        values.Add(obj.ToString( ));
                    }
                }

                var co = SerializationContext.Peek( ) as ICalendarObject;
                if (co != null)
                {
                    // Encode the string as needed.
                    var dt = new EncodableDataType
                    {
                        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);
        }
示例#10
0
        public override object Deserialize(TextReader tr)
        {
            if (tr == null)
            {
                return(null);
            }

            var value = tr.ReadToEnd();

            // NOTE: this can deserialize into an IList<string> or simply a string,
            // depending on the input text.  Anything that uses this serializer should
            // be prepared to receive either a string, or an IList<string>.

            var serializeAsList = false;

            // Determine if we can serialize this property
            // with multiple values per line.
            var co = SerializationContext.Peek() as ICalendarObject;

            if (co is ICalendarProperty)
            {
                serializeAsList = GetService <DataTypeMapper>().GetPropertyAllowsMultipleValues(co);
            }

            // Try to decode the string
            EncodableDataType dt = null;

            if (co != null)
            {
                dt = new EncodableDataType
                {
                    AssociatedObject = co
                };
            }

            var encodedValues = serializeAsList ? UnescapedCommas.Split(value) : new[] { value };
            var escapedValues = encodedValues.Select(v => Decode(dt, v)).ToList();
            var values        = escapedValues.Select(Unescape).ToList();

            if (co is ICalendarProperty)
            {
                // Is this necessary?
                co.SetService("EscapedValue", escapedValues.Count == 1 ? escapedValues[0] : (object)escapedValues);
            }

            // Return either a single value, or the entire list.
            if (values.Count == 1)
            {
                return(values[0]);
            }
            return(values);
        }
        protected override IValidationResultCollection ValidateProperty(ICalendarProperty p)
        {
            ValidationResultCollection result = new ValidationResultCollection(ResourceManager);
            if (p != null)
            {
                result.Passed = true;

                // Get the escaped value for this property.
                // This is stored during deserialization when
                // SerializationSettings.StoreExtraSerializationData is true.
                object escapedValue = p.GetService("EscapedValue");

                List<string> values = new List<string>();
                if (escapedValue is string)
                    values.Add((string)escapedValue);
                else if (escapedValue is IList<string>)
                    values.AddRange((IList<string>)escapedValue);

                // Validate the encoding
                EncodableDataType dt = new EncodableDataType();
                dt.AssociatedObject = p;
                EncodableDataTypeValidation validation = new EncodableDataTypeValidation(ResourceManager, dt);
                result.Add(validation.Validate());

                foreach (string value in values)
                {
                    // Find single commas
                    if (Regex.IsMatch(value, @"(?<!\\),"))
                    {
                        Error(result, "textEscapeCommasError", p.Line, p.Column, p.Name);
                    }

                    // Find single semicolons
                    if (Regex.IsMatch(value, @"(?<!\\);"))
                    {
                        Error(result, "textEscapeSemicolonsError", p.Line, p.Column, p.Name);
                    }

                    // Find backslashes that are not escaped
                    if (Regex.IsMatch(value, @"\\([^\\nN;,])"))
                    {
                        Error(result, "textEscapeBackslashesError", p.Line, p.Column, p.Name);
                    }
                }
            }

            return result;
        }
示例#12
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);
        }
示例#13
0
        public override string SerializeToString(object obj)
        {
            if (obj is Uri)
            {
                Uri uri = (Uri)obj;

                ICalendarObject co = SerializationContext.Peek() as ICalendarObject;
                if (co != null)
                {
                    EncodableDataType dt = new EncodableDataType();
                    dt.AssociatedObject = co;
                    return(Encode(dt, uri.OriginalString));
                }
                return(uri.OriginalString);
            }
            return(null);
        }
示例#14
0
        public override string SerializeToString(object obj)
        {
            if (obj is Uri)
            {
                Uri uri = (Uri)obj;

                ICalendarObject co = SerializationContext.Peek() as ICalendarObject;
                if (co != null)
                {
                    EncodableDataType dt = new EncodableDataType();
                    dt.AssociatedObject = co;
                    return Encode(dt, uri.OriginalString);
                }
                return uri.OriginalString;
            }
            return null;
        }
示例#15
0
        public override string SerializeToString(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var values = new List <string>(128);

            if (obj is string)
            {
                values.Add((string)obj);
            }
            else if (obj is IEnumerable)
            {
                values.AddRange(from object child in (IEnumerable)obj select child.ToString());
            }
            else
            {
                values.Add(obj.ToString());
            }

            var co = SerializationContext.Peek() as ICalendarObject;

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

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

            for (var i = 0; i < values.Count; i++)
            {
                values[i] = Escape(values[i]);
            }
            return(string.Join(",", values));
        }
示例#16
0
        public override string SerializeToString(object obj)
        {
            if (!(obj is Uri))
            {
                return(null);
            }

            var uri = (Uri)obj;

            if (SerializationContext.Peek() is ICalendarObject co)
            {
                var dt = new EncodableDataType
                {
                    AssociatedObject = co
                };
                return(Encode(dt, uri.OriginalString));
            }
            return(uri.OriginalString);
        }
示例#17
0
 public override string SerializeToString(object enumValue)
 {
     try
     {
         ICalendarObject obj = SerializationContext.Peek() as ICalendarObject;
         if (obj != null)
         {
             // Encode the value as needed.
             EncodableDataType dt = new EncodableDataType();
             dt.AssociatedObject = obj;
             return(Encode(dt, enumValue.ToString()));
         }
         return(enumValue.ToString());
     }
     catch
     {
         return(null);
     }
 }
示例#18
0
 public override string SerializeToString(object enumValue)
 {
     try
     {
         ICalendarObject obj = SerializationContext.Peek() as ICalendarObject;
         if (obj != null)
         {
             // Encode the value as needed.
             EncodableDataType dt = new EncodableDataType();
             dt.AssociatedObject = obj;
             return Encode(dt, enumValue.ToString());
         }
         return enumValue.ToString();
     }
     catch
     {
         return null;
     }
 }
示例#19
0
        /// <summary>
        ///     Serializes to string.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        public override string SerializeToString(object obj)
        {
            var uri1 = obj as Uri;

            if (uri1 != null)
            {
                Uri uri = uri1;

                var co = SerializationContext.Peek( ) as ICalendarObject;
                if (co != null)
                {
                    var dt = new EncodableDataType
                    {
                        AssociatedObject = co
                    };
                    return(Encode(dt, uri.OriginalString));
                }
                return(uri.OriginalString);
            }
            return(null);
        }
示例#20
0
        public override string SerializeToString(object integer)
        {
            try
            {
                int i = Convert.ToInt32(integer);

                ICalendarObject obj = SerializationContext.Peek() as ICalendarObject;
                if (obj != null)
                {
                    // Encode the value as needed.
                    EncodableDataType dt = new EncodableDataType();
                    dt.AssociatedObject = obj;
                    return(Encode(dt, i.ToString()));
                }
                return(i.ToString());
            }
            catch
            {
                return(null);
            }
        }
示例#21
0
        public override string SerializeToString(object integer)
        {
            try
            {
                int i = Convert.ToInt32(integer);

                ICalendarObject obj = SerializationContext.Peek() as ICalendarObject;
                if (obj != null)
                {
                    // Encode the value as needed.
                    EncodableDataType dt = new EncodableDataType();
                    dt.AssociatedObject = obj;
                    return Encode(dt, i.ToString());
                }
                return i.ToString();
            }
            catch
            {
                return null;
            }
        }
示例#22
0
        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);
                }

                // Remove "-" characters while parsing Enum values.
                return(Enum.Parse(m_EnumType, value.Replace("-", ""), true));
            }
            catch { }

            return(value);
        }
示例#23
0
        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);
                }

                // Remove "-" characters while parsing Enum values.
                return Enum.Parse(m_EnumType, value.Replace("-", ""), true);
            }
            catch { }

            return value;
        }
示例#24
0
        /// <summary>
        ///     Serializes to string.
        /// </summary>
        /// <param name="integer">The integer.</param>
        /// <returns></returns>
        public override string SerializeToString(object integer)
        {
            try
            {
                int i = Convert.ToInt32(integer);

                var obj = SerializationContext.Peek( ) as ICalendarObject;
                if (obj != null)
                {
                    // Encode the value as needed.
                    var dt = new EncodableDataType
                    {
                        AssociatedObject = obj
                    };
                    return(Encode(dt, i.ToString(CultureInfo.InvariantCulture)));
                }
                return(i.ToString(CultureInfo.InvariantCulture));
            }
            catch
            {
                return(null);
            }
        }
示例#25
0
        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;
        }
 public EncodableDataTypeValidation(IResourceManager mgr, EncodableDataType obj)
     : base(mgr)
 {
     Object = obj;
 }
示例#27
0
        public override object Deserialize(TextReader tr)
        {
            if (tr != null)
            {
                string value = tr.ReadToEnd();

                // NOTE: this can deserialize into an IList<string> or simply a string,
                // depending on the input text.  Anything that uses this serializer should
                // be prepared to receive either a string, or an IList<string>.

                bool serializeAsList = false;

                // Determine if we can serialize this property
                // with multiple values per line.
                ICalendarObject co = SerializationContext.Peek() as ICalendarObject;
                if (co is ICalendarProperty)
                {
                    serializeAsList = GetService <IDataTypeMapper>().GetPropertyAllowsMultipleValues(co);
                }

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

                // Try to decode the string
                EncodableDataType dt = null;
                if (co != null)
                {
                    dt = new EncodableDataType();
                    dt.AssociatedObject = co;
                }

                List <string> escapedValues = new List <string>();
                List <string> values        = new List <string>();

                int i = 0;
                if (serializeAsList)
                {
                    MatchCollection matches = Regex.Matches(value, @"[^\\](,)");
                    foreach (Match match in matches)
                    {
                        string newValue = dt != null?Decode(dt, value.Substring(i, match.Index - i + 1)) : value.Substring(i, match.Index - i + 1);

                        escapedValues.Add(newValue);
                        values.Add(Unescape(newValue));
                        i = match.Index + 2;
                    }
                }

                if (i < value.Length)
                {
                    string newValue = dt != null?Decode(dt, value.Substring(i, value.Length - i)) : value.Substring(i, value.Length - i);

                    escapedValues.Add(newValue);
                    values.Add(Unescape(newValue));
                }

                if (co is ICalendarProperty)
                {
                    // Determine if our we're supposed to store extra information during
                    // the serialization process.  If so, let's store the escaped value.
                    ICalendarProperty      property = (ICalendarProperty)co;
                    ISerializationSettings settings = GetService <ISerializationSettings>();
                    if (settings != null &&
                        settings.StoreExtraSerializationData)
                    {
                        // Store the escaped value
                        co.SetService("EscapedValue", escapedValues.Count == 1 ?
                                      (object)escapedValues[0] :
                                      (object)escapedValues);
                    }
                }

                // Return either a single value, or the entire list.
                if (values.Count == 1)
                {
                    return(values[0]);
                }
                else
                {
                    return(values);
                }
            }
            return(null);
        }
 public EncodableDataTypeSerializer(EncodableDataType dataType) : base(dataType)
 {
     _DataType = dataType;
 }
示例#29
0
        public override object Deserialize(TextReader tr)
        {
            if (tr != null)
            {
                string value = tr.ReadToEnd();

                // NOTE: this can deserialize into an IList<string> or simply a string,
                // depending on the input text.  Anything that uses this serializer should
                // be prepared to receive either a string, or an IList<string>.

                bool serializeAsList = false;

                // Determine if we can serialize this property
                // with multiple values per line.
                ICalendarObject co = SerializationContext.Peek() as ICalendarObject;
                if (co is ICalendarProperty)
                    serializeAsList = GetService<IDataTypeMapper>().GetPropertyAllowsMultipleValues(co);

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

                // Try to decode the string
                EncodableDataType dt = null;
                if (co != null)
                {
                    dt = new EncodableDataType();
                    dt.AssociatedObject = co;
                }

                List<string> escapedValues = new List<string>();
                List<string> values = new List<string>();

                int i = 0;
                if (serializeAsList)
                {
                    MatchCollection matches = Regex.Matches(value, @"[^\\](,)");
                    foreach (Match match in matches)
                    {
                        string newValue = dt != null ? Decode(dt, value.Substring(i, match.Index - i + 1)) : value.Substring(i, match.Index - i + 1);
                        escapedValues.Add(newValue);
                        values.Add(Unescape(newValue));
                        i = match.Index + 2;
                    }
                }

                if (i < value.Length)
                {
                    string newValue = dt != null ? Decode(dt, value.Substring(i, value.Length - i)) : value.Substring(i, value.Length - i);
                    escapedValues.Add(newValue);
                    values.Add(Unescape(newValue));
                }

                if (co is ICalendarProperty)
                {
                    // Determine if our we're supposed to store extra information during
                    // the serialization process.  If so, let's store the escaped value.
                    ICalendarProperty property = (ICalendarProperty)co;
                    ISerializationSettings settings = GetService<ISerializationSettings>();
                    if (settings != null &&
                        settings.StoreExtraSerializationData)
                    {
                        // Store the escaped value
                        co.SetService("EscapedValue", escapedValues.Count == 1 ? 
                            (object)escapedValues[0] :
                            (object)escapedValues);
                    }
                }

                // Return either a single value, or the entire list.
                if (values.Count == 1)
                    return values[0];
                else
                    return values;                
            }
            return null;
        }
示例#30
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;
        }