Ejemplo n.º 1
0
        private bool MoveUpElementCanExecute(object parameter)
        {
            IDsmElement current  = SelectedProvider;
            IDsmElement previous = _application.PreviousSibling(current);

            return((current != null) && (previous != null));
        }
Ejemplo n.º 2
0
        private bool MoveDownElementCanExecute(object parameter)
        {
            IDsmElement current = SelectedProvider;
            IDsmElement next    = _application.NextSibling(current);

            return((current != null) && (next != null));
        }
Ejemplo n.º 3
0
        private void UpdateCellTooltip(int?row, int?column)
        {
            if (row.HasValue && column.HasValue)
            {
                IDsmElement consumer = _elementViewModelLeafs[column.Value].Element;
                IDsmElement provider = _elementViewModelLeafs[row.Value].Element;

                if ((consumer != null) && (provider != null))
                {
                    int       weight    = _application.GetDependencyWeight(consumer, provider);
                    CycleType cycleType = _application.IsCyclicDependency(consumer, provider);

                    string cycleText = "";
                    if (cycleType == CycleType.Hierarchical)
                    {
                        cycleText = "with hierarchical cycle";
                    }
                    if (cycleType == CycleType.System)
                    {
                        cycleText = "with system cycle";
                    }
                    CellTooltip = $"[{consumer.Order}] {consumer.Fullname} to [{consumer.Order}] {consumer.Fullname} weight={weight} {cycleText}";
                }
            }
        }
Ejemplo n.º 4
0
        private HashSet <int> GetIdsOfElementAndItsChidren(IDsmElement element)
        {
            HashSet <int> ids = new HashSet <int>();

            GetIdsOfElementAndItsChidren(element, ids);
            return(ids);
        }
Ejemplo n.º 5
0
        public int GetSystemCycleCount(IDsmElement element)
        {
            int cyclesCount = 0;

            CountCycles(element, CycleType.System, ref cyclesCount);
            return(cyclesCount / 2);
        }
Ejemplo n.º 6
0
        private void OnRunSearch()
        {
            _foundElements = _application.SearchElements(SearchText).ToList();
            int count = _foundElements.Count;

            if (count == 0)
            {
                SearchState  = SearchState.NoMatch;
                SearchResult = SearchText.Length > 0 ? "None found" : "";
            }
            else if (count == 1)
            {
                IDsmElement foundElement = _foundElements.FirstOrDefault();
                if ((foundElement != null) && (foundElement.Fullname != SearchText))
                {
                    SearchText = foundElement.Fullname;
                }
                SearchState  = SearchState.OneMatch;
                SearchResult = "1 found";
            }
            else if (count > 1)
            {
                SearchState  = SearchState.ManyMatches;
                SearchResult = $"{count} found";
            }
        }
Ejemplo n.º 7
0
        public void GivenAnElementIsInTheModelWhenSearchIsCalledWithTextPartOfItsNameThenElementIsFound()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.ImportElement(1, "a", "type", 10, true, null, false);

            Assert.IsNotNull(a);

            IDsmElement b = model.ImportElement(2, "b", "type", 11, true, a.Id, false);

            Assert.IsNotNull(b);

            IDsmElement foundElement = model.SearchElements(".b").ToList().FirstOrDefault();

            Assert.IsNotNull(foundElement);
            Assert.AreEqual(2, foundElement.Id);
            Assert.AreEqual("b", foundElement.Name);
            Assert.AreEqual("a.b", foundElement.Fullname);
            Assert.AreEqual("type", foundElement.Type);
            Assert.AreEqual(11, foundElement.Order);
            Assert.AreEqual(true, foundElement.IsExpanded);
            Assert.AreEqual(a, foundElement.Parent);
        }
Ejemplo n.º 8
0
        public int GetElementSize(IDsmElement elenent)
        {
            int count = 0;

            CountChildern(elenent, ref count);
            return(count);
        }
Ejemplo n.º 9
0
        public int GetHierarchicalCycleCount(IDsmElement element)
        {
            int cyclesCount = 0;

            CountCycles(element, CycleType.Hierarchical, ref cyclesCount);
            return(cyclesCount / 2);
        }
