Beispiel #1
0
        public ActionResult Delete(long id)
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();


            try
            {
                MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(id);
                // delete local files
                if (XmlSchemaManager.Delete(metadataStructure))
                {
                    metadataStructureManager.Delete(metadataStructure);
                }

                if (metadataStructureManager.Repo.Get(id) == null)
                {
                    return(Json(true));
                }

                return(Json(false));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
            finally
            {
                metadataStructureManager.Dispose();
            }
        }
Beispiel #2
0
 // Adds the schemas to the schema manager.
 void AddUserSchemas()
 {
     while (widget.AddedSchemas.Count > 0)
     {
         XmlSchemaManager.AddUserSchema(widget.AddedSchemas[0]);
         widget.AddedSchemas.RemoveAt(0);
     }
 }
Beispiel #3
0
 // Removes the schemas from the schema manager.
 void RemoveUserSchemas()
 {
     while (widget.RemovedSchemas.Count > 0)
     {
         XmlSchemaManager.RemoveUserSchema(widget.RemovedSchemas [0].NamespaceUri);
         widget.RemovedSchemas.RemoveAt(0);
     }
 }
Beispiel #4
0
        private void ImportSchema(string name, string filename, string root, string entity, string entityFullName, string titlePath, string descriptionPath)
        {
            long   metadataStructureid = 0;
            string schemaName          = name;

            string filepath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "Metadata", name,
                                           filename);

            XmlSchemaManager xmlSchemaManager = new XmlSchemaManager();

            //load
            try
            {
                xmlSchemaManager.Load(filepath, "application");
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //generate
            try
            {
                metadataStructureid = xmlSchemaManager.GenerateMetadataStructure(root, schemaName);

                try
                {
                    //set parameters
                    string mappingFileImport = xmlSchemaManager.mappingFileNameImport;
                    string mappingFileExport = xmlSchemaManager.mappingFileNameExport;

                    StoreParametersToMetadataStruture(
                        metadataStructureid,
                        titlePath,
                        descriptionPath,
                        entity,
                        entityFullName,
                        mappingFileImport,
                        mappingFileExport);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                xmlSchemaManager.Delete(schemaName);
            }
        }
Beispiel #5
0
        private void LoadXSDSchema(string username)
        {
            TaskManager = (ImportMetadataStructureTaskManager)Session["TaskManager"];

            string path = TaskManager.Bus[ImportMetadataStructureTaskManager.FILEPATH].ToString();

            //open schema
            XmlSchemaManager xmlSchemaManager = new XmlSchemaManager();

            xmlSchemaManager.Load(path, username);

            if (TaskManager.Bus.ContainsKey(ImportMetadataStructureTaskManager.XML_SCHEMA_MANAGER))
            {
                TaskManager.Bus[ImportMetadataStructureTaskManager.XML_SCHEMA_MANAGER] = xmlSchemaManager;
            }
            else
            {
                TaskManager.Bus.Add(ImportMetadataStructureTaskManager.XML_SCHEMA_MANAGER, xmlSchemaManager);
            }
        }
Beispiel #6
0
 public void EmptyString()
 {
     Assert.IsFalse(XmlSchemaManager.IsXmlSchemaNamespace(String.Empty));
 }
Beispiel #7
0
 public void IsNotXmlSchemaNamespace()
 {
     Assert.IsFalse(XmlSchemaManager.IsXmlSchemaNamespace("http://foo.com"));
 }
Beispiel #8
0
 public void IsXmlSchemaNamespace()
 {
     Assert.IsTrue(XmlSchemaManager.IsXmlSchemaNamespace("http://www.w3.org/2001/XMLSchema"));
 }
        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;

            if (!RegExHelper.IsFilenameValid(schemaName))
            {
                model.ErrorList.Add(new Error(ErrorType.Other,
                                              "Name : \" " + schemaName + " \" is invalid. These special characters are not allowed : \\/:*?\"<>|"));
            }
            else
            {
                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));
        }
