private void DoRefreshIdocTree()
        {
            _idocTreeNodes.Clear();

            var selectedRepositoryItem = this.IdocItemsView.CurrentItem as ControlItem <RepositoryItem>;

            if (selectedRepositoryItem == null ||
                selectedRepositoryItem.Value == null ||
                selectedRepositoryItem.Value.Count == 0)
            {
                return;
            }

            var xmlIdocFilePath = selectedRepositoryItem.Value.XmlIdocFiles.First();

            XDocument document;

            using (var stream = File.OpenRead(xmlIdocFilePath))
            {
                document = XDocument.Load(stream);
            }

            var isAlreadyAutoFocused = false;

            var segmentElements = document.XPathSelectElements("//*[@SEGMENT='1']");

            foreach (var segmentElement in segmentElements)
            {
                var segmentTreeNode = new IdocTreeNode(null)
                {
                    Name = segmentElement.Name.LocalName
                };
                SubscribeToNode(segmentTreeNode);
                _idocTreeNodes.Add(segmentTreeNode);

                var fieldElements = segmentElement.Descendants();
                foreach (var fieldElement in fieldElements)
                {
                    var fieldTreeNode = new IdocTreeNode(segmentTreeNode)
                    {
                        Name       = fieldElement.Name.LocalName,
                        Value      = fieldElement.Value,
                        IsSelected = !isAlreadyAutoFocused && !this.AutoFocusedValue.IsNullOrEmpty() &&
                                     fieldElement.Value == this.AutoFocusedValue
                    };

                    if (fieldTreeNode.IsSelected)
                    {
                        isAlreadyAutoFocused = true;
                    }

                    SubscribeToNode(fieldTreeNode);
                    segmentTreeNode.Children.Add(fieldTreeNode);
                }
            }
        }
 private void SubscribeToNode(IdocTreeNode node)
 {
     node.PropertyChanged += this.IdocTreeNode_PropertyChanged;
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="IdocTreeNode"/> class.
 /// </summary>
 internal IdocTreeNode(IdocTreeNode parent)
 {
     this.Parent   = parent;
     this.Children = new ObservableCollection <IdocTreeNode>();
 }