Exemplo n.º 1
0
        public override void Read(string[] text, ref int lineNum)
        {
            // my first line is my title
            name = text[lineNum++].Trim('"');
            if (text[lineNum++].Trim() != "{")
            {
                throw new Exception("error expected token {");
            }

            while (lineNum < text.Length && text[lineNum] != "}")
            {
                // read one or more property groups or nvp
                if (NameValuePairTreeItem.IsNVP(text[lineNum]))
                {
                    NameValuePairTreeItem nvp = new NameValuePairTreeItem(this);
                    nvp.Read(text, ref lineNum);
                    children.Add(nvp);
                    continue;
                }

                // group the first thing in quotes, there should be only one of those
                // then exclude anything after that isn't whitespace, and definitely NOT = or "
                string l = text[lineNum];

                if (Regex.IsMatch(text[lineNum], "^\"{1}(.[^\"]+)\"{1}\\s*$"))
                {
                    PropertyGroupTreeItem group = new PropertyGroupTreeItem(this);
                    group.Read(text, ref lineNum);
                    // do not add the hierarchy stuff, it's mostly unhelpful, and contains lots of nasty duplicate group items - we could sort this out by making keys up later
                    // which comprise sub properties to uniquely identify them, or just take each entry as a whole string/key.
                    if (group.name != "Hierarchy")
                    {
                        children.Add(group);
                    }

                    // if the group contains a sourcepath, add that to the name
                    foreach (var child in group.children)
                    {
                        if (child is NameValuePairTreeItem)
                        {
                            var nvp = child as NameValuePairTreeItem;
                            if (nvp.name == "SourcePath")
                            {
                                group.name += $"({nvp.value})";
                            }
                        }
                    }
                    continue;
                }
            }
            lineNum++; // last }
        }
Exemplo n.º 2
0
        private void GetThingsChanged()
        {
            // for those matching items - which are key/value pairs report those whose values have changed.
            var intersection = oldItems.mapOfTreeItems.Keys.Intersect(newItems.mapOfTreeItems.Keys);

            foreach (var key in intersection)
            {
                TreeItem itemold = oldItems.mapOfTreeItems[key];
                TreeItem itemnew = newItems.mapOfTreeItems[key];
                if (itemold is NameValuePairTreeItem)
                {
                    NameValuePairTreeItem nvpOld = itemold as NameValuePairTreeItem;
                    NameValuePairTreeItem nvpNew = itemnew as NameValuePairTreeItem;
                    if (nvpOld.value != nvpNew.value)
                    {
                        changed.AppendLine(nvpOld.Key);
                        changed.AppendLine($"old: {nvpOld.value}\nnew: {nvpNew.value}\n");
                    }
                }
                // else - shouldn't actually have any diffs on anything other than NVPs.
            }
        }