Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="metadataStructureId"></param>
        /// <returns></returns>
        public XDocument CreateMetadataXml(long metadataStructureId, XDocument importXml = null)
        {
            using (IUnitOfWork uow = this.GetUnitOfWork())
                using (MetadataStructureManager metadataStructureManager = new MetadataStructureManager())
                {
                    MetadataStructure metadataStructure = this.GetUnitOfWork().GetReadOnlyRepository <MetadataStructure>().Get(metadataStructureId);

                    List <Int64> packageIds = metadataStructureManager.GetEffectivePackageIds(metadataStructureId).ToList();

                    // Create xml Document
                    // Create the xml document containe
                    XDocument doc = new XDocument(); // Create the XML Declaration, and append it to XML document
                                                     //XDeclaration dec = new XDeclaration("1.0", null, null);
                                                     //doc.Add(dec);// Create the root element
                    XElement root = new XElement("Metadata");
                    root.SetAttributeValue("id", metadataStructure.Id.ToString());
                    doc.Add(root);


                    IList <MetadataPackageUsage>  packages = uow.GetReadOnlyRepository <MetadataPackageUsage>().Get(p => packageIds.Contains(p.Id));
                    List <MetadataAttributeUsage> attributes;
                    foreach (MetadataPackageUsage mpu in packages)
                    {
                        XElement package;

                        // create the role
                        XElement role = CreateXElement(mpu.Label, XmlNodeType.MetadataPackageUsage);
                        if (_mode.Equals(XmlNodeMode.xPath))
                        {
                            role.SetAttributeValue("name", mpu.Label);
                        }

                        role.SetAttributeValue("id", mpu.Id.ToString());
                        root.Add(role);

                        // create the package
                        package = CreateXElement(mpu.MetadataPackage.Name, XmlNodeType.MetadataPackage);
                        if (_mode.Equals(XmlNodeMode.xPath))
                        {
                            package.SetAttributeValue("name", mpu.MetadataPackage.Name);
                        }
                        package.SetAttributeValue("roleId", mpu.Id.ToString());
                        package.SetAttributeValue("id", mpu.MetadataPackage.Id.ToString());
                        package.SetAttributeValue("number", "1");
                        role.Add(package);

                        setChildren(package, mpu, importXml);

                        //attributes = mpu.MetadataPackage.MetadataAttributeUsages.ToList();

                        //foreach (MetadataAttributeUsage mau in attributes)
                        //{
                        //    XElement attribute;

                        //    XElement attributeRole = CreateXElement(mau.Label, XmlNodeType.MetadataAttributeUsage);
                        //    if (_mode.Equals(XmlNodeMode.xPath))
                        //    {
                        //        attributeRole.SetAttributeValue("name", mau.Label);
                        //        attributeRole.SetAttributeValue("id", mau.Id.ToString());
                        //    }
                        //    package.Add(attributeRole);

                        //    attribute = CreateXElement(mau.MetadataAttribute.Name, XmlNodeType.MetadataAttribute);
                        //    if (_mode.Equals(XmlNodeMode.xPath)) attribute.SetAttributeValue("name", mau.MetadataAttribute.Name);

                        //    attribute.SetAttributeValue("roleId", mau.Id.ToString());
                        //    attribute.SetAttributeValue("id", mau.MetadataAttribute.Id.ToString());
                        //    attribute.SetAttributeValue("number", "1");

                        //    string xpath = attributeRole.GetAbsoluteXPath() + attribute.GetAbsoluteXPath();

                        //    attributeRole.Add(attribute);

                        //    setChildren(attribute, mau, importXml);

                        //}
                    }

                    return(doc);
                }
        }