示例#1
0
        public void getFilefromS3(resume resume, string zipName)
        {
            zipDirectoryName = zipName;
            System.IO.Directory.CreateDirectory(zipDirectoryName);

            //string baseFilename = resume.LastName + "_" + resume.FirstName + "_resume";
            string baseFilename = resume.resumeID.ToString() +"_" + resume.LastName + "_" + resume.FirstName + "_resume";

            using (client = Amazon.AWSClientFactory.CreateAmazonS3Client("AKIAJ47VSG7WMA62WLCA", "3tqlHujlftpk6j/z5OtDw2eg9N2FJtz1RwL8bEa3"))
            {

                string keyName;

                if (resume.hasIMG)
                {
                    var pageNo = 0;
                    var append = false;
                    for (int i = 0; i < (resume.pageCnt.HasValue? resume.pageCnt: 1 ); i++ )
                    {
                        keyName = "img/" + resume.resumeID.ToString();
                        keyName = append ? (keyName + "_" + pageNo.ToString()) : keyName;

                        getAndSaveFile(keyName, baseFilename + ((pageNo==0)? "": ("_" + pageNo.ToString())) + ".jpg");

                        append = true;
                        pageNo++;
                    }
                }

                if (resume.hasTXT)
                {
                    keyName = "txt/" + resume.resumeID.ToString();
                    getAndSaveFile(keyName, baseFilename +  ".txt");
                }

                if (resume.hasPDF)
                {
                    keyName = "pdf/" + resume.resumeID.ToString();
                    getAndSaveFile(keyName, baseFilename + ".pdf");
                }

                if (resume.hasDOCX)
                {
                    keyName = "docx/" + resume.resumeID.ToString();
                    getAndSaveFile(keyName, baseFilename + ".doc");
                }
            }
        }
