예제 #1
0
        //ToDO -> David <- do not store the files on the server
        public string Convert(long datasetVersionId)
        {
            string            datarepo          = _dataRepo.Name;
            SubmissionManager publishingManager = new SubmissionManager();

            using (DatasetManager datasetManager = new DatasetManager())
                using (DataStructureManager dataStructureManager = new DataStructureManager())
                    using (PublicationManager publicationManager = new PublicationManager())
                        using (ZipFile zip = new ZipFile())
                        {
                            DatasetVersion datasetVersion = datasetManager.GetDatasetVersion(datasetVersionId);
                            long           datasetId      = datasetVersion.Dataset.Id;

                            Publication publication =
                                publicationManager.GetPublication()
                                .Where(
                                    p =>
                                    p.DatasetVersion.Id.Equals(datasetVersion.Id) &&
                                    p.Broker.Name.ToLower().Equals(_broker.Name))
                                .FirstOrDefault();

                            // if(broker exist)
                            if (publication == null && _broker != null)
                            {
                                Broker broker = _broker;

                                if (broker != null)
                                {
                                    OutputMetadataManager.GetConvertedMetadata(datasetId, TransmissionType.mappingFileExport,
                                                                               broker.MetadataFormat);

                                    // get primary data
                                    // check the data sturcture type ...
                                    if (datasetVersion.Dataset.DataStructure.Self is StructuredDataStructure)
                                    {
                                        OutputDataManager odm = new OutputDataManager();
                                        // apply selection and projection

                                        odm.GenerateAsciiFile(datasetId, datasetVersion.Id, broker.PrimaryDataFormat, false);
                                    }

                                    int versionNr = datasetManager.GetDatasetVersionNr(datasetVersion);

                                    string zipName         = publishingManager.GetZipFileName(datasetId, versionNr);
                                    string zipPath         = publishingManager.GetDirectoryPath(datasetId, broker.Name);
                                    string dynamicZipPath  = publishingManager.GetDynamicDirectoryPath(datasetId, broker.Name);
                                    string zipFilePath     = Path.Combine(zipPath, zipName);
                                    string dynamicFilePath = Path.Combine(dynamicZipPath, zipName);

                                    FileHelper.CreateDicrectoriesIfNotExist(Path.GetDirectoryName(zipFilePath));

                                    if (FileHelper.FileExist(zipFilePath))
                                    {
                                        if (FileHelper.WaitForFile(zipFilePath))
                                        {
                                            FileHelper.Delete(zipFilePath);
                                        }
                                    }

                                    // add datastructure
                                    //ToDo put that functiom to the outputDatatructureManager

                                    #region datatructure

                                    long          dataStructureId = datasetVersion.Dataset.DataStructure.Id;
                                    DataStructure dataStructure   = dataStructureManager.StructuredDataStructureRepo.Get(dataStructureId);

                                    if (dataStructure != null)
                                    {
                                        try
                                        {
                                            string dynamicPathOfDS = "";
                                            dynamicPathOfDS = storeGeneratedFilePathToContentDiscriptor(datasetId, datasetVersion,
                                                                                                        "datastructure", ".txt");
                                            string datastructureFilePath = AsciiWriter.CreateFile(dynamicPathOfDS);

                                            string json = OutputDataStructureManager.GetVariableListAsJson(dataStructureId);

                                            AsciiWriter.AllTextToFile(datastructureFilePath, json);
                                        }
                                        catch (Exception ex)
                                        {
                                            throw ex;
                                        }
                                    }

                                    #endregion datatructure

                                    foreach (ContentDescriptor cd in datasetVersion.ContentDescriptors)
                                    {
                                        string path = Path.Combine(AppConfiguration.DataPath, cd.URI);
                                        string name = cd.URI.Split('\\').Last();

                                        if (FileHelper.FileExist(path))
                                        {
                                            zip.AddFile(path, "");
                                        }
                                    }

                                    // add xsd of the metadata schema
                                    string xsdDirectoryPath = OutputMetadataManager.GetSchemaDirectoryPath(datasetId);
                                    if (Directory.Exists(xsdDirectoryPath))
                                    {
                                        zip.AddDirectory(xsdDirectoryPath, "Schema");
                                    }

                                    XmlDocument manifest = OutputDatasetManager.GenerateManifest(datasetId, datasetVersion.Id);

                                    if (manifest != null)
                                    {
                                        string dynamicManifestFilePath = OutputDatasetManager.GetDynamicDatasetStorePath(datasetId,
                                                                                                                         versionNr, "manifest", ".xml");
                                        string fullFilePath = Path.Combine(AppConfiguration.DataPath, dynamicManifestFilePath);

                                        manifest.Save(fullFilePath);
                                        zip.AddFile(fullFilePath, "");
                                    }

                                    string message = string.Format("dataset {0} version {1} was published for repository {2}", datasetId,
                                                                   datasetVersion.Id, broker.Name);
                                    LoggerFactory.LogCustom(message);

                                    //Session["ZipFilePath"] = dynamicFilePath;

                                    zip.Save(zipFilePath);

                                    return(zipFilePath);
                                }
                            }

                            return("");
                        }
        }
예제 #2
0
        public async Task <ActionResult> SendDataToDataRepo(long datasetId, string datarepo)
        {
            PublicationManager publicationManager = new PublicationManager();
            DatasetManager     datasetManager     = new DatasetManager();

            try
            {
                string zipfilepath = "";
                if (Session["ZipFilePath"] != null)
                {
                    zipfilepath = Session["ZipFilePath"].ToString();
                }

                DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId);

                Publication publication =
                    publicationManager.GetPublication()
                    .Where(
                        p =>
                        p.DatasetVersion.Id.Equals(datasetVersion.Id) &&
                        p.Broker.Name.ToLower().Equals(datarepo.ToLower()))
                    .FirstOrDefault();

                if (publication == null)
                {
                    //ToDo [SUBMISSION] -> create broker specfic function
                    // check case for gfbio
                    if (datarepo.ToLower().Contains("gfbio"))
                    {
                        #region GFBIO

                        //SubmissionManager publishingManager = new SubmissionManager();
                        //publishingManager.Load();
                        //DataRepository dataRepository = publishingManager.DataRepositories.Where(d => d.Name.Equals(datarepo)).FirstOrDefault();

                        Broker broker =
                            publicationManager.GetBroker()
                            .Where(b => b.Name.ToLower().Equals(datarepo.ToLower()))
                            .FirstOrDefault();


                        if (broker != null)
                        {
                            //Store ro in db
                            string title = xmlDatasetHelper.GetInformationFromVersion(datasetVersion.Id,
                                                                                      NameAttributeValues.title);
                            publicationManager.CreatePublication(datasetVersion, broker, title, 0, zipfilepath, "", "no status available");

                            //sendToGFBIO(broker, datasetId, datasetVersion, zipfilepath);
                        }

                        #endregion
                    }

                    if (datarepo.ToLower().Contains("pensoft"))
                    {
                        #region pensoft
                        Broker broker =
                            publicationManager.BrokerRepo.Get()
                            .Where(b => b.Name.ToLower().Equals(datarepo.ToLower()))
                            .FirstOrDefault();

                        Repository repository =
                            publicationManager.RepositoryRepo.Get()
                            .Where(b => b.Name.ToLower().Equals(datarepo.ToLower()))
                            .FirstOrDefault();

                        string title = xmlDatasetHelper.GetInformationFromVersion(datasetVersion.Id, NameAttributeValues.title);
                        publicationManager.CreatePublication(datasetVersion, broker, repository, title, 0, zipfilepath, "",
                                                             "no status available");
                        #endregion
                    }

                    if (datarepo.ToLower().Equals("generic"))
                    {
                        #region GENERIC

                        Broker broker =
                            publicationManager.BrokerRepo.Get()
                            .Where(b => b.Name.ToLower().Equals(datarepo.ToLower()))
                            .FirstOrDefault();
                        string title = xmlDatasetHelper.GetInformationFromVersion(datasetVersion.Id, NameAttributeValues.title);
                        publicationManager.CreatePublication(datasetVersion, broker, title, 0, zipfilepath, "",
                                                             "created");

                        #endregion
                    }
                }
                else
                {
                    Json("Publication exist.");
                }
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
            finally
            {
                publicationManager.Dispose();
                datasetManager.Dispose();
            }

            return(Json(true));
        }