示例#1
0
文件: Migration.cs 项目: BEXIS2/Core
        public string TransferPublications()
        {
            string xsdPath = Path.Combine(AppConfiguration.DataPath, "Temp", "Administrator");
            PublicationManager pms = new PublicationManager();
            MetadataCreator metadataCreator = new MetadataCreator();
            //Import MetaDataStructure
            string schemaFile = xsdPath + @"\publication.xsd";
            //open schema
            XmlSchemaManager xmlSchemaManager = new XmlSchemaManager();
            string userName = "******";
            xmlSchemaManager.Load(schemaFile, userName);
            long metadataStructureId = 0;
            try
            {
                metadataStructureId = metadataCreator.importMetadataStructure(schemaFile, userName, schemaFile, "Publication", "Metadata/publicationDetails/publicationDetails/title/title", "Metadata/publicationDetails/publicationDetails/information/information");// xmlSchemaManager.GenerateMetadataStructure("publication", "publication");
            }
            catch (Exception ex)
            {
                xmlSchemaManager.Delete("publication");
                return "Couldn't create publication metadatastructure!";
            }
            //Create an empty publication
            MetadataStructureManager msm = new MetadataStructureManager();
            MetadataStructure metadataStructure = msm.Repo.Get(metadataStructureId);
            XmlDocument metadataXmlTemplate = BExIS.Xml.Helpers.XmlMetadataWriter.ToXmlDocument(metadataCreator.createXmlTemplate(metadataStructureId));
            var publicationsMetaData = metadataCreator.getPublicationsMetadataXml(DataBase);
            var xmlMapperManager = new XmlMapperManager();
            string filePath = AppConfiguration.GetModuleWorkspacePath("BMM");
            string path_mappingFile = filePath + @"\bexis_publication_metadata_mapping.xml";
            foreach (var publicationMetaData in publicationsMetaData)
            {
                var pc = pms.CreateEmptyPublication(metadataStructure);
                var publicationId = pc.Id;
                if (pms.IsPublicationCheckedOutFor(publicationId, userName) || pms.CheckOutPublication(publicationId, userName))
                {

                    PublicationVersion workingCopy = pms.GetPublicationWorkingCopy(publicationId);
                    // XML mapper + mapping file
                    xmlMapperManager.Load(path_mappingFile, "Publication");
                    XmlDocument metadataBpp = xmlMapperManager.Generate(publicationMetaData.MetaDataXml, 99);
                    metadataBpp = metadataCreator.fillInXmlAttributes(metadataBpp, metadataXmlTemplate);
                    workingCopy.Metadata = metadataBpp;

                    foreach (var pbContent in publicationMetaData.PublicationContentDescriptors)
                    {
                        string storePath = Path.Combine(AppConfiguration.DataPath, "Publications", publicationId.ToString());
                        storePath = Path.Combine(storePath, publicationId.ToString() + "_" + workingCopy.VersionNo.ToString() + "_" + pbContent.Name);
                        File.Move(pbContent.URI, storePath);
                        pbContent.URI = storePath;
                        pbContent.PublicationVersion = workingCopy;
                        workingCopy.PublicationContentDescriptors.Add(pbContent);
                    }
                    pms.CheckInPublication(publicationId, "Metadata was submited.", userName);
                }
            }
            return "";
        }