Exemplo n.º 1
0
            private static void PopulateSegmentWithXml(GeneratedSegment tag, XElement xTag)
            {
                try {
                    var xmlProps = XmlAttributeAttribute.GetXmlProperties(typeof(GeneratedSegment));
                    foreach (var attr in xTag.Attributes())
                    {
                        var name = attr.Name.LocalName;


                        //skip renderer name
                        if (name == TemplateNamePropertyName)
                        {
                            continue;
                        }

                        var prop  = xmlProps[name];
                        var value = XmlAttributeAttribute.ParsePropertyValue(prop, attr.Value);
                        prop.SetValue(tag, value);
                    }
                }
                catch (Exception ex) {
                    Debug.DebugHere(ex);
                    throw;
                }
            }
Exemplo n.º 2
0
            private static GeneratedSegment ParseXml(TextRange range)
            {
                try {
                    var tag      = new GeneratedSegment(range);
                    var xmlProps = XmlAttributeAttribute.GetXmlProperties(typeof(GeneratedSegment));
                    var xTag     = ExtractXml(range);
                    foreach (var attr in xTag.Attributes())
                    {
                        var name = attr.Name.LocalName;


                        //skip renderer name
                        if (name == XmlRendererAttributeName)
                        {
                            continue;
                        }

                        var prop = xmlProps[name];
                        prop.SetValue(tag, ParseXmlAttributeValue(prop, attr.Value));
                    }
                    return(tag);
                }
                catch (Exception ex) {
                    Debug.DebugHere(ex);
                    throw;
                }
            }
Exemplo n.º 3
0
            private static GeneratedSegment ParseJson(TextRange range)
            {
                var tag  = new GeneratedSegment(range);
                var json = ExtractJson(range);

                JsonConvert.PopulateObject(json, tag);
                return(tag);
            }
Exemplo n.º 4
0
        public void Remove(Writer info)
        {
            var taggedRanges = GeneratedSegment.FindSegments(info.TargetRange);

            foreach (var t in taggedRanges)
            {
                t.Range.DeleteText();
            }
        }
Exemplo n.º 5
0
            /// <summary>
            /// Insert or Replace text in taggedRange if outdated (or set to always generate)
            /// </summary>
            /// <returns></returns>
            /// <remarks></remarks>
            public bool InsertOrReplace()
            {
                var generatedSegments = GeneratedSegment.Find(this);
                var needInsert        = false;

                if (generatedSegments.Length == 0)
                {
                    //if none found, then insert
                    needInsert = true;
                }
                else
                {
                    //if any is outdated, delete, and reinsert
                    foreach (var t in
                             from t1 in generatedSegments
                             where t1.IsOutdated(OptionTag)
                             select t1)
                    {
                        t.Range.DeleteText();
                        needInsert = true;
                    }
                }
                if (!needInsert)
                {
                    return(false);
                }

                InsertAndFormat();
                //!Open file if requested
                if (OpenFileOnGenerated && Class != null)
                {
                    if (!Class.ProjectItem.IsOpen)
                    {
                        Class.ProjectItem.Open();
                    }
                }
                return(true);
            }
Exemplo n.º 6
0
            /// <summary>
            /// Find tagged segment within GenInfo.SearchStart and GenInfo.SearchEnd
            /// </summary>
            /// <returns></returns>
            /// <remarks>
            /// Not using EditPoint.FindPattern because it can only search from startpoint to end of doc, no way to limit to selection
            /// Not using DTE Find because it has to change params of current find dialog, might screw up normal find usage
            ///  </remarks>
            static public GeneratedSegment[] FindSegments(TaggedRange searchRange)
            {
                try {
                    var regex      = _regexDict[searchRange.TagFormat][searchRange.SegmentType];
                    var searchText = searchRange.GetText();
                    var matches    = regex.Matches(searchText);
                    var segments   = new List <GeneratedSegment>();
                    foreach (var m in matches.Cast <Match>())
                    {
                        var matchRange = ConvertRegexMatchToTextRange(m, searchRange.StartPoint);
                        var segment    = new GeneratedSegment(matchRange);
                        switch (searchRange.TagFormat)
                        {
                        case TagFormat.Json:
                            var json = ExtractJson(m);
                            try {
                                JsonConvert.PopulateObject(json, segment);
                            }
                            catch (Exception e) {
                                Debug.DebugHere(e);
                                throw;
                            }
                            break;

                        case TagFormat.Xml:
                            var x = ExtractXml(m, searchRange.SegmentType);
                            PopulateSegmentWithXml(segment, x);
                            break;
                        }
                        segments.Add(segment);
                    }
                    return(segments.ToArray());
                }
                catch (Exception e) {
                    Debug.DebugHere(e);
                    throw;
                }
            }