예제 #1
0
        public TreeNodeViewModel(Element element, TreeNodeViewModel parent)
        {
            _element = element;
            _parent = parent;

            IsExpanded = true; //defaults

            _children = new ObservableCollection<TreeNodeViewModel>(
                    (from child in _element.Children
                     select new TreeNodeViewModel(child, this))
                     .ToList<TreeNodeViewModel>());

            if (_children.Count > 0)
                hasChildren = true;
            else
                hasChildren = false;
        }
예제 #2
0
        public string getRelativeAddress(TreeNodeViewModel node)
        {
            string address = "";
            TreeNodeViewModel temp = this;

            if (this.Children.Count >= 0)
                address = this.getName();

            while (temp.Parent != null)
            {
                if (temp.Parent.isEqual(node))
                    break; // if this goes in header of while loop it will result in exception sometimes

                temp = temp.Parent;
                if (!temp.getName().Equals(address))
                    address = temp.getName() + "/" + address;
            }

            return address;
        }
예제 #3
0
        public bool isEqual(TreeNodeViewModel node)
        {
            if (node != null)
            {
                if (this.Type == node.Type && this.Name.Equals(node.Name))//this.EValue.Equals(node.EValue) && --> gives exception
                    return true;
            }

            return false;
        }
예제 #4
0
        public void generateChildren(XPathReader reader)
        {
            reader.MoveToContent();
            int counter = 0;

            while (reader.ReadUntilMatch())
            {

                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        //MessageBox.Show("element -> " + reader.Name);
                        Element newElement = createModelElement(reader);
                        TreeNodeViewModel newNode = new TreeNodeViewModel(newElement, this);

                        //check if it has children
                        if (reader.HasAttributes || !reader.IsEmptyElement)
                            newNode.hasChildren = true;
                        else
                            newNode.hasChildren = false;

                        newNode.IsExpanded = false;
                        this.addChild(newNode);

                        counter++;

                        break;

                    case XmlNodeType.Attribute:
                        Element newAttr = createAttributeElement(reader);
                        TreeNodeViewModel attrNode = new TreeNodeViewModel(newAttr, this);
                        attrNode.hasChildren = false;
                        attrNode.IsExpanded = false;
                        //MessageBox.Show("attribute -> " + reader.Name + " : " + reader.Value);
                        this.Children.Add(attrNode);

                        counter++;

                        break;

                    case XmlNodeType.Text:

                        Element newTextElement = createValueElement(reader);
                        TreeNodeViewModel newTextElementNode = new TreeNodeViewModel(newTextElement, this);
                        newTextElementNode.hasChildren = false;
                        newTextElementNode.IsExpanded = false;
                        //MessageBox.Show("text -> " + reader.Value);
                        this.addChild(newTextElementNode);

                        counter++;

                        break;
                    default:
                        break;
                }
                if (counter > 10)
                    break;
            }
        }
예제 #5
0
        public string generateXSLTSnippet(TreeNodeViewModel relativeParentNode)
        {
            string XSLTcode = "";
            //XSLTcode += "<";
            XSLTcode += "xsl:value-of select=\"";
            XSLTcode += getRelativeAddress(relativeParentNode);
            XSLTcode += "\"";
            //XSLTcode += "/>";

            return XSLTcode;
        }
