Пример #1
0
        private void ReadActor(XmlNode actor)
        {
            foreach (XmlNode childnode in actor.ChildNodes)
            {
                if (childnode.Name == "xmi:Extension")
                {
                    continue;
                }

                string type   = getType(childnode),
                       parent = getParent(childnode),
                       name   = getName(childnode),
                       id     = getId(childnode);

                if (childnode.Name == ElementTypes.Generalization)
                {
                    type = ElementTypes.Generalization;
                    string from = childnode.Attributes.GetNamedItem("specific")?.Value,
                           to   = childnode.Attributes.GetNamedItem("general")?.Value;

                    elements.Add(id, new Arrow(id, type, name, parent, from, to));
                }
                else
                {
                    mistakes.Add(UCMistakeFactory.Create(MistakesTypes.ERROR, $"Недопустимый элемент: {type} - {name}", ALL_MISTAKES.UCNOAVALABELELEMENT));
                }
            }
        }
Пример #2
0
        private void ReadPackage(XmlNode package)
        {
            foreach (XmlNode childnode in package.ChildNodes)
            {
                if (childnode.Name == "xmi:Extension")
                {
                    continue;
                }

                string type   = getType(childnode),
                       parent = getParent(childnode),
                       name   = getName(childnode),
                       id     = getId(childnode);

                switch (type)
                {
                case ElementTypes.Association:
                {
                    // обработка ассоциации
                    string from = childnode.ChildNodes[1].Attributes.GetNamedItem("type")?.Value,
                           to   = childnode.ChildNodes[2].Attributes.GetNamedItem("type")?.Value;
                    elements.Add(id, new Arrow(id, type, name, parent, from, to));
                    break;
                }

                case ElementTypes.Precedent:
                {
                    elements.Add(id, new Element(id, type, name, parent));
                    ReadPrecedent(childnode);
                    break;
                }

                default:
                {
                    if (childnode.Name == ElementTypes.Comment)
                    {
                        type = ElementTypes.Comment;
                        string to = childnode.Attributes.GetNamedItem("annotatedElement")?.Value;
                        name = childnode.Attributes.GetNamedItem("body")?.Value;
                        elements.Add(id, new Arrow(id, type, name, parent, null, to));
                    }
                    else
                    {
                        mistakes.Add(UCMistakeFactory.Create(
                                         MistakesTypes.ERROR,
                                         $"Недопустимый элемент внутри системы {getName(package)}: {id} - {name}", ALL_MISTAKES.UCNOAVALABELELEMENTINSYSTEM));
                    }
                    break;
                }
                }
            }
        }
Пример #3
0
        private void ReadPrecedent(XmlNode precedent)
        {
            foreach (XmlNode childnode in precedent.ChildNodes)
            {
                if (childnode.Name == "xmi:Extension")
                {
                    continue;
                }

                string type   = childnode.Name,
                       parent = getParent(childnode),
                       name   = getName(childnode),
                       id     = getId(childnode);

                switch (type)
                {
                case ElementTypes.Include:
                {
                    string from = childnode.Attributes.GetNamedItem("includingCase")?.Value,
                           to   = childnode.Attributes.GetNamedItem("addition")?.Value;
                    elements.Add(id, new Arrow(id, type, name, parent, from, to));
                    break;
                }

                case ElementTypes.Extend:
                {
                    string from = childnode.Attributes.GetNamedItem("extension")?.Value,
                           to   = childnode.Attributes.GetNamedItem("extendedCase")?.Value;
                    elements.Add(id, new Arrow(id, type, name, parent, from, to));
                    break;
                }

                case ElementTypes.ExtensionPoint:
                {
                    string to = childnode.Attributes.GetNamedItem("useCase")?.Value;
                    elements.Add(id, new Arrow(id, type, name, parent, null, to));
                    break;
                }

                default:
                {
                    mistakes.Add(UCMistakeFactory.Create(
                                     MistakesTypes.ERROR,
                                     $"Недопустимый элемент элемент внутри системы {getName(precedent.ParentNode)}: {type} - {name}", ALL_MISTAKES.UCNOAVALABELELEMENTINSYSTEM));
                    break;
                }
                }
            }
        }
Пример #4
0
        private void CheckComments()
        {
            var comments = elements.Where(element => element.Value.Type == ElementTypes.Comment);

            foreach (var comment in comments)
            {
                if (string.IsNullOrEmpty(comment.Value.Name))
                {
                    mistakes.Add(UCMistakeFactory.Create(
                                     MistakesTypes.ERROR,
                                     $"Отсутствует текст в условии расширения",
                                     comment.Value, ALL_MISTAKES.UCNOTEXT));
                }
            }
        }