Ejemplo n.º 10
0
        public IEnumerable <IDsmRelation> FindInternalRelations(IDsmElement element)
        {
            List <IDsmRelation> relations   = new List <IDsmRelation>();
            HashSet <int>       consumerIds = GetIdsOfElementAndItsChidren(element);

            foreach (int consumerId in consumerIds)
            {
                if (_relationsByConsumer.ContainsKey(consumerId))
                {
                    foreach (Dictionary <string, DsmRelation> relationPerType in _relationsByConsumer[consumerId].Values)
                    {
                        foreach (DsmRelation relation in relationPerType.Values)
                        {
                            if (consumerIds.Contains(relation.ProviderId))
                            {
                                if (!relation.IsDeleted)
                                {
                                    relations.Add(relation);
                                }
                            }
                        }
                    }
                }
            }
            return(relations);
        }
Ejemplo n.º 11
0
        private void WriteElement(XmlWriter writer, IDsmElement element, IProgress <ProgressInfo> progress)
        {
            writer.WriteStartElement(ElementXmlNode);
            writer.WriteAttributeString(ElementIdXmlAttribute, element.Id.ToString());
            writer.WriteAttributeString(ElementOrderXmlAttribute, element.Order.ToString());
            writer.WriteAttributeString(ElementNameXmlAttribute, element.Name);
            writer.WriteAttributeString(ElementTypeXmlAttribute, element.Type);
            writer.WriteAttributeString(ElementExpandedXmlAttribute, element.IsExpanded.ToString());
            if (element.IsDeleted)
            {
                writer.WriteAttributeString(ElementDeletedXmlAttribute, "true");
            }
            if ((element.Parent != null) && (element.Parent.Id > 0))
            {
                writer.WriteAttributeString(ElementParentXmlAttribute, element.Parent.Id.ToString());
            }
            writer.WriteEndElement();

            _progressedElementCount++;
            UpdateProgress(progress);

            foreach (IDsmElement child in element.ExportedChildren)
            {
                WriteElement(writer, child, progress);
            }
        }
Ejemplo n.º 12
0
        public void GivenAnElementIsInTheModelWhenFindByIdIsCalledWithItsNameThenElementIsFound()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.ImportElement(1, "a", "type", 10, true, null, false);

            Assert.IsNotNull(a);

            IDsmElement b = model.ImportElement(2, "b", "type", 11, true, a.Id, false);

            Assert.IsNotNull(b);

            IDsmElement foundElement = model.FindElementByFullname("a.b");

            Assert.IsNotNull(foundElement);
            Assert.AreEqual(2, foundElement.Id);
            Assert.AreEqual("b", foundElement.Name);
            Assert.AreEqual("a.b", foundElement.Fullname);
            Assert.AreEqual("type", foundElement.Type);
            Assert.AreEqual(11, foundElement.Order);
            Assert.AreEqual(true, foundElement.IsExpanded);
            Assert.AreEqual(a, foundElement.Parent);
        }
Ejemplo n.º 13
0
        public IDsmElement AddElement(string name, string type, int?parentId)
        {
            Logger.LogDataModelMessage($"Add element name={name} type={type} parentId={parentId}");

            string fullname = name;

            if (parentId.HasValue)
            {
                if (_elementsById.ContainsKey(parentId.Value))
                {
                    ElementName elementName = new ElementName(_elementsById[parentId.Value].Fullname);
                    elementName.AddNamePart(name);
                    fullname = elementName.FullName;
                }
            }

            IDsmElement element = FindElementByFullname(fullname);

            if (element == null)
            {
                _lastElementId++;
                element = AddElement(_lastElementId, name, type, 0, false, parentId, false);
            }

            return(element);
        }
Ejemplo n.º 14
0
        public ElementMoveDownAction(IDsmModel model, IDsmElement element)
        {
            _model = model;
            Debug.Assert(_model != null);

            _element = element;
            Debug.Assert(_element != null);
        }
Ejemplo n.º 15
0
 public AlphabeticalSortAlgorithm(object[] args)
 {
     Debug.Assert(args.Length == 2);
     _model = args[0] as IDsmModel;
     Debug.Assert(_model != null);
     _element = args[1] as IDsmElement;
     Debug.Assert(_element != null);
 }
