/// <summary>
        /// Import ReqIF Specification
        /// </summary>
        /// <param name="file"></param>
        /// <param name="eaObjectType"></param>
        /// <param name="eaStereotype"></param>
        /// <param name="reqIfContentIndex"></param>
        /// <param name="reqIfSpecIndex"></param>
        /// <param name="stateNew"></param>
        /// <returns></returns>
        private bool ImportSpecification(string file, string eaObjectType, string eaStereotype, int reqIfContentIndex, int reqIfSpecIndex, string stateNew)
        {
            CopyEmbeddedFilesToTarget(file);

            // Deserialize
            ReqIfDeserialized = DeSerializeReqIf(file, validate: Settings.ValidateReqIF);
            if (ReqIfDeserialized == null)
            {
                return(MessageBox.Show("", @"Continue with next reqif file or cancel", MessageBoxButtons.OKCancel) == DialogResult.OK);
            }

            _moduleAttributeDefinitions = GetTypesModule(ReqIfDeserialized, reqIfContentIndex, reqIfSpecIndex);

            // prepare EA, existing requirements to detect deleted and changed requirements
            ReadEaPackageRequirements();
            CreateEaPackageDeletedObjects();


            // Add requirements recursive for module to requirement table
            InitializeReqIfRequirementsTable(ReqIfDeserialized);
            Specification reqIfModule = ReqIfDeserialized.CoreContent[reqIfContentIndex].Specifications[reqIfSpecIndex];

            Rep.BatchAppend     = true;
            Rep.EnableUIUpdates = false;
            UpdatePackage();

            // Read the requirements and put them to data Table
            AddReqIfRequirementsToDataTable(DtRequirements, reqIfModule.Children, 1);

            // Check imported ReqIF requirements
            if (CheckImportedRequirements(file))
            {
                //Rep.RefreshModelView(Pkg.PackageID);
                CreateUpdateDeleteEaRequirements(eaObjectType, eaStereotype, stateNew, "", file);

                //Rep.RefreshModelView(Pkg.PackageID);
                MoveDeletedRequirements();


                // handle links
                ReqIfRelation relations = new ReqIfRelation(ReqIfDeserialized, Rep, Settings);
            }

            Rep.BatchAppend     = false;
            Rep.EnableUIUpdates = true;

            // Update package content
            Rep.ReloadPackage(Pkg.PackageID);
            Rep.RefreshModelView(Pkg.PackageID);
            return(true);
        }
        /// <summary>
        /// Import and update ReqIF Requirements. You can set EA ObjectType like "Requirement" or EA Stereotype like "FunctionalRequirement"
        /// </summary>
        /// async Task
        public override bool ImportForFile(string eaObjectType = "Requirement",
                                           string eaStereotype = "",
                                           string stateNew     = "",
                                           string stateChanged = "")
        {
            bool result = true;

            Rep.BatchAppend     = true;
            Rep.EnableUIUpdates = false;

            // Deserialize
            var reqIf = DeSerializeReqIf(ImportModuleFile, validate: Settings.ValidateReqIF);

            if (reqIf == null)
            {
                return(false);
            }

            InitializeDoorsRequirementsTable(reqIf);


            //reqIf.CoreContent[0].Specifications.Dump();
            // over all submodules
            Specification elModule = reqIf.CoreContent[0].Specifications[0];

            AddRequirements(DtRequirements, elModule.Children, 1);



            base.ReadEaPackageRequirements();
            CreateEaPackageDeletedObjects();



            Count        = 0;
            CountChanged = 0;
            CountNew     = 0;
            List <int> parentElementIdsPerLevel = new List <int> {
                0
            };
            int parentElementId = 0;
            int lastElementId   = 0;

            int oldLevel = 0;

            foreach (DataRow row in DtRequirements.Rows)
            {
                Count += 1;
                string objectId     = row["Id"].ToString();
                string reqAbsNumber = objectId;
                //string reqAbsNumber = GetAbsoluteNumerFromDoorsId(objectId);
                int    objectLevel   = Int32.Parse(row["Object Level"].ToString()) - 1;
                string objectNumber  = row["Object Number"].ToString();
                string objectType    = row["Object Type"].ToString();
                string objectHeading = row["Object Heading"].ToString();


                // Maintain parent ids of level
                // get parent id
                if (objectLevel > oldLevel)
                {
                    if (parentElementIdsPerLevel.Count <= objectLevel)
                    {
                        parentElementIdsPerLevel.Add(lastElementId);
                    }
                    else
                    {
                        parentElementIdsPerLevel[objectLevel] = lastElementId;
                    }
                    parentElementId = lastElementId;
                }
                if (objectLevel < oldLevel)
                {
                    parentElementId = parentElementIdsPerLevel[objectLevel];
                }

                oldLevel = objectLevel;
                string name;
                string notes;

                // Estimate if header
                if (objectType == "headline" || !String.IsNullOrWhiteSpace(objectHeading))
                {
                    name  = $"{objectNumber} {objectHeading}";
                    notes = row["Object Heading"].ToString();
                }
                else
                {
                    notes = row["Object Text"].ToString();
                    string objectShorttext = GetTextExtract(notes);
                    objectShorttext = objectShorttext.Length > ShortNameLength?objectShorttext.Substring(0, ShortNameLength) : objectShorttext;

                    name = objectShorttext;
                    //name = $"{reqAbsNumber.PadRight(7)} {objectShorttext}";
                }
                // Check if requirement with Doors ID already exists
                bool isExistingRequirement = DictPackageRequirements.TryGetValue(reqAbsNumber, out int elId);


                EA.Element el;
                if (isExistingRequirement)
                {
                    el = (EA.Element)Rep.GetElementByID(elId);
                    if (el.Alias != objectId ||
                        el.Name != name ||
                        el.Notes != notes ||
                        el.Type != eaObjectType ||
                        el.Stereotype != eaStereotype)
                    {
                        if (stateChanged != "")
                        {
                            el.Status = stateChanged;
                        }
                        CountChanged += 1;
                    }
                }
                else
                {
                    el = (EA.Element)Pkg.Elements.AddNew(name, "Requirement");
                    if (stateNew != "")
                    {
                        el.Status = stateNew;
                    }
                    CountChanged += 1;
                }


                el.Alias        = objectId;
                el.Name         = name;
                el.Multiplicity = reqAbsNumber;
                el.Notes        = notes;
                el.TreePos      = Count * 10;
                el.PackageID    = Pkg.PackageID;
                el.ParentID     = parentElementId;
                el.Type         = eaObjectType;
                el.Stereotype   = eaStereotype;

                el.Update();
                Pkg.Elements.Refresh();
                lastElementId = el.ElementID;

                // handle the remaining columns/ tagged values
                var cols = from c in DtRequirements.Columns.Cast <DataColumn>()
                           where !ColumnNamesNoTaggedValues.Any(n => n == c.ColumnName)
                           select new
                {
                    Name  = c.ColumnName,
                    Value = row[c].ToString()
                }

                ;
                // Update/Create Tagged value
                foreach (var c in cols)
                {
                    TaggedValue.SetUpdate(el, c.Name, c.Value);
                }
            }

            MoveDeletedRequirements();
            UpdatePackage();

            Rep.BatchAppend     = false;
            Rep.EnableUIUpdates = true;
            Rep.ReloadPackage(Pkg.PackageID);
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Import and update Requirements. You can set EA ObjectType like "Requirement" or EA Stereotype like "FunctionalRequirement"
        /// </summary>
        /// async Task
        public override bool ImportForFile(string eaObjectType = "Requirement",
                                           string eaStereotype = "",
                                           string stateNew     = "",
                                           string stateChanged = "")
        {
            bool result = true;

            Rep.BatchAppend     = true;
            Rep.EnableUIUpdates = false;

            // Read xml file
            XElement xElFile;

            try
            {
                xElFile = XElement.Parse(HoUtil.ReadAllText(ImportModuleFile));
            }
            catch (Exception e)
            {
                Rep.BatchAppend     = false;
                Rep.EnableUIUpdates = true;
                MessageBox.Show($@"File: {ImportModuleFile}{Environment.NewLine}{Environment.NewLine}{e}", @"Can't import structured *.xml");
                return(false);
            }

            InitializeXmlStructTable(xElFile);

            // Go through hierarchy and store in DataTable
            var level    = 1;
            var children = xElFile.Descendants(xmlChildrenName).FirstOrDefault(); //.Dump();

            if (OutputChildren(children, level) == false)
            {
                return(false);
            }



            ReadEaPackageRequirements();
            CreateEaPackageDeletedObjects();

            Count        = 0;
            CountChanged = 0;
            CountNew     = 0;
            List <int> parentElementIdsPerLevel = new List <int> {
                0
            };
            int parentElementId = 0;
            int lastElementId   = 0;

            int oldLevel = 0;

            string notesColumn = _settings.AttrNotes ?? "";

            foreach (DataRow row in DtRequirements.Rows)
            {
                Count += 1;



                int objectLevel = Int32.Parse(row["Object Level"].ToString()) - 1;

                // Maintain parent ids of level
                // get parent id
                if (objectLevel > oldLevel)
                {
                    if (parentElementIdsPerLevel.Count <= objectLevel)
                    {
                        parentElementIdsPerLevel.Add(lastElementId);
                    }
                    else
                    {
                        parentElementIdsPerLevel[objectLevel] = lastElementId;
                    }
                    parentElementId = lastElementId;
                }

                if (objectLevel < oldLevel)
                {
                    parentElementId = parentElementIdsPerLevel[objectLevel];
                }

                oldLevel = objectLevel;

                string objectId  = CombineAttrValues(_settings.IdList, row, ShortNameLength);
                string alias     = CombineAttrValues(_settings.AliasList, row, ShortNameLength);
                string name      = CombineAttrValues(_settings.AttrNameList, row, ShortNameLength);
                string notes     = notesColumn != "" ? row[notesColumn].ToString() : row[1].ToString();
                string nameShort = name.Length > ShortNameLength?name.Substring(0, ShortNameLength) : name;

                // Check if requirement with Doors ID already exists
                bool isExistingRequirement = DictPackageRequirements.TryGetValue(objectId, out int elId);


                EA.Element el;
                if (isExistingRequirement)
                {
                    el = Rep.GetElementByID(elId);
                    if (el.Alias != alias ||
                        el.Name != nameShort ||
                        el.Notes != notes)
                    {
                        if (stateChanged != "")
                        {
                            el.Status = stateChanged;
                        }
                        CountChanged += 1;
                    }
                }
                else
                {
                    el = (EA.Element)Pkg.Elements.AddNew(name, "Requirement");
                    if (stateNew != "")
                    {
                        el.Status = stateNew;
                    }
                    CountChanged += 1;
                }


                el.Alias        = alias;
                el.Name         = name;
                el.Multiplicity = objectId;
                el.Notes        = notes;
                el.TreePos      = Count * 10;
                el.PackageID    = Pkg.PackageID;
                el.ParentID     = parentElementId;
                el.Type         = eaObjectType;
                el.Stereotype   = eaStereotype;

                el.Update();
                Pkg.Elements.Refresh();
                lastElementId = el.ElementID;

                // handle the remaining columns/ tagged values
                var cols = from c in DtRequirements.Columns.Cast <DataColumn>()
                           where !ColumnNamesNoTaggedValues.Any(n => n == c.ColumnName)
                           select new
                {
                    Name  = c.ColumnName,
                    Value = row[c].ToString()
                }

                ;


                // Update/Create Tagged value
                foreach (var c in cols)
                {
                    if (notesColumn != c.Name)
                    {
                        TaggedValue.SetUpdate(el, c.Name, c.Value ?? "");
                    }
                }
            }

            MoveDeletedRequirements();
            UpdatePackage(xElFile);

            Rep.BatchAppend     = false;
            Rep.EnableUIUpdates = true;
            Rep.ReloadPackage(Pkg.PackageID);
            return(result);
        }