コード例 #1
0
 /// <summary>
 /// Adds an element to the tree but not to the head
 /// </summary>
 void AddElementNotToHead(Operator cursor, ITreeElement newElement, ref bool isElementAdded)
 {
     if (cursor == null)
     {
         throw new InvalidOperationException("Error");
     }
     if (!isElementAdded)
     {
         if (cursor.Left == null)
         {
             cursor.Left    = newElement;
             isElementAdded = true;
             return;
         }
         if (cursor.Left is Operator)
         {
             AddElementNotToHead(cursor.Left as Operator, newElement, ref isElementAdded);
         }
     }
     if (!isElementAdded)
     {
         if (cursor.Right == null)
         {
             cursor.Right   = newElement;
             isElementAdded = true;
             return;
         }
         if (cursor.Right is Operator)
         {
             AddElementNotToHead(cursor.Right as Operator, newElement, ref isElementAdded);
         }
     }
 }
コード例 #2
0
 public Tree(ITreeElement root)
 {
     this.parameters = new Dictionary <IFilter, string>();
     this.Root       = root;
     this.Current    = root;
     this.stack      = new Stack <ITreeElement>();
 }
コード例 #3
0
        private string ToString(ITreeElement element, int depth)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(' ', depth).Append(element.Caption);
            foreach (IFilter f in element.AvailableFilters)
            {
                builder.Append("   ").Append(f.Name).Append(": ");
                foreach (string s in element.GetFilterValues(f))
                {
                    builder.Append(s).Append(" ");
                }
            }
            foreach (ITreeElement el in element.Children)
            {
                builder.Append("\n").Append(this.ToString(el, depth + 1));
            }

            /*foreach(ITreeElement el in element.Children)
             * {
             *  builder.Append(' ', depth).Append(el.Caption);
             *  foreach(IFilter f in el.AvailableFilters)
             *  {
             *      builder.Append("   ").Append(f.Name).Append(": ");
             *      foreach (string s in el.GetFilterValues(f))
             *          builder.Append(s).Append(" ");
             *  }
             *
             *  builder.Append("\n").Append(this.ToString(el, depth + 1));
             * }*/
            return(builder.ToString());
        }
コード例 #4
0
        public Deserializer(string filepath, string localization)
        {
            this.localization = localization;

            //Parse JSON into our auxiliary system
            string data = System.IO.File.ReadAllText(filepath);

            this.dataStructure = new AuxiliaryDataStructure();
            JToken token = (JToken)JsonConvert.DeserializeObject(data);

            this.dataStructure = token.ToObject <AuxiliaryDataStructure>();
            JToken            treeToken = token.Children <JProperty>().FirstOrDefault(x => x.Name == "tree");
            AuxiliaryTreeNode tree      = new AuxiliaryTreeNode();

            FillAuxiliaryTree(treeToken, ref tree);
            this.dataStructure.Tree = tree;

            //Set available_filters category
            this.availableFilters = new HashSet <IFilter>(dataStructure.AvailableFilters.Items.Values
                                                          .Select(x => new Filter.Filter(this.GetNameWithLocalization(x.Caption), x.Values.Values
                                                                                         .Select(y => this.GetNameWithLocalization(y.Caption)))));

            this.defaultFilters = new HashSet <IFilter>(this.availableFilters
                                                        .Where(x => this.dataStructure.AvailableFilters.Items
                                                               .Where(y => this.dataStructure.AvailableFilters.DefaultList.Contains(y.Key))
                                                               .Select(z => this.GetNameWithLocalization(z.Value.Caption))
                                                               .Contains(x.Name)));

            //Set tree_elements category
            this.treeElements = new HashSet <ITreeElement>();
            foreach (KeyValuePair <string, AuxiliaryItem> pair in this.dataStructure.TreeElements)
            {
                Dictionary <IFilter, IEnumerable <string> > filters = new Dictionary <IFilter, IEnumerable <string> >();
                if (pair.Value.Filters != null)
                {
                    foreach (KeyValuePair <string, List <string> > f in pair.Value.Filters)
                    {
                        filters.Add(this.GetFilter(f.Key), f.Value.Select(fil => this.GetNameWithLocalization(this.dataStructure.AvailableFilters.Items[f.Key].Values[fil].Caption)));
                    }
                }
                this.treeElements.Add(new TreeElement.TreeElement(
                                          pair.Key,
                                          pair.Value.Caption == null ? pair.Key : this.GetNameWithLocalization(pair.Value.Caption),
                                          this.defaultFilters
                                          .Union(pair.Value.FilterList == null ? new List <IFilter>() : this.availableFilters
                                                 .Where(x => this.dataStructure.AvailableFilters.Items
                                                        .Where(y => pair.Value.FilterList.Contains(y.Key))
                                                        .Select(z => this.GetNameWithLocalization(z.Value.Caption))
                                                        .Contains(x.Name))),
                                          filters
                                          ));
            }

            //Generate Tree
            ITreeElement root = this.GetTreeElement(this.dataStructure.Tree.Children.First().Key);

            this.FillResultTree(root, this.dataStructure.Tree.Children.First().Value);
            this.Tree = new Tree.Tree(root);
        }