Ejemplo n.º 16
0
 private void NavigateToSelectedElement()
 {
     if (_foundElementIndex.HasValue)
     {
         IDsmElement foundElement = _foundElements[_foundElementIndex.Value];
         ActiveMatrix?.NavigateToSelectedElement(foundElement);
     }
 }
Ejemplo n.º 17
0
        public void GivenMultipleElementAreInTheModelWhenAssignElementOrderIsCalledThenElementsHaveOrderSet()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.ImportElement(1, "a", "", 0, false, null, false);

            Assert.AreEqual(1, a.Id);
            IDsmElement a1 = model.ImportElement(2, "a1", "eta", 0, false, a.Id, false);

            Assert.AreEqual(2, a1.Id);

            IDsmElement b = model.ImportElement(3, "b", "", 0, false, null, false);

            Assert.AreEqual(3, b.Id);
            IDsmElement b1 = model.ImportElement(4, "b1", "etb", 0, false, b.Id, false);

            Assert.AreEqual(4, b1.Id);
            IDsmElement b2 = model.ImportElement(5, "b2", "etb", 0, false, b.Id, false);

            Assert.AreEqual(5, b2.Id);

            IDsmElement c = model.ImportElement(6, "c", "", 0, false, null, false);

            Assert.AreEqual(6, c.Id);
            IDsmElement c1 = model.ImportElement(7, "c1", "etc", 0, false, c.Id, false);

            Assert.AreEqual(7, c1.Id);
            IDsmElement c2 = model.ImportElement(8, "c2", "etc", 0, false, c.Id, false);

            Assert.AreEqual(8, c2.Id);
            IDsmElement c3 = model.ImportElement(9, "c3", "etc", 0, false, c.Id, false);

            Assert.AreEqual(9, c3.Id);

            Assert.AreEqual(0, a.Order);
            Assert.AreEqual(0, a1.Order);
            Assert.AreEqual(0, b.Order);
            Assert.AreEqual(0, b1.Order);
            Assert.AreEqual(0, b2.Order);
            Assert.AreEqual(0, c.Order);
            Assert.AreEqual(0, c1.Order);
            Assert.AreEqual(0, c2.Order);
            Assert.AreEqual(0, c3.Order);

            model.AssignElementOrder();

            Assert.AreEqual(1, a.Order);
            Assert.AreEqual(2, a1.Order);
            Assert.AreEqual(3, b.Order);
            Assert.AreEqual(4, b1.Order);
            Assert.AreEqual(5, b2.Order);
            Assert.AreEqual(6, c.Order);
            Assert.AreEqual(7, c1.Order);
            Assert.AreEqual(8, c2.Order);
            Assert.AreEqual(9, c3.Order);
        }
Ejemplo n.º 18
0
        public object Do()
        {
            _element = _model.AddElement(_name, _type, _parent.Id);
            Debug.Assert(_element != null);

            _model.AssignElementOrder();

            return(_element);
        }
Ejemplo n.º 19
0
        public ElementCreateAction(IDsmModel model, string name, string type, IDsmElement parent)
        {
            _model = model;
            Debug.Assert(_model != null);

            _name   = name;
            _type   = type;
            _parent = parent;
        }
Ejemplo n.º 20
0
        public void Undo()
        {
            IDsmElement nextElement = _model.NextSibling(_element);

            Debug.Assert(nextElement != null);

            _model.Swap(nextElement, _element);
            _model.AssignElementOrder();
        }
Ejemplo n.º 21
0
        public void Undo()
        {
            IDsmElement previousElement = _model.PreviousSibling(_element);

            Debug.Assert(previousElement != null);

            _model.Swap(previousElement, _element);
            _model.AssignElementOrder();
        }
Ejemplo n.º 22
0
        public void ChangeElementType(IDsmElement element, string type)
        {
            DsmElement changedElement = element as DsmElement;

            if (changedElement != null)
            {
                changedElement.Type = type;
            }
        }
Ejemplo n.º 23
0
        public IEnumerable <IDsmResolvedRelation> FindRelations(IDsmElement consumer, IDsmElement provider)
        {
            var relations = ResolveRelations(_model.FindRelations(consumer, provider))
                            .OrderBy(x => x.ProviderElement.Fullname)
                            .ThenBy(x => x.ConsumerElement.Fullname)
                            .ToList();

            return(relations);
        }
Ejemplo n.º 24
0
        private void CountChildern(IDsmElement element, ref int count)
        {
            count++;

            foreach (IDsmElement child in element.Children)
            {
                CountChildern(child, ref count);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Remove a child from the element.
        /// </summary>
        /// <param name="child">The child to be added</param>
        public void RemoveChild(IDsmElement child)
        {
            _children.Remove(child);
            DsmElement c = child as DsmElement;

            if (c != null)
            {
                c._parent = null;
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Add a child to the element.
        /// </summary>
        /// <param name="child">The child to be added</param>
        public void AddChild(IDsmElement child)
        {
            _children.Add(child);
            DsmElement c = child as DsmElement;

            if (c != null)
            {
                c._parent = this;
            }
        }
Ejemplo n.º 27
0
        public ElementEditNameViewModel(IDsmApplication application, IDsmElement element)
        {
            _application = application;
            _element     = element;

            Title = $"Edit element name {element.Fullname}";
            Name  = _element.Name;

            AcceptChangeCommand = new RelayCommand <object>(AcceptChangeExecute, AcceptChangeCanExecute);
        }
Ejemplo n.º 28
0
        public object Do()
        {
            IDsmElement nextElement = _model.NextSibling(_element);

            Debug.Assert(nextElement != null);

            _model.Swap(_element, nextElement);
            _model.AssignElementOrder();
            return(null);
        }
Ejemplo n.º 29
0
        public void GivenMultipleElementAreInTheModelWhenGetElementsIsCalledTheyAreAllReturned()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.AddElement("a", "", null);

            Assert.AreEqual(1, a.Id);
            IDsmElement a1 = model.AddElement("a1", "eta", a.Id);

            Assert.AreEqual(2, a1.Id);

            IDsmElement b = model.AddElement("b", "", null);

            Assert.AreEqual(3, b.Id);
            IDsmElement b1 = model.AddElement("b1", "etb", b.Id);

            Assert.AreEqual(4, b1.Id);
            IDsmElement b2 = model.AddElement("b2", "etb", b.Id);

            Assert.AreEqual(5, b2.Id);

            IDsmElement c = model.AddElement("c", "", null);

            Assert.AreEqual(6, c.Id);
            IDsmElement c1 = model.AddElement("c1", "etc", c.Id);

            Assert.AreEqual(7, c1.Id);
            IDsmElement c2 = model.AddElement("c2", "etc", c.Id);

            Assert.AreEqual(8, c2.Id);
            IDsmElement c3 = model.AddElement("c3", "etc", c.Id);

            Assert.AreEqual(9, c3.Id);

            List <IDsmElement> rootElements = model.GetRootElement().Children.OrderBy(x => x.Id).ToList();

            Assert.AreEqual(3, rootElements.Count);

            Assert.AreEqual(a, rootElements[0]);
            Assert.AreEqual(1, rootElements[0].Children.Count);
            Assert.AreEqual(a1, rootElements[0].Children[0]);

            Assert.AreEqual(b, rootElements[1]);
            Assert.AreEqual(2, rootElements[1].Children.Count);
            Assert.AreEqual(b1, rootElements[1].Children[0]);
            Assert.AreEqual(b2, rootElements[1].Children[1]);

            Assert.AreEqual(c, rootElements[2]);
            Assert.AreEqual(3, rootElements[2].Children.Count);
            Assert.AreEqual(c1, rootElements[2].Children[0]);
            Assert.AreEqual(c2, rootElements[2].Children[1]);
            Assert.AreEqual(c3, rootElements[2].Children[2]);
        }
Ejemplo n.º 30
0
        public ElementSortAction(IDsmModel model, IDsmElement element, string algorithm)
        {
            _model = model;
            Debug.Assert(_model != null);

            _element = element;
            Debug.Assert(_element != null);

            _algorithm = algorithm;
            _order     = "";
        }