public StepModelHelper() { StepId = 0; Usage = new BaseUsage(); Number = 0; XPath = ""; Childrens = new List<StepModelHelper>(); Activated = SetActiveByPreload(); Level = 0; }
public StepModelHelper(int stepId, int number, BaseUsage usage, string xpath, StepModelHelper parent) { StepId = stepId; Usage = usage; Number = number; XPath = xpath; Childrens = new List<StepModelHelper>(); Parent = parent; Choice = IsChoice(usage); if (parent != null) Level = parent.Level + 1; }
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 (UsageHelper.IsSimple(usage)) { MetadataAttributeModels.Add(MetadataAttributeModel.Convert(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 (UsageHelper.IsSimple(usage)) { MetadataAttributeModels.Add(MetadataAttributeModel.Convert(usage, mnau, metadataStructureId, Number, stepId)); } } } } } }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="metadataXml"></param> /// <param name="packageUsage"></param> /// <param name="packageNumber"></param> /// <param name="attributeUsage"></param> /// <param name="number"></param> /// <returns></returns> public XDocument RemoveAttribute(XDocument metadataXml, BaseUsage attributeUsage, int number, string attributeName, string parentXPath) { _tempXDoc = metadataXml; /* * In the xml the structure is everytime usage/type * * e.g. personUsage/PersonType/name/NameType * * has a attribute has cardinality more then one * the usage is the sequence node * * personUsage/PersonType/name/NameType[1] * personUsage/PersonType/name/NameType[2] * * in this function the parent is e.g PersonType * so we need to add the usage name to the xpath to select the right node to remove the attribute */ string usageXPath = parentXPath + "/" + attributeUsage.Label; XElement role = Get(usageXPath); if (role != null) { if (Exist(attributeName, number, role)) { XElement attribute = Get(attributeName, number, role); List <XElement> listOfPackagesAfter = GetChildren(attributeName, role).Where(p => p.Attribute("number") != null && Convert.ToInt64(p.Attribute("number").Value) > number).ToList(); if (attribute != null) { attribute.Remove(); } listOfPackagesAfter.ForEach(p => p.Attribute("number").SetValue(Convert.ToInt64(p.Attribute("number").Value) - 1)); } } else { throw new Exception("attribute exist"); } return(_tempXDoc); }
//Add Attribute to a package return a apackage /// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="metadataXml"></param> /// <param name="packageUsage"></param> /// <param name="packageNumber"></param> /// <param name="attributeUsage"></param> /// <param name="number"></param> /// <returns></returns> public XDocument AddAttribute(XDocument metadataXml, BaseUsage attributeUsage, int number, string attributeTypeName, string attributeId, string parentXPath) { _tempXDoc = metadataXml; /* * In the xml the structure is everytime usage/type * * e.g. personUsage/PersonType/name/NameType * * has a attribute has cardinality more then one * the usage is the sequence node * * personUsage/PersonType/name/NameType[1] * personUsage/PersonType/name/NameType[2] * * in this function the parent is e.g PersonType * so we need to add the usage name to the xpath to select the right node to add the attribute */ string usageXPath = parentXPath + "/" + attributeUsage.Label; XElement role = Get(usageXPath); XElement element = CreateXElement(attributeTypeName, XmlNodeType.MetadataAttribute); if (_mode.Equals(XmlNodeMode.xPath)) { element.SetAttributeValue("name", attributeTypeName); } element.SetAttributeValue("roleId", attributeUsage.Id.ToString()); element.SetAttributeValue("id", attributeId); element.SetAttributeValue("number", number); if (!Exist(attributeTypeName, number, role)) { role = UpdateNumberOfSameElements(role, element, attributeTypeName, number); } else { role = UpdateNumberOfSameElements(role, element, attributeTypeName, number); } return(_tempXDoc); }
public static List<BaseUsage> GetCompoundChildrens(BaseUsage usage) { List<BaseUsage> temp = new List<BaseUsage>(); if (usage is MetadataPackageUsage) { MetadataPackageUsage mpu = (MetadataPackageUsage)usage; foreach (BaseUsage childUsage in mpu.MetadataPackage.MetadataAttributeUsages) { if(IsCompound(childUsage)) temp.Add(childUsage); } } if (usage is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)usage; if (mau.MetadataAttribute.Self is MetadataCompoundAttribute) { foreach (BaseUsage childUsage in ((MetadataCompoundAttribute)mau.MetadataAttribute.Self).MetadataNestedAttributeUsages) { if (IsCompound(childUsage)) temp.Add(childUsage); } } } if (usage is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage; if (mnau.Member.Self is MetadataCompoundAttribute) { foreach (BaseUsage childUsage in ((MetadataCompoundAttribute)mnau.Member.Self).MetadataNestedAttributeUsages) { if (IsCompound(childUsage)) temp.Add(childUsage); } } } return temp; }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="metadataXml"></param> /// <param name="packageUsage"></param> /// <param name="packageNumber"></param> /// <param name="attributeUsage"></param> /// <param name="number"></param> /// <param name="value"></param> /// <returns></returns> public XDocument Update(XDocument metadataXml, BaseUsage attributeUsage, int number, object value, string attributeTypeName, string parentXpath) { _tempXDoc = metadataXml; XElement parent = Get(parentXpath); if (parent != null) { //attribute role exist if (Exist(attributeUsage.Label, parent)) { XElement attributeRole = Get(attributeUsage.Label, parent); if (attributeRole != null) { XElement attribute = Get(attributeTypeName, number, attributeRole); attribute.SetValue(value.ToString()); } } } return(_tempXDoc); }
public static MetadataPackageModel CreateMetadataPackageModel(BaseUsage mPUsage, int number) { MetadataPackageUsage metadataPackageUsage = (MetadataPackageUsage)mPUsage; if (metadataPackageUsage != null) { return(new MetadataPackageModel { Source = metadataPackageUsage, Number = number, MetadataAttributeModels = new List <MetadataAttributeModel>(), DisplayName = metadataPackageUsage.Label, Discription = metadataPackageUsage.Description, MinCardinality = metadataPackageUsage.MinCardinality, MaxCardinality = metadataPackageUsage.MaxCardinality }); } else { return(null); } }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="metadataXml"></param> /// <param name="packageUsage"></param> /// <param name="number"></param> /// <returns></returns> public XDocument RemovePackage(XDocument metadataXml, BaseUsage packageUsage, int number, string typeName) { this._tempXDoc = metadataXml; XElement role; //check if role exist if (Exist(packageUsage.Label, packageUsage.Id)) { role = Get(packageUsage.Label, packageUsage.Id); XElement package = Get(typeName, number, role); List <XElement> listOfPackagesAfter = GetChildren(typeName, role).Where(p => p.Attribute("number") != null && Convert.ToInt64(p.Attribute("number").Value) > number).ToList(); if (package != null) { package.Remove(); } listOfPackagesAfter.ForEach(p => p.Attribute("number").SetValue(Convert.ToInt64(p.Attribute("number").Value) - 1)); } return(metadataXml); }
public string GetNameOfType(BaseUsage usage) { if (usage is MetadataPackageUsage) { MetadataPackageUsage mpu = (MetadataPackageUsage)usage; return(mpu.MetadataPackage.Name); } if (usage is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)usage; return(mau.MetadataAttribute.Name); } if (usage is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage; return(mnau.Member.Name); } return(""); }
public long GetIdOfType(BaseUsage usage) { if (usage is MetadataPackageUsage) { MetadataPackageUsage mpu = (MetadataPackageUsage)usage; return(mpu.MetadataPackage.Id); } if (usage is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)usage; return(mau.MetadataAttribute.Id); } if (usage is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage; return(mnau.Member.Id); } return(0); }
public static MetadataCompoundAttributeModel ConvertToModel(BaseUsage metadataAttributeUsage, int number) { return new MetadataCompoundAttributeModel { Id = metadataAttributeUsage.Id, Number = number, //PackageModelNumber = packageModelNumber, //MetadataStructureId = metadataStructureId, //Parent = metadataPackageUsage, Source = metadataAttributeUsage, DisplayName = metadataAttributeUsage.Label, Discription = metadataAttributeUsage.Description, //DataType = metadataAttributeUsage..MetadataAttribute.DataType.Name, //SystemType = metadataAttributeUsage.MetadataAttribute.DataType.SystemType, MinCardinality = metadataAttributeUsage.MinCardinality, MaxCardinality = metadataAttributeUsage.MaxCardinality, NumberOfSourceInPackage = 1, first = true, ////DomainList = domainConstraintList, last = true }; }
public static long GetIdOfType(BaseUsage usage) { if (usage is MetadataPackageUsage) { MetadataPackageUsage mpu = (MetadataPackageUsage)usage; return mpu.MetadataPackage.Id; } if (usage is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)usage; return mau.MetadataAttribute.Id; } if (usage is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage; return mnau.Member.Id; } return 0; }
public static bool IsSimple(BaseUsage usage) { if (usage is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)usage; if (mau.MetadataAttribute.Self is MetadataSimpleAttribute) return true; } if (usage is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage; if (mnau.Member.Self is MetadataSimpleAttribute) return true; } return false; }
public static BaseUsage GetMetadataAttributeUsageById(long Id) { BaseUsage usage = new BaseUsage(); MetadataPackageManager mpm = new MetadataPackageManager(); var q = from p in mpm.MetadataPackageRepo.Get() from u in p.MetadataAttributeUsages where u.Id == Id // && p.Id.Equals(parentId) select u; return q.FirstOrDefault(); }
//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 List <XElement> AddAndReturnAttribute(XElement current, BaseUsage attributeUsage, int number, int countOfTypes) { List <XElement> tmp = new List <XElement>(); string typeName = ""; string id = ""; string roleId = ""; if (attributeUsage is MetadataAttributeUsage) { MetadataAttributeUsage metadataAttributeUsage = (MetadataAttributeUsage)attributeUsage; typeName = metadataAttributeUsage.MetadataAttribute.Name; id = metadataAttributeUsage.MetadataAttribute.Id.ToString(); roleId = metadataAttributeUsage.Id.ToString(); } else { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)attributeUsage; typeName = mnau.Member.Name; id = mnau.Member.Id.ToString(); roleId = mnau.Id.ToString(); } 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()); } for (int i = 0; i < countOfTypes; i++) { 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", i + 1); role.Add(element); tmp.Add(element); } current.Add(role); //Debug.WriteLine("Element: " + element.Name); return(tmp); } else { throw new Exception("attribute exist"); } }
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); }
public static BaseUsage GetSimpleUsageById(BaseUsage parent, long Id) { BaseUsage usage = new BaseUsage(); if (parent is MetadataPackageUsage) { MetadataPackageManager mpm = new MetadataPackageManager(); var q = from p in mpm.MetadataPackageRepo.Get() from u in p.MetadataAttributeUsages where p.Id.Equals(parent.Id) && u.Id == Id && u.MetadataAttribute.Self is MetadataSimpleAttribute select u; if (q != null && q.ToList().Count > 0) { return q.FirstOrDefault(); } else return null; } else if (parent is MetadataNestedAttributeUsage) { MetadataAttributeManager mam = new MetadataAttributeManager(); MetadataNestedAttributeUsage pUsage = (MetadataNestedAttributeUsage)parent; MetadataCompoundAttribute mca = mam.MetadataCompoundAttributeRepo.Get(pUsage.Member.Self.Id); var x = from nestedUsage in mca.MetadataNestedAttributeUsages where nestedUsage.Id == Id && nestedUsage.Member.Self is MetadataSimpleAttribute select nestedUsage; //var x = from c in mam.MetadataCompoundAttributeRepo.Get() // from u in c.Self.MetadataNestedAttributeUsages // where u.Id.Equals(parent.Id) && u.Member.Self.Id == Id && u.Member.Self is MetadataSimpleAttribute // select u; return x.FirstOrDefault(); } else if (parent is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)parent; if (mau.MetadataAttribute.Self is MetadataCompoundAttribute) { MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mau.MetadataAttribute.Self; return mca.MetadataNestedAttributeUsages.Where(m => m.Id.Equals(Id)).FirstOrDefault(); } } return null; }
public void ConvertMetadataAttributeModels(BaseUsage source, long metadataStructureId, int 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 (UsageHelper.IsSimple(usage)) // { // MetadataAttributeModels.Add(MetadataAttributeModel.Convert(usage, mau, metadataStructureId, Number)); // } // } // } // } //} //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 (UsageHelper.IsSimple(usage)) // { // MetadataAttributeModels.Add(MetadataAttributeModel.Convert(usage, mnau, metadataStructureId, Number)); // } // } // } // } //} if (Source is MetadataPackageUsage) { MetadataPackageUsage mpu = (MetadataPackageUsage)Source; if (mpu.MetadataPackage is MetadataPackage) { MetadataPackage mp = mpu.MetadataPackage; if (mp != null) { foreach (MetadataAttributeUsage usage in mp.MetadataAttributeUsages) { if (metadataStructureUsageHelper.IsSimple(usage)) { MetadataAttributeModels.Add(FormHelper.CreateMetadataAttributeModel(usage, mpu, metadataStructureId, Number, stepId)); } } } } } }
/// <summary> /// Search in the packageusages /// </summary> /// <param name="Id"></param> /// <returns></returns> public static BaseUsage GetUsageById(long Id) { BaseUsage usage = new BaseUsage(); MetadataStructureManager msm = new MetadataStructureManager(); var q = from p in msm.PackageUsageRepo.Get() where p.Id == Id select p; if (q != null && q.ToList().Count > 0) { return q.FirstOrDefault(); } return null; //else //{ // MetadataAttributeManager mam = new MetadataAttributeManager(); // var x = from c in mam.MetadataCompoundAttributeRepo.Get() // from u in c.Self.MetadataNestedAttributeUsages // where u.Id == Id // select u; // return x.FirstOrDefault(); //} }
public static bool HasUsagesWithSimpleType(BaseUsage usage) { if (usage is MetadataPackageUsage) { MetadataPackageUsage mpu = (MetadataPackageUsage)usage; foreach (BaseUsage childUsage in mpu.MetadataPackage.MetadataAttributeUsages) { if(IsSimple(childUsage)) return true; } } if (usage is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)usage; if (mau.MetadataAttribute.Self is MetadataCompoundAttribute) { foreach (BaseUsage childUsage in ((MetadataCompoundAttribute)mau.MetadataAttribute.Self).MetadataNestedAttributeUsages) { if(IsSimple(childUsage)) return true; } } } if (usage is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage; if (mnau.Member.Self is MetadataCompoundAttribute) { foreach (BaseUsage childUsage in ((MetadataCompoundAttribute)mnau.Member.Self).MetadataNestedAttributeUsages) { if (IsSimple(childUsage)) return true; } } } return false; }
private static bool IsCompound(BaseUsage usage) { MetadataAttributeManager mam = new MetadataAttributeManager(); if (usage is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)usage; MetadataAttribute ma = mam.MetadataAttributeRepo.Get(mau.MetadataAttribute.Id); if (ma.Self is MetadataCompoundAttribute) return true; } if (usage is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage; MetadataAttribute ma = mam.MetadataAttributeRepo.Get(mnau.Member.Id); if (ma.Self is MetadataCompoundAttribute) return true; } return false; }
public static void addUsageAsLinkElement(BaseUsage usage, string parentXpath, LinkElementRootModel rootModel, LinkElementModel parent) { int min = usage.MinCardinality; string childName = ""; //MappingManager mappingManager = new MappingManager(); string usageName = usage.Label; string typeName = "x"; long typeId = 0; string typeDescription = ""; string xPath = parentXpath; LinkElementType type = LinkElementType.ComplexMetadataAttribute; LinkElementComplexity complexity = LinkElementComplexity.Complex; bool addTypeAsLinkElement = false; if (usage is MetadataPackageUsage) { type = LinkElementType.MetadataPackageUsage; typeName = ((MetadataPackageUsage)usage).MetadataPackage.Name; } else if (usage is MetadataNestedAttributeUsage) { type = LinkElementType.MetadataNestedAttributeUsage; MetadataNestedAttributeUsage n = (MetadataNestedAttributeUsage)usage; typeName = n.Member.Name; if (n.Member.Self is MetadataCompoundAttribute) { addTypeAsLinkElement = true; typeId = n.Member.Self.Id; typeDescription = n.Member.Self.Description; } if (n.Member.Self is MetadataSimpleAttribute) { complexity = LinkElementComplexity.Simple; } } else if (usage is MetadataAttributeUsage) { type = LinkElementType.MetadataAttributeUsage; MetadataAttributeUsage u = (MetadataAttributeUsage)usage; typeName = u.MetadataAttribute.Name; if (u.MetadataAttribute.Self is MetadataCompoundAttribute) { addTypeAsLinkElement = true; typeId = u.MetadataAttribute.Self.Id; typeDescription = u.MetadataAttribute.Self.Description; } if (u.MetadataAttribute.Self is MetadataSimpleAttribute) { complexity = LinkElementComplexity.Simple; } } // add usage xPath = parentXpath + "/" + usageName.Replace(" ", string.Empty) + "/" + typeName; long linkElementId = 0; string mask = ""; LinkElement linkElement = type.GetUnitOfWork().GetReadOnlyRepository <LinkElement>().Get() .FirstOrDefault(le => le.ElementId.Equals(usage.Id) && le.Type.Equals(type)); if (linkElement != null) { linkElementId = linkElement.Id; } LinkElementModel LEModel = new LinkElementModel( linkElementId, usage.Id, type, usage.Label, xPath, rootModel.Position, complexity, usage.Description); LEModel.Parent = parent; rootModel.LinkElements.Add(LEModel); //add type if (addTypeAsLinkElement) { linkElementId = 0; linkElement = type.GetUnitOfWork().GetReadOnlyRepository <LinkElement>().Get() .FirstOrDefault( le => le.ElementId.Equals(typeId) && le.Type.Equals(LinkElementType.ComplexMetadataAttribute)); if (linkElement != null) { linkElementId = linkElement.Id; } LEModel = new LinkElementModel( linkElementId, typeId, LinkElementType.ComplexMetadataAttribute, typeName, xPath, rootModel.Position, complexity, typeDescription); LEModel.Parent = parent; if (!rootModel.LinkElements.Any(le => le.ElementId.Equals(typeId) && le.Type.Equals(LinkElementType.ComplexMetadataAttribute))) { rootModel.LinkElements.Add(LEModel); } } //Debug.WriteLine("1: " + LEModel.Name + " " + LEModel.Type); List <BaseUsage> childrenUsages = metadataStructureUsageHelper.GetChildren(usage.Id, usage.GetType()); if (childrenUsages.Count > 0) { foreach (BaseUsage childUsage in childrenUsages) { addUsageAsLinkElement(childUsage, xPath, rootModel, LEModel); } //AddChildrens //addLinkElementsFromChildrens(usage, xPath, rootModel); } }
public List <BaseUsage> GetCompoundChildrens(long usageId, Type type) { using (IUnitOfWork unitOfWork = this.GetUnitOfWork()) { List <BaseUsage> temp = new List <BaseUsage>(); BaseUsage usage = loadUsage(usageId, type); if (type.Equals(typeof(MetadataPackageUsage))) { MetadataPackageUsage mpu = (MetadataPackageUsage)usage; var mauRepo = unitOfWork.GetReadOnlyRepository <MetadataAttributeUsage>(); foreach (MetadataAttributeUsage childUsage in mpu.MetadataPackage.MetadataAttributeUsages) { if (IsCompound(childUsage)) { mauRepo.LoadIfNot(childUsage.MetadataAttribute); temp.Add(childUsage); } } } if (type.Equals(typeof(MetadataAttributeUsage))) { MetadataAttributeUsage mau = (MetadataAttributeUsage)usage; if (mau.MetadataAttribute.Self.GetType().Equals(typeof(MetadataCompoundAttribute))) { var mnauRepo = unitOfWork.GetReadOnlyRepository <MetadataNestedAttributeUsage>(); foreach (MetadataNestedAttributeUsage childUsage in ((MetadataCompoundAttribute)mau.MetadataAttribute.Self).MetadataNestedAttributeUsages) { if (IsCompound(childUsage)) { mnauRepo.LoadIfNot(childUsage.Member); temp.Add(childUsage); } } } } if (type.Equals(typeof(MetadataNestedAttributeUsage))) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage; if (mnau.Member.Self.GetType().Equals(typeof(MetadataCompoundAttribute))) { var mnauRepo = unitOfWork.GetReadOnlyRepository <MetadataNestedAttributeUsage>(); foreach (MetadataNestedAttributeUsage childUsage in ((MetadataCompoundAttribute)mnau.Member.Self).MetadataNestedAttributeUsages) { if (IsCompound(childUsage)) { mnauRepo.LoadIfNot(childUsage.Member); temp.Add(childUsage); } } } } return(temp); } }
private bool IsChoice(BaseUsage usage) { if (usage.Extra != null) { XmlDocument doc = usage.Extra as XmlDocument; XElement element = XmlUtility.GetXElementByAttribute("type", "name", "choice", XmlUtility.ToXDocument(doc)); if (element != null) return true; } return false; }
private List<StepInfo> GetChildrenStepsFromMetadata(BaseUsage usage, StepInfo parent, string parentXpath, StepModelHelper parentStepModelHelper) { List<StepInfo> childrenSteps = new List<StepInfo>(); List<BaseUsage> childrenUsages = UsageHelper.GetCompoundChildrens(usage); List<StepModelHelper> stepHelperModelList = (List<StepModelHelper>)TaskManager.Bus[CreateTaskmanager.METADATA_STEP_MODEL_HELPER]; if (childrenUsages.Count > 0) { foreach (BaseUsage u in childrenUsages) { int number = 1;//childrenUsages.IndexOf(u) + 1; string xPath = parentXpath + "//" + u.Label.Replace(" ", string.Empty) + "[" + number + "]"; bool complex = false; string actionName = ""; string attrName = ""; if (u is MetadataPackageUsage) { actionName = "SetMetadataPackage"; } else { actionName = "SetMetadataCompoundAttribute"; if (u is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)u; if (mau.MetadataAttribute.Self is MetadataCompoundAttribute) { complex = true; attrName = mau.MetadataAttribute.Self.Name; } } if (u is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mau = (MetadataNestedAttributeUsage)u; if (mau.Member.Self is MetadataCompoundAttribute) { complex = true; attrName = mau.Member.Self.Name; } } } if (complex) { StepInfo s = new StepInfo(u.Label) { Id = TaskManager.GenerateStepId(), parentTitle = attrName, Parent = parent, IsInstanze = false, GetActionInfo = new ActionInfo { ActionName = actionName, ControllerName = "CreateSetMetadataPackage", AreaName = "DCM" }, PostActionInfo = new ActionInfo { ActionName = actionName, ControllerName = "CreateSetMetadataPackage", AreaName = "DCM" } }; //only not optional if (TaskManager.StepInfos.Where(z => z.Id.Equals(s.Id)).Count() == 0) { StepModelHelper newStepModelHelper = new StepModelHelper(s.Id, 1, u, xPath, parentStepModelHelper); stepHelperModelList.Add(newStepModelHelper); s = LoadStepsBasedOnUsage(u, s, xPath, newStepModelHelper); childrenSteps.Add(s); } } //} } } return childrenSteps; }
public static string GetNameOfType(BaseUsage usage) { if (usage is MetadataPackageUsage) { MetadataPackageUsage mpu = (MetadataPackageUsage)usage; return mpu.MetadataPackage.Name; } if (usage is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)usage; return mau.MetadataAttribute.Name; } if (usage is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage; return mnau.Member.Name; } return ""; }
private List<BaseUsage> GetCompoundAttributeUsages(BaseUsage usage) { List<BaseUsage> list = new List<BaseUsage>(); if (usage is MetadataPackageUsage) { MetadataPackageUsage mpu = (MetadataPackageUsage)usage; foreach (MetadataAttributeUsage mau in mpu.MetadataPackage.MetadataAttributeUsages) { list.AddRange(GetCompoundAttributeUsages(mau)); } } if (usage is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)usage; if (mau.MetadataAttribute.Self is MetadataCompoundAttribute) { list.Add(mau); MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mau.MetadataAttribute.Self; foreach (MetadataNestedAttributeUsage mnau in mca.MetadataNestedAttributeUsages) { list.AddRange(GetCompoundAttributeUsages(mnau)); } } } if (usage is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage; if (mnau.Member.Self is MetadataCompoundAttribute) { list.Add(mnau); MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mnau.Member.Self; foreach (MetadataNestedAttributeUsage m in mca.MetadataNestedAttributeUsages) { list.AddRange(GetCompoundAttributeUsages(m)); } } } return list; }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="metadataXml"></param> /// <param name="packageUsage"></param> /// <param name="number"></param> /// <returns></returns> public XDocument AddPackage(XDocument metadataXml, BaseUsage usage, int number, string typeName, long typeId, List <BaseUsage> children, XmlNodeType xmlType, XmlNodeType xmlUsageType, string xpath) { this._tempXDoc = metadataXml; XElement role; //check if role exist if (Exist(xpath)) { role = Get(xpath); } else { // create the role role = CreateXElement(usage.Label, xmlUsageType); if (_mode.Equals(XmlNodeMode.xPath)) { role.SetAttributeValue("name", usage.Label); } role.SetAttributeValue("id", usage.Id.ToString()); } //root.Add(role); string xPathForNewElement = xpath + "//" + typeName + "[" + number + "]";; //xpath.Substring (0,xpath.Length-2)+number+"]"; XElement package; // create the package package = CreateXElement(typeName, xmlType); if (_mode.Equals(XmlNodeMode.xPath)) { package.SetAttributeValue("name", typeName); } package.SetAttributeValue("roleId", usage.Id.ToString()); package.SetAttributeValue("id", typeId); package.SetAttributeValue("number", number); //if (!Exist(xPathForNewElement)) if (!Exist(typeName, number, role)) { role.Add(package); foreach (BaseUsage attribute in children) { AddAttribute(package, attribute, 1); } //XElement element = XmlUtility.GetXElementByAttribute(usage.Label, "id", usage.Id.ToString(), metadataXml); //element.Add(package); } else { role = UpdateNumberOfSameElements(role, package, typeName, number); foreach (BaseUsage attribute in children) { AddAttribute(package, attribute, 1); } } return(metadataXml); }
//private StepModelHelper GetStepModelhelper(long usageId, int number) //{ // TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; // if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATA_STEP_MODEL_HELPER)) // { // return ((List<StepModelHelper>)TaskManager.Bus[CreateTaskmanager.METADATA_STEP_MODEL_HELPER]).Where(s => s.Usage.Id.Equals(usageId) && s.Number.Equals(number)).FirstOrDefault(); // } // return null; //} //private int GetNumberOfUsageInStepModelHelper(long usageId) //{ // TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; // if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATA_STEP_MODEL_HELPER)) // { // return ((List<StepModelHelper>)TaskManager.Bus[CreateTaskmanager.METADATA_STEP_MODEL_HELPER]).Where(s => s.Usage.Id.Equals(usageId)).Count() - 1; // } // return 0; //} //private void GenerateModelsForChildrens(StepModelHelper modelHelper, long metadataStructureId) //{ // foreach (StepModelHelper item in modelHelper.Childrens) // { // if (item.Childrens.Count() > 0) // { // GenerateModelsForChildrens(item, metadataStructureId); // } // if (item.Model == null) // { // BaseUsage u = LoadUsage(item.Usage); // if (u is MetadataAttributeUsage || u is MetadataNestedAttributeUsage) // { // item.Model = MetadataCompoundAttributeModel.ConvertToModel(u, item.Number); // ((MetadataCompoundAttributeModel)item.Model).ConvertMetadataAttributeModels(u, metadataStructureId, item.StepId); // } // if (u is MetadataPackageUsage) // { // item.Model = MetadataPackageModel.Convert(u, item.Number); // ((MetadataPackageModel)item.Model).ConvertMetadataAttributeModels(u, metadataStructureId, item.StepId); // } // } // } //} //private StepModelHelper GenerateModelsForChildrens(StepInfo stepInfo, long metadataStructureId) //{ // StepModelHelper stepModelHelper = GetStepModelhelper(stepInfo.Id); // if (stepModelHelper.Model == null) // { // if (stepModelHelper.Usage is MetadataPackageUsage) // stepModelHelper.Model = CreatePackageModel(stepInfo.Id, false); // if (stepModelHelper.Usage is MetadataNestedAttributeUsage) // stepModelHelper.Model = CreateCompoundModel(stepInfo.Id, false); // getChildModelsHelper(stepModelHelper); // } // return stepModelHelper; //} private BaseUsage LoadUsage(BaseUsage usage) { if (usage is MetadataPackageUsage) { MetadataStructureManager msm = new MetadataStructureManager(); return msm.PackageUsageRepo.Get(usage.Id); } if (usage is MetadataNestedAttributeUsage) { MetadataAttributeManager mam = new MetadataAttributeManager(); var x = from c in mam.MetadataCompoundAttributeRepo.Get() from u in c.Self.MetadataNestedAttributeUsages where u.Id == usage.Id //&& c.Id.Equals(parentId) select u; return x.FirstOrDefault(); } if (usage is MetadataAttributeUsage) { MetadataPackageManager mpm = new MetadataPackageManager(); var q = from p in mpm.MetadataPackageRepo.Get() from u in p.MetadataAttributeUsages where u.Id == usage.Id // && p.Id.Equals(parentId) select u; return q.FirstOrDefault(); } return usage; }
//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); }
private void RemoveCompoundAttributeToXml(BaseUsage usage, int number) { TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; XDocument metadataXml = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML]; XmlMetadataWriter xmlMetadataWriter = new XmlMetadataWriter(XmlNodeMode.xPath); metadataXml = xmlMetadataWriter.RemovePackage(metadataXml, usage, number, UsageHelper.GetNameOfType(usage)); TaskManager.Bus[CreateTaskmanager.METADATA_XML] = metadataXml; }
public static BaseUsage GetMetadataCompoundAttributeUsageById(long Id) { BaseUsage usage = new BaseUsage(); MetadataAttributeManager mam = new MetadataAttributeManager(); var x = from c in mam.MetadataCompoundAttributeRepo.Get() from u in c.Self.MetadataNestedAttributeUsages where u.Id == Id //&& c.Id.Equals(parentId) select u; return x.FirstOrDefault(); }
private void UpdateCompoundAttributeToXml(BaseUsage usage, int number, string xpath) { TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; XDocument metadataXml = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML]; XmlMetadataWriter xmlMetadataWriter = new XmlMetadataWriter(XmlNodeMode.xPath); metadataXml = xmlMetadataWriter.AddPackage(metadataXml, usage, number, UsageHelper.GetNameOfType(usage), UsageHelper.GetIdOfType(usage), UsageHelper.GetChildren(usage), BExIS.Xml.Helpers.XmlNodeType.MetadataAttribute, BExIS.Xml.Helpers.XmlNodeType.MetadataAttributeUsage, xpath); TaskManager.Bus[CreateTaskmanager.METADATA_XML] = metadataXml; }
public static MetadataAttributeModel CreateMetadataAttributeModel(BaseUsage current, BaseUsage parent, long metadataStructureId, int packageModelNumber, long parentStepId) { MetadataAttribute metadataAttribute; List <object> domainConstraintList = new List <object>(); string constraintsDescription = ""; if (current is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)current; metadataAttribute = mnau.Member; } else { MetadataAttributeUsage mau = (MetadataAttributeUsage)current; metadataAttribute = mau.MetadataAttribute; } if (metadataAttribute.Constraints.Where(c => (c is DomainConstraint)).Count() > 0) { domainConstraintList = createDomainContraintList(metadataAttribute); } if (metadataAttribute.Constraints.Count > 0) { foreach (Constraint c in metadataAttribute.Constraints) { if (string.IsNullOrEmpty(constraintsDescription)) { constraintsDescription = c.FormalDescription; } else { constraintsDescription = String.Format("{0}\n{1}", constraintsDescription, c.FormalDescription); } } } //load displayPattern DataTypeDisplayPattern dtdp = DataTypeDisplayPattern.Materialize(metadataAttribute.DataType.Extra); string displayPattern = ""; if (dtdp != null) { displayPattern = dtdp.StringPattern; } return(new MetadataAttributeModel { Id = current.Id, Number = 1, ParentModelNumber = packageModelNumber, MetadataStructureId = metadataStructureId, Parent = parent, Source = current, DisplayName = current.Label, Discription = current.Description, ConstraintDescription = constraintsDescription, DataType = metadataAttribute.DataType.Name, SystemType = metadataAttribute.DataType.SystemType, DisplayPattern = displayPattern, MinCardinality = current.MinCardinality, MaxCardinality = current.MaxCardinality, NumberOfSourceInPackage = 1, first = true, DomainList = domainConstraintList, last = true, MetadataAttributeId = metadataAttribute.Id, ParentStepId = parentStepId, Errors = null }); }
public static bool IsRequired(BaseUsage usage) { if (usage.MinCardinality > 0) return true; else return false; }
private List<StepInfo> GetChildrenStepsUpdated(BaseUsage usage, StepInfo parent, string parentXpath) { List<StepInfo> childrenSteps = new List<StepInfo>(); List<BaseUsage> childrenUsages = UsageHelper.GetCompoundChildrens(usage); List<StepModelHelper> stepHelperModelList = (List<StepModelHelper>)TaskManager.Bus[CreateTaskmanager.METADATA_STEP_MODEL_HELPER]; foreach (BaseUsage u in childrenUsages) { string label = u.Label.Replace(" ", string.Empty); string xPath = parentXpath + "//" + label + "[1]"; bool complex = false; string actionName = ""; if (u is MetadataPackageUsage) { actionName = "SetMetadataPackage"; } else { actionName = "SetMetadataCompoundAttribute"; if (u is MetadataAttributeUsage) { MetadataAttributeUsage mau = (MetadataAttributeUsage)u; if (mau.MetadataAttribute.Self is MetadataCompoundAttribute) complex = true; } if (u is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mau = (MetadataNestedAttributeUsage)u; if (mau.Member.Self is MetadataCompoundAttribute) complex = true; } } if (complex) { StepInfo s = new StepInfo(u.Label) { Id = TaskManager.GenerateStepId(), Parent = parent, IsInstanze = false, //GetActionInfo = new ActionInfo //{ // ActionName = actionName, // ControllerName = "CreateSetMetadataPackage", // AreaName = "DCM" //}, //PostActionInfo = new ActionInfo //{ // ActionName = actionName, // ControllerName = "CreateSetMetadataPackage", // AreaName = "DCM" //} }; s.Children = UpdateStepsBasedOnUsage(u, s, xPath).ToList(); childrenSteps.Add(s); if (TaskManager.Root.Children.Where(z => z.title.Equals(s.title)).Count() == 0) { StepModelHelper p = GetStepModelhelper(parent.Id); stepHelperModelList.Add(new StepModelHelper(s.Id, 1, u, xPath, p)); } } } return childrenSteps; }
static void Main(string[] args) { BaseUsage.Run(); Console.Read(); }
private StepInfo LoadStepsBasedOnUsage(BaseUsage usage, StepInfo current, string parentXpath, StepModelHelper parent) { // genertae action, controller base on usage string actionName = ""; string childName = ""; int min = usage.MinCardinality; if (usage is MetadataPackageUsage) { actionName = "SetMetadataPackageInstanze"; childName = ((MetadataPackageUsage)usage).MetadataPackage.Name; } else { actionName = "SetMetadataCompoundAttributeInstanze"; if (usage is MetadataNestedAttributeUsage) childName = ((MetadataNestedAttributeUsage)usage).Member.Name; if (usage is MetadataAttributeUsage) childName = ((MetadataAttributeUsage)usage).MetadataAttribute.Name; } List<StepInfo> list = new List<StepInfo>(); List<StepModelHelper> stepHelperModelList = (List<StepModelHelper>)TaskManager.Bus[CreateTaskmanager.METADATA_STEP_MODEL_HELPER]; if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATA_XML)) { XDocument xMetadata = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML]; //var x = new XElement("null"); XElement parentXElement = new XElement("tmp"); Dictionary<string, string> keyValueDic = new Dictionary<string, string>(); keyValueDic.Add("id", usage.Id.ToString()); if (usage is MetadataPackageUsage) { keyValueDic.Add("type", BExIS.Xml.Helpers.XmlNodeType.MetadataPackageUsage.ToString()); //elements = XmlUtility.GetXElementsByAttribute(usage.Label, keyValueDic, xMetadata).ToList(); parentXElement = XmlUtility.GetXElementByXPath(parent.XPath, xMetadata); } else { keyValueDic.Add("type", BExIS.Xml.Helpers.XmlNodeType.MetadataAttributeUsage.ToString()); //elements = XmlUtility.GetXElementsByAttribute(usage.Label, keyValueDic, xMetadata, parentXpath).ToList(); parentXElement = XmlUtility.GetXElementByXPath(parent.XPath, xMetadata); } //foreach (var x in elements) //{ XElement x = parentXElement; if (x != null && !x.Name.Equals("null")) { IEnumerable<XElement> xelements = x.Elements(); if (xelements.Count() > 0) { int counter = 0; XElement last = null; foreach (XElement element in xelements) { // if the last has not the same name reset count if (last != null && !last.Name.Equals(element.Name)) { counter = 0; } last = element; counter++; string title = counter.ToString(); //usage.Label+" (" + counter + ")"; long id = Convert.ToInt64((element.Attribute("roleId")).Value.ToString()); StepInfo s = new StepInfo(title) { Id = TaskManager.GenerateStepId(), Parent = current, IsInstanze = true, HasContent = UsageHelper.HasUsagesWithSimpleType(usage), //GetActionInfo = new ActionInfo //{ // ActionName = actionName, // ControllerName = "CreateSetMetadataPackage", // AreaName = "DCM" //}, //PostActionInfo = new ActionInfo //{ // ActionName = actionName, // ControllerName = "CreateSetMetadataPackage", // AreaName = "DCM" //} }; string xPath = parentXpath + "//" + childName.Replace(" ", string.Empty) + "[" + counter + "]"; if (TaskManager.Root.Children.Where(z => z.title.Equals(title)).Count() == 0) { StepModelHelper newStepModelHelper = new StepModelHelper(s.Id, counter, usage, xPath, parent); stepHelperModelList.Add(newStepModelHelper); s.Children = GetChildrenStepsFromMetadata(usage, s, xPath, newStepModelHelper); current.Children.Add(s); } } } } //} //TaskManager.AddToBus(CreateDatasetTaskmanager.METADATAPACKAGE_IDS, MetadataPackageDic); } return current; }
public static MetadataCompoundAttributeModel CreateMetadataCompoundAttributeModel(BaseUsage metadataAttributeUsage, int number) { return(new MetadataCompoundAttributeModel { Id = metadataAttributeUsage.Id, Number = number, Source = metadataAttributeUsage, DisplayName = metadataAttributeUsage.Label, Discription = metadataAttributeUsage.Description, MinCardinality = metadataAttributeUsage.MinCardinality, MaxCardinality = metadataAttributeUsage.MaxCardinality, NumberOfSourceInPackage = 1, first = true, last = true }); }
private void RemoveAttributeToXml(BaseUsage parentUsage, int packageNumber, BaseUsage attribute, int number, string metadataAttributeName, string parentXPath) { TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; XDocument metadataXml = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML]; XmlMetadataWriter xmlMetadataWriter = new XmlMetadataWriter(XmlNodeMode.xPath); metadataXml = xmlMetadataWriter.RemoveAttribute(metadataXml, attribute, number, metadataAttributeName, parentXPath); TaskManager.Bus[CreateTaskmanager.METADATA_XML] = metadataXml; // locat path //string path = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "metadataTemp.Xml"); //metadataXml.Save }
public static MetadataAttributeModel CreateMetadataAttributeModel(BaseUsage current, BaseUsage parent, long metadataStructureId, int packageModelNumber, long parentStepId) { MetadataAttribute metadataAttribute; List <object> domainConstraintList = new List <object>(); string constraintsDescription = ""; double lowerBoundary = 0; double upperBoundary = 0; LinkElementType type = LinkElementType.MetadataNestedAttributeUsage; bool locked = false; bool entityMappingExist = false; bool partyMappingExist = false; string metadataAttributeName = ""; //simple bool partySimpleMappingExist = false; //complex bool partyComplexMappingExist = false; if (current is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)current; metadataAttribute = mnau.Member; type = LinkElementType.MetadataNestedAttributeUsage; } else { MetadataAttributeUsage mau = (MetadataAttributeUsage)current; metadataAttribute = mau.MetadataAttribute; type = LinkElementType.MetadataAttributeUsage; } if (metadataAttribute.Constraints.Where(c => (c is DomainConstraint)).Count() > 0) { domainConstraintList = createDomainContraintList(metadataAttribute); } if (metadataAttribute.Constraints.Count > 0) { foreach (Constraint c in metadataAttribute.Constraints) { if (string.IsNullOrEmpty(constraintsDescription)) { constraintsDescription = c.FormalDescription; } else { constraintsDescription = String.Format("{0}\n{1}", constraintsDescription, c.FormalDescription); } } if (metadataAttribute.DataType.Name == "string" && metadataAttribute.Constraints.Where(c => (c is RangeConstraint)).Count() > 0) { foreach (RangeConstraint r in metadataAttribute.Constraints.Where(c => (c is RangeConstraint))) { lowerBoundary = r.Lowerbound; upperBoundary = r.Upperbound; } } } //set metadata attr name metadataAttributeName = metadataAttribute.Name; //load displayPattern DataTypeDisplayPattern dtdp = DataTypeDisplayPattern.Materialize(metadataAttribute.DataType.Extra); string displayPattern = ""; if (dtdp != null) { displayPattern = dtdp.StringPattern; } //ToDO/Check if dim is active //check if its linked with a system field // locked = MappingUtils.ExistSystemFieldMappings(current.Id, type); // check if a mapping for parties exits partyMappingExist = MappingUtils.ExistMappingWithParty(current.Id, type); // check if mapping to this metadata attribute is simple or complex. // complex means, that the attribute is defined in the context of the parent // e.g. name of User // simple means, that the attribute is not defined in the context of the // e.g. DataCreator Name in Contacts as list of contacts partySimpleMappingExist = hasSimpleMapping(current.Id, type); partyComplexMappingExist = hasComplexMapping(current.Id, type); // check if a mapping for entites exits entityMappingExist = MappingUtils.ExistMappingWithEntity(current.Id, type); return(new MetadataAttributeModel { Id = current.Id, Number = 1, ParentModelNumber = packageModelNumber, MetadataStructureId = metadataStructureId, MetadataAttributeName = metadataAttributeName, Parent = parent, Source = current, DisplayName = current.Label, Discription = current.Description, ConstraintDescription = constraintsDescription, DataType = metadataAttribute.DataType.Name, SystemType = metadataAttribute.DataType.SystemType, DisplayPattern = displayPattern, MinCardinality = current.MinCardinality, MaxCardinality = current.MaxCardinality, NumberOfSourceInPackage = 1, first = true, DomainList = domainConstraintList, last = true, MetadataAttributeId = metadataAttribute.Id, ParentStepId = parentStepId, Errors = null, Locked = locked, EntityMappingExist = entityMappingExist, PartyMappingExist = partyMappingExist, PartySimpleMappingExist = partySimpleMappingExist, PartyComplexMappingExist = partyComplexMappingExist, LowerBoundary = lowerBoundary, UpperBoundary = upperBoundary, }); }
private void UpdateAttribute(BaseUsage parentUsage, int packageNumber, BaseUsage attribute, int number, object value, string parentXpath) { TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; XDocument metadataXml = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML]; XmlMetadataWriter xmlMetadataWriter = new XmlMetadataWriter(XmlNodeMode.xPath); metadataXml = xmlMetadataWriter.Update(metadataXml, attribute, number, value, UsageHelper.GetNameOfType(attribute), parentXpath); TaskManager.Bus[CreateTaskmanager.METADATA_XML] = metadataXml; // locat path string path = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "metadataTemp.Xml"); metadataXml.Save(path); }
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); }
private List<StepInfo> UpdateStepsBasedOnUsage(BaseUsage usage, StepInfo currentSelected, string parentXpath) { // genertae action, controller base on usage string actionName = ""; string childName = ""; if (usage is MetadataPackageUsage) { actionName = "SetMetadataPackageInstanze"; childName = ((MetadataPackageUsage)usage).MetadataPackage.Name; } else { actionName = "SetMetadataCompoundAttributeInstanze"; if (usage is MetadataNestedAttributeUsage) childName = ((MetadataNestedAttributeUsage)usage).Member.Name; if (usage is MetadataAttributeUsage) childName = ((MetadataAttributeUsage)usage).MetadataAttribute.Name; } List<StepInfo> list = new List<StepInfo>(); List<StepModelHelper> stepHelperModelList = (List<StepModelHelper>)TaskManager.Bus[CreateTaskmanager.METADATA_STEP_MODEL_HELPER]; if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATA_XML)) { XDocument xMetadata = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML]; var x = XmlUtility.GetXElementByXPath(parentXpath, xMetadata); if (x != null && !x.Name.Equals("null")) { StepInfo current = currentSelected; IEnumerable<XElement> xelements = x.Elements(); if (xelements.Count() > 0) { int counter = 0; foreach (XElement element in xelements) { counter++; string title = counter.ToString(); if (current.Children.Where(s => s.title.Equals(title)).Count() == 0) { long id = Convert.ToInt64((element.Attribute("roleId")).Value.ToString()); StepInfo s = new StepInfo(title) { Id = TaskManager.GenerateStepId(), Parent = current, IsInstanze = true, //GetActionInfo = new ActionInfo //{ // ActionName = actionName, // ControllerName = "CreateSetMetadataPackage", // AreaName = "DCM" //}, //PostActionInfo = new ActionInfo //{ // ActionName = actionName, // ControllerName = "CreateSetMetadataPackage", // AreaName = "DCM" //} }; string xPath = parentXpath + "//" + childName.Replace(" ", string.Empty) + "[" + counter + "]"; s.Children = GetChildrenStepsUpdated(usage, s, xPath); list.Add(s); if (TaskManager.Root.Children.Where(z => z.Id.Equals(s.Id)).Count() == 0) { StepModelHelper parent = GetStepModelhelper(current.Id); StepModelHelper newStepModelHelper = new StepModelHelper(s.Id, counter, usage, xPath, parent); stepHelperModelList.Add(newStepModelHelper); } }//end if }//end foreach }//end if } } return list; }
public static MetadataAttributeModel Convert(BaseUsage current , BaseUsage parent, long metadataStructureId, int packageModelNumber, long parentStepId) { MetadataAttribute metadataAttribute; List<object> domainConstraintList = new List<object>(); string constraintsDescription=""; if (current is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)current; metadataAttribute = mnau.Member; } else { MetadataAttributeUsage mau = (MetadataAttributeUsage)current; metadataAttribute = mau.MetadataAttribute; } if (metadataAttribute.Constraints.Where(c => (c is DomainConstraint)).Count() > 0) domainConstraintList = createDomainContraintList(metadataAttribute); if (metadataAttribute.Constraints.Count > 0) { foreach (Constraint c in metadataAttribute.Constraints) { if (string.IsNullOrEmpty(constraintsDescription)) constraintsDescription = c.FormalDescription; else constraintsDescription = String.Format("{0}\n{1}", constraintsDescription, c.FormalDescription); } } //load displayPattern DataTypeDisplayPattern dtdp = DataTypeDisplayPattern.Materialize(metadataAttribute.DataType.Extra); string displayPattern=""; if(dtdp !=null) displayPattern = dtdp.StringPattern; return new MetadataAttributeModel { Id = current.Id, Number = 1, ParentModelNumber = packageModelNumber, MetadataStructureId = metadataStructureId, Parent = parent, Source = current, DisplayName = current.Label, Discription = current.Description, ConstraintDescription = constraintsDescription, DataType = metadataAttribute.DataType.Name, SystemType = metadataAttribute.DataType.SystemType, DisplayPattern = displayPattern, MinCardinality = current.MinCardinality, MaxCardinality = current.MaxCardinality, NumberOfSourceInPackage = 1, first = true, DomainList = domainConstraintList, last = true, MetadataAttributeId = metadataAttribute.Id, ParentStepId = parentStepId, Errors = null }; }