コード例 #5
0
 private void FillResultTree(ITreeElement treeElement, AuxiliaryTreeNode nodeInfo)
 {
     foreach (KeyValuePair <string, AuxiliaryTreeNode> pair in nodeInfo.Children)
     {
         ITreeElement child = this.GetTreeElement(pair.Key);
         FillResultTree(child, pair.Value);
         treeElement.AddChild(child);
     }
 }
コード例 #6
0
        private string Depth(ITreeElement element)
        {
            if (element.Parent != null)
            {
                return($"-{Depth(element.Parent)}");
            }

            return("");
        }
コード例 #7
0
        public void Update()
        {
            TreeView tree = View.docTreeViewControl;

            if (tree.SelectedItem != null)
            {
                ITreeElement selected_item = tree.SelectedItem as ITreeElement;
                this.Path.Text = Utils.getFullPath(selected_item.Node);
            }
        }
コード例 #8
0
        /// <summary>
        /// Adds an element to the tree
        /// </summary>
        void AddElementInTree(ITreeElement newElement)
        {
            if (head == null)
            {
                head = newElement;
                return;
            }

            bool addedElement = false;

            AddElementNotToHead(head as Operator, newElement, ref addedElement);
        }
コード例 #9
0
        public void Update()
        {
            TreeView tree = View.docTreeViewControl;

            if (tree.SelectedItem != null)
            {
                ITreeElement selected_item = tree.SelectedItem as ITreeElement;
                this.Path.Text = Utils.getFullPath(selected_item.Node);
            }
            NextValue.Text = ((SequenceTransformRule)Copy).NextValueItem;
            NextIndex.Text = ((SequenceTransformRule)Copy).NextValue.ToString();
        }
コード例 #10
0
 private void TreeViewItem_MouseRightButton(object source, RoutedEventArgs e)
 {
     if (!e.Handled)
     {
         TreeViewItem el      = source as TreeViewItem;
         ITreeElement tree_el = el?.DataContext as ITreeElement;
         if (tree_el != null)
         {
             tree_el.Expanded = true;
             tree_el.ChainExpand();
         }
         e.Handled = true;
     }
 }
コード例 #11
0
        public void Update()
        {
            TreeView tree = View.docTreeViewControl;

            if (tree.SelectedItem != null)
            {
                ITreeElement selected_item = tree.SelectedItem as ITreeElement;
                this.Path.Text = Utils.getFullPath(selected_item.Node);
                if (this.CurVal.Text == string.Empty)
                {
                    this.CurVal.Text = selected_item.Node.InnerText;
                }
            }
        }
コード例 #12
0
        private void NewIncrement_Clicked(object source, RoutedEventArgs e)
        {
            ITreeElement item          = (ITreeElement)View.ruleTree.docTreeViewer.SelectedItem;
            string       path          = Utils.getFullPath(item?.Node as XmlNode);
            string       current_value = "";

            if (item != null)
            {
                current_value = ((XmlNode)item.Node).InnerText;
            }
            IncrementStringTransformRule rule = new IncrementStringTransformRule(current_value, path);

            RulePropsDrawer.DrawRule(View.ruleProps, rule, View);
            CollapseExpander();
        }
コード例 #13
0
        /// <summary>
        /// Prints a tree element
        /// </summary>
        void PrintTreeElement(ITreeElement currentElement)
        {
            if (currentElement is Operator && (currentElement as Operator).Left != null)
            {
                Console.Write("( ");
                PrintTreeElement((currentElement as Operator).Left);
            }

            currentElement.Print();
            Console.Write(" ");

            if (currentElement is Operator && (currentElement as Operator).Right != null)
            {
                PrintTreeElement((currentElement as Operator).Right);
                Console.Write(") ");
            }
        }
コード例 #14
0
        private void NewSequence_Clicked(object source, RoutedEventArgs e)
        {
            ITreeElement item          = (ITreeElement)View.ruleTree.docTreeViewer.SelectedItem;
            string       path          = Utils.getFullPath(item?.Node as XmlNode);
            string       current_value = "Value";

            if (item != null)
            {
                current_value = item.Node.InnerText;
            }
            SequenceTransformRule rule = new SequenceTransformRule(new List <string>()
            {
                current_value
            }, path, 0);

            RulePropsDrawer.DrawRule(View.ruleProps, rule, View);
            CollapseExpander();
        }
