Пример #1
0
        public static ZoneCollection GetZones(string[] html, out LayoutHtmlCollection result)
        {
            Regex zoneRegex = new Regex("name=\"(ZoneName|LayoutId|ID)\".+value=\"(.+)\">");

            result = new LayoutHtmlCollection();
            ZoneCollection zones = new ZoneCollection();

            for (int i = 0; i < html.Count(); i++)
            {
                var item = html[i];
                if (item == ZoneEntity.ZoneTag)
                {
                    i++;
                    item = html[i];
                    ZoneEntity zone = new ZoneEntity();
                    item.Split(new[] { "<input" }, StringSplitOptions.RemoveEmptyEntries).Each(part =>
                    {
                        zoneRegex.Replace(part, evaluator =>
                        {
                            if (evaluator.Groups[1].Value.Equals("ZoneName"))
                            {
                                zone.ZoneName = evaluator.Groups[2].Value;
                            }
                            else if (evaluator.Groups[1].Value.Equals("LayoutId"))
                            {
                                zone.LayoutId = evaluator.Groups[2].Value;
                            }
                            else if (evaluator.Groups[1].Value.Equals("ID"))
                            {
                                zone.ID = evaluator.Groups[2].Value;
                            }
                            return("");
                        });
                    });
                    zone.ID = zone.ID ?? Guid.NewGuid().ToString("N");
                    zones.Add(zone);
                    result.Add(new LayoutHtml {
                        Html = ZoneEntity.ZoneTag
                    });
                    result.Add(new LayoutHtml {
                        Html = zone.ID
                    });
                    result.Add(new LayoutHtml {
                        Html = ZoneEntity.ZoneEndTag
                    });
                    i++;
                }
                else
                {
                    result.Add(new LayoutHtml {
                        Html = item
                    });
                }
            }
            return(zones);
        }
Пример #2
0
        public static ZoneCollection GetZones(string[] html, out LayoutHtmlCollection result)
        {
            ZoneEntity zone          = null;
            bool       initZoneStart = false;

            result = new LayoutHtmlCollection();
            ZoneCollection zones = new ZoneCollection();

            foreach (string item in html)
            {
                if (item == ZoneEntity.ZoneTag)
                {
                    zone          = new ZoneEntity();
                    initZoneStart = true;
                    continue;
                }
                else if (item == ZoneEntity.ZoneEndTag)
                {
                    initZoneStart = false;
                    if (zone.ID.IsNullOrEmpty())
                    {
                        zone.ID = Guid.NewGuid().ToString("N");
                    }
                    zones.Add(zone);
                    result.Add(new LayoutHtml {
                        Html = ZoneEntity.ZoneTag
                    });
                    result.Add(new LayoutHtml {
                        Html = zone.ID
                    });
                    result.Add(new LayoutHtml {
                        Html = ZoneEntity.ZoneEndTag
                    });
                    continue;
                }

                if (!initZoneStart)
                {
                    result.Add(new LayoutHtml {
                        Html = item
                    });
                }
                else
                {
                    if (item.Contains("name=\"ZoneName\"") || item.Contains("name=\"ZoneId\""))
                    {
                        string[] zoneInfo = item.Split(new string[] { "<input" }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string zonePart in zoneInfo)
                        {
                            if (zonePart.Contains("name=\"ZoneName\""))
                            {
                                zone.ZoneName = zonePart.GetInnerContent("value=\"", "\"", 0);
                            }
                            else if (zonePart.Contains("name=\"ID\""))
                            {
                                zone.ID = zonePart.GetInnerContent("value=\"", "\"", 0);
                            }
                            else if (zonePart.Contains("name=\"LayoutId\""))
                            {
                                zone.LayoutId = zonePart.GetInnerContent("value=\"", "\"", 0);
                            }
                        }
                    }
                }
            }
            return(zones);
        }