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;
}