コード例 #15
0
 public ITreeElement GoToChild(ITreeElement child)
 {
     if (this.Current.Children.Contains(child))
     {
         ITreeElement c = child;
         do
         {
             stack.Push(Current);
             Current = c;
             if (Current.Children.Count() == 0)
             {
                 return(this.Current);
             }
             c = c.Children.First();
         } while (Current.Children.Count() == 1);
         return(this.Current);
     }
     return(null);
 }
コード例 #16
0
        public void Save()
        {
            // Check if Node is Valid
            ITreeElement sel_element = View.ruleTree.docTreeViewer.SelectedItem as ITreeElement;
            XmlNode      node        = sel_element?.Node; // TODO change

            if (node != null)
            {
                if (!Copy.Validator.Validate(node))
                {
                    MessageBox.Show("This rule is not valid for the selected Node. Please select other node/rule.", "Invalid Node/Rule", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    View.ViewModel.CloseProps();
                    return;
                }
                View.ViewModel.testCase.AddRule(Copy.Path, Copy);
                if (Rule.Parent == null)
                {
                    View.ViewModel.Rules.Add(Copy);
                }
                else
                {
                    if (MessageBox.Show("Are you sure to modify?", "Modify Rule", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                    {
                        View.ViewModel.testCase.RemoveRule(Rule.Path, Rule);
                        int obsIndex = View.ViewModel.Rules.IndexOf(Rule);
                        View.ViewModel.Rules[obsIndex] = Copy;
                    }
                    else
                    {
                        View.ViewModel.testCase.RemoveRule(Copy.Path, Rule);
                    }
                }
            }
            View.ViewModel.CloseProps();
            View.testCase.Document.TestSuiteSaver.SaveSuite();
        }
コード例 #17
0
        private void TreeViewItem_Loaded(object source, RoutedEventArgs e)
        {
            // tw is the TreeViewItem that gets loaded
            TreeViewItem tw = source as TreeViewItem;

            if (tw != null)
            {
                ITreeElement xNode = tw.DataContext as ITreeElement;
                if (xNode != null && (xNode.Node.NodeType == XmlNodeType.Element || xNode.Node.NodeType == XmlNodeType.Attribute))
                {
                    string path = Utils.getFullPath(xNode.Node);
                    // add the current treeviewitem to the table
                    NodeMap[path] = tw;
                    // Try get the previous state of this node. Copy expanded attribute if found
                    PreviousState.TryGetValue(path, out ITreeElement prev);
                    if (prev != null && prev.Expanded)
                    {
                        tw.IsExpanded = true;
                    }
                    PreviousState[path] = xNode;
                    Act();
                }
            }
        }
コード例 #18
0
 public void SetLeft(ITreeElement left)
 {
     this.left = left;
 }
コード例 #19
0
        public Tree(string input)
        {
            int index = 0;

            this.root = CreateParserTree(input, ref index);
        }
コード例 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AdditionOperationTreeElement"/> class.
 /// </summary>
 /// <param name="leftTreeElement">Pointer to the left son.</param>
 /// <param name="rightTreeElement">Pointer to the right son.</param>
 public AdditionOperationTreeElement(ITreeElement leftTreeElement, ITreeElement rightTreeElement)
     : base(leftTreeElement, rightTreeElement)
 {
 }
コード例 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OperationTreeElement"/> class.
 /// </summary>
 /// <param name="leftTreeElement">Pointer to the left son.</param>
 /// <param name="rightTreeElement">Pointer to the right son.</param>
 protected OperationTreeElement(ITreeElement leftTreeElement, ITreeElement rightTreeElement)
 {
     this.LeftTreeElement  = leftTreeElement ?? throw new ArgumentNullException(nameof(leftTreeElement));
     this.RightTreeElement = rightTreeElement ?? throw new ArgumentNullException(nameof(rightTreeElement));
 }
コード例 #22
0
 public void AddChild(ITreeElement child)
 {
     this.children.Add(child);
 }
コード例 #23
0
 public void SetRight(ITreeElement right)
 {
     this.right = right;
 }
コード例 #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultiplicationOperationTreeElement"/> class.
 /// </summary>
 /// <param name="leftTreeElement">Pointer to the left son.</param>
 /// <param name="rightTreeElement">Pointer to the right son.</param>
 public MultiplicationOperationTreeElement(ITreeElement leftTreeElement, ITreeElement rightTreeElement)
     : base(leftTreeElement, rightTreeElement)
 {
 }
コード例 #25
0
        private void VisitChildrens(ITreeElement element)
        {
            IEnumerable<ITreeElement> childrens = element.GetChilds();

            foreach (var children in childrens)
            {
                children.Visit(this);
            }
        }
コード例 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubtractionOperationTreeElement"/> class.
 /// </summary>
 /// <param name="leftTreeElement">Pointer to the left son.</param>
 /// <param name="rightTreeElement">Pointer to the right son.</param>
 public SubtractionOperationTreeElement(ITreeElement leftTreeElement, ITreeElement rightTreeElement)
     : base(leftTreeElement, rightTreeElement)
 {
 }