예제 #6
0
        public XmlNode createSignatureNode(TreeNodeViewModel node)
        {
            XmlDocument xDoc = new XmlDocument();
            XmlNode xnode = null;

            if (this.isMatched == true)
            {
                xnode = xDoc.CreateElement(this.Name) as XmlNode;

                if (this.ruleIndex != -1)
                {
                    XmlAttribute attr = xDoc.CreateAttribute("ruleIndex");
                    attr.AppendChild(xDoc.CreateTextNode(this.ruleIndex.ToString()));//fetch the value

                    xnode.Attributes.Append(attr);
                }

                //continue for children
                foreach (AbstractTreeLatticeNode n in this.Children)
                {
                    TreeNodeViewModel tn = node.findInChidlsByName(n.Name);
                    if (tn != null)
                        xnode.AppendChild(xnode.OwnerDocument.ImportNode(n.createSignatureNode(tn),true));
                    else
                    {
                        xnode.AppendChild(xnode.OwnerDocument.ImportNode(n.createSignatureNode(),true));
                        MessageBox.Show("Could not find \"" + n.Name + "\" in treeNode");
                    }
                }
            }
            else
            {
                xnode = xDoc.CreateElement(this.Name) as XmlNode;
                //get values (children with only one child and no further dicendant) from node

                TreeNodeViewModel temp = node.findInChidlsByName(this.Name);
                XmlAttribute attr = xDoc.CreateAttribute("value");
                //attr.AppendChild(xDoc.CreateTextNode(temp.Children.ElementAt(0).Name));//fetch the value
                attr.AppendChild(xDoc.CreateTextNode(temp.EValue));//fetch the value, not sure, added to get rid of an exception

                xnode.Attributes.Append(attr);
            }

            return xnode;
        }
예제 #7
0
 //testing from visual element
 public void addChild(TreeNodeViewModel t)
 {
     Children.Add(t);
     OnPropertyChanged("Children");
 }
예제 #8
0
        public void processVisual_TreeNodeDrop(TreeNodeViewModel treeN, String FullAddress)
        {
            //set header for template XSLT
            templateVM.HeaderNode = treeN; // I do not think these will be used, they have been used in visualiser to check and set visualfunction abstraction

            //set address Id for template XSLT
            templateVM.TemplateAddress = FullAddress; // I do not think these will be used

            AbstractTreeLatticeNode matchingNode = (ParentWindow as Visualiser).sourceASTL.getAbstractNodeAtAddress(FullAddress);

            //define correspondence
            if (matchingNode != null)//if you have found the node
            {
                if (matchingNode.ruleIndex == -1)
                {
                    sourceLatticeNodeToMatch = matchingNode;
                }
                else if (matchingNode.parent != null)
                {
                    //create a duplicate****************************** duplicate not implemented yet
                    sourceLatticeNodeToMatch = matchingNode.duplicate();
                    matchingNode.parent.Children.Add(sourceLatticeNodeToMatch);
                }

                sourceLatticeNodeToMatch.isMatched = true;
                sourceLatticeNodeToMatch.ruleIndex = RULEINDEX;//assign an index for current rule

                //assign same rule index for this.abstractTree
                this.abstractTree.Root.ruleIndex = sourceLatticeNodeToMatch.ruleIndex;
                this.abstractTree.Root.isMatched = true;

                //increment index for other correspondences
                RULEINDEX++;

                //go for reverse, the top part will be obsolete
                //this.abstractTreeReverse = new AbstractLattice(matchingNode);//might not need abstract tree for reverse, as one way suggestion will eb shown
                this.ReverseData = matchingNode.ToXML();// treeNode.ToXML();//matchingNode might have worked as well but the signature problems might get in the way
                this.templateVMR.TemplateName = this.Data.Name;
            }

            //suggester initiation
            AbstractLattice sourceAST = new AbstractLattice(matchingNode);
            this.abstractTree.prepare();
            SuggesterConfig config = new SuggesterConfig();
            config.UseNameSimSuggester = true;
            config.UseTypeSimSuggester = true;
            config.UseIsoRankSimSuggester = true;
            config.UseValueSimSuggester = true;
            config.UseStructSimSuggester = true;
            (ParentWindow as Visualiser).visualiserSuggester = new Suggester(sourceAST, this.abstractTree, config);

            (ParentWindow as Visualiser).updateSuggestions((ParentWindow as Visualiser).visualiserSuggester.getSuggestionsAsStrings((ParentWindow as Visualiser).visualiserSuggester.imFeelingLucky()));

            //log event
            (ParentWindow as Visualiser).logger.log("\"" + FullAddress + "\" was dropped on \"" + this.VEName + "\"", ReportIcon.OK);
            (ParentWindow as Visualiser).ReportStatusBar.ShowStatus("Mapping " + treeN.Name + " to " + this.Data.Name, ReportIcon.Info);
        }
