public override bool TryCombine(IEnumerable<Property> properties, PropertyMeta meta, out Property property)
        {
            if (SubProperties(meta).Except(properties.Select(o => o.Name)).Count() > 0)
            {
                property = null;
                return false;
            }

            string value = String.Join(" ", Filter(properties, meta).OrderBy(o => o.Item2).Select(o => o.Item1.Value));
            property = new Property(meta.Name, value);
            return true;
        }
Exemple #2
0
        public override bool TryCombine(IEnumerable <Property> properties, PropertyMeta meta, out Property property)
        {
            if (SubProperties(meta).Except(properties.Select(o => o.Name)).Count() > 0)
            {
                property = null;
                return(false);
            }

            string value = String.Join(" ", Filter(properties, meta).OrderBy(o => o.Item2).Select(o => o.Item1.Value));

            property = new Property(meta.Name, value);
            return(true);
        }
 protected override IEnumerable<Property> Split(List<string> splitted, PropertyMeta meta)
 {
     for (int i = 0; i < splitted.Count; i++)
     {
         if (_mappings.ContainsKey(splitted.Count))
         {
             foreach (var each in _mappings[splitted.Count][i].Split(','))
             {
                 yield return new Property(CombineName(meta, each), splitted[i]);
             }
         }
     }
 }
Exemple #4
0
 protected override IEnumerable <Property> Split(List <string> splitted, PropertyMeta meta)
 {
     for (int i = 0; i < splitted.Count; i++)
     {
         if (_mappings.ContainsKey(splitted.Count))
         {
             foreach (var each in _mappings[splitted.Count][i].Split(','))
             {
                 yield return(new Property(CombineName(meta, each), splitted[i]));
             }
         }
     }
 }
        private IEnumerable<Tuple<Property, int>> Filter(IEnumerable<Property> properties, PropertyMeta meta)
        {
            string[] highestMapping = _mappings.OrderByDescending(o => o.Key).First().Value;

            foreach (var each in properties)
            {
                string name = each.Name.Substring(meta.Name.Length + 1);
                int i = 0;
                for (; i < highestMapping.Length && highestMapping[i] != name; i++) ;
                if (i < highestMapping.Length)
                {
                    yield return new Tuple<Property, int>(each, i);
                }
            }
        }
        public override bool TryCombine(IEnumerable <Property> properties, PropertyMeta meta, out Property property)
        {
            StringBuilder builder = new StringBuilder();

            foreach (var propertyNames in _list)
            {
                if ((propertyNames.Type == SubListType.Sequencial || propertyNames.Type == SubListType.MustContains) &&
                    !properties.Any(o => o.Name == propertyNames.First()))
                {
                    property = null;
                    return(false);
                }

                var propertyName = propertyNames.GetEnumerator();
                int i            = 0;
                while (propertyName.MoveNext())
                {
                    var p = properties.FirstOrDefault(o => o.Name == propertyName.Current);
                    if (p == null)
                    {
                        continue;
                    }

                    if (i == 0)
                    {
                        if (builder.Length > 0)
                        {
                            builder.Append(' ');
                        }
                    }
                    else if (propertyNames.Type == SubListType.Sequencial)
                    {
                        builder.Append('/');
                    }
                    else
                    {
                        builder.Append(' ');
                    }

                    builder.Append(p.Value);

                    i++;
                }
            }

            property = new Property(meta.Name, builder.ToString());
            return(true);
        }
Exemple #7
0
        protected override IEnumerable <Property> Split(List <string> splitted, PropertyMeta meta)
        {
            Property left = null, top = null;

            foreach (var each in base.Split(splitted, meta, CreateMatchList(_splitGrammar)))
            {
                switch (each.Name)
                {
                case "background-position-left":
                    left = each;
                    break;

                case "background-position-top":
                    top = each;
                    break;

                default:
                    yield return(each);

                    break;
                }
            }

            if (left != null || top != null)
            {
                StringBuilder builder = new StringBuilder();
                if (left != null)
                {
                    builder.Append(left.Value);
                }
                if (top != null)
                {
                    if (builder.Length > 0)
                    {
                        builder.Append(" ");
                    }
                    builder.Append(top.Value);
                }

                yield return(new Property("background-position", builder.ToString()));
            }
        }
