Пример #1
0
        private string[] GetTemplate()
        {
            if (_parts != null)
                return _parts;

            ContentRecord templateRec;
            if (!_data.TryGetValue(TemplatePath, out templateRec) || !templateRec.HasContentStoreId)
                return _parts = new string[] { String.Empty };

            string text = Encoding.UTF8.GetString(_data.ReadContent(templateRec, true));
            
            List<string> parts = new List<string>();
            int offset = 0;

            foreach(Match m in TemplatePattern.Matches(text))
            {
                parts.Add(text.Substring(offset, m.Index - offset));
                parts.Add(m.Groups["closed"].Value + m.Groups["name"]);
                offset = m.Index + m.Length;
            }

            parts.Add(text.Substring(offset, text.Length - offset));

            _parts = parts.ToArray();

            _valuePartOffset = -1;
            MatchCollection[] found = new MatchCollection[_parts.Length];
            for (int i = 0; i < _parts.Length; i++)
            {
                found[i] = FormInputPattern.Matches(_parts[i]);
                if(found[i].Count == 1)
                    _valuePartIndex = i;
            }

            found = found.Where(mc => mc.Count > 0).ToArray();
            if (found.Length == 1 && found[0].Count == 1)
            {
                //we have a single match, good.
                Match m = found[0][0];
                Group grpValue = m.Groups["value"];
                if (grpValue.Success && grpValue.Captures.Count == 1)
                {
                    _valuePartOffset = grpValue.Index + 1;
                }
            }

            if (_valuePartOffset == -1)
                _valuePartIndex = -1;

            return _parts;
        }