public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MddComponent = await _context.MddComponents
                           .Include(x => x.MddApplication)
                           .Include(x => x.MddProperties).FirstOrDefaultAsync(m => m.Id == id);

            if (MddComponent == null)
            {
                return(NotFound());
            }

            return(Page());
        }
Ejemplo n.º 2
0
        public async Task XmiParserAsync(UmlModel model, string filePath)
        {
            var xmiMetaModel = new XmlDocument();

            xmiMetaModel.Load(filePath);

            var stereotypes = GetMddStereotypes(xmiMetaModel.DocumentElement);
            var useCases    = GetUmlUseCase(xmiMetaModel);
            var actors      = GetUmlActor(xmiMetaModel);

            foreach (var useCase in useCases)
            {
                useCase.MddApplicationId = model.MddApplicationId;

                var stereotypesUsed = stereotypes.Where(a => a.ElementId == useCase.UmlElementId);

                if (stereotypesUsed.Any())
                {
                    useCase.MddComponents = new List <MddComponent>();

                    foreach (var stereotype in stereotypesUsed)
                    {
                        if (_context.MddComponents.Any(x => x.MddApplicationId == model.MddApplicationId && x.UmlElementId == stereotype.ElementId && x.Stereotype == stereotype.Name))
                        {
                            break;
                        }

                        var filePathJson = Path.Combine(Directory.GetCurrentDirectory(), "_json", $"{stereotype.Name.ToLower()}.json");

                        var component = new MddComponent();

                        if (File.Exists(filePathJson))
                        {
                            var file = File.ReadAllText(filePathJson);
                            component = JsonConvert.DeserializeObject <MddComponent>(file);
                        }

                        if (component.MddComponents != null && component.MddComponents.Any())
                        {
                            foreach (var comp in component.MddComponents)
                            {
                                comp.Id               = $"{useCase.Id}-{comp.Id}";
                                comp.ParentId         = useCase.Id;
                                comp.MddApplicationId = model.MddApplicationId;
                                comp.UmlUseCaseId     = useCase.Id;


                                if (!string.IsNullOrEmpty(comp.Stereotype))
                                {
                                    var filePathJsonChild = Path.Combine(Directory.GetCurrentDirectory(), "_json", $"{comp.Stereotype}.json");

                                    var childComponent = new MddComponent();

                                    if (File.Exists(filePathJsonChild))
                                    {
                                        var file = File.ReadAllText(filePathJsonChild);
                                        childComponent = JsonConvert.DeserializeObject <MddComponent>(file);
                                    }

                                    comp.Type          = childComponent.Type;
                                    comp.Description   = childComponent.Description;
                                    comp.Configurable  = childComponent.Configurable;
                                    comp.MddProperties = childComponent.MddProperties;
                                }

                                if (!string.IsNullOrEmpty(comp.Connections))
                                {
                                    var connections = comp.Connections.Split(' ').ToArray();

                                    for (var i = 0; i < connections.Length; i++)
                                    {
                                        connections[i] = $"{useCase.Id}-{connections[i]}";
                                    }
                                    comp.Connections = string.Join(' ', connections);
                                }

                                useCase.MddComponents.Add(comp);
                            }
                        }
                        else
                        {
                            component.Id = Guid.NewGuid().ToString();
                            component.MddApplicationId = model.MddApplicationId;
                            component.Stereotype       = stereotype.Name;
                            component.ParentId         = useCase.Id;
                            component.UmlElementId     = useCase.Id;
                            component.UmlUseCaseId     = useCase.Id;

                            useCase.MddComponents.Add(component);
                        }
                    }
                }

                _context.Add(useCase);
                await _context.SaveChangesAsync();
            }
        }