Exemple #8
0
        protected override IEnumerable<Property> Split(List<string> splitted, PropertyMeta meta)
        {
            Property left = null, top = null;
            foreach (var each in base.Split(splitted, meta, CreateMatchList(_splitGrammar)))
            {
                switch (each.Name)
                {
                    case "background-position-left":
                        left = each;
                        break;
                    case "background-position-top":
                        top = each;
                        break;
                    default:
                        yield return each;
                        break;
                }

            }

            if (left != null || top != null)
            {
                StringBuilder builder = new StringBuilder();
                if (left != null)
                {
                    builder.Append(left.Value);
                }
                if (top != null)
                {
                    if (builder.Length > 0)
                    {
                        builder.Append(" ");
                    }
                    builder.Append(top.Value);
                }

                yield return new Property("background-position", builder.ToString());
            }
        }
Exemple #9
0
 protected abstract IEnumerable <Property> Split(List <string> splitted, PropertyMeta meta);
Exemple #10
0
        public IEnumerable <Property> Split(Property property, PropertyMeta meta)
        {
            if (String.IsNullOrEmpty(property.Value))
            {
                return(Enumerable.Empty <Property>());
            }

            string        value         = property.Value;
            List <string> splitted      = new List <string>();
            int           p             = 0;
            int           propertyStart = 0;
            ReadStatus    status        = ReadStatus.Separator;

            while (p < value.Length)
            {
                char ch = value[p];
                if (Char.IsWhiteSpace(ch))
                {
                    if (status == ReadStatus.Property)
                    {
                        splitted.Add(value.Substring(propertyStart, p - propertyStart));
                        status = ReadStatus.Separator;
                    }
                }
                else if (ch == '"' || ch == '\'')
                {
                    if (status == ReadStatus.Quote)
                    {
                        status = ReadStatus.Property;
                    }
                    else
                    {
                        if (status == ReadStatus.Separator)
                        {
                            propertyStart = p;
                        }
                        status = ReadStatus.Quote;
                    }
                }
                else if (ch == ',')
                {
                    status = ReadStatus.Comma;
                }
                else
                {
                    if (status == ReadStatus.Separator)
                    {
                        propertyStart = p;
                        status        = ReadStatus.Property;
                    }
                    else if (status == ReadStatus.Comma)
                    {
                        status = ReadStatus.Property;
                    }
                }
                p++;
            }

            if (status == ReadStatus.Property)
            {
                splitted.Add(value.Substring(propertyStart, p - propertyStart));
            }

            return(Split(splitted, meta));
        }
Exemple #11
0
 public abstract IEnumerable <string> SubProperties(PropertyMeta meta);
Exemple #12
0
 public override bool TryCombine(IEnumerable<Property> properties, PropertyMeta meta, out Property property)
 {
     property = null;
     return false;
 }
 public override IEnumerable<string> SubProperties(PropertyMeta meta)
 {
     return _subProperties.Select(o => CombineName(meta, o));
 }
Exemple #14
0
 public override bool TryCombine(IEnumerable<Property> properties, PropertyMeta meta, out Property property)
 {
     // We do not combine background for background-image not supported by email client.
     property = null;
     return false;
 }
 protected virtual string CombineName(PropertyMeta meta, string name)
 {
     return meta.Name + "-" + name;
 }
