Exemplo n.º 1
0
 bool CompareOne(OneXmlNode a, OneXmlNode b)
 {
     if (a == null)
     {
         if (b != null)
         {
             b.IsEnable = true;
             return(false);
         }
         return(true);
     }
     else if (b == null)
     {
         return(false);
     }
     if (a.NodeName == b.NodeName)
     {
         if (a.Text == b.Text)   // possible? may be not
         {
             if (a.Tag != b)
             {
                 b.IsEnable = false;
             }
             return(true);
         }
     }
     b.IsEnable = true;
     return(false);
 }
Exemplo n.º 2
0
        void Compare(OneXmlNode a, OneXmlNode b)
        {
            CompareOne(a, b);
            var map = new Dictionary <ElemIndex, OneXmlNode>();

            foreach (var ca in a.Children)
            {
                map[ca.ChildIndex] = ca;
            }
            foreach (var cb in b.Children)
            {
                if (map.ContainsKey(cb.ChildIndex))
                {
                    var ca = map[cb.ChildIndex];
                    cb.Tag = new OneXmlNode[2] {
                        a, ca
                    };
                    Compare(ca, cb);
                }
                else
                {
                    cb.Tag = new OneXmlNode[2] {
                        a, null
                    };
                    CompareOne(null, cb);
                }
            }
        }
Exemplo n.º 3
0
        private void ToDo2()
        {
            var a = new SimpleXmlChecker(2);

            //list2.Items.Clear();
            if (String.IsNullOrEmpty(file2) || !File.Exists(file2))
            {
                MessageBox.Show("No file2 found");
                return;
            }
            String xml = File.ReadAllText(file2);

            xml_str2 = xml;
            if (!a.Check(xml))
            {
                MessageBox.Show("\"" + file2 + "+\" " + a.err_desc + "!\n" + a.detailed_err);
                return;
            }
            OneXmlNode node = new OneXmlNode(a.doc.Root);

            list2.ItemsSource = new BindingList <OneXmlNode> {
                node
            };
            list2_nodes = node;
            Compare(list1_nodes, list2_nodes);
        }
Exemplo n.º 4
0
        private void ToDo1()
        {
            var a = new SimpleXmlChecker(2);

            //list1.Items.Clear();
            b_changed = false;
            if (String.IsNullOrEmpty(file1) || !File.Exists(file1))
            {
                MessageBox.Show("No file found");
                return;
            }

            String xml = File.ReadAllText(file1);

            xml_str1 = xml;
            if (!a.Check(xml))
            {
                MessageBox.Show("\"" + file1 + "+\" " + a.err_desc + "!\n" + a.detailed_err);
                return;
            }

            OneXmlNode node = new OneXmlNode(a.doc.Root);

            node.IsChecked    = true;
            node.IsEnable     = false;
            list1.ItemsSource = new BindingList <OneXmlNode> {
                node
            };
            list1_nodes      = node;
            b_changed        = false;
            btn_f2.IsEnabled = true;
        }
Exemplo n.º 5
0
        public OneXmlNode(XComment comment, ElemIndex pos, OneXmlNode parent)
        {
            SomeInit(parent, COMMENT_NAME);
            XCommentNode = comment;
            Text         = comment.Value;

            ChildIndex = pos;
            Type       = 2;
        }
Exemplo n.º 6
0
        void CheckAll(OneXmlNode n, bool b)
        {
            var l = new List <OneXmlNode>();

            CheckAll_(n, l, b);
            foreach (var n1 in l)
            {
                n1.OnAllChanged();
            }
        }
Exemplo n.º 7
0
 void CheckAll_(OneXmlNode n, List <OneXmlNode> changed, bool b)
 {
     if (n.IsEnable && n.IsChecked != b)
     {
         n.IsChecked = b;
         changed.Add(n);
     }
     foreach (var nn in n.Children)
     {
         CheckAll_(nn, changed, b);
     }
 }
Exemplo n.º 8
0
        public OneXmlNode(XElement root, ElemIndex pos = null, OneXmlNode parent = null)
        {
            SomeInit(parent, root.Name.ToString());

            Root = root;
            Text = Root.Name.ToString();
            if (pos == null)
            {
                ChildIndex = new ElemIndex("", "", 0);
            }
            else
            {
                ChildIndex = pos;
            }
            Type = 1;
        }
Exemplo n.º 9
0
        protected void SomeInit(OneXmlNode parent, string node_name)
        {
            child = new BindingList <OneXmlNode>();
            //elem_dic=new Dictionary<string, int>();
            NodeName = node_name;


            if (parent != null)
            {
                IsEnable  = parent.IsEnable;
                IsChecked = parent.IsChecked;
                Path      = parent.Path + '/' + NodeName;
            }
            else
            {
                Path = '/' + NodeName;
            }

            ParentNode = parent;
        }
