コード例 #1
0
ファイル: Migration.cs プロジェクト: BEXIS2/Core
        public void DataSetTransfer()
        {
            string filePath = AppConfiguration.GetModuleWorkspacePath("BMM");
            //string xsdPath = @"C:\Data\Temp\Administrator";
            string xsdPath = Path.Combine(AppConfiguration.DataPath, "Temp", "Administrator");
            string xsdUserName = "******";
            string researchPlanName = "Research plan";

            MappingReader mappingReader = new MappingReader();
            AttributeCreator attributeCreator = new AttributeCreator();
            MetadataCreator metadataCreator = new MetadataCreator();
            MigrationHelpers migrationHelpers = new MigrationHelpers();

            #region create datatypes, unit, dimensions for datastructure from mapping file
            // read data types from excel mapping file
            DataTable mappedDataTypes = mappingReader.readDataTypes(filePath);
            // create read data types in bpp
            attributeCreator.CreateDataTypes(ref mappedDataTypes);

            // read dimensions from excel mapping file
            DataTable mappedDimensions = mappingReader.readDimensions(filePath);
            // create dimensions in bpp
            attributeCreator.CreateDimensions(ref mappedDimensions);

            // read units from excel mapping file
            DataTable mappedUnits = mappingReader.readUnits(filePath, mappedDimensions);
            // create read units in bpp
            attributeCreator.CreateUnits(ref mappedUnits, mappedDataTypes);

            // read attributes from excel mapping file
            DataTable mappedAttributes = mappingReader.readAttributes(filePath, mappedUnits, mappedDataTypes);
            // Speicher freigeben
            mappedDataTypes.Clear();
            mappedDimensions.Clear();
            // create read attributes in bpp
            attributeCreator.CreateAttributes(ref mappedAttributes);

            // read variables from XLSX or TSV (tab seperated values) mapping file
            //DataTable mappedVariables = mappingReader.readVariables(filePath, mappedAttributes);
            DataTable mappedVariables = mappingReader.readVariablesTSV(filePath, mappedAttributes, mappedUnits);
            // Speicher freigeben
            mappedAttributes.Clear();
            mappedUnits.Clear();

            #endregion

            #region create metadatastructure and prepare a xmltemplate based on the structure

            // if not existing: import METADATA structure, using file "schema.xsd" similar to bexis1 schema
            long metadataStructureId = metadataCreator.importMetadataStructure(xsdPath, xsdUserName);
            // create BppmetadataXmlTemplate to get XmlAttributes
            XmlDocument metadataXmlTemplate = BExIS.Xml.Helpers.XmlMetadataWriter.ToXmlDocument(metadataCreator.createXmlTemplate(metadataStructureId));

            #endregion

            #region create Dataset(Metadata,Datastructure)
            // the dataStructure, metadata and dataset of these bexis1 datasets will be transfered
            DataStructureCreator dataStructureCreator = new DataStructureCreator();
            DatasetCreator datasetCreator = new DatasetCreator();
            List<string> datasetIds = migrationHelpers.getDatasets(filePath);
            foreach (string dataSetID in datasetIds)
            {
                dataStructureCreator = new DataStructureCreator();
                datasetCreator = new DatasetCreator();
                XmlDocument metadataXml = new XmlDocument();
                List<string> variableNames = new List<string>();
                string fileType = "";

                // get metadata from Bexis1 DB and restructure it for Bpp using xml-mapping file
                metadataXml = metadataCreator.createMetadata(dataSetID, filePath, DataBase, ref variableNames, ref fileType);

                //long dataStructureId = -1;
                BExIS.Dlm.Entities.DataStructure.DataStructure dataStructure = null;
                if (fileType == "structuredData" || fileType == "lookupTable")
                {
                    // create dataStructure on bpp
                    dataStructure = dataStructureCreator.CreateDataStructure(dataSetID, mappedVariables, variableNames);
                }
                else if (fileType.Length > 0)
                {
                    // create unstructured dataStructure on bpp
                    dataStructure = dataStructureCreator.CreateDataStructure(fileType);
                }

                long datasetId = -1;
                if (dataStructure.Id > 0)
                {
                    datasetId = datasetCreator.DatasetExistsByOldDatasetId(dataSetID, dataStructure.Id);
                }

                if (datasetId <= 0) // dataset not exists => create dataset
                {
                    // integrate BppXmlAttributes by using metadataXmlTemplate
                    metadataXml = metadataCreator.fillInXmlAttributes(metadataXml, metadataXmlTemplate);

                    // create dataset with Bexis1_metadata
                    datasetId = datasetCreator.createDataset(dataSetID, metadataXml, metadataStructureId, dataStructure, researchPlanName);
                }

                string DatasetMappingPath = Path.Combine(AppConfiguration.DataPath, "DatasetMapping.txt");
                string[] DatasetMappingtexts = File.ReadAllLines(DatasetMappingPath);
                string DatasetMappingtext = DatasetMappingtexts.FirstOrDefault(item => item.Split('\t')[0] == dataSetID);
                //to prevent of repeating data
                if (DatasetMappingtext != null)
                    File.WriteAllLines(DatasetMappingPath, DatasetMappingtexts.Where(item => item != DatasetMappingtext));
                File.AppendAllText(DatasetMappingPath, dataSetID + "\t" + datasetId + "\r\n");

            }
            #endregion
        }
コード例 #2
0
ファイル: Migration.cs プロジェクト: BEXIS2/Core
        public void PrimaryDataTransfer()
        {
            string filePath = AppConfiguration.GetModuleWorkspacePath("BMM");

            PrimaryData primaryData = new PrimaryData();
            MigrationHelpers migrationHelpers = new MigrationHelpers();

            List<string> datasets = migrationHelpers.getDatasets(filePath);
            foreach (string dataSetID in datasets)
            {
                // transfer primary data to bpp
                primaryData.uploadData(dataSetID, DataBase);
            }
        }