Beispiel #1
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;
        }
Beispiel #2
0
        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;
        }
Beispiel #3
0
        /// <summary>
        /// Update metadataattributemodels in a parentmodel.
        /// Update number of childrens, based on the usage id
        /// </summary>
        /// <param name="stepModelHelper"></param>
        /// <param name="usageId"></param>
        /// <returns></returns>
        private StepModelHelper UpdateChildrens(StepModelHelper stepModelHelper, long usageId)
        {
            IEnumerable<MetadataAttributeModel> mams = stepModelHelper.Model.MetadataAttributeModels.Where(m => m.Source.Id.Equals(usageId));

            for (int i = 0; i < mams.Count(); i++)
            {
                MetadataAttributeModel child = mams.ElementAt(i);
                child.NumberOfSourceInPackage = mams.Count();
                child.Number = i + 1;
            }

            mams = UpdateFirstAndLast(mams.ToList()).AsEnumerable();

            return stepModelHelper;
        }
Beispiel #4
0
        private StepModelHelper UpdateChildrens(StepModelHelper stepModelHelper)
        {
            int count = stepModelHelper.Model.MetadataAttributeModels.Count;

            for (int i = 0; i < count; i++)
            {
                MetadataAttributeModel child = stepModelHelper.Model.MetadataAttributeModels.ElementAt(i);
                child.NumberOfSourceInPackage = count;
                child.Number = i + 1;
            }

            stepModelHelper.Model.MetadataAttributeModels = UpdateFirstAndLast(stepModelHelper.Model.MetadataAttributeModels);

            return stepModelHelper;
        }
Beispiel #5
0
        private StepModelHelper UpComplexModel(StepModelHelper stepModelHelperParent, long id, int number)
        {
            List<StepModelHelper> list = stepModelHelperParent.Childrens;

            return stepModelHelperParent;
        }
Beispiel #6
0
        private StepModelHelper Up(StepModelHelper stepModelHelperParent, long id, int number)
        {
            List<MetadataAttributeModel> list = stepModelHelperParent.Model.MetadataAttributeModels;

            MetadataAttributeModel temp = list.Where(m => m.Id.Equals(id) && m.Number.Equals(number)).FirstOrDefault();
            int index = list.IndexOf(temp);

            list.RemoveAt(index);
            list.Insert(index - 1, temp);

            return stepModelHelperParent;
        }
Beispiel #7
0
 private void setStepModelActive(StepModelHelper model)
 {
     model.Activated = true;
     if (model.Parent != null)
         setStepModelActive(model.Parent);
 }
Beispiel #8
0
        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;
        }
Beispiel #9
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;
        }
Beispiel #10
0
        /// <summary>
        /// insert at a spezific number in the same children usages
        /// </summary>
        /// <param name="childModel"></param>
        /// <param name="stepModelHelperParent"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        private StepModelHelper Insert(MetadataAttributeModel childModel, StepModelHelper stepModelHelperParent, int number)
        {
            MetadataAttributeModel childrensWithSameUsage = stepModelHelperParent.Model.MetadataAttributeModels.Where(m => m.Source.Id.Equals(childModel.Source.Id)).First();
            int indexOfFirstUsage = stepModelHelperParent.Model.MetadataAttributeModels.IndexOf(childrensWithSameUsage);

            stepModelHelperParent.Model.MetadataAttributeModels.Insert(indexOfFirstUsage + number - 1, childModel);

            return stepModelHelperParent;
        }
Beispiel #11
0
        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;
        }
Beispiel #12
0
        private StepModelHelper getChildModelsHelper(StepModelHelper stepModelHelper)
        {
            if (stepModelHelper.Model.StepInfo.Children.Count > 0)
            {
                foreach (var childStep in stepModelHelper.Model.StepInfo.Children)
                {
                    StepModelHelper childStepModelHelper = GetStepModelhelper(childStep.Id);

                    if (childStepModelHelper.Model == null)
                    {
                        if (childStepModelHelper.Usage is MetadataPackageUsage)
                            childStepModelHelper.Model = CreatePackageModel(childStep.Id, false);

                        if (childStepModelHelper.Usage is MetadataNestedAttributeUsage)
                            childStepModelHelper.Model = CreateCompoundModel(childStep.Id, false);

                        if (childStepModelHelper.Usage is MetadataAttributeUsage)
                            childStepModelHelper.Model = CreateCompoundModel(childStep.Id, false);

                        if (childStepModelHelper.Model.StepInfo.IsInstanze)
                            LoadSimpleAttributesForModelFromXml(childStepModelHelper);
                    }

                    childStepModelHelper = getChildModelsHelper(childStepModelHelper);
                    stepModelHelper.Childrens.Add(childStepModelHelper);
                }
            }

            return stepModelHelper;
        }
