Пример #1
0
        /// <summary>
        /// Import and update Requirements. You can set EA ObjectType like "Requirement" or EA Stereotype like "FunctionalRequirement"
        /// </summary>
        /// async Task
        public virtual bool ImportForFile(string eaObjectType = "Requirement",
                                          string eaStereotype = "",
                                          string stateNew     = "",
                                          string stateChanged = "")
        {
            _rep.BatchAppend     = true;
            _rep.EnableUIUpdates = false;

            // Prepare
            _dtRequirements = ExpImp.MakeDataTableFromCsvFile(_importModuleFile, ',');

            ReadEaPackageRequirements();
            CreateEaPackageDeletedObjects();

            _count        = 0;
            _countAll     = 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  = GetAbsoluteNumerFromDoorsId(objectId);
                int    objectLevel   = Int32.Parse(row["Object Level"].ToString()) - 1;
                string objectNumber  = row["Object Number"].ToString();
                string objectType    = row["ObjectType"].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 = $"{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 = _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(true);
        }