Exemple #16
0
 protected virtual string CombineName(PropertyMeta meta, string name)
 {
     return(meta.Name + "-" + name);
 }
        protected virtual IEnumerable <Property> Split(List <string> splitted, PropertyMeta meta, List <SubList> matchList)
        {
            foreach (var value in splitted)
            {
                if (_groupable && value.Contains('/'))
                {
                    // In case like "font-size/line-height"
                    string[] subValues = value.Split('/');
                    for (int i = 0; i < matchList.Count; i++)
                    {
                        var propertyNames = matchList[i];

                        if (matchList[i].Type != SubListType.Sequencial || matchList[i].Count() < subValues.Length)
                        {
                            continue;
                        }

                        var subMeta = PropertyMeta.GetMeta(propertyNames.First());
                        if (subMeta != null && subMeta.ValueType.IsValid(subValues[0]))
                        {
                            var propertyName = propertyNames.GetEnumerator();
                            var subValue     = subValues.GetEnumerator();
                            while (subValue.MoveNext() && propertyName.MoveNext())
                            {
                                yield return(new Property(propertyName.Current, subValue.Current.ToString()));
                            }

                            matchList.RemoveAt(i);
                            break;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < matchList.Count; i++)
                    {
                        var propertyNames = matchList[i];

                        if (propertyNames.Type == SubListType.Alternative)
                        {
                            Property property = null;
                            for (int j = 0; j < propertyNames.Count; j++)
                            {
                                var subMeta = PropertyMeta.GetMeta(propertyNames[j]);
                                if (subMeta != null && subMeta.ValueType.IsValid(value))
                                {
                                    property = new Property(propertyNames[j], value);;
                                    propertyNames.RemoveAt(j);
                                    break;
                                }
                            }
                            if (property != null)
                            {
                                yield return(property);

                                break;
                            }
                        }
                        else
                        {
                            var subMeta = PropertyMeta.GetMeta(propertyNames.First());
                            if (subMeta != null && subMeta.ValueType.IsValid(value))
                            {
                                yield return(new Property(propertyNames.First(), value));

                                matchList.RemoveAt(i);
                                break;
                            }
                        }
                    }
                }
            }
        }
 protected override IEnumerable <Property> Split(List <string> splitted, PropertyMeta meta)
 {
     return(Split(splitted, meta, CreateMatchList(_list)));
 }
 public override IEnumerable <string> SubProperties(PropertyMeta meta)
 {
     return(_list.SelectMany(o => o));
 }
Exemple #20
0
 public abstract bool TryCombine(IEnumerable <Property> properties, PropertyMeta meta, out Property property);
Exemple #21
0
 public override IEnumerable <string> SubProperties(PropertyMeta meta)
 {
     return(_subProperties.Select(o => CombineName(meta, o)));
 }
Exemple #22
0
 public abstract IEnumerable<string> SubProperties(PropertyMeta meta);
Exemple #23
0
 protected abstract IEnumerable<Property> Split(List<string> splitted, PropertyMeta meta);
 protected override string CombineName(PropertyMeta meta, string name)
 {
     string[] splitted = meta.Name.Split('-');
     return(splitted[0] + "-" + name + "-" + splitted[1]);
 }
Exemple #25
0
        private IEnumerable <Tuple <Property, int> > Filter(IEnumerable <Property> properties, PropertyMeta meta)
        {
            string[] highestMapping = _mappings.OrderByDescending(o => o.Key).First().Value;

            foreach (var each in properties)
            {
                string name = each.Name.Substring(meta.Name.Length + 1);
                int    i    = 0;
                for (; i < highestMapping.Length && highestMapping[i] != name; i++)
                {
                    ;
                }
                if (i < highestMapping.Length)
                {
                    yield return(new Tuple <Property, int>(each, i));
                }
            }
        }
Exemple #26
0
 public override bool TryCombine(IEnumerable <Property> properties, PropertyMeta meta, out Property property)
 {
     // We do not combine background for background-image not supported by email client.
     property = null;
     return(false);
 }
Exemple #27
0
 public abstract bool TryCombine(IEnumerable<Property> properties, PropertyMeta meta, out Property property);
 protected override string CombineName(PropertyMeta meta, string name)
 {
     string[] splitted = meta.Name.Split('-');
     return splitted[0] + "-" + name + "-" + splitted[1];
 }
Exemple #29
0
        public IEnumerable<Property> Split(Property property, PropertyMeta meta)
        {
            if (String.IsNullOrEmpty(property.Value))
                return Enumerable.Empty<Property>();

            string value = property.Value;
            List<string> splitted = new List<string>();
            int p = 0;
            int propertyStart = 0;
            ReadStatus status = ReadStatus.Separator;
            while (p < value.Length)
            {
                char ch = value[p];
                if (Char.IsWhiteSpace(ch))
                {
                    if (status == ReadStatus.Property)
                    {
                        splitted.Add(value.Substring(propertyStart, p - propertyStart));
                        status = ReadStatus.Separator;
                    }
                }
                else if (ch == '"' || ch == '\'')
                {
                    if (status == ReadStatus.Quote)
                    {
                        status = ReadStatus.Property;
                    }
                    else
                    {
                        if (status == ReadStatus.Separator)
                        {
                            propertyStart = p;
                        }
                        status = ReadStatus.Quote;
                    }
                }
                else if (ch == ',')
                {
                    status = ReadStatus.Comma;
                }
                else
                {
                    if (status == ReadStatus.Separator)
                    {
                        propertyStart = p;
                        status = ReadStatus.Property;
                    }
                    else if(status == ReadStatus.Comma)
                    {
                        status = ReadStatus.Property;
                    }
                }
                p++;
            }

            if (status == ReadStatus.Property)
            {
                splitted.Add(value.Substring(propertyStart, p - propertyStart));
            }

            return Split(splitted, meta);
        }
 public override bool TryCombine(IEnumerable <Property> properties, PropertyMeta meta, out Property property)
 {
     property = null;
     return(false);
 }