コード例 #1
0
        private PanageaMetadata getMetadata(XmlDocument metadata, long metadataStructureId)
        {
            List <string> tmp = new List <string>();

            PanageaMetadata pangaeaMetadata = new PanageaMetadata();

            //get title
            tmp = MappingUtils.GetValuesFromMetadata((int)Key.Title, LinkElementType.Key,
                                                     metadataStructureId, XmlUtility.ToXDocument(metadata));

            if (tmp != null)
            {
                pangaeaMetadata.Title = string.Join(",", tmp.ToArray());
            }

            //get Description
            tmp = MappingUtils.GetValuesFromMetadata((int)Key.Description, LinkElementType.Key,
                                                     metadataStructureId, XmlUtility.ToXDocument(metadata));

            if (tmp != null)
            {
                pangaeaMetadata.Abstract = string.Join(",", tmp.ToArray());
            }

            // get Authors
            tmp = MappingUtils.GetValuesFromMetadata((int)Key.Author, LinkElementType.Key,
                                                     metadataStructureId, XmlUtility.ToXDocument(metadata));

            if (tmp != null)
            {
                pangaeaMetadata.AuthorIDs = tmp;
            }

            // get Projects
            tmp = MappingUtils.GetValuesFromMetadata((int)Key.ProjectTitle, LinkElementType.Key,
                                                     metadataStructureId, XmlUtility.ToXDocument(metadata));

            if (tmp != null)
            {
                pangaeaMetadata.ProjectIDs = tmp;
            }

            // Defauls sets
            //ExportFileName
            pangaeaMetadata.ExportFilename = Regex.Replace(pangaeaMetadata.Title, "[^0-9a-zA-Z]+", "");

            return(pangaeaMetadata);
        }
コード例 #2
0
        //ToDO -> David <- do not store the files on the server
        public string Convert(long datasetVersionId)
        {
            DatasetManager datasetManager = new DatasetManager();

            PublicationManager publicationManager = new PublicationManager();

            try
            {
                _broker   = publicationManager.GetBroker(_broker.Id);
                _dataRepo = publicationManager.GetRepository(_dataRepo.Id);

                /***
                 *  Generate a txt file for pangaea
                 *  1. json metadata
                 *  2. tabseperated primary Data
                 *
                 *
                 * if data only unstructred, then only metadata
                 */

                string primaryDataFilePath = "";

                #region create primary Data


                primaryDataFilePath = generatePrimaryData(datasetVersionId);


                #endregion


                DatasetVersion datasetVersion      = datasetManager.GetDatasetVersion(datasetVersionId);
                long           datasetId           = datasetVersion.Dataset.Id;
                long           metadataStructureId = datasetVersion.Dataset.MetadataStructure.Id;

                DataStructureDataList datastructureDataList = OutputDataStructureManager.GetVariableList(datasetId);

                PanageaMetadata metadata = getMetadata(datasetVersion.Metadata, metadataStructureId);
                metadata.ParameterIDs = datastructureDataList.Variables;

                string json = JsonConvert.SerializeObject(metadata, Formatting.Indented);


                SubmissionManager submissionManager = new SubmissionManager();



                string path     = submissionManager.GetDirectoryPath(datasetId, _broker.Name);
                string filename = submissionManager.GetFileNameForDataRepo(datasetVersionId, datasetId, _dataRepo.Name, "txt");

                string filepath = Path.Combine(path, filename);

                try
                {
                    if (File.Exists(filepath))
                    {
                        File.Delete(filepath);
                    }

                    FileHelper.Create(filepath).Close();
                    File.WriteAllText(filepath, json + Environment.NewLine + Environment.NewLine);

                    if (!string.IsNullOrEmpty(primaryDataFilePath))
                    {
                        File.AppendAllText(filepath, File.ReadAllText(primaryDataFilePath));
                    }

                    return(filepath);
                }
                catch (Exception exception)
                {
                    throw exception;
                }



                return("");
            }
            finally
            {
                datasetManager.Dispose();
                publicationManager.Dispose();
            }
        }