예제 #9
0
        public bool processElement_TreeNodeDrop(string sourceElement, string targetElement, TreeNodeViewModel sourceNode)
        {
            if (templateVM.HeaderNode != null && sourceLatticeNodeToMatch != null)
            {
                string source = sourceElement;
                if (sourceNode.Name.Equals(templateVM.HeaderNode.Name))//attribute
                    source = ".";
                //else
                //source = sourceNode.getRelativeAddress(templateVM.HeaderNode);

                string target = targetElement.Substring(targetElement.IndexOf('/') + 1);

                templateVM.updateXmlNodeByValue(target, sourceElement);

                //for reverse
                string rsource = sourceNode.getRelativeAddress(templateVM.HeaderNode); //this might give wrong ones, but will not be a problem

                if (rsource.IndexOf("@") == 0) //is an attribute, so send it with its parent get its parent name behind it
                    rsource = sourceNode.Parent.Name + "/" + rsource;//if @ index is more than 0, the parent has already been included

                //MessageBox.Show(rsource + "\n\n" + target);
                templateVMR.updateXmlNodeByValue(rsource, target);

                //MessageBox.Show(templateVM.TemplateXmlNode.OuterXml + "\n\n" + templateVMR.TemplateXmlNode.OuterXml);

                //Abstraction mechanism and rule indexing (no use)
                AbstractTreeLatticeNode toMatch = sourceLatticeNodeToMatch.findChildrenByAddress(sourceNode.getRelativeAddress(templateVM.HeaderNode));
                AbstractTreeLatticeNode targetMatch = abstractTree.getAbstractNodeAtAddress(targetElement);

                if (toMatch != null && targetMatch != null)
                {
                    //assign an index for source rule correspondence
                    toMatch.isMatched = true;
                    toMatch.ruleIndex = RULEINDEX;

                    //assign same rule index for this.abstractTree
                    targetMatch.isMatched = true;
                    targetMatch.ruleIndex = RULEINDEX;

                    //increment index for other correspondences
                    RULEINDEX++;

                }

                return true;
            }
            else
            {
                ShowStatus("Please set the top element correspondence first!", ReportIcon.Error);
                return false;
            }
        }
예제 #10
0
        /// <summary>
        /// Analyse abstract Tree node and check for signature with values from treeVNodeViewModel node
        /// </summary>
        /// <param name="node">null if signature is based on AbstractLattice only</param>
        public XmlNode createSignature(TreeNodeViewModel node)
        {
            XmlDocument xDoc = new XmlDocument();

            if (/*this.isAllNodesMatched() ||*/ node == null)
            {
                //create signature form abstract tree
                return this.Root.createSignatureNode();
            }
            else
            {
                //create signature using tree node
                return this.Root.createSignatureNode(node);
                //throw new NotImplementedException();
            }
        }
예제 #11
0
        /// <summary>
        /// Processing based on On-Demand approach
        /// </summary>
        /// <param name="strFile"></param>
        /// <returns></returns>
        private TreeNodeViewModel processXml(string strFile)
        {
            Element root = new Element();//root element
            TreeNodeViewModel rootNode = null;

            try
            {
                using (var reader = XmlReader.Create(strFile))
                {
                    //reader.MoveToContent();

                    //pass any whitespace or useless element
                    while (reader.NodeType != XmlNodeType.Element)
                        reader.Read();

                    //first element
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        //create starting element
                        root = createModelElement(reader);
                        rootNode = new TreeNodeViewModel(root);

                        if ((reader.NodeType == XmlNodeType.Element) && (reader.HasAttributes || !reader.IsEmptyElement))
                            rootNode.hasChildren = true;
                        else if (reader.IsEmptyElement || reader.NodeType == XmlNodeType.Text)
                            rootNode.hasChildren = false;

                    }
                    else
                        MessageBox.Show("First element of Model file is not an XML Element","Exception",MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (XmlException e)
            {
                Console.WriteLine("error occured: " + e.Message);
            }

            return rootNode;
        }
예제 #12
0
        private void initiate(Element rootElement)
        {
            _rootElement = new TreeNodeViewModel(rootElement);

            FirstChild = new Collection<TreeNodeViewModel>(
                new TreeNodeViewModel[]
                {
                    _rootElement
                });
        }