private MetadataCompoundAttribute addMetadataAttributeToMetadataCompoundAttribute(MetadataCompoundAttribute compoundAttribute, XmlSchemaElement element, string internalXPath, string externalXPath)
{
MetadataAttribute attribute;
if (metadataAttributeManager.MetadataAttributeRepo != null &&
getExistingMetadataAttribute(GetTypeOfName(element.Name)) != null)
{
attribute = metadataAttributeManager.MetadataAttributeRepo.Get().Where(m => m.Name.Equals(GetTypeOfName(element.Name))).First();
}
else
{
attribute = createMetadataAttribute(element);
}
if (attribute != null)
{
int min = 0;
if (element.MinOccurs > int.MinValue)
{
min = Convert.ToInt32(element.MinOccurs);
}
int max = 0;
if (element.MaxOccurs < int.MaxValue)
max = Convert.ToInt32(element.MaxOccurs);
else
max = int.MaxValue;
#region choice
//if element is a choise
XmlDocument extra = new XmlDocument();
//check if element is a choice
if (XmlSchemaUtility.IsChoiceType(element))
{
extra = XmlDatasetHelper.AddReferenceToXml(new XmlDocument(), "choice", "true", "elementType", @"extra/type");
}
#endregion
MetadataNestedAttributeUsage u1 = new MetadataNestedAttributeUsage()
{
Label = element.Name,
Description = attribute.Description,
MinCardinality = min,
MaxCardinality = max,
Master = compoundAttribute,
Member = attribute
};
if (extra.DocumentElement != null) u1.Extra = extra;
#region generate MappingRoute
addToExportMappingFile(mappingFileInternalToExternal, internalXPath, externalXPath, element.MaxOccurs, element.Name, attribute.Name);
addToImportMappingFile(mappingFileExternalToInternal, externalXPath, internalXPath, element.MaxOccurs, element.Name, attribute.Name);
#endregion
if (compoundAttribute.MetadataNestedAttributeUsages.Where(n => n.Label.Equals(attribute.Name)).Count()==0)
compoundAttribute.MetadataNestedAttributeUsages.Add(u1);
}
return compoundAttribute;
}