Beispiel #10
0
        /// <summary>
        /// Load from mapping file
        /// create a XmlMapper
        /// </summary>
        /// <returns></returns>
        public XmlMapper Load(string mappingFilePath, string username)
        {
            xmlMapper = new XmlMapper();

            mappingFile = new XmlDocument();
            mappingFile.Load(mappingFilePath);

            XmlNode root = mappingFile.DocumentElement;

            #region get id and name of standard

            XmlNode mapping = mappingFile.GetElementsByTagName(XmlMapperTags.mapping.ToString())[0];

            if (mapping.Attributes.Count > 0)
            {
                foreach (XmlAttribute attr in mapping.Attributes)
                {
                    if (attr.Name.Equals(XmlMapperAttributes.id.ToString()))
                    {
                        xmlMapper.Id = Convert.ToInt32(attr.Value);
                    }

                    if (attr.Name.Equals(XmlMapperAttributes.name.ToString()))
                    {
                        xmlMapper.Name = attr.Value;
                    }
                }
            }

            #endregion get id and name of standard

            #region create Header as xmlMappingHeader

            XmlMappingHeader xmlMappingHeader = new XmlMappingHeader();

            XmlNode header = mappingFile.GetElementsByTagName(XmlMapperTags.header.ToString())[0];

            foreach (XmlNode xmlNode in header.ChildNodes)
            {
                if (xmlNode.NodeType.Equals(System.Xml.XmlNodeType.Element))
                {
                    #region create destination

                    if (xmlNode.Name.Equals(XmlMapperTags.destination.ToString()))
                    {
                        xmlMappingHeader.Destination = Destination.Convert(xmlNode);
                    }

                    #endregion create destination

                    #region read & add packages

                    if (xmlNode.Name.Equals(XmlMapperTags.packages.ToString()))
                    {
                        foreach (XmlNode childNode in xmlNode.ChildNodes)
                        {
                            if (childNode.Name.Equals(XmlMapperTags.package.ToString()))
                            {
                                xmlMappingHeader.AddToPackages(childNode);
                            }
                        }
                    }

                    #endregion read & add packages

                    #region read & add Attributes

                    if (xmlNode.Name.Equals(XmlMapperTags.attributes.ToString()))
                    {
                        foreach (XmlNode childNode in xmlNode.ChildNodes)
                        {
                            if (childNode.Name.Equals(XmlMapperTags.attribute.ToString()))
                            {
                                xmlMappingHeader.AddToAttributes(childNode);
                            }
                        }
                    }

                    #endregion read & add Attributes

                    #region read & add schemas

                    if (xmlNode.Name.Equals(XmlMapperTags.schema.ToString()))
                    {
                        xmlMappingHeader.AddToSchemas(xmlNode);
                    }

                    #endregion read & add schemas
                }
            }

            xmlMapper.Header = xmlMappingHeader;

            #endregion create Header as xmlMappingHeader

            #region create Routes

            XmlNodeList routes = mappingFile.GetElementsByTagName(XmlMapperTags.routes.ToString())[0].ChildNodes;
            foreach (XmlNode childNode in routes)
            {
                xmlMapper.Routes.Add(XmlMappingRoute.Convert(childNode));
            }

            #endregion create Routes

            #region xmlschema

            xmlSchemaManager = new XmlSchemaManager();

            if (xmlMapper.Header.Schemas.Count > 0)
            {
                xmlSchemaManager = new XmlSchemaManager();
                string schemaPath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), xmlMapper.Header.Schemas.First().Value);
                xmlSchemaManager.Load(schemaPath, username);
            }

            #endregion xmlschema

            return(xmlMapper);
        }
Beispiel #11
0
 /// <summary>
 /// Gets XML schema for this class.
 /// <para />
 /// Implemented to support WCF serialization for all types deriving from this type.
 /// </summary>
 /// <param name="schemaSet">The schema set.</param>
 /// <returns>System.Xml.XmlQualifiedName.</returns>
 public static XmlQualifiedName GetModelBaseXmlSchema(XmlSchemaSet schemaSet)
 {
     return(XmlSchemaManager.GetXmlSchema(typeof(ModelBase), schemaSet));
 }