public PageDescriptionEntity LoadDocumentPage(PostedDataEntity postedData) { PageDescriptionEntity loadedPage = new PageDescriptionEntity(); try { // get/set parameters string documentGuid = postedData.guid; int pageNumber = postedData.page; string password = (string.IsNullOrEmpty(postedData.password)) ? null : postedData.password; using (Comparer comparer = new Comparer(documentGuid, GetLoadOptions(password))) { IDocumentInfo info = comparer.Source.GetDocumentInfo(); string encodedImage = GetPageData(pageNumber - 1, documentGuid, password); loadedPage.SetData(encodedImage); loadedPage.height = info.PagesInfo[pageNumber - 1].Height; loadedPage.width = info.PagesInfo[pageNumber - 1].Width; loadedPage.number = pageNumber; } } catch (Exception ex) { throw new FileLoadException("Exception occurred while loading result page", ex); } return(loadedPage); }
/// <summary> /// Gets document pages data, dimensions and rotation angles. /// </summary> /// <param name="postedData">Posted data with document guid.</param> /// <param name="loadAllPages">Flag to load all pages.</param> /// <returns>Document pages data, dimensions and rotation angles.</returns> private static LoadDocumentEntity GetDocumentPages(PostedDataEntity postedData, bool loadAllPages, bool printVersion = false) { // get/set parameters string documentGuid = postedData.guid; string password = string.IsNullOrEmpty(postedData.password) ? null : postedData.password; var fileFolderName = Path.GetFileName(documentGuid).Replace(".", "_"); string fileCacheSubFolder = Path.Combine(cachePath, fileFolderName); if (!File.Exists(documentGuid)) { throw new GroupDocsViewerException("File not found."); } IViewerCache cache = new FileViewerCache(cachePath, fileCacheSubFolder); LoadDocumentEntity loadDocumentEntity; if (globalConfiguration.GetViewerConfiguration().GetIsHtmlMode() && !printVersion) { using (HtmlViewer htmlViewer = new HtmlViewer(documentGuid, cache, GetLoadOptions(password))) { loadDocumentEntity = GetLoadDocumentEntity(loadAllPages, documentGuid, fileCacheSubFolder, htmlViewer, printVersion); } } else { using (PngViewer pngViewer = new PngViewer(documentGuid, cache, GetLoadOptions(password))) { loadDocumentEntity = GetLoadDocumentEntity(loadAllPages, documentGuid, fileCacheSubFolder, pngViewer, printVersion); } } return(loadDocumentEntity); }
public HttpResponseMessage loadFileTree(PostedDataEntity postedData) { // get request body string relDirPath = postedData.path; // get file list from storage path try { // get all the files from a directory if (string.IsNullOrEmpty(relDirPath)) { relDirPath = globalConfiguration.GetEditorConfiguration().GetFilesDirectory(); } else { relDirPath = Path.Combine(globalConfiguration.GetEditorConfiguration().GetFilesDirectory(), relDirPath); } List <FileDescriptionEntity> fileList = new List <FileDescriptionEntity>(); List <string> allFiles = new List <string>(Directory.GetFiles(relDirPath)); allFiles.AddRange(Directory.GetDirectories(relDirPath)); allFiles.Sort(new FileNameComparator()); allFiles.Sort(new FileTypeComparator()); foreach (string file in allFiles) { FileInfo fileInfo = new FileInfo(file); // check if current file/folder is hidden if (fileInfo.Attributes.HasFlag(FileAttributes.Hidden) || Path.GetFileName(file).Equals(Path.GetFileName(globalConfiguration.GetEditorConfiguration().GetFilesDirectory())) || Path.GetFileName(file).Equals(".gitkeep")) { // ignore current file and skip to next one continue; } else { FileDescriptionEntity fileDescription = new FileDescriptionEntity(); fileDescription.guid = Path.GetFullPath(file); fileDescription.name = Path.GetFileName(file); // set is directory true/false fileDescription.isDirectory = fileInfo.Attributes.HasFlag(FileAttributes.Directory); // set file size if (!fileDescription.isDirectory) { fileDescription.size = fileInfo.Length; } // add object to array list fileList.Add(fileDescription); } } return(Request.CreateResponse(HttpStatusCode.OK, fileList)); } catch (System.Exception ex) { return(Request.CreateResponse(HttpStatusCode.OK, new Resources().GenerateException(ex))); } }
public List <FileDescriptionEntity> LoadFiles(PostedDataEntity fileTreeRequest) { // get request body string relDirPath = fileTreeRequest.path; // get file list from storage path try { // get all the files from a directory if (string.IsNullOrEmpty(relDirPath)) { relDirPath = globalConfiguration.Comparison.GetFilesDirectory(); } else { relDirPath = Path.Combine(globalConfiguration.Comparison.GetFilesDirectory(), relDirPath); } List <string> allFiles = new List <string>(Directory.GetFiles(relDirPath)); allFiles.AddRange(Directory.GetDirectories(relDirPath)); List <FileDescriptionEntity> fileList = new List <FileDescriptionEntity>(); allFiles.Sort(new FileNameComparator()); allFiles.Sort(new FileTypeComparator()); foreach (string file in allFiles) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(file); // check if current file/folder is hidden if (!(fileInfo.Attributes.HasFlag(FileAttributes.Hidden) || Path.GetFileName(file).StartsWith(".") || Path.GetFileName(file).Equals(Path.GetFileName(globalConfiguration.Comparison.GetFilesDirectory())) || Path.GetFileName(file).Equals(Path.GetFileName(globalConfiguration.Comparison.GetResultDirectory())))) { FileDescriptionEntity fileDescription = new FileDescriptionEntity { guid = Path.GetFullPath(file), name = Path.GetFileName(file), // set is directory true/false isDirectory = fileInfo.Attributes.HasFlag(FileAttributes.Directory) }; // set file size if (!fileDescription.isDirectory) { fileDescription.size = fileInfo.Length; } // add object to array list fileList.Add(fileDescription); } } return(fileList); } catch (Exception ex) { throw new FileLoadException("Exception occurred while loading files", ex); } }
public HttpResponseMessage RemoveFromIndex(PostedDataEntity postedData) { try { SearchService.RemoveFileFromIndex(postedData.guid); return(this.Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex))); } }
public HttpResponseMessage LoadDocumentDescription(PostedDataEntity postedData) { try { LoadDocumentEntity loadDocumentEntity = LoadDocument(postedData.guid, postedData.password); // return document description return(Request.CreateResponse(HttpStatusCode.OK, loadDocumentEntity)); } catch (System.Exception ex) { // set exception message return(Request.CreateResponse(HttpStatusCode.Forbidden, new Resources().GenerateException(ex, postedData.password))); } }
public HttpResponseMessage GetPrintVersion(PostedDataEntity loadDocumentRequest) { try { LoadDocumentEntity loadPrintDocument = GetDocumentPages(loadDocumentRequest, true, true); // return document description return(this.Request.CreateResponse(HttpStatusCode.OK, loadPrintDocument)); } catch (Exception ex) { // set exception message return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex, loadDocumentRequest.password))); } }
public HttpResponseMessage RotateDocumentPages(PostedDataEntity postedData) { try { var documentGuid = postedData.guid; var pageNumber = postedData.pages[0]; string password = string.IsNullOrEmpty(postedData.password) ? null : postedData.password; var fileFolderName = Path.GetFileName(documentGuid).Replace(".", "_"); string fileCacheSubFolder = Path.Combine(cachePath, fileFolderName); // Delete page cache-files before regenerating with another angle. var cacheFiles = Directory.GetFiles(fileCacheSubFolder).Where(f => Path.GetFileName(f).StartsWith($"p{pageNumber}")); cacheFiles.ForEach(f => File.Delete(f)); // Getting new rotation angle value. var currentAngle = GetCurrentAngle(pageNumber, Path.Combine(fileCacheSubFolder, "PagesInfo.xml")); int newAngle = GetNewAngleValue(currentAngle, postedData.angle); SaveChangedAngleInCache(fileCacheSubFolder, pageNumber, newAngle); IViewerCache cache = new FileViewerCache(cachePath, fileCacheSubFolder); PageDescriptionEntity page; if (globalConfiguration.GetViewerConfiguration().GetIsHtmlMode()) { using (HtmlViewer htmlViewer = new HtmlViewer(documentGuid, cache, GetLoadOptions(password), pageNumber, newAngle)) { page = this.GetPageDescritpionEntity(htmlViewer, documentGuid, pageNumber, fileCacheSubFolder); } } else { using (PngViewer pngViewer = new PngViewer(documentGuid, cache, GetLoadOptions(password), pageNumber, newAngle)) { page = this.GetPageDescritpionEntity(pngViewer, documentGuid, pageNumber, fileCacheSubFolder); } } return(this.Request.CreateResponse(HttpStatusCode.OK, page)); } catch (Exception ex) { // set exception message return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex))); } }
public HttpResponseMessage LoadDocumentDescription(PostedDataEntity loadResultPageRequest) { try { LoadDocumentEntity document = ComparisonServiceImpl.LoadDocumentPages(loadResultPageRequest.guid, loadResultPageRequest.password, globalConfiguration.GetComparisonConfiguration().GetPreloadResultPageCount() == 0); return(Request.CreateResponse(HttpStatusCode.OK, document)); } catch (PasswordProtectedFileException ex) { // set exception message return(Request.CreateResponse(HttpStatusCode.Forbidden, new Resources().GenerateException(ex, loadResultPageRequest.password))); } catch (Exception ex) { // set exception message return(Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex, loadResultPageRequest.password))); } }
public HttpResponseMessage GetDocumentData(PostedDataEntity postedData) { try { LoadDocumentEntity loadDocumentEntity = GetDocumentPages(postedData, globalConfiguration.GetViewerConfiguration().GetPreloadPageCount() == 0); // return document description return(this.Request.CreateResponse(HttpStatusCode.OK, loadDocumentEntity)); } catch (PasswordRequiredException ex) { // set exception message return(this.Request.CreateResponse(HttpStatusCode.Forbidden, new Resources().GenerateException(ex, postedData.password))); } catch (Exception ex) { // set exception message return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex, postedData.password))); } }
public HttpResponseMessage GetDocumentPage(PostedDataEntity postedData) { string password = string.Empty; try { string documentGuid = postedData.guid; int pageNumber = postedData.page; password = string.IsNullOrEmpty(postedData.password) ? null : postedData.password; var fileFolderName = Path.GetFileName(documentGuid).Replace(".", "_"); string fileCacheSubFolder = Path.Combine(cachePath, fileFolderName); IViewerCache cache = new FileViewerCache(cachePath, fileCacheSubFolder); PageDescriptionEntity page; if (globalConfiguration.GetViewerConfiguration().GetIsHtmlMode()) { using (HtmlViewer htmlViewer = new HtmlViewer(documentGuid, cache, GetLoadOptions(password))) { page = this.GetPageDescritpionEntity(htmlViewer, documentGuid, pageNumber, fileCacheSubFolder); } } else { using (PngViewer pngViewer = new PngViewer(documentGuid, cache, GetLoadOptions(password))) { page = this.GetPageDescritpionEntity(pngViewer, documentGuid, pageNumber, fileCacheSubFolder); } } return(this.Request.CreateResponse(HttpStatusCode.OK, page)); } catch (Exception ex) { // set exception message return(this.Request.CreateResponse(HttpStatusCode.Forbidden, new Resources().GenerateException(ex, password))); } }
public HttpResponseMessage LoadFileTree(PostedDataEntity fileTreeRequest) { try { List <IndexedFileDescriptionEntity> filesList = new List <IndexedFileDescriptionEntity>(); string filesDirectory = string.IsNullOrEmpty(fileTreeRequest.path) ? this.globalConfiguration.GetSearchConfiguration().GetFilesDirectory() : fileTreeRequest.path; if (!string.IsNullOrEmpty(this.globalConfiguration.GetSearchConfiguration().GetFilesDirectory())) { filesList = this.LoadFiles(filesDirectory); } return(this.Request.CreateResponse(HttpStatusCode.OK, filesList)); } catch (Exception ex) { return(this.Request.CreateResponse(HttpStatusCode.OK, new Resources().GenerateException(ex))); } }
public void FileTreeStatusCodeTest() { string path = AppDomain.CurrentDomain.BaseDirectory + "/../../../src"; using (var server = new DirectServer(path)) { PostedDataEntity requestData = new PostedDataEntity(); requestData.path = ""; var request = new SerialisableRequest { Method = "POST", RequestUri = "/editor/loadfiletree", Content = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(requestData)), Headers = new Dictionary <string, string> { { "Content-Type", "application/json" }, { "Content-Length", JsonConvert.SerializeObject(requestData).Length.ToString() } } }; var result = server.DirectCall(request); Assert.That(result.StatusCode, Is.EqualTo(200)); } }
public HttpResponseMessage loadFileTree(PostedDataEntity postedData) { // get request body string relDirPath = postedData.path; // get file list from storage path try { // get all the files from a directory if (string.IsNullOrEmpty(relDirPath)) { relDirPath = GlobalConfiguration.GetConversionConfiguration().GetFilesDirectory(); } else { relDirPath = Path.Combine(GlobalConfiguration.GetConversionConfiguration().GetFilesDirectory(), relDirPath); } List <string> allFiles = new List <string>(Directory.GetFiles(relDirPath)); allFiles.AddRange(Directory.GetDirectories(relDirPath)); List <ConversionTypesEntity> fileList = new List <ConversionTypesEntity>(); allFiles.Sort(new FileNameComparator()); allFiles.Sort(new FileTypeComparator()); foreach (string file in allFiles) { FileInfo fileInfo = new FileInfo(file); // check if current file/folder is hidden if (fileInfo.Attributes.HasFlag(FileAttributes.Hidden) || Path.GetFileName(file).Equals(Path.GetFileName(GlobalConfiguration.GetConversionConfiguration().GetFilesDirectory())) || Path.GetFileName(file).Equals(Path.GetFileName(GlobalConfiguration.GetConversionConfiguration().GetResultDirectory())) || Path.GetFileName(file).Equals(".gitkeep")) { // ignore current file and skip to next one continue; } else { ConversionTypesEntity fileDescription = new ConversionTypesEntity { conversionTypes = new List <string>(), guid = Path.GetFullPath(file), name = Path.GetFileName(file), // set is directory true/false isDirectory = fileInfo.Attributes.HasFlag(FileAttributes.Directory) }; // set file size if (!fileDescription.isDirectory) { fileDescription.size = fileInfo.Length; } string documentExtension = Path.GetExtension(fileDescription.name).TrimStart('.'); if (!string.IsNullOrEmpty(documentExtension)) { string[] availableConversions = GetPosibleConversions(documentExtension); //list all available conversions foreach (string name in availableConversions) { fileDescription.conversionTypes.Add(name); } } // add object to array list fileList.Add(fileDescription); } } return(Request.CreateResponse(HttpStatusCode.OK, fileList)); } catch (System.Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, Resources.GenerateException(ex))); } }
public HttpResponseMessage loadFileTree(PostedDataEntity fileTreeRequest) { return(Request.CreateResponse(HttpStatusCode.OK, comparisonService.LoadFiles(fileTreeRequest))); }
public HttpResponseMessage LoadDocumentPage(PostedDataEntity postedData) { return(Request.CreateResponse(HttpStatusCode.OK, comparisonService.LoadDocumentPage(postedData))); }
public LoadDocumentEntity GetPagesThumbnails(PostedDataEntity loadDocumentRequest) { return(GetDocumentPages(loadDocumentRequest, true)); }