コード例 #1
0
ファイル: FrmSettings.cs プロジェクト: sonixsoftware/Quill
        private void FrmSettings_Load(object sender, EventArgs e)
        {
            richTextBox1.Text = "Client ID: " + clientID;
            label3.Text       = secret;
            DPI.Items.Add("150");
            DPI.Items.Add("300");
            DPI.Text = GetConfiguration.GetConfigurationValueDPI();

            int count = 5000;

            while (count > 0)
            {
                metatoll.Items.Add(count.ToString());
                count--;
            }
            metatoll.Text = GetConfiguration.GetConfigurationValueMeta();

            ocrtype.Items.Add("Microsoft Cloud");
            ocrtype.Items.Add("Google Cloud");
            ocrtype.Items.Add("Quill Cloud");
            ocrtype.Items.Add("AWS Textract");
            ocrtype.Text = GetConfiguration.GetConfigurationValueOCR();
            string grayScale = GetConfiguration.GetConfigurationValueGrayScale();

            if (grayScale.Trim().Equals("1"))
            {
                grayscale.Checked = true;
            }
            else
            {
                grayscale.Checked = false;
            }
        }
コード例 #2
0
ファイル: FrmHome.cs プロジェクト: sonixsoftware/Quill
        private void FrmHome_Load(object sender, EventArgs e)
        {
            Loading ld = new Loading();

            ld.Show();
            ld.Activate();
            DataTable languageTable = null;

            try
            {
                languageTable = servRef.GetLanguages(clientID, secret);
            }
            catch (Exception exe)
            {
                if (exe.ToString().Contains("Document Limit Reached"))
                {
                    MessageBox.Show("Document Limit Reached. You must purchase a license to continue, please visit www.QuillDigital.co.uk", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.Close();
                    System.Windows.Forms.Application.Exit();
                    return;
                }
            }


            languages.Items.Add("NONE");
            foreach (DataRow langRow in languageTable.Rows)
            {
                languages.Items.Add(langRow[0].ToString());
            }
            languages.Text = "NONE";

            string pages = servRef.GetPagesLeft(clientID, secret);

            label8.Text           = "Pages left: " + pages;
            extractFields.Checked = true;
            savePath.Text         = GetConfiguration.GetConfigurationValueSaveLocation();
            if (string.IsNullOrEmpty(savePath.Text.Trim()))
            {
                string runDir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
                if (!Directory.Exists(Path.Combine(runDir, "TEMPS")))
                {
                    Directory.CreateDirectory(Path.Combine(runDir, "TEMPS"));
                }
                savePath.Text = Path.Combine(runDir, "TEMPS");
                GetConfiguration.ConfigurationValueSaveLocation(Path.Combine(runDir, "TEMPS"));
            }
            else
            {
                savePath.Text = GetConfiguration.GetConfigurationValueSaveLocation();
            }

            Globals.ocrType = GetConfiguration.GetConfigurationValueOCR();
            Globals.meta    = GetConfiguration.GetConfigurationValueMeta();
            Globals.dpi     = GetConfiguration.GetConfigurationValueDPI();
            string refreshDate = servRef.GetRefreshDate(clientID, secret);

            label5.Text = refreshDate;
            ld.Close();
        }
コード例 #3
0
ファイル: FrmHome.cs プロジェクト: sonixsoftware/Quill
        private void Main_Run_DoWork(object sender, DoWorkEventArgs e)
        {
            #region Set Up Run
            DataTable finishedRun = new DataTable();
            finishedRun.Columns.Add("Digitised Text");
            finishedRun.Columns.Add("Translated Text");
            finishedRun.Columns.Add("Fields Found");
            finishedRun.Columns.Add("Clauses Found");

            Globals.dpi     = GetConfiguration.GetConfigurationValueDPI();
            Globals.meta    = GetConfiguration.GetConfigurationValueMeta();
            Globals.ocrType = GetConfiguration.GetConfigurationValueOCR();
            strLineRemoval  = GetConfiguration.GetConfigurationValueGrayScale();
            if (Globals.ocrType.Equals("Microsoft Cloud"))
            {
                Globals.ocrType = "1";
            }
            else if (Globals.ocrType.Equals("Google Cloud"))
            {
                Globals.ocrType = "2";
            }
            else if (Globals.ocrType.Equals("AWS Textract"))
            {
                Globals.ocrType = "3";
            }
            else
            {
                Globals.ocrType = "0";
            }

            //Make sure thread does not send PC to sleep
            Kernel32.SetThreadExecutionState(Kernel32.EXECUTION_STATE.ES_CONTINUOUS |
                                             Kernel32.EXECUTION_STATE.ES_SYSTEM_REQUIRED |
                                             Kernel32.EXECUTION_STATE.ES_AWAYMODE_REQUIRED);
            string[] docList = null;
            if (fileType.Checked == false)
            {
                try
                {
                    if (searchSubDirects == true)
                    {
                        docList = Directory.GetFiles(folderPath.Text.Trim(), "*.*", SearchOption.AllDirectories);
                    }
                    else
                    {
                        docList = Directory.GetFiles(folderPath.Text.Trim(), "*.*");
                    }
                }
                catch
                {
                    MessageBox.Show("Unable to find Run directory..", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }
            }
            else
            {
                if (Globals.files != null)
                {
                    docList = Globals.files;
                }
                else
                {
                    MessageBox.Show("Please choose some files..", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }
            }
            docList = Array.FindAll(docList, isNotLockFile);
            if (!Directory.Exists(savePath.Text.Trim()))
            {
                MessageBox.Show("Unable to find Save directory..", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }
            if (docList.Length <= 0)
            {
                MessageBox.Show("Unable to find any files in the Run directory..", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            //Prepare Run
            string prepare = servRef.PrepareRun(clientID, secret, Globals.sqlCon);
            if (!prepare.ToUpper().Equals("SUCCESS"))
            {
                MessageBox.Show("Oops. Something went wrong.", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }
            #endregion
            string lastFile = docList[docList.Length - 1];
            foreach (string file in docList)
            {
                UpdateStatusProgressDelegate UpdateProgress = Progress;
                UpdateProgressTextDelegate   UpdateText     = ProgressLabel;
                UpdateStatusTextDelegate     UpdateStatus   = StatusLabel;
                UpdatePagesTextDelegate      UpdatePages    = PagesLabel;
                bool   convertedFile = false;
                string runFile       = file;
                string tempFile      = file;
                bool   corruptFile   = false;
                if (Path.GetExtension(file).ToUpper().Trim().Equals(".DOCX"))
                {
                    Invoke(UpdateStatus, "Resaving Word Document as PDF");
                    try
                    {
                        //check for mixed media
                        var wordApplication = new Microsoft.Office.Interop.Word.Application();
                        wordApplication.Visible = false;

                        var  document = wordApplication.Documents.Open(file, false, true);
                        Guid strGuid  = Guid.NewGuid();
                        //convert to pdf
                        string tempPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                        tempPath = Path.Combine(tempPath, "temps");
                        if (!Directory.Exists(tempPath))
                        {
                            Directory.CreateDirectory(tempPath);
                        }
                        string tempFileName = Path.GetFileNameWithoutExtension(file);
                        document.ExportAsFixedFormat(System.IO.Path.Combine(tempPath, strGuid + ".pdf"), WdExportFormat.wdExportFormatPDF);
                        runFile       = System.IO.Path.Combine(tempPath, strGuid + ".pdf");
                        convertedFile = true;

                        // Close word
                        wordApplication.Quit();
                        document        = null;
                        wordApplication = null;
                        GC.Collect();
                    }
                    catch (Exception exe)
                    {
                        if (wordWarning == false)
                        {
                            MessageBox.Show("Without Microsoft Word on this machine we will only be able to use the native text these types of document(.DOCX) document. To digitise any pictures in the document, please install Microsoft Word. Alternatively convert it to a .pdf and rerun Quill.", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            wordWarning = true;
                        }
                    }
                }

                #region Loop Files
                if (cancelMain == true)
                {
                    break;
                }

                string fileName = Path.GetFileName(runFile);
                Invoke(UpdateProgress, 0);
                if (!string.IsNullOrEmpty(tempFile))
                {
                    Invoke(UpdateText, "Working on file: " + Path.GetFileName(tempFile));
                }
                else
                {
                    Invoke(UpdateText, "Working on file: " + fileName);
                }

                Invoke(UpdateStatus, "Transmitting File..");
                #region Send File
                //Convert to Bytes
                FileInfo     fi        = new FileInfo(runFile);
                long         numBytes  = fi.Length;
                FileStream   fs        = new FileStream(runFile, FileMode.Open, FileAccess.Read);
                BinaryReader br        = new BinaryReader(fs);
                byte[]       fileArray = br.ReadBytes((int)numBytes);
                br.Close();
                fs.Close();
                fs.Dispose();
                Invoke(UpdateStatus, "Transmitting");
                //Transmit File
                Invoke(UpdateProgress, 10);
                if (cancelMain == true)
                {
                    return;
                }
                string transmit            = servRef.SaveClientFile(fileArray, runFile, clientID, secret);
                bool   invalidTypeContinue = false;
                if (!transmit.ToUpper().Equals("SUCCESS"))
                {
                    DialogResult type = MessageBox.Show("Oops. Quill Can't convert: " + runFile + " Would you like to continue?", "Quill", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                    if (DialogResult.No == type)
                    {
                        cancelMain = true;
                        break;
                    }
                    else
                    {
                        invalidTypeContinue = true;
                    }
                }
                if (cancelMain == true)
                {
                    break;
                }
                #endregion
                if (invalidTypeContinue == false)
                {
                    #region Get File ID
                    Invoke(UpdateStatus, "Get File ID");
                    string fileID = servRef.GetFileID(fileName, clientID, secret);
                    Invoke(UpdateProgress, 20);
                    #endregion

                    #region Check file type
                    Invoke(UpdateStatus, "Native Check..");
                    string native = servRef.NativeTextCheck(fileName, Globals.sqlCon, false, clientID, secret, fileID, Globals.meta, Globals.ignoreMeta);
                    if (native.Contains("QuillException: Document Limit Reached"))
                    {
                        MessageBox.Show("Document Limit Reached. You must purchase a license to continue, please visit www.QuillDigital.co.uk", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    Invoke(UpdateProgress, 30);
                    //Digitise
                    string fullText = string.Empty;
                    #endregion
                    #region Digitise
                    if (native.ToUpper().Equals("TRUE"))
                    {
                        if (cancelMain == true)
                        {
                            break;
                        }
                        Invoke(UpdateStatus, "Getting Text..");
                        fullText = servRef.GetFullTextByID(fileID, clientID, secret);
                        if (fullText.Contains("QuillException: Document Limit Reached"))
                        {
                            MessageBox.Show("Document Limit Reached. You must purchase a license to continue, please visit www.QuillDigital.co.uk", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                        fullText = Regex.Replace(fullText, @"(\r\n){2,}", Environment.NewLine);

                        Invoke(UpdateProgress, 40);
                    }
                    else
                    {
                        Invoke(UpdateStatus, "Digitising..");
                        try
                        {
                            if (cancelMain == true)
                            {
                                break;
                            }
                            Invoke(UpdateProgress, 40);
                            string digitise = servRef.Digitise(fileName, fileID, clientID, secret, Globals.sqlCon, Globals.ocrType, strLineRemoval, Globals.dpi, "0");
                            if (digitise.Contains("QuillException: Document limit reached"))
                            {
                                MessageBox.Show("Document Limit Reached. You must purchase a license or more pages to continue, please visit www.QuillDigital.co.uk", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            if (digitise.Contains("File Corrupt- unable to convert"))
                            {
                                corruptFile = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            //wait here for retort
                        }
                        Invoke(UpdateProgress, 50);
                        Invoke(UpdateStatus, "Getting Text..");
                        if (cancelMain == true)
                        {
                            break;
                        }
                        if (corruptFile == false)
                        {
                            fullText = servRef.GetFullTextByID(fileID, clientID, secret);
                            if (fullText.Contains("QuillException: Document limit reached"))
                            {
                                MessageBox.Show("Document Limit Reached. You must purchase a license to continue, please visit www.QuillDigital.co.uk", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            fullText = Regex.Replace(fullText, @"(\r\n){2,}", Environment.NewLine);
                        }
                        else
                        {
                            fullText = "File Corrupt - unable to convert";
                        }
                    }
                    string clausesFound = string.Empty;
                    string fields       = string.Empty;
                    string translated   = string.Empty;
                    #endregion
                    if (corruptFile == false)
                    {
                        Invoke(UpdateProgress, 50);
                        #region Translate
                        //Translate
                        if (!translationlang.ToUpper().Trim().Equals("NONE"))
                        {
                            Invoke(UpdateProgress, 60);
                            Invoke(UpdateStatus, "Translating..");
                            if (cancelMain == true)
                            {
                                break;
                            }
                            translated = servRef.TranslateByFileID(clientID, secret, Globals.sqlCon, fileID, translationlang);
                            if (translated.Contains("QuillException: Document Limit Reached"))
                            {
                                MessageBox.Show("Document Limit Reached. You must purchase a license to continue, please visit www.QuillDigital.co.uk", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            translated = Regex.Replace(translated, @"(\r\n){2,}", Environment.NewLine);
                        }
                        #endregion

                        //extract fields
                        #region Extract Fields
                        if (extractFields.Checked == true)
                        {
                            if (cancelMain == true)
                            {
                                break;
                            }



                            Invoke(UpdateProgress, 70);
                            Invoke(UpdateStatus, "Extracting Fields..");



                            if (cancelMain == true)
                            {
                                break;
                            }
                            fields = servRef.ExtractFieldsByFileID(fileID, fileName, clientID, secret, Globals.sqlCon, "0", GetConfiguration.GetConfigurationValueFields(), "0");
                            if (fields.Contains("QuillException: Document Limit Reached"))
                            {
                                MessageBox.Show("Document Limit Reached. You must purchase a license to continue, please visit www.QuillDigital.co.uk", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            fields = Regex.Replace(fields, @"(\r\n){1,}", Environment.NewLine);
                        }
                        #endregion
                        if (cancelMain == true)
                        {
                            break;
                        }

                        #region Check Clauses
                        if (clauses.Checked == true)
                        {
                            Invoke(UpdateProgress, 80);
                            Invoke(UpdateStatus, "Extracting Clauses..");
                            string    clausesOUT     = GetConfiguration.GetConfigurationValueClauses();
                            DataTable dtclausesFound = servRef.CheckForClausesByFileID(clientID, secret, Globals.sqlCon, fileID, fileName, clausesOUT);
                            if (clausesFound.Contains("QuillException: Document Limit Reached"))
                            {
                                MessageBox.Show("Document Limit Reached. You must purchase a license to continue, please visit www.QuillDigital.co.uk", "Quill", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }

                            if (dtclausesFound.Rows.Count <= 0)
                            {
                                clausesFound = "No Clauses Found.";
                            }
                            else
                            {
                                clausesFound = string.Empty;
                                foreach (DataRow row in dtclausesFound.Rows)
                                {
                                    string tagOne = row["TagOne"].ToString();
                                    if (string.IsNullOrEmpty(tagOne))
                                    {
                                        tagOne = "Tag One not found..";
                                    }
                                    string tagTwo = row["TagTwo"].ToString();
                                    if (string.IsNullOrEmpty(tagTwo))
                                    {
                                        tagTwo = "Tag Two not found..";
                                    }
                                    string tagThree = row["TagThree"].ToString();
                                    if (string.IsNullOrEmpty(tagThree))
                                    {
                                        tagThree = "Tag Three not found..";
                                    }
                                    string tagFour = row["TagFour"].ToString();
                                    if (string.IsNullOrEmpty(tagFour))
                                    {
                                        tagFour = "Tag Four not found..";
                                    }
                                    string tagFive = row["TagFive"].ToString();
                                    if (string.IsNullOrEmpty(tagFive))
                                    {
                                        tagFive = "Tag Five not found..";
                                    }
                                    string clauseFound  = row["ClauseFound"].ToString();
                                    string probablility = row["Probability"].ToString();
                                    clausesFound = clausesFound + Environment.NewLine + tagOne + Environment.NewLine + tagTwo + Environment.NewLine + tagThree + Environment.NewLine + tagFour
                                                   + Environment.NewLine + tagFive + Environment.NewLine + "Levenstein Distance: " + probablility + Environment.NewLine + Environment.NewLine;
                                }
                            }
                            clausesFound = Regex.Replace(clausesFound, @"(\r\n){2,}", Environment.NewLine);
                            //need to extract clauses
                        }

                        #endregion
                    }
                    #region NLP
                    if (Globals.nlpAnns != null)
                    {
                        Invoke(UpdateProgress, 90);
                        Invoke(UpdateStatus, "Running NLP..");
                        foreach (string anns in Globals.nlpAnns)
                        {
                            if (!string.IsNullOrEmpty(anns.Trim()))
                            {
                                Invoke(UpdateStatus, "Running " + anns + "..");
                                string nlpOUT = servRef.ProcessQuillNLP(fileID, anns.ToLower().Trim(), clientID, secret);
                            }
                        }
                    }
                    #endregion


                    Invoke(UpdateProgress, 90);
                    Invoke(UpdateStatus, "Writing Report..");
                    #region Write Report

                    string xmlDoc    = string.Empty;
                    string xmlReport = servRef.GetReportByID(clientID, secret, fileID);

                    if (string.IsNullOrEmpty(tempFile))
                    {
                        xmlDoc = Path.GetFileNameWithoutExtension(file) + ".xml";
                        System.IO.File.WriteAllText(Path.Combine(savePath.Text, xmlDoc), xmlReport);
                    }
                    else
                    {
                        xmlDoc = Path.GetFileNameWithoutExtension(tempFile) + ".xml";
                        System.IO.File.WriteAllText(Path.Combine(savePath.Text, xmlDoc), xmlReport);
                    }
                    if (convertedFile == true)
                    {
                        File.Delete(runFile);
                    }
                    if (file.ToUpper().Trim().Equals(lastFile.ToUpper().Trim()) | tempFile.ToUpper().Trim().Equals(lastFile.ToUpper().Trim()))
                    {
                        break;
                    }
                    #endregion
                    #endregion
                }
                string pages = servRef.GetPagesLeft(clientID, secret);
                Invoke(UpdatePages, "Pages left: " + pages);
            }

            return;
        }