GenerateMetadataStructure() публичный Метод

public GenerateMetadataStructure ( string nameOfStartNode, string schemaName ) : long
nameOfStartNode string
schemaName string
Результат long
        public ActionResult GenerateMS()
        {
            //open schema
                XmlSchemaManager xmlSchemaManager = new XmlSchemaManager();

                string root = "";
                string schemaName = "";
                long metadataStructureid = 0;

                TaskManager = (ImportMetadataStructureTaskManager) Session["TaskManager"];

                if (TaskManager.Bus.ContainsKey(ImportMetadataStructureTaskManager.ROOT_NODE))
                    root = TaskManager.Bus[ImportMetadataStructureTaskManager.ROOT_NODE].ToString();

                if (TaskManager.Bus.ContainsKey(ImportMetadataStructureTaskManager.SCHEMA_NAME))
                    schemaName = TaskManager.Bus[ImportMetadataStructureTaskManager.SCHEMA_NAME].ToString();

                string path = TaskManager.Bus[ImportMetadataStructureTaskManager.FILEPATH].ToString();
                //path = @"https://code.ecoinformatics.org/code/eml/tags/RELEASE_EML_2_1_1/eml.xsd";

                ReadSourceModel model = new ReadSourceModel(TaskManager.Current());
                model.SchemaName = schemaName;
                model.RootNode = root;

                try
                {
                    //file.WriteLine("check schema exist");
                    if (SchemaNameExist(schemaName))
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other,
                            "A Metadata structure with this name already exist. Please choose a other name."));
                    }
                    else
                    if (String.IsNullOrEmpty(schemaName))
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other, "A Metadata structure must have a name."));
                    }
                    else
                        xmlSchemaManager.Load(path, GetUserNameOrDefault());

                    if (!String.IsNullOrEmpty(model.RootNode) && !xmlSchemaManager.Elements.Any(e => e.Name.Equals(model.RootNode)))
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other, "Root node not exist"));
                    }

                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    model.ErrorList.Add(new Error(ErrorType.Other, "Can not create metadatastructure."));
                    throw ex;
                }

                if (model.ErrorList.Count == 0)
                {
                    try
                    {
                        metadataStructureid = xmlSchemaManager.GenerateMetadataStructure(root, schemaName);
                    }
                    catch (Exception ex)
                    {
                        xmlSchemaManager.Delete(schemaName);
                        ModelState.AddModelError("", ex.Message);
                        model.ErrorList.Add(new Error(ErrorType.Other, "Can not create metadatastructure."));
                    }
                }

                TaskManager.AddToBus(ImportMetadataStructureTaskManager.MAPPING_FILE_NAME_IMPORT,
                    xmlSchemaManager.mappingFileNameImport);
                TaskManager.AddToBus(ImportMetadataStructureTaskManager.MAPPING_FILE_NAME_EXPORT,
                    xmlSchemaManager.mappingFileNameExport);

                model.StepInfo.notExecuted = false;

                if (model.ErrorList.Count == 0)
                {
                    model.IsGenerated = true;

                    if (TaskManager.Bus.ContainsKey(ImportMetadataStructureTaskManager.IS_GENERATE))
                        TaskManager.Bus[ImportMetadataStructureTaskManager.IS_GENERATE] = true;
                    else
                        TaskManager.Bus.Add(ImportMetadataStructureTaskManager.IS_GENERATE, true);

                    if (TaskManager.Bus.ContainsKey(ImportMetadataStructureTaskManager.METADATASTRUCTURE_ID))
                        TaskManager.Bus[ImportMetadataStructureTaskManager.METADATASTRUCTURE_ID] = metadataStructureid;
                    else
                        TaskManager.Bus.Add(ImportMetadataStructureTaskManager.METADATASTRUCTURE_ID, metadataStructureid);
                }

            return PartialView("ReadSource",model);
        }
Пример #2
0
        // import metadata structure
        public long importMetadataStructure(string filePath, string userName, string schemaFile = "", string schemaName = "", string titlePath = "", string descriptionPath = "")
        {
            if (string.IsNullOrEmpty(schemaFile))
                schemaFile = filePath + @"\schema_toImport.xsd";

            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            XmlSchemaManager xmlSchemaManager = new XmlSchemaManager();
            MetadataStructure metadataStructure = new MetadataStructure();
            if (string.IsNullOrEmpty(schemaName))
                schemaName = "BExIS";
            string root = "";
            if (string.IsNullOrEmpty(titlePath))
                titlePath = "Metadata/general/general/title/title";
            if (string.IsNullOrEmpty(descriptionPath))
                descriptionPath = "Metadata/methodology/methodology/introduction/introduction";

            MetadataStructure existMetadataStructures = metadataStructureManager.Repo.Get(m => m.Name.Equals(schemaName)).FirstOrDefault();

            if (existMetadataStructures == null)
            {
                // load schema xsd
                long metadataStructureid = 0;
                xmlSchemaManager.Load(schemaFile, userName);
                try
                {
                    metadataStructureid = xmlSchemaManager.GenerateMetadataStructure(root, schemaName);
                }
                catch
                {
                    xmlSchemaManager.Delete(schemaName);
                }
                metadataStructure = metadataStructureManager.Repo.Get(metadataStructureid);
                try
                {
                    // set parameters:
                    XmlDocument xmlDoc = new XmlDocument();
                    if (metadataStructure.Extra != null)
                    {
                        xmlDoc = (XmlDocument)metadataStructure.Extra;
                    }

                    // add title Node
                    xmlDoc = AddReferenceToMetadatStructure(metadataStructure, "title", titlePath, "extra/nodeReferences/nodeRef", xmlDoc);
                    // add Description
                    xmlDoc = AddReferenceToMetadatStructure(metadataStructure, "description", descriptionPath, "extra/nodeReferences/nodeRef", xmlDoc);

                    metadataStructure.Extra = xmlDoc;
                    metadataStructureManager.Update(metadataStructure);
                }
                catch
                {
                    //
                }
            }
            else
            {
                metadataStructure = existMetadataStructures;
            }

            return metadataStructure.Id;
        }