Beispiel #13
0
        public ActionResult AddComplexUsage(int parentStepId, int number)
        {
            TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];

            //TaskManager.SetCurrent(TaskManager.Get(parentStepId));

            long metadataStructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.METADATASTRUCTURE_ID]);
            int position = number + 1;

            StepModelHelper parentStepModelHelper = GetStepModelhelper(parentStepId);
            BaseUsage u = LoadUsage(parentStepModelHelper.Usage);

            //Create new step
            StepInfo newStep = new StepInfo(UsageHelper.GetNameOfType(u))
            {
                Id = TaskManager.GenerateStepId(),
                parentTitle = parentStepModelHelper.Model.StepInfo.title,
                Parent = parentStepModelHelper.Model.StepInfo,
                IsInstanze = true,
            };

            string xPath = parentStepModelHelper.XPath + "//" + UsageHelper.GetNameOfType(u) + "[" + position + "]";

            // add to parent stepId
            parentStepModelHelper.Model.StepInfo.Children.Add(newStep);
            TaskManager.StepInfos.Add(newStep);

            // create Model
            AbstractMetadataStepModel model = null;

            if (u is MetadataAttributeUsage || u is MetadataNestedAttributeUsage)
            {
                model = MetadataCompoundAttributeModel.ConvertToModel(parentStepModelHelper.Usage, number);
                model.Number = position;

                ((MetadataCompoundAttributeModel)model).ConvertMetadataAttributeModels(LoadUsage(parentStepModelHelper.Usage), metadataStructureId, newStep.Id);

                //Update metadata xml
                //add step to metadataxml
                AddCompoundAttributeToXml(model.Source, model.Number, parentStepModelHelper.XPath);
            }

            if (u is MetadataPackageUsage)
            {
                model = MetadataPackageModel.Convert(parentStepModelHelper.Usage, number);
                model.Number = position;
                ((MetadataPackageModel)model).ConvertMetadataAttributeModels(LoadUsage(parentStepModelHelper.Usage), metadataStructureId, newStep.Id);

                //Update metadata xml
                //add step to metadataxml
                AddPackageToXml(model.Source, model.Number, parentStepModelHelper.XPath);
            }

            // create StepModel for new step
            StepModelHelper newStepModelhelper = new StepModelHelper
            {
                StepId = newStep.Id,
                Usage = parentStepModelHelper.Usage,
                Number = position,
                Model = model,
                XPath = xPath,
                Level = parentStepModelHelper.Level+1,
                Activated = true
            };

            newStep.Children = GetChildrenSteps(u, newStep, xPath, newStepModelhelper);
            newStepModelhelper.Model.StepInfo = newStep;
            newStepModelhelper = getChildModelsHelper(newStepModelhelper);

            // add stepmodel to dictionary
            AddStepModelhelper(newStepModelhelper);

            //add stepModel to parentStepModel
            parentStepModelHelper.Childrens.Insert(newStepModelhelper.Number - 1, newStepModelhelper);

            //update childrens of the parent step based on number
            for (int i = 0; i < parentStepModelHelper.Childrens.Count; i++)
            {
                StepModelHelper smh = parentStepModelHelper.Childrens.ElementAt(i);
                smh.Number = i + 1;
            }

            // add step to parent and update title of steps
            //parentStepModelHelper.Model.StepInfo.Children.Insert(newStepModelhelper.Number - 1, newStep);
            for (int i = 0; i < parentStepModelHelper.Model.StepInfo.Children.Count; i++)
            {
                StepInfo si = parentStepModelHelper.Model.StepInfo.Children.ElementAt(i);
                si.title = (i + 1).ToString();
            }

            //// load InstanzB for parentmodel
            parentStepModelHelper.Model.ConvertInstance((XDocument)(TaskManager.Bus[CreateTaskmanager.METADATA_XML]), parentStepModelHelper.XPath);

            if (u is MetadataAttributeUsage || u is MetadataNestedAttributeUsage)
            {
                return PartialView("_metadataCompoundAttributeView", parentStepModelHelper);
            }

            if (u is MetadataPackageUsage)
            {
                return PartialView("_metadataCompoundAttributeView", parentStepModelHelper);
            }

            return null;
        }
Beispiel #14
0
        private void AdvanceTaskManagerBasedOnExistingMetadata(long MetadataStructureId)
        {
            TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];

            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            List<MetadataPackageUsage> metadataPackageList = metadataStructureManager.GetEffectivePackages(MetadataStructureId).ToList();

            List<StepModelHelper> stepModelHelperList = new List<StepModelHelper>();
            if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATA_STEP_MODEL_HELPER))
            {
                TaskManager.Bus[CreateTaskmanager.METADATA_STEP_MODEL_HELPER] = stepModelHelperList;
            }
            else
            {
                TaskManager.Bus.Add(CreateTaskmanager.METADATA_STEP_MODEL_HELPER, stepModelHelperList);
            }

            TaskManager.StepInfos = new List<StepInfo>();

            foreach (MetadataPackageUsage mpu in metadataPackageList)
            {
                //only add none optional usages
                StepInfo si = new StepInfo(mpu.Label)
                {
                    Id = TaskManager.GenerateStepId(),
                    parentTitle = mpu.MetadataPackage.Name,
                    Parent = TaskManager.Root,
                    IsInstanze = false,
                };

                TaskManager.StepInfos.Add(si);
                StepModelHelper stepModelHelper = new StepModelHelper(si.Id, 1, mpu, "Metadata//" + mpu.Label.Replace(" ", string.Empty) + "[1]", null);

                stepModelHelperList.Add(stepModelHelper);

                si = LoadStepsBasedOnUsage(mpu, si, "Metadata//" + mpu.Label.Replace(" ", string.Empty) + "[1]", stepModelHelper);
                TaskManager.Root.Children.Add(si);

                TaskManager.Bus[CreateTaskmanager.METADATA_STEP_MODEL_HELPER] = stepModelHelperList;

            }

            TaskManager.Bus[CreateTaskmanager.METADATA_STEP_MODEL_HELPER] = stepModelHelperList;
            Session["CreateDatasetTaskmanager"] = TaskManager;
        }
Beispiel #15
0
        private StepModelHelper AddStepModelhelper(StepModelHelper stepModelHelper)
        {
            TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];
            if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATA_STEP_MODEL_HELPER))
            {
                ((List<StepModelHelper>)TaskManager.Bus[CreateTaskmanager.METADATA_STEP_MODEL_HELPER]).Add(stepModelHelper);

                return stepModelHelper;
            }

            return stepModelHelper;
        }