Exemple #1
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));
        }