BExIS.Web.Shell.Areas.DCM.Models.CreateDataset.StepModelHelper.GetXPathFromSimpleAttribute C# (CSharp) Method

GetXPathFromSimpleAttribute() public method

public GetXPathFromSimpleAttribute ( long id ) : string
id long
return string
        public string GetXPathFromSimpleAttribute(long id)
        {
            if (Model != null && Model.MetadataAttributeModels != null && Model.MetadataAttributeModels.Any())
            {
                MetadataAttributeModel temp = Model.MetadataAttributeModels.Where(a => a.Id.Equals(id) && a.Number.Equals(Number)).First();

                return XPath + "//" + temp.Source.Label + "[1]//" + temp.GetMetadataAttribute().Self.Name;
            }

            return "";
        }

Same methods

StepModelHelper::GetXPathFromSimpleAttribute ( long id, long number ) : string

Usage Example

Example #1
0
        private AbstractMetadataStepModel LoadSimpleAttributesForModelFromXml(StepModelHelper stepModelHelper)
        {
            TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];
            XDocument metadata = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML];

            XElement complexElement = XmlUtility.GetXElementByXPath(stepModelHelper.XPath, metadata);
            List<MetadataAttributeModel> additionalyMetadataAttributeModel = new List<MetadataAttributeModel>();

            foreach (MetadataAttributeModel simpleMetadataAttributeModel in stepModelHelper.Model.MetadataAttributeModels)
            {
                int numberOfSMM = 1;
                if (complexElement != null)
                {
                    //Debug.WriteLine("XXXXXXXXXXXXXXXXXXXX");
                    //Debug.WriteLine(simpleMetadataAttributeModel.Source.Label);
                    IEnumerable<XElement> childs = XmlUtility.GetChildren(complexElement).Where(e => e.Attribute("id").Value.Equals(simpleMetadataAttributeModel.Id.ToString()));

                    if (childs.Any())
                        numberOfSMM = childs.First().Elements().Count();
                }

                for (int i = 1; i <= numberOfSMM; i++)
                {
                    string xpath = stepModelHelper.GetXPathFromSimpleAttribute(simpleMetadataAttributeModel.Id, i);
                    XElement simpleElement = XmlUtility.GetXElementByXPath(xpath, metadata);

                    if (i == 1)
                    {

                        if (simpleElement != null && !String.IsNullOrEmpty(simpleElement.Value))
                        {
                            simpleMetadataAttributeModel.Value = simpleElement.Value;
                            // if at least on item has a value, the parent should be activated
                            setStepModelActive(stepModelHelper);
                        }

                    }
                    else
                    {
                        MetadataAttributeModel newMetadataAttributeModel = simpleMetadataAttributeModel.Kopie(i, numberOfSMM);
                        newMetadataAttributeModel.Value = simpleElement.Value;
                        if (i == numberOfSMM) newMetadataAttributeModel.last = true;
                        additionalyMetadataAttributeModel.Add(newMetadataAttributeModel);
                    }

                }
            }

            foreach (var item in additionalyMetadataAttributeModel)
            {
                List<MetadataAttributeModel> tempList = stepModelHelper.Model.MetadataAttributeModels;

                int indexOfLastSameAttribute = tempList.IndexOf(tempList.Where(a => a.Id.Equals(item.Id)).Last());
                tempList.Insert(indexOfLastSameAttribute + 1, item);
            }

            return stepModelHelper.Model;
        }