Exemplo n.º 1
0
        private void AddBibTexLinks()
        {
            using (ResourceDataAccess resourceDAL = new ResourceDataAccess(this.CreateContext()))
            {
                if (!IsSecurityAwareControl || (UserPermissions != null && UserPermissions.Contains(UserResourcePermissions.Read)))
                {
                    ScholarlyWork scholarlyWorkObj = (ScholarlyWork)resourceDAL.GetScholarlyWorkWithCitedScholarlyWorks(SubjectResource.Id);

                    if (scholarlyWorkObj != null && scholarlyWorkObj.Cites.Count > 0)
                    {
                        BibTexExportLink.Visible = true;
                    }
                    else
                    {
                        BibTexExportLink.Visible = false;
                    }
                }

                if (!IsSecurityAwareControl || (UserPermissions != null && UserPermissions.Contains(UserResourcePermissions.Update)))
                {
                    BibTexImportLink.Visible = true;
                }
                else
                {
                    BibTexImportLink.Visible = false;
                }

                SeperatorLabel.Visible = (BibTexExportLink.Visible == false || BibTexImportLink.Visible == false) ? false : true;
            }

            this.Controls.Add(BibTexPanel);
        }
Exemplo n.º 2
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;
                    }
                }
            }
        }