Example #1
0
        /// <summary>
        /// Persists a compound metadata attribute in the database
        /// </summary>
        /// <param name="entity">is an unsaved compound metadata data attribute</param>
        /// <returns>The saved compound metadata attribute</returns>
        /// <remarks>The attribute should have at least two other attributes as its member to be considered a compound! Also it should have at least a non empty short name.</remarks>
        public MetadataCompoundAttribute Create(MetadataCompoundAttribute entity)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(entity.ShortName));
            //Contract.Requires(entity.DataType != null && entity.DataType.Id >= 0);
            //Contract.Requires(entity.Unit != null && entity.Unit.Id >= 0);
            Contract.Requires(entity.MetadataNestedAttributeUsages != null && entity.MetadataNestedAttributeUsages.Count >= 2);

            Contract.Ensures(Contract.Result <MetadataCompoundAttribute>() != null && Contract.Result <MetadataCompoundAttribute>().Id >= 0);
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <MetadataCompoundAttribute> repo = uow.GetRepository <MetadataCompoundAttribute>();
                repo.Put(entity);
                uow.Commit();
            }
            return(entity);
        }
        public void ConvertMetadataAttributeModels(BaseUsage source, long metadataStructureId, long stepId)
        {
            Source = source;

            if (Source is MetadataAttributeUsage)
            {
                MetadataAttributeUsage mau = (MetadataAttributeUsage)Source;

                if (mau.MetadataAttribute.Self is MetadataCompoundAttribute)
                {
                    MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mau.MetadataAttribute.Self;

                    if (mca != null)
                    {
                        foreach (MetadataNestedAttributeUsage usage in mca.MetadataNestedAttributeUsages)
                        {
                            if (metadataStructureUsageHelper.IsSimple(usage))
                            {
                                MetadataAttributeModels.Add(FormHelper.CreateMetadataAttributeModel(usage, mau, metadataStructureId, Number, stepId));
                            }
                        }
                    }
                }
            }

            if (Source is MetadataNestedAttributeUsage)
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)Source;
                if (mnau.Member.Self is MetadataCompoundAttribute)
                {
                    MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mnau.Member.Self;

                    if (mca != null)
                    {
                        foreach (MetadataNestedAttributeUsage usage in mca.MetadataNestedAttributeUsages)
                        {
                            if (metadataStructureUsageHelper.IsSimple(usage))
                            {
                                MetadataAttributeModels.Add(FormHelper.CreateMetadataAttributeModel(usage, mnau, metadataStructureId, Number, stepId));
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        private static List <LinkElementModel> getChildrenFromComplexMetadataAttribute(long metadataCompountAttributeId, LinkElementPostion position)
        {
            List <LinkElementModel> tmp = new List <LinkElementModel>();

            MetadataAttributeManager metadataAttributeManager = new MetadataAttributeManager();

            try
            {
                MetadataCompoundAttribute mca = metadataAttributeManager.MetadataCompoundAttributeRepo.Get(metadataCompountAttributeId);

                foreach (var attr in mca.MetadataNestedAttributeUsages)
                {
                    LinkElementComplexity complexity = LinkElementComplexity.None;
                    LinkElementType       type       = LinkElementType.ComplexMetadataAttribute;

                    complexity = attr.Member.Self is MetadataSimpleAttribute
                        ? LinkElementComplexity.Simple
                        : LinkElementComplexity.Complex;

                    //type = attr.Member.Self is MetadataSimpleAttribute
                    //    ? LinkElementType.SimpleMetadataAttribute
                    //    : LinkElementType.ComplexMetadataAttribute;

                    type = LinkElementType.MetadataNestedAttributeUsage;


                    tmp.Add(
                        new LinkElementModel(
                            0,
                            attr.Id,
                            type, attr.Label, "", position, complexity, attr.Description)
                        );
                }

                return(tmp);
            }
            finally
            {
                metadataAttributeManager.Dispose();
            }
        }
Example #4
0
        //Add Attribute to a package return a apackage
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="package"></param>
        /// <param name="attributeUsage"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        private XElement AddAttribute(XElement current, BaseUsage attributeUsage, int number)
        {
            string typeName = "";
            string id       = "";
            string roleId   = "";
            List <MetadataNestedAttributeUsage> children = new List <MetadataNestedAttributeUsage>();

            if (attributeUsage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage metadataAttributeUsage = (MetadataAttributeUsage)attributeUsage;
                typeName = metadataAttributeUsage.MetadataAttribute.Name;
                id       = metadataAttributeUsage.MetadataAttribute.Id.ToString();
                roleId   = metadataAttributeUsage.MetadataAttribute.Id.ToString();
            }
            else
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)attributeUsage;
                typeName = mnau.Member.Name;
                id       = mnau.Member.Id.ToString();
                roleId   = mnau.Id.ToString();

                if (mnau.Member.Self is MetadataCompoundAttribute)
                {
                    MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mnau.Member.Self;
                    children = mca.MetadataNestedAttributeUsages.ToList();
                }
            }

            if (!Exist(typeName, number, current))
            {
                XElement role = Get(attributeUsage.Label, current);
                if (role == null)
                {
                    role = CreateXElement(attributeUsage.Label, XmlNodeType.MetadataAttributeUsage);
                    if (_mode.Equals(XmlNodeMode.xPath))
                    {
                        role.SetAttributeValue("name", attributeUsage.Label);
                    }
                    role.SetAttributeValue("id", attributeUsage.Id.ToString());
                }

                XElement element = CreateXElement(typeName, XmlNodeType.MetadataAttribute);

                if (_mode.Equals(XmlNodeMode.xPath))
                {
                    element.SetAttributeValue("name", typeName);
                }
                element.SetAttributeValue("roleId", roleId);
                element.SetAttributeValue("id", id);
                element.SetAttributeValue("number", number);

                if (children.Count > 0)
                {
                    foreach (BaseUsage baseUsage in children)
                    {
                        element = AddAttribute(element, baseUsage, 1);
                    }
                }

                role.Add(element);
                current.Add(role);
            }
            else
            {
                throw new Exception("attribute exist");
            }

            return(current);
        }
Example #5
0
        private XElement setChildren(XElement element, BaseUsage usage, XDocument importDocument = null)
        {
            MetadataAttribute metadataAttribute = null;
            MetadataPackage   metadataPackage   = null;

            if (usage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage metadataAttributeUsage = (MetadataAttributeUsage)usage;
                metadataAttribute = metadataAttributeUsage.MetadataAttribute;
            }
            else if (usage is MetadataNestedAttributeUsage)
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage;
                metadataAttribute = mnau.Member;
            }
            else
            {
                MetadataPackageUsage mpu = (MetadataPackageUsage)usage;
                metadataPackage = mpu.MetadataPackage;
            }

            if (metadataAttribute != null && metadataAttribute.Self is MetadataCompoundAttribute)
            {
                MetadataCompoundAttribute mca = this.GetUnitOfWork().GetReadOnlyRepository <MetadataCompoundAttribute>().Get(metadataAttribute.Self.Id);

                foreach (MetadataNestedAttributeUsage nestedUsage in mca.MetadataNestedAttributeUsages)
                {
                    if (importDocument != null)
                    {
                        string parentPath = element.GetAbsoluteXPathWithIndex();

                        string usagePath = parentPath + "/" + nestedUsage.Label;

                        XElement        usageElement = importDocument.XPathSelectElement(usagePath);
                        List <XElement> typeList     = new List <XElement>();

                        if (usageElement != null && usageElement.HasElements)
                        {
                            int num = usageElement.Elements().Count();

                            if (num == 0)
                            {
                                typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                            }
                            else
                            {
                                typeList = AddAndReturnAttribute(element, nestedUsage, 1, num);
                            }
                        }
                        else
                        {
                            Debug.WriteLine("NULL OR EMPTY:------> " + usagePath);

                            typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                        }

                        foreach (var type in typeList)
                        {
                            setChildren(type, nestedUsage, importDocument);
                        }
                    }
                    else
                    {
                        List <XElement> typeList = new List <XElement>();

                        typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                        setChildren(typeList.FirstOrDefault(), nestedUsage, importDocument);
                    }
                }
            }
            else
            {
                if (metadataPackage != null)
                {
                    foreach (MetadataAttributeUsage attrUsage in metadataPackage.MetadataAttributeUsages)
                    {
                        if (importDocument != null)
                        {
                            string parentPath = element.GetAbsoluteXPathWithIndex();

                            string usagePath = parentPath + "/" + attrUsage.Label;

                            XElement        usageElement = importDocument.XPathSelectElement(usagePath);
                            List <XElement> typeList     = new List <XElement>();

                            if (usageElement != null && usageElement.HasElements)
                            {
                                int num = usageElement.Elements().Count();

                                if (num == 0)
                                {
                                    typeList = AddAndReturnAttribute(element, attrUsage, 1, 1);
                                }
                                else
                                {
                                    typeList = AddAndReturnAttribute(element, attrUsage, 1, num);
                                }
                            }
                            else
                            {
                                Debug.WriteLine("NULL OR EMPTY:------> " + usagePath);

                                typeList = AddAndReturnAttribute(element, attrUsage, 1, 1);
                            }

                            foreach (var type in typeList)
                            {
                                setChildren(type, attrUsage, importDocument);
                            }
                        }
                        else
                        {
                            List <XElement> typeList = new List <XElement>();

                            typeList = AddAndReturnAttribute(element, attrUsage, 1, 1);
                            setChildren(typeList.FirstOrDefault(), attrUsage, importDocument);
                        }
                    }
                }
            }

            return(element);
        }
Example #6
0
        private XElement setChildren(XElement element, BaseUsage usage, XDocument importDocument = null)
        {
            MetadataAttribute metadataAttribute;

            if (usage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage metadataAttributeUsage = (MetadataAttributeUsage)usage;
                metadataAttribute = metadataAttributeUsage.MetadataAttribute;
            }
            else
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage;
                metadataAttribute = mnau.Member;
            }

            if (metadataAttribute.Self is MetadataCompoundAttribute)
            {
                //MetadataCompoundAttribute mca = (MetadataCompoundAttribute)metadataAttribute.Self;

                MetadataCompoundAttribute mca = this.GetUnitOfWork().GetReadOnlyRepository <MetadataCompoundAttribute>().Get(metadataAttribute.Self.Id);

                foreach (MetadataNestedAttributeUsage nestedUsage in mca.MetadataNestedAttributeUsages)
                {
                    //Debug.WriteLine("MetadataCompoundAttribute:            " + element.Name);
                    //Debug.WriteLine("*************************:            " + element.Name);
                    //XElement x = element.Descendants().Where(e => e.Name.Equals(nestedUsage.Member.Name)).First();

                    if (importDocument != null)
                    {
                        string parentPath = element.GetAbsoluteXPathWithIndex();

                        string usagePath = parentPath + "/" + nestedUsage.Label;
                        //+"/"+ nestedUsage.Member.Name;

                        XElement        usageElement = importDocument.XPathSelectElement(usagePath);
                        List <XElement> typeList     = new List <XElement>();

                        if (usageElement != null && usageElement.HasElements)
                        {
                            int num = usageElement.Elements().Count();
                            //importDocument.XPathSelectElements(childPath).Count();
                            //num = XmlUtility.ToXmlDocument(importDocument).SelectNodes(childPath).Count;

                            if (num == 0)
                            {
                                typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                                //x = setChildren(x, nestedUsage, importDocument);
                            }
                            else
                            {
                                typeList = AddAndReturnAttribute(element, nestedUsage, 1, num);
                            }
                        }
                        else
                        {
                            Debug.WriteLine("NULL OR EMPTY:------> " + usagePath);

                            typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                        }

                        foreach (var type in typeList)
                        {
                            setChildren(type, nestedUsage, importDocument);
                        }
                    }
                    else
                    {
                        List <XElement> typeList = new List <XElement>();

                        typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                        setChildren(typeList.FirstOrDefault(), nestedUsage, importDocument);
                    }
                }
            }

            return(element);
        }