示例#2
0
        public void putInS3Bucket(resume resume, string txtResults, string[] generatedFiles, string storedFilePath, string generatedFilePath)
        {
            using (client = Amazon.AWSClientFactory.CreateAmazonS3Client("AKIAJ47VSG7WMA62WLCA", "3tqlHujlftpk6j/z5OtDw2eg9N2FJtz1RwL8bEa3"))
            {

                string keyName;
                S3Response response;

                if (resume.hasIMG)
                {
                    var pageNo = 0;
                    var append = false;
                    foreach (string fileName in generatedFiles)
                    {
                        keyName = "img/" + resume.resumeID.ToString();
                        keyName = append ? (keyName + "_" + pageNo.ToString()) : keyName;
                        PutObjectRequest imgRequest = new PutObjectRequest();
                        imgRequest.WithBucketName("intelrecruiter")
                            .WithCannedACL(S3CannedACL.PublicRead)
                            .WithFilePath(fileName)
                            .WithKey(keyName);

                        response = client.PutObject(imgRequest);
                        response.Dispose();
                        append = true;
                        pageNo++;
                    }
                }

                if (resume.hasTXT)
                {
                    keyName = "txt/" + resume.resumeID.ToString();
                    PutObjectRequest txtRequest = new PutObjectRequest();

                    if (resume.hasDOCX)
                    {
                        txtRequest.WithBucketName("intelrecruiter")
                            .WithCannedACL(S3CannedACL.PublicRead)
                            .WithContentBody(txtResults)
                            .WithKey(keyName);
                    }
                    else
                    {
                        txtRequest.WithBucketName("intelrecruiter")
                            .WithCannedACL(S3CannedACL.PublicRead)
                            .WithFilePath(generatedFilePath)
                            .WithKey(keyName);
                    }
                    response = client.PutObject(txtRequest);
                    response.Dispose();
                }

                if (resume.hasPDF)
                {
                    keyName = "pdf/" + resume.resumeID.ToString();
                    PutObjectRequest pdfRequest = new PutObjectRequest();
                    pdfRequest.WithBucketName("intelrecruiter")
                        .WithCannedACL(S3CannedACL.PublicRead)
                        .WithFilePath(storedFilePath)
                        .WithKey(keyName);

                    response = client.PutObject(pdfRequest);
                    response.Dispose();
                }

                if (resume.hasDOCX)
                {
                    keyName = "docx/" + resume.resumeID.ToString();
                    PutObjectRequest imgRequest = new PutObjectRequest();
                    imgRequest.WithBucketName("intelrecruiter")
                        .WithCannedACL(S3CannedACL.PublicRead)
                        .WithFilePath(storedFilePath)
                        .WithKey(keyName);

                    response = client.PutObject(imgRequest);
                    response.Dispose();
                }
            }
        }
        public ActionResult Create(FormCollection collection)
        {
            bool appCall = false;
            bool.TryParse(collection["appCall"], out appCall);

            string log = "";
            log += "Instantiating new resume\n";
            resume resume = new resume();
            resume.addedBy = collection["addedBy"];

            string[] generatedFiles = null;
            string newfilePath;

            string executableDir = Server.MapPath("~/executables");

            //if (!System.IO.Directory.Exists(uploadDir))
            //    System.IO.Directory.CreateDirectory(uploadDir);
            string uploadDir = getUploadDir();

            try
            {
                //if file uploaded
                bool externalSrc=false;
                string txtResults = "";

                if ((collection["src"] != null )&& collection["src"].Equals("SHPE"))
                {
                    var shpeResumeName = downloadSHPEResume(collection["ownerGUID"], ref txtResults);
                    newfilePath = Path.Combine(uploadDir, shpeResumeName);
                    //Response.AddHeader("FileName", newfilePath);
                    externalSrc = true;
                    appCall = true;
                }else if((collection["src"] != null )&& collection["src"].Equals("NSBE")){
                    //var nsbeResumeFilePath = getNSBEResume(collection["memid"], true);
                    var nsbeResumeFilePath = nsbeSearcher.getNSBEResume(collection["memid"], true, uploadDir);
                    newfilePath = nsbeResumeFilePath;
                    //Response.AddHeader("FileName", newfilePath);
                }else
                {
                    var upload = Request.Files[0];
                    string filename = Path.GetFileName(upload.FileName);
                    newfilePath = Path.Combine(uploadDir, filename);
                    upload.SaveAs(newfilePath);
                }
                Response.AddHeader("FileName", Path.GetFileName(newfilePath));
                var imgFilePath = newfilePath;
                var outfilePath = newfilePath + ".txt";

                bool convert = false;
                if (newfilePath.EndsWith("docx"))
                {
                    resume.hasDOCX = true;
                    resume.hasTXT = true;
                    txtResults = ReadDocx2(newfilePath);
                }
                else if (newfilePath.EndsWith("pdf"))
                {
                        resume.hasPDF = true;
                        resume.hasTXT = true;
                        resume.hasIMG = true;
                        convert = true;

                }
                //else if (newfilePath.EndsWith("doc") && externalSrc
                else if (newfilePath.EndsWith("doc"))
                {

                    resume.hasTXT = true;
                    resume.hasDOCX = true;
                    txtResults = ReadDocx(newfilePath);
                }
                else if (newfilePath.EndsWith("txt"))
                {
                    resume.hasTXT = true;
                    outfilePath = newfilePath;
                    //needs to be refactored
                    using (var finalTextOutputStream = System.IO.File.OpenText(outfilePath))
                    {
                        txtResults = finalTextOutputStream.ReadToEnd();
                    }

                }
                else if (Request.Files[0].ContentType.StartsWith("image")) //for camera shots from device
                {

                    resume.hasIMG = true;

                }
                else if (newfilePath.EndsWith("tif")) //for images from scanner
                {
                    resume.hasTXT = true;
                    resume.hasIMG = true;
                    resume.addedBy = Request.Params["user"];
                    resume.moreDetails = DateTime.FromBinary(Convert.ToInt64(Request.Params["timeStamp"])).ToString();
                    convert = true;
                    appCall = true;

                }
                else
                {
                    ViewData["message"] = "Cannot read file type: " + Path.GetExtension(newfilePath);
                    return View("Error");
                }

                if (convert)
                {
                    //if (resume.hasPDF)
                        imgFilePath = newfilePath + ".jpg";
                    //var myCommand = "\"C:\\Program Files (x86)\\ImageMagick-6.8.2-Q16\\convert.exe\" -density 300 " + Path.GetFileName(newfilePath) + " " + Path.GetFileName(imgFilePath);
                    var myCommand = "\"" + executableDir + "\\convert.exe\" -density 300 " + Path.GetFileName(newfilePath) + " " + Path.GetFileName(imgFilePath);

                    //var myCommand2 = "\"C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe\" " + Path.GetFileName(imgFilePath) + " " + Path.GetFileName(newfilePath);
                    var myCommand2 = "\"" + executableDir + "\\tesseract.exe\" " + Path.GetFileName(imgFilePath) + " " + Path.GetFileName(newfilePath);

                    log += "converting file...\n";
                    Directory.SetCurrentDirectory(uploadDir);
                    //if(resume.hasPDF)
                        ExecuteCommandSync(myCommand);

                    generatedFiles = Directory.GetFiles(uploadDir, Path.GetFileNameWithoutExtension(newfilePath) + "*jpg");
                    if (generatedFiles.Length == 1)
                    {
                        ExecuteCommandSync(myCommand2); //Maybe should be done asynchronosly
                    }
                    else
                    {
                        //TEMPORARY FIX. Multi-page resumes no longer supported
                        myCommand2 = "\"" + executableDir + "\\tesseract.exe\" " + Path.GetFileName(generatedFiles[0]) + " " + Path.GetFileName(newfilePath);
                        ExecuteCommandSync(myCommand2);

                        //TO DO: Fix- NO LONGER WORKS ON SERVER.
                        /*
                        using (var mainFileStream = new System.IO.StreamWriter(Path.GetFileName(outfilePath)))
                        {
                            string fragmentTextFile = "fragment";
                            string fileContent;
                            foreach (string fileName in generatedFiles)
                            {
                                //myCommand2 = "\"C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe\" " + fileName + " " + fragmentTextFile;
                                myCommand2 = "\"" + executableDir + "\\tesseract.exe\" " + Path.GetFileName(fileName) + " " + fragmentTextFile;

                                ExecuteCommandSync(myCommand2);
                                using (var fragmentFileStream = System.IO.File.OpenText(fragmentTextFile + ".txt"))
                                {
                                    fileContent = fragmentFileStream.ReadToEnd();
                                }
                                System.IO.File.Delete(fragmentTextFile + ".txt");
                                mainFileStream.Write(fileContent); //doesnt work
                                mainFileStream.Flush();
                            }
                        }
                        */
                    }

                    txtResults = outfilePath;
                    using (var finalTextOutputStream = System.IO.File.OpenText(outfilePath))
                    {
                        txtResults = finalTextOutputStream.ReadToEnd();
                    }

                }
                else
                {
                    generatedFiles = new string[1];
                    generatedFiles[0] = imgFilePath;
                }

                resume.dateAdded = DateTime.Now;
                resume.pageCnt = generatedFiles.Length;
                resume.resume_content = txtResults;
                resumeRepository.Add(resume);
                resumeRepository.Save();

               //refactored 11/18/2012
                resumeFilesHandler.putInS3Bucket(resume, txtResults, generatedFiles, newfilePath, outfilePath);

                //string[] uploadedFiles = Directory.GetFiles(uploadDir, "*");
                //foreach (string f in uploadedFiles)
                //{
                //    System.IO.File.Delete(f);
                //}

                //System.IO.File.Create(Path.Combine(uploadDir,"placeholder.txt"));

                Response.AddHeader("resumeID", resume.resumeID.ToString());
                Response.AddHeader("pageCnt", generatedFiles.Length.ToString());

                if (appCall)
                {
                    Response.Write(resume.resume_content);
                    return new EmptyResult();
                }
                else
                {
                    return View("Details", resume);
                }

            }
            catch(System.Exception ex)
            {

                if (appCall)
                {
                    Response.Write("error:" + ex.Message + "<br>" + "log: " + log);
                    return new EmptyResult();
                }
                else
                {
                    ViewData["message"] = "error:" + ex.Message + "<br>" + "log: " + log;
                    return View("Error");
                }

            }
        }
 public void Delete(resume resume)
 {
     db.memberOfs.DeleteAllOnSubmit(resume.memberOfs);
     db.resumes.DeleteOnSubmit(resume);
 }
 //
 // Insert/Delete Methods
 public void Add(resume resume)
 {
     db.resumes.InsertOnSubmit(resume);
 }
 partial void Deleteresume(resume instance);
 partial void Updateresume(resume instance);
 partial void Insertresume(resume instance);