public ActionResult CreateTestDatasets(int n) { DatasetManager datasetManager = new DatasetManager(); DataStructureManager dataStructureManager = new DataStructureManager(); MetadataStructureManager metadataStructureManager = new MetadataStructureManager(); ResearchPlanManager researchPlanManager = new ResearchPlanManager(); try { var structure = dataStructureManager.UnStructuredDataStructureRepo.Get(1); var metadatastructure = metadataStructureManager.Repo.Get(1); var researchplan = researchPlanManager.Repo.Get(1); var xmlDatasetHelper = new XmlDatasetHelper(); var xmlMetadatWriter = new XmlMetadataWriter(XmlNodeMode.xPath); var metadataXml = xmlMetadatWriter.CreateMetadataXml(metadatastructure.Id); for (int i = 0; i < n; i++) { var dataset = datasetManager.CreateEmptyDataset(structure, researchplan, metadatastructure); if (datasetManager.IsDatasetCheckedOutFor(dataset.Id, "test") || datasetManager.CheckOutDataset(dataset.Id, "test")) { DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(dataset.Id); datasetManager.EditDatasetVersion(workingCopy, null, null, null); datasetManager.CheckInDataset(dataset.Id, "", "test", ViewCreationBehavior.None); workingCopy.Metadata = Xml.Helpers.XmlWriter.ToXmlDocument(metadataXml); string xpath = xmlDatasetHelper.GetInformationPath(metadatastructure.Id, NameAttributeValues.title); workingCopy.Metadata.SelectSingleNode(xpath).InnerText = i.ToString(); workingCopy.Title = i.ToString(); datasetManager.EditDatasetVersion(workingCopy, null, null, null); datasetManager.CheckInDataset(dataset.Id, "", "test", ViewCreationBehavior.None); } } } catch (Exception ex) { throw ex; } finally { datasetManager.Dispose(); dataStructureManager.Dispose(); metadataStructureManager.Dispose(); researchPlanManager.Dispose(); } return(View("Index")); }
private MetadataStructureModel convertToMetadataStructureModel(MetadataStructure metadataStructure, MetadataStructureManager metadataStructureManager) { MetadataStructureModel metadataStructureModel = new MetadataStructureModel(); metadataStructureModel.Id = metadataStructure.Id; metadataStructureModel.Name = metadataStructure.Name; try { metadataStructureModel.MetadataNodes = GetAllXPath(metadataStructure.Id); //get all informaions from xml metadataStructureModel.EntityClasses = GetEntityModelList(); string EntityClassName = xmlDatasetHelper.GetEntityNameFromMetadatStructure(metadataStructure.Id, metadataStructureManager); var entityModel = metadataStructureModel.EntityClasses.Where(e => e.Name.Equals(EntityClassName)) .FirstOrDefault(); if (entityModel != null) { metadataStructureModel.Entity = entityModel; } string xpath = xmlDatasetHelper.GetInformationPath(metadataStructure.Id, NameAttributeValues.title); var searchMetadataNode = metadataStructureModel.MetadataNodes.Where(e => e.XPath.Equals(xpath)).FirstOrDefault(); if (searchMetadataNode != null) { metadataStructureModel.TitleNode = searchMetadataNode.DisplayName; } xpath = xmlDatasetHelper.GetInformationPath(metadataStructure.Id, NameAttributeValues.description); //check if xsd exist string schemapath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "Metadata", metadataStructure.Name); if (Directory.Exists(schemapath) && Directory.GetFiles(schemapath).Length > 0) { metadataStructureModel.HasSchema = true; } var firstOrDefault = metadataStructureModel.MetadataNodes.Where(e => e.XPath.Equals(xpath)).FirstOrDefault(); if (firstOrDefault != null) { metadataStructureModel.DescriptionNode = firstOrDefault.DisplayName; } metadataStructureModel.MetadataNodes = GetAllXPath(metadataStructureModel.Id); metadataStructureModel.Active = xmlDatasetHelper.IsActive(metadataStructure.Id); } catch (Exception exception) { metadataStructureModel = new MetadataStructureModel(); metadataStructureModel.Id = metadataStructure.Id; metadataStructureModel.Name = metadataStructure.Name; } return(metadataStructureModel); }