Ejemplo n.º 1
0
        private ConstraintViewModel BuildConstraint(DB.IObjectRepository tdb, string baseLink,
                                                    IGSettingsManager igSettings, DB.TemplateConstraint dbConstraint, int constraintCount, int?aParentConstraintId = null)
        {
            IFormattedConstraint fc         = FormattedConstraintFactory.NewFormattedConstraint(tdb, igSettings, dbConstraint);
            WIKIParser           wikiParser = new WIKIParser(tdb);

            ConstraintViewModel lGreenViewModel = new ConstraintViewModel()
            {
                constraintLabel    = dbConstraint.Label,
                headingDescription = dbConstraint.HeadingDescription,
                id            = dbConstraint.Id,
                order         = dbConstraint.Order,
                isHeading     = dbConstraint.IsHeading,
                isPrimitive   = dbConstraint.IsPrimitive,
                primitiveText = dbConstraint.PrimitiveText,
                templateId    = dbConstraint.TemplateId,
                number        = dbConstraint.Number,
                text          = fc.GetPlainText(false, false, false),
                conformance   = dbConstraint.Conformance,
                value         = dbConstraint.Value
            };

            lGreenViewModel.constraintDescription = GetConstraintDescription(dbConstraint);

            DB.GreenConstraint lGreenConstraint = dbConstraint.GreenConstraints.DefaultIfEmpty(null).FirstOrDefault();

            if (lGreenConstraint != null)
            {
                lGreenViewModel.Use(c =>
                {
                    c.businessName       = lGreenConstraint.Description;
                    c.elementName        = lGreenConstraint.Name;
                    c.xPath              = lGreenConstraint.RootXpath;
                    c.greenConstraintId  = lGreenConstraint.Id;
                    c.hasGreenConstraint = true;

                    if (lGreenConstraint.ImplementationGuideTypeDataTypeId.HasValue)
                    {
                        c.datatype   = lGreenConstraint.ImplementationGuideTypeDataType.DataTypeName;
                        c.datatypeId = lGreenConstraint.ImplementationGuideTypeDataType.Id;
                    }
                });
            }

            if (aParentConstraintId.HasValue)
            {
                lGreenViewModel.parentConstraintId = aParentConstraintId.Value;
            }

            int nextConstraintCount = 0;

            foreach (DB.TemplateConstraint cDbConstraint in dbConstraint.ChildConstraints.Where(cc => cc.IsPrimitive == false).OrderBy(y => y.Order))
            {
                ConstraintViewModel nextNewConstraint
                    = BuildConstraint(tdb, baseLink, igSettings, cDbConstraint, ++nextConstraintCount, dbConstraint.Id);
                lGreenViewModel.children.Add(nextNewConstraint);
            }

            return(lGreenViewModel);
        }
Ejemplo n.º 2
0
        private void UpdateConstraint(DB.GreenTemplate aTemplate, ConstraintViewModel aViewModel, DB.GreenConstraint aParentConstraint = null)
        {
            if ((aViewModel.hasGreenConstraint || aViewModel.isDeleted) && aViewModel.greenConstraintId.HasValue)
            {
                this.UpdateConstraint(aViewModel);
            }

            if (aViewModel.hasGreenConstraint && aViewModel.greenConstraintId.HasValue == false && aViewModel.isDeleted == false) //Is New
            {
                DB.GreenConstraint lNewConstraint = this.AddNewConstraint(aViewModel);

                if (aParentConstraint != null)
                {
                    aParentConstraint.ChildGreenConstraints.Add(lNewConstraint);
                }

                aTemplate.ChildGreenConstraints.Add(lNewConstraint);

                foreach (ConstraintViewModel lChild in aViewModel.children)
                {
                    this.UpdateConstraint(aTemplate, lChild, lNewConstraint);
                }
            }
            else
            {
                foreach (ConstraintViewModel lChild in aViewModel.children)
                {
                    this.UpdateConstraint(aTemplate, lChild);
                }
            }
        }
Ejemplo n.º 3
0
        private void UpdateConstraint(ConstraintViewModel aConstraint)
        {
            if (aConstraint.greenConstraintId.HasValue && aConstraint.isDeleted)
            {
                DB.GreenConstraint lModelToDelete = _tdb.GreenConstraints.Single(gc => gc.Id == aConstraint.greenConstraintId);

                foreach (DB.GreenConstraint lChild in lModelToDelete.ChildGreenConstraints.ToList())
                {
                    lChild.ParentGreenConstraint   = null;
                    lChild.ParentGreenConstraintId = null;
                }

                _tdb.GreenConstraints.DeleteObject(lModelToDelete);
            }
            else if (aConstraint.greenConstraintId.HasValue && aConstraint.isDeleted == false)
            {
                DB.GreenConstraint lModelToUpdate = _tdb.GreenConstraints.DefaultIfEmpty(null).SingleOrDefault(gc => gc.Id == aConstraint.greenConstraintId);
                if (lModelToUpdate == null)
                {
                    return;
                }

                if (!string.Equals(lModelToUpdate.Name, aConstraint.elementName))
                {
                    lModelToUpdate.Name = aConstraint.elementName;
                }
                if (!string.Equals(lModelToUpdate.Description, aConstraint.businessName))
                {
                    lModelToUpdate.Description = aConstraint.businessName;
                }
                if (lModelToUpdate.TemplateConstraintId != aConstraint.id)
                {
                    lModelToUpdate.TemplateConstraintId = aConstraint.id;
                }
                if (lModelToUpdate.ImplementationGuideTypeDataTypeId != aConstraint.datatypeId)
                {
                    lModelToUpdate.ImplementationGuideTypeDataTypeId = aConstraint.datatypeId;
                }
            }
        }
Ejemplo n.º 4
0
        private DB.GreenConstraint AddNewConstraint(ConstraintViewModel aNewConstraint)
        {
            DB.TemplateConstraint lUnderlyingConstraint = _tdb.TemplateConstraints.Single(tc => tc.Id == aNewConstraint.id);

            ConstraintXpathBuilder lXpathBuilder = new ConstraintXpathBuilder(_tdb);
            string lXpath = lXpathBuilder.GenerateXpath(lUnderlyingConstraint);

            DB.GreenConstraint lNewModel = new DB.GreenConstraint()
            {
                Description          = aNewConstraint.businessName,
                Name                 = aNewConstraint.elementName,
                TemplateConstraintId = aNewConstraint.id,
                RootXpath            = lXpath
            };

            if (aNewConstraint.datatypeId.HasValue)
            {
                DB.ImplementationGuideTypeDataType lDataType = _tdb.ImplementationGuideTypeDataTypes.Single(dt => dt.Id == aNewConstraint.datatypeId.Value);
                lNewModel.ImplementationGuideTypeDataType = lDataType;
            }

            return(lNewModel);
        }