Exemplo n.º 10
0
        private void ToggleButton_OnChecked_Changes(object sender, RoutedEventArgs e)
        {
            CheckBox me  = (CheckBox)sender;
            var      one = (OneXmlNode)me.Tag;

            if (one.Tag == null)
            {
                return;
            }
            var other_arr = (OneXmlNode[])null;

            try
            {
                other_arr = (OneXmlNode[])one.Tag;
            }
            catch (System.InvalidCastException)
            {
                ToggleButton_OnChecked_Changes_list1(sender, e);    // 勾选A列的时候
                return;
            }
            b_changed = true;
            // 勾选B列的时候
            if (other_arr != null && other_arr.Count() == 2)
            {
                var other_parent = other_arr[0];
                if (other_parent == null)
                {
                    return;
                }
                var other = other_arr[1];
                if (other == null)
                {   // 新增节点
                    var map = new Dictionary <ElemIndex, KeyValuePair <int, OneXmlNode> >();
                    int i   = 0;
                    foreach (var ca in other_parent.Children)       // 对A父节点下的子节点建立索引
                    {
                        map[ca.ChildIndex] = new KeyValuePair <int, OneXmlNode>(i++, ca);
                    }
                    i = 0;
                    OneXmlNode last_elem = null;
                    if (me.IsChecked.GetValueOrDefault(false))      // 勾选
                    {
                        foreach (var cb in one.ParentNode.Children)
                        {
                            if (map.ContainsKey(cb.ChildIndex))
                            {
                                i         = map[cb.ChildIndex].Key + 1;
                                last_elem = map[cb.ChildIndex].Value;
                            }
                            if (cb == one)
                            {
                                break;
                            }
                        }
                        // add // refresh // check b
                        OneXmlNode n;
                        if (one.NodeName == OneXmlNode.COMMENT_NAME)
                        {
                            var ee = new XComment(one.Text);
                            if (last_elem != null)
                            {
                                last_elem.GeneralNode.AddAfterSelf(ee);
                                //ee = (XComment)last_elem.GeneralNode.NextNode;
                            }
                            else
                            {
                                other_parent.Root.AddFirst(ee);
                                //ee = (XComment)other_parent.Root.FirstNode;
                            }
                            n = new OneXmlNode(ee, one.ChildIndex, other_parent);
                        }
                        else
                        {
                            var ee = new XElement(one.Root.Name);
                            if (last_elem != null)
                            {
                                last_elem.GeneralNode.AddAfterSelf(ee);
                                //ee = (XElement)last_elem.GeneralNode.NextNode;
                            }
                            else
                            {
                                other_parent.Root.AddFirst(ee);
                                //ee = (XElement)other_parent.Root.FirstNode;
                            }
                            n = new OneXmlNode(ee, one.ChildIndex, other_parent);
                        }
                        n.Tag      = one;
                        n.IsEnable = true;
                        other_parent.Children.Insert(i, n);
                        var tn = list1.ItemContainerGenerator.ContainerFromItem(other_parent) as TreeViewItem;
                        if (tn != null)
                        {
                            tn.BringIntoView();
                        }
                        Compare(n, one);
                    }
                    else                // 取消勾选
                    {
                        if (map.ContainsKey(one.ChildIndex))
                        {
                            other = other_parent.Children[map[one.ChildIndex].Key];
                            if (other.Type == 1 && other.Root != null)
                            {
                                other.Root.Remove(); other.Root = null;
                            }
                            else if (other.Type == 2 && other.XCommentNode != null)
                            {
                                other.XCommentNode.Remove(); other.XCommentNode = null;
                            }
                            other_parent.Children.RemoveAt(map[one.ChildIndex].Key);
                        }
                    }
                }
                else    // 修改节点
                {
                    if (me.IsChecked.GetValueOrDefault(false))
                    {
                        other.ReplacedText = one.Text;
                        other.IsChecked    = true;
                        other.IsEnable     = true;
                        other.Tag          = new Tuple <OneXmlNode>(one);
                    }
                    else
                    {
                        other.ReplacedText = "";
                        other.IsEnable     = false;
                        other.Tag          = null;

                        other.OnAllChanged();
                        other.IsChecked = true;
                    }
                    if (other.Type == 2)
                    {
                        other.XCommentNode.Value = !string.IsNullOrEmpty(other.ReplacedText) ? other.ReplacedText : other.Text;
                    }
                    other.OnAllChanged();
                }
            }
        }