Ejemplo n.º 1
0
        public HttpResponseMessage GetManuscriptEstimated(TransproManuscript Data)
        {
            HttpResponseMessage response;
            DocumentData        Estimation = new DocumentData();
            DocumentScanner     Scanner    = new DocumentScanner();

            Scanner.DocumentContent = Data.PlainText;
            Scanner.RemoveExcessWhitespaceLinebreak();
            Scanner.EstimateDocument(ref Estimation);
            response = Request.CreateResponse(HttpStatusCode.OK, Estimation);
            return(response);
        }
Ejemplo n.º 2
0
        public async Task <HttpResponseMessage> UploadDocuments(long userID, string culture)
        {
            DocumentScanner     descriptor;
            HttpResponseMessage response;
            DocumentData        docData;
            List <DocumentData> docList = new List <DocumentData>();

            try
            {
                if (this.ModelState.IsValid)
                {
                    string fileName, OriginalFileName;
                    var    root = HttpContext.Current.Server.MapPath("~/App_Data/UploadFiles");
                    Directory.CreateDirectory(root);
                    var provider = new MultipartFormDataStreamProvider(root);
                    var result   = await Request.Content.ReadAsMultipartAsync(provider);

                    string subFolderParentName = "Documents";
                    string subFolderName       = "";
                    string UploadPath          = "~/Upload/";
                    string UploadPhysicalPath;
                    string FinalFilePath;

                    if (subFolderParentName != "")
                    {
                        UploadPath = UploadPath + "/" + subFolderParentName + "/";
                    }
                    if (subFolderName != "")
                    {
                        UploadPath = UploadPath + subFolderName + "/";
                    }

                    UploadPhysicalPath = HttpContext.Current.Server.MapPath(UploadPath);
                    Utility.CreateDirectory(UploadPhysicalPath);

                    foreach (MultipartFileData fileData in result.FileData)
                    {
                        fileName = fileData.Headers.ContentDisposition.FileName;
                        if (fileName.StartsWith("\"") && fileName.EndsWith("\""))
                        {
                            fileName = fileName.Trim('"');
                        }
                        if (fileName.Contains(@"/") || fileName.Contains(@"\"))
                        {
                            fileName = Path.GetFileName(fileName);
                        }
                        OriginalFileName = fileName;
                        FinalFilePath    = Path.Combine(UploadPhysicalPath, fileName);
                        {
                            fileName      = Path.GetFileNameWithoutExtension(FinalFilePath);
                            fileName      = DocumentScanner.AddDateIntoFileName(fileName);
                            fileName      = DocumentScanner.RefractorFileName(fileName) + Path.GetExtension(FinalFilePath);
                            FinalFilePath = Path.Combine(UploadPhysicalPath, fileName);
                        }
                        File.Copy(fileData.LocalFileName, FinalFilePath, true);

                        // Start parsing operation and count number of words
                        // In the document file with the help of a DocumentDescriptor objct
                        docData                  = new DocumentData();
                        docData.FileName         = fileName;
                        docData.OriginalFileName = OriginalFileName;
                        docData.DownloadURL      = Request.RequestUri.GetLeftPart(UriPartial.Authority) + "/Upload/Documents/" + fileName;
                        docData.UploadDate       = DateTime.Now;
                        FileInfo fileinfo = new FileInfo(FinalFilePath);
                        docData.FileSize    = fileinfo.Length.ToString();
                        docData.Extension   = fileinfo.Extension;
                        descriptor          = new DocumentScanner();
                        descriptor.Document = FinalFilePath;
                        descriptor.ParseDocument();
                        descriptor.RemoveExcessWhitespaceLinebreak();
                        descriptor.EstimateDocument(ref docData);
                        docList.Add(docData);
                    }
                    response = Request.CreateResponse(HttpStatusCode.OK, docList);
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }
            return(response);
        }