예제 #1
0
        /// <summary>
        /// prepare data for the broker and repo
        /// and return a tuple
        /// tuple.item1 = filepath
        /// tuple.item2 = mimetype
        /// </summary>
        /// <param name="datasetVersionId"></param>
        /// <param name="datasetId"></param>
        /// <param name="datarepo"></param>
        /// <param name="broker"></param>
        /// <returns></returns>
        public Tuple <string, string> PrepareData(long datasetVersionId, long datasetId, string datarepo, string broker)
        {
            Tuple <string, string> tmp;

            try
            {
                PublicationManager publicPublicationManager = new PublicationManager();
                Repository         repository =
                    publicPublicationManager.RepositoryRepo
                    .Query().FirstOrDefault(p => p.Name.ToLower().Equals(datarepo.ToLower()) &&
                                            p.Broker.Name.ToLower().Equals(broker.ToLower()));



                switch (datarepo.ToLower())
                {
                case "pangaea":
                {
                    PangaeaDataRepoConverter dataRepoConverter = new PangaeaDataRepoConverter(repository);

                    tmp = new Tuple <string, string>(dataRepoConverter.Convert(datasetVersionId), "text/txt");
                    return(tmp);
                }

                case "collections":
                {
                    GenericDataRepoConverter dataRepoConverter = new GenericDataRepoConverter(repository);
                    tmp = new Tuple <string, string>(dataRepoConverter.Convert(datasetVersionId), "application/zip");
                    return(tmp);
                }

                case "pensoft":
                {
                    PensoftDataRepoConverter dataRepoConverter = new PensoftDataRepoConverter(repository);
                    tmp = new Tuple <string, string>(dataRepoConverter.Convert(datasetVersionId), "text/xml");
                    return(tmp);
                }

                default:
                {
                    GenericDataRepoConverter dataRepoConverter = new GenericDataRepoConverter(repository);
                    tmp = new Tuple <string, string>(dataRepoConverter.Convert(datasetVersionId), "application/zip");
                    return(tmp);
                }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }


            return(null);
        }
예제 #2
0
        // GET: Export
        /// <summary>
        ///
        /// </summary>
        /// <param name="datasetVersionId"></param>
        /// <param name="primaryDataFormat">mimetype like text/csv, text/plain</param>
        /// <returns></returns>
        public ActionResult GetZipOfDatasetVersion(long datasetVersionId, string primaryDataFormat = "")
        {
            using (var uow = this.GetUnitOfWork())
            {
                DatasetVersion    dsv = uow.GetReadOnlyRepository <DatasetVersion>().Get(datasetVersionId);
                MetadataStructure metadataStructure = uow.GetReadOnlyRepository <MetadataStructure>().Get(dsv.Dataset.MetadataStructure.Id);
                Broker            broker            = new Broker();
                broker.Name           = "generic";
                broker.MetadataFormat = metadataStructure.Name;
                broker.MetadataFormat = primaryDataFormat;

                Repository dataRepo = new Repository();
                dataRepo.Name   = "generic";
                dataRepo.Broker = broker;

                GenericDataRepoConverter dataRepoConverter = new GenericDataRepoConverter(dataRepo);
                Tuple <string, string>   tmp = new Tuple <string, string>(dataRepoConverter.Convert(datasetVersionId), "application/zip");

                return(File(tmp.Item1, tmp.Item2, Path.GetFileName(tmp.Item1)));
            }
        }