Пример #5
0
        private void CheckActors()
        {
            var actors = elements.Where(element => element.Value.Type == ElementTypes.Actor);

            foreach (var actorName in actors.GroupBy(a => a.Value.Name))
            {
                if (actorName.Count() > 1)
                {
                    var errorElements = elements
                                        .Where(element => element.Value.Type == ElementTypes.Actor && element.Value.Name == actorName.Key);

                    foreach (var element in errorElements)
                    {
                        mistakes.Add(UCMistakeFactory.Create(
                                         MistakesTypes.ERROR,
                                         $"Имя актора не уникально: {actorName.Key}",
                                         element.Value, ALL_MISTAKES.UCREPEAT));
                    }
                }
                var firstWord = actorName.Key.Split(' ')[0];
                if (string.IsNullOrEmpty(actorName.Key.Trim()) || !char.IsUpper(actorName.Key[0]) || !IsNoun(firstWord))
                {
                    var errorElements = elements
                                        .Where(element => element.Value.Type == ElementTypes.Actor && element.Value.Name == actorName.Key);

                    foreach (var element in errorElements)
                    {
                        mistakes.Add(UCMistakeFactory.Create(
                                         MistakesTypes.ERROR,
                                         $"Имя актора не представлено в виде существительного с заглавной буквы: {actorName.Key}",
                                         element.Value, ALL_MISTAKES.UCNOUN));
                    }
                }
            }

            foreach (var actor in actors)
            {
                if (!HaveConnection(actor.Key, ElementTypes.Association))
                {
                    mistakes.Add(UCMistakeFactory.Create(
                                     MistakesTypes.ERROR,
                                     $"Актор не имеет ни одной связи типа ассоцияция с прецедентами: {actor.Value.Name}",
                                     actor.Value, ALL_MISTAKES.UCNOLINK));
                }
            }
        }
Пример #6
0
        private void СheckPackages()
        {
            var packages = elements.Where(element => element.Value.Type == ElementTypes.Package);

            if (packages.Count() == 0)
            {
                mistakes.Add(UCMistakeFactory.Create(
                                 MistakesTypes.ERROR,
                                 $"Отсутствует граница системы", ALL_MISTAKES.UCNOBORDER));
            }


            foreach (var package in packages)
            {
                if (string.IsNullOrEmpty(package.Value.Name.Trim()))
                {
                    mistakes.Add(UCMistakeFactory.Create(
                                     MistakesTypes.ERROR,
                                     $"Отсутствует назние системы",
                                     package.Value, ALL_MISTAKES.UCNONAME));
                }
            }
        }
Пример #7
0
        // Считывание данных во внутреннее представление
        public void ReadData(XmlElement root)
        {
            foreach (XmlNode childnode in root.FirstChild.ChildNodes)
            {
                if (childnode.Name == "packageImport" || childnode.Name == "xmi:Extension")
                {
                    continue;
                }

                string type   = getType(childnode),
                       parent = getParent(childnode),
                       name   = getName(childnode),
                       id     = getId(childnode);

                if (ElementTypes.List.Contains(type))
                {
                    switch (type)
                    {
                    case ElementTypes.Association:
                    {
                        // обработка ассоциации
                        string from = childnode.ChildNodes[1].Attributes.GetNamedItem("type")?.Value,
                               to   = childnode.ChildNodes[2].Attributes.GetNamedItem("type")?.Value;
                        elements.Add(id, new Arrow(id, type, name, parent, from, to));
                        break;
                    }

                    case ElementTypes.Actor:
                    {
                        ReadActor(childnode);
                        var actor = new Element(id, type, name, parent);
                        elements.Add(id, actor);
                        if (!string.IsNullOrWhiteSpace(name))
                        {
                            diagram.Actors.Add(actor);
                        }

                        break;
                    }

                    case ElementTypes.Package:
                    {
                        ReadPackage(childnode);
                        elements.Add(id, new Element(id, type, name, parent));
                        break;
                    }

                    case ElementTypes.Precedent:
                    {
                        elements.Add(id, new Element(id, type, name, parent));
                        ReadPrecedent(childnode);
                        break;
                    }

                    default:
                    {
                        if (childnode.Name == ElementTypes.Comment)
                        {
                            type = ElementTypes.Comment;
                            string to = childnode.Attributes.GetNamedItem("annotatedElement")?.Value;
                            name = childnode.Attributes.GetNamedItem("body")?.Value;
                            elements.Add(id, new Arrow(id, type, name, parent, null, to));
                        }
                        else
                        {
                            mistakes.Add(UCMistakeFactory.Create(
                                             MistakesTypes.ERROR,
                                             $"Элемент находится за пределами системы: {type} - {name}", ALL_MISTAKES.UCBEHINDBORDER));
                        }
                        break;
                    }
                    }
                }
                else
                {
                    mistakes.Add(UCMistakeFactory.Create(
                                     MistakesTypes.ERROR,
                                     $"Недопустимый элемент: {type} - {name}", ALL_MISTAKES.UCNOAVALABELELEMENT));
                }
            }

            // Считывание координат
            if (diagram.Image != null)
            {
                if (!ReadCoordinates(root))
                {
                    mistakes.Add(UCMistakeFactory.Create(MistakesTypes.WARNING, "Координаты отсутствуют", ALL_MISTAKES.UCNOCOORDINATE));
                }
            }
        }
Пример #8
0
        private void CheckPrecedents()
        {
            var extensionPoints = elements.Where(element => element.Value.Type == ElementTypes.ExtensionPoint);

            foreach (var point in extensionPoints)
            {
                if (string.IsNullOrEmpty(point.Value.Name.Trim()))
                {
                    mistakes.Add(UCMistakeFactory.Create(
                                     MistakesTypes.ERROR,
                                     $"Отсутствует текст в точке расширения прецедента",
                                     point.Value, ALL_MISTAKES.UCNOTEXTINPRECEDENT));
                }
            }

            var precedents = elements.Where(element => element.Value.Type == ElementTypes.Precedent);

            foreach (var precedentName in precedents.GroupBy(p => p.Value.Name))
            {
                if (precedentName.Count() > 1)
                {
                    var errorElements = elements
                                        .Where(element => element.Value.Type == ElementTypes.Precedent && element.Value.Name == precedentName.Key);

                    foreach (var element in errorElements)
                    {
                        mistakes.Add(UCMistakeFactory.Create(
                                         MistakesTypes.ERROR,
                                         $"Имя прецедента не уникально: {precedentName.Key}",
                                         element.Value, ALL_MISTAKES.UCREPETEDNAME));
                    }
                }
                var firstWord = precedentName.Key.Split(' ')[0];
                if (string.IsNullOrEmpty(precedentName.Key.Trim()) || !char.IsUpper(precedentName.Key[0]) || !IsVerb(firstWord))
                {
                    var errorElements = elements
                                        .Where(element => element.Value.Type == ElementTypes.Precedent && element.Value.Name == precedentName.Key);

                    foreach (var element in errorElements)
                    {
                        mistakes.Add(UCMistakeFactory.Create(
                                         MistakesTypes.ERROR,
                                         $"Имя прецедента не представлено в виде действия, начинаясь с заглавной буквы: {precedentName.Key}",
                                         element.Value, ALL_MISTAKES.UCBIGLETTER));
                    }
                }
            }

            foreach (var precedent in precedents)
            {
                bool haveAssociation        = HaveConnection(precedent.Value.Id, ElementTypes.Association),
                         haveGeneralization = HaveConnection(precedent.Value.Id, ElementTypes.Generalization),
                         haveExtendsion     = HaveConnection(precedent.Value.Id, ElementTypes.Extend),
                         haveIncluding      = HaveConnection(precedent.Value.Id, ElementTypes.Include);

                if (!haveAssociation && !haveGeneralization && !haveExtendsion && !haveIncluding)
                {
                    mistakes.Add(UCMistakeFactory.Create(
                                     MistakesTypes.ERROR,
                                     $"Прецедент должен иметь связь с актором в виде ассоциации," +
                                     $" либо иметь отношения расширения," +
                                     $" дополнения или включения с другими прецедентами: {precedent.Value.Name}",
                                     precedent.Value, ALL_MISTAKES.UCASSOSIATION));
                }

                if (haveExtendsion)
                {
                    bool havePoint = elements.Where(element =>
                    {
                        if (element.Value.Type != ElementTypes.ExtensionPoint)
                        {
                            return(false);
                        }
                        if (((Arrow)element.Value).To.Equals(precedent.Key))
                        {
                            return(true);
                        }
                        return(false);
                    }).Count() > 0;
                    bool extended = elements.Where(element =>
                    {
                        if (element.Value.Type != ElementTypes.Extend)
                        {
                            return(false);
                        }
                        if (((Arrow)element.Value).To.Equals(precedent.Key))
                        {
                            return(true);
                        }
                        return(false);
                    }).Count() > 0;

                    if (extended && !havePoint)
                    {
                        mistakes.Add(UCMistakeFactory.Create(
                                         MistakesTypes.ERROR,
                                         $"Отсутствие точки расширения у прецедента с отношением расширения: {precedent.Value.Name}",
                                         precedent.Value, ALL_MISTAKES.UCNOPRECEDENTDOT));
                    }
                }

                if (haveIncluding)
                {
                    var includesFrom = elements
                                       .Where(element =>
                    {
                        if (element.Value.Type != ElementTypes.Include)
                        {
                            return(false);
                        }
                        if (((Arrow)element.Value).From.Equals(precedent.Key))
                        {
                            return(true);
                        }
                        return(false);
                    });

                    var includesTo = elements
                                     .Where(element =>
                    {
                        if (element.Value.Type != ElementTypes.Include)
                        {
                            return(false);
                        }
                        if (((Arrow)element.Value).To.Equals(precedent.Key))
                        {
                            return(true);
                        }
                        return(false);
                    });

                    if (includesFrom.Count() > 0 && includesFrom.Count() < 2)
                    {
                        mistakes.Add(UCMistakeFactory.Create(
                                         MistakesTypes.WARNING,
                                         $"Прецедент включает всего один прецедент: {precedent.Value.Name}",
                                         precedent.Value, ALL_MISTAKES.UCONLYONEPRECEDENT));
                    }

                    if (includesFrom.Count() > 0 && includesTo.Count() > 0)
                    {
                        mistakes.Add(UCMistakeFactory.Create(
                                         MistakesTypes.WARNING,
                                         $"Злоупотребление отношением включения: {precedent.Value.Name}",
                                         precedent.Value, ALL_MISTAKES.UCINCLUDE));
                    }
                }
            }
        }