Exemplo n.º 1
0
        void BibTexExportLink_Click(object sender, EventArgs e)
        {
            if (SubjectResource == null)
            {
                return;
            }

            ScholarlyWork scholarlyWorkObj = null;

            using (ResourceDataAccess resourceDAL = new ResourceDataAccess(this.CreateContext()))
            {
                scholarlyWorkObj = (ScholarlyWork)resourceDAL.GetScholarlyWorkWithCitedScholarlyWorks(SubjectResource.Id);

                if (scholarlyWorkObj != null)
                {
                    ICollection <ScholarlyWork> citationsList = scholarlyWorkObj.Cites;
                    List <ScholarlyWork>        citations     = resourceDAL.GetAuthorizedResources <ScholarlyWork>
                                                                    (AuthenticatedToken, UserResourcePermissions.Read, citationsList).ToList();
                    if (citations.Count > 0)
                    {
                        String fileNameToSend = scholarlyWorkObj.Id.ToString() + _bibExtention;
                        String value          = _attachment + fileNameToSend;
                        this.Page.Response.ContentType = _contentTypeOctetStream;
                        this.Page.Response.AddHeader(_responseHeader, value);
                        this.Page.Response.Clear();
                        BibTeXConverter bibConverter = new BibTeXConverter(BibTeXParserBehavior.IgnoreParseErrors);

                        foreach (ScholarlyWork swork in citations)
                        {
                            swork.Authors.Load();
                            swork.Editors.Load();
                        }
                        bibConverter.Export(citations, this.Page.Response.OutputStream);
                        this.Page.Response.Flush();
                        this.Page.Response.End();
                    }
                    else
                    {
                        BibTexExportLink.Visible = false;
                        SeperatorLabel.Visible   = false;
                    }
                }
            }
        }
Exemplo n.º 2
0
    protected void Step1NextButton_Click(object sender, EventArgs e)
    {
        if (this.fileUploadBibTeXFile.HasFile)
        {
            //this.LabelFileUploadMessage.Visible = false;
            using (Stream fileStream = this.fileUploadBibTeXFile.FileContent)
            {
                BibTeXConverter             bibConverter    = new BibTeXConverter(BibTeXParserBehavior.IgnoreParseErrors);
                ICollection <ScholarlyWork> importResources = (ICollection <ScholarlyWork>)bibConverter.Import(fileStream);

                if (importResources.Count == 0)
                {
                    this.PanelParsedEntries.Visible = false;
                    this.DisplayCannotImportMessage(Resources.Resources.BibtexImportNothingFound);
                    this.DisplayParsingErrors(bibConverter.ParserErrors, bibConverter.MappingErrors);
                }
                else
                {
                    ICollection <ScholarlyWork> scholarlyWorksExistsAndCited    = new List <ScholarlyWork>();
                    ICollection <ScholarlyWork> scholarlyWorksExistsButNotCited = new List <ScholarlyWork>();
                    ICollection <Guid>          resourceExistsButNotCitedId     = new List <Guid>();
                    ICollection <ScholarlyWork> newResources = new List <ScholarlyWork>();
                    IQueryable <ScholarlyWork>  citationsOfAScholarlyWork = null;

                    this.PanelParsedEntries.Visible = true;


                    // Create collection because of Linq query operate on "context.Resources" does not accept
                    // equals method in the predicate
                    // Get cites resource of selected resource

                    if (_scholarlyWorkObj != null)
                    {
                        citationsOfAScholarlyWork = _scholarlyWorkObj.Cites.AsQueryable <ScholarlyWork>();
                    }
                    else
                    {
                        this.DisplayError(Resources.Resources.ResourceNotFound);
                        return;
                    }

                    List <ScholarlyWork> actualResourceMatchCriteria = new List <ScholarlyWork>();
                    foreach (ScholarlyWork resource in importResources)
                    {
                        actualResourceMatchCriteria.Clear();
                        using (ResourceDataAccess resourceDAL = new ResourceDataAccess())
                        {
                            var resourcesInZentityContext = resourceDAL.GetResources <ScholarlyWork>
                                                                (Zentity.Web.UI.ResourceStringComparison.Equals, resource.Title);

                            foreach (ScholarlyWork tempResourcInZentityContext in resourcesInZentityContext)
                            {
                                if (tempResourcInZentityContext.GetType().Equals(resource.GetType()))
                                {
                                    actualResourceMatchCriteria.Add(tempResourcInZentityContext);
                                    break;
                                }
                            }
                        }

                        if (actualResourceMatchCriteria.Count > 0)
                        {
                            var resourceInCites = citationsOfAScholarlyWork.Where(
                                citeResource => citeResource.Id.Equals
                                    (actualResourceMatchCriteria.First <ScholarlyWork>().Id));
                            if (resourceInCites.Count() > 0)
                            {
                                // current resource's title and type matches with cited resource of selected resource
                                scholarlyWorksExistsAndCited.Add(actualResourceMatchCriteria.First());
                            }
                            else
                            {
                                // current resource's title and type matches with resource in the repository but not in cited
                                scholarlyWorksExistsButNotCited.Add(actualResourceMatchCriteria.First());
                                resourceExistsButNotCitedId.Add(actualResourceMatchCriteria.First().Id);
                            }
                        }
                        else
                        {
                            // Current resource is not exist in the repository
                            newResources.Add(resource);
                        }
                    }
                    AuthenticatedToken          token = Session[Constants.AuthenticationTokenKey] as AuthenticatedToken;
                    ICollection <ScholarlyWork> filteredResourceToBeCited = FilterResourcesBasedOnPermissions(token,
                                                                                                              Constants.PermissionRequiredForAssociation, scholarlyWorksExistsButNotCited);
                    ICollection <ScholarlyWork> resourceNotToBeCited         = scholarlyWorksExistsButNotCited.Except(filteredResourceToBeCited).ToList();
                    ICollection <ScholarlyWork> filteredResourceToBeImported = FilterResourcesBasedOnPermissions(token,
                                                                                                                 UserResourcePermissions.Create, newResources);
                    ICollection <ScholarlyWork> resourceNotToBeImported = newResources.Except(filteredResourceToBeImported).ToList();

                    Session.Add(_bibtexImportResource, filteredResourceToBeImported);
                    Session.Add(_bibtexResourceToBeCitedId, filteredResourceToBeCited.Select(tuple => tuple.Id).ToList());
                    ResourcesCitedDataSource           = scholarlyWorksExistsAndCited;
                    ResourcesToBeCitedDataSource       = filteredResourceToBeCited;
                    ResourcesNotToBeCitedDataSource    = resourceNotToBeCited;
                    ResourcesNotToBeImportedDataSource = resourceNotToBeImported;

                    RefreshResults(ResourcesCited, scholarlyWorksExistsAndCited);
                    RefreshResults(ResourcesToBeCited, filteredResourceToBeCited);
                    RefreshResults(ResourcesToBeImported, filteredResourceToBeImported);

                    if (resourceNotToBeCited.Count > 0)
                    {
                        RefreshResults(ResourcesNotToBeCited, resourceNotToBeCited);
                    }
                    else
                    {
                        ResourcesNotToBeCitedLabel.Visible = false;
                    }

                    if (resourceNotToBeImported.Count > 0)
                    {
                        RefreshResults(ResourcesNotToBeImported, resourceNotToBeImported);
                    }
                    else
                    {
                        ResourcesNotToBeImportedLabel.Visible = false;
                    }

                    this.DisplayParsingErrors(bibConverter.ParserErrors, bibConverter.MappingErrors);
                }
            }
            Wizard1.ActiveStepIndex = 1;
        }
    }