Exemplo n.º 1
0
        // AdminReviewedSources

        public AdminReviewedSource GetOrCreateAdminReviewedSource(int sourceId, int adminSourceSearchId)
        {
            Source            source = this.sourceTasks.GetSource(sourceId);
            AdminSourceSearch ass    = this.adminSourceSearchRepository.Get(adminSourceSearchId);

            IDictionary <string, object> criteria = new Dictionary <string, object>();

            criteria.Add("Source", source);
            criteria.Add("AdminSourceSearch", ass);
            AdminReviewedSource ars = this.adminReviewedSourceRepository.FindOne(criteria);

            if (ars == null)
            {
                // TODO when creating a new Reviewed record, this source might be marked relevant in another
                // equivalent search.  However this new Review will be more recent.
                // We could prompt the user to remind them to mark it as relevant when they review the source...
                ars = new AdminReviewedSource();
                ars.ReviewedDateTime  = DateTime.Now;
                ars.Source            = source;
                ars.AdminSourceSearch = ass;
                ars.Archive           = false;
                ars = this.adminReviewedSourceRepository.SaveOrUpdate(ars);
            }
            return(ars);
        }
Exemplo n.º 2
0
        public void IsUnknown(int id, int?adminSourceSearchId)
        {
            Source source = this.sourceTasks.GetSource(id);

            if (source != null)
            {
                // set IsRelevant for this source
                if (adminSourceSearchId.HasValue)
                {
                    AdminReviewedSource ars = this.sourceAttachmentTasks.GetOrCreateAdminReviewedSource(id, adminSourceSearchId.Value);
                    ars.IsRelevant = null;

                    Response.StatusCode = (int)HttpStatusCode.OK;
                }
                else
                {
                    Response.StatusCode        = (int)HttpStatusCode.NotFound;
                    Response.StatusDescription = "No adminSourceSearchId was specified.";
                }
            }
            else
            {
                Response.StatusCode        = (int)HttpStatusCode.NotFound;
                Response.StatusDescription = "That source doesn't exist.";
            }
        }
Exemplo n.º 3
0
        public JsonNetResult Details(int id, int?adminSourceSearchId)
        {
            SourceDTO dto = this.sourceTasks.GetSourceDTO(id);

            if (dto != null)
            {
                if (((PrfPrincipal)User).CanAccess(dto, this.sourceTasks.GetSourceAuthors(id).ToArray(), this.sourceTasks.GetSourceOwners(id).ToArray()))
                {
                    // create AdminReviewedSource if not already exists - necessary for frontend to receive current search terms
                    if (adminSourceSearchId.HasValue)
                    {
                        AdminReviewedSource ars = this.sourceAttachmentTasks.GetOrCreateAdminReviewedSource(id, adminSourceSearchId.Value);
                    }

                    SourceInfoView view = new SourceInfoView(dto);

                    if (AsposeService.WordExtensions.Contains(dto.FileExtension))
                    {
                        try
                        {
                            view.DocumentProperties = this.sourceContentTasks.GetWordDocumentProperties(id);
                        }
                        catch (Exception e)
                        {
                            log.Error("Source ID=" + id + " encountered error retrieving word document properties...", e);
                        }
                    }

                    view.SetAdminReviewedSources(this.sourceAttachmentTasks.GetReviewsForSource(id));
                    view.SetAdminSourceImports(this.sourceAttachmentTasks.GetAdminImportsForSource(id));
                    view.SetPersonSources(this.sourceAttachmentTasks.GetPersonSources(id));
                    view.SetEventSources(this.sourceAttachmentTasks.GetEventSources(id));
                    view.SetUnitSources(this.sourceAttachmentTasks.GetUnitSources(id));
                    view.SetOperationSources(this.sourceAttachmentTasks.GetOperationSources(id));
                    view.SetParentSource(this.sourceAttachmentTasks.GetParentSourceOf(id));
                    view.SetChildSources(this.sourceAttachmentTasks.GetChildSourcesOf(id));
                    view.SetSourceAuthors(this.sourceTasks.GetSourceAuthors(id));
                    view.SetSourceOwners(this.sourceTasks.GetSourceOwners(id));

                    return(JsonNet(view));
                }
                else
                {
                    Response.StatusCode        = (int)HttpStatusCode.Forbidden;
                    Response.StatusDescription = "You don't have permission to view this source.";
                    return(JsonNet(Response.StatusDescription));
                }
            }
            else
            {
                Response.StatusCode        = (int)HttpStatusCode.NotFound;
                Response.StatusDescription = "That source doesn't exist.";
                return(JsonNet(Response.StatusDescription));
            }
        }
Exemplo n.º 4
0
        public ActionResult Download(int id, int?adminSourceSearchId)
        {
            SourceDTO dto = this.sourceTasks.GetSourceDTO(id);

            if (dto != null && dto.FileSize > 0)
            {
                if (((PrfPrincipal)User).CanAccess(dto, this.sourceTasks.GetSourceAuthors(id).ToArray(), this.sourceTasks.GetSourceOwners(id).ToArray()))
                {
                    if (!dto.IsReadOnly)
                    {
                        // record WasDownloaded for this search
                        if (adminSourceSearchId.HasValue)
                        {
                            AdminReviewedSource ars = this.sourceAttachmentTasks.GetOrCreateAdminReviewedSource(id, adminSourceSearchId.Value);
                            ars.WasDownloaded = true;
                        }

                        string contentType = dto.GetDTOFileExtension();
                        Stream stream      = this.sourceTasks.GetSourceData(id, dto.HasOcrText);
                        return(new FileStreamResult(stream, contentType)
                        {
                            FileDownloadName = dto.GetFileDownloadName()
                        });
                    }
                    else
                    {
                        return(new HttpUnauthorizedResult());
                    }
                }
                else
                {
                    return(new HttpUnauthorizedResult());
                }
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }
Exemplo n.º 5
0
        public void Preview(int id, int?adminSourceSearchId)
        {
            Source source = this.sourceTasks.GetSource(id);

            if (source != null && source.FileData != null)
            {
                if (((PrfPrincipal)User).CanAccess(source))
                {
                    // record WasPreviewed for this search
                    if (adminSourceSearchId.HasValue)
                    {
                        AdminReviewedSource ars = this.sourceAttachmentTasks.GetOrCreateAdminReviewedSource(id, adminSourceSearchId.Value);
                        ars.WasPreviewed = true;
                    }

                    string contentType = MIMEAssistant.GetMIMEType(source.SourceName);
                    if (!string.IsNullOrEmpty(contentType) && source.HasOcrText())
                    {
                        Response.ContentType = "text/plain";
                        Response.OutputStream.Write(source.FileData, 0, source.FileData.Length);
                    }
                    else if (!string.IsNullOrEmpty(contentType) && (contentType.StartsWith("image") || contentType.StartsWith("text/plain")))
                    {
                        Response.ContentType = contentType;
                        Response.OutputStream.Write(source.FileData, 0, source.FileData.Length);
                    }
                    else if (!string.IsNullOrEmpty(contentType) && contentType.StartsWith("text/html"))
                    {
                        Response.ContentType = contentType;
                        Response.OutputStream.Write(source.FileData, 0, source.FileData.Length);
                    }
                    else
                    {
                        try
                        {
                            using (MemoryStream ms = new MemoryStream())
                            {
                                byte[] previewBytes = this.sourceContentTasks.GetHtmlPreview(source, ms);
                                if (previewBytes != null)
                                {
                                    Response.ContentType = "text/html";
                                    Response.OutputStream.Write(previewBytes, 0, previewBytes.Length);
                                }
                                else
                                {
                                    Response.StatusCode = (int)HttpStatusCode.NotImplemented;
                                    byte[] error = Encoding.UTF8.GetBytes("Preview for this file not supported.");
                                    Response.OutputStream.Write(error, 0, error.Length);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Problem generating HTML preview.", e);
                            byte[] error = Encoding.UTF8.GetBytes("Problem generating HTML preview: " + e.Message);
                            Response.ContentType = "text/html";
                            Response.OutputStream.Write(error, 0, error.Length);
                        }
                    }
                }
                else
                {
                    Response.StatusCode        = (int)HttpStatusCode.Forbidden;
                    Response.StatusDescription = "You don't have permission to view this source.";
                }
            }
            else
            {
                Response.StatusCode        = (int)HttpStatusCode.NotFound;
                Response.StatusDescription = "That source doesn't exist.";
            }
        }