Ejemplo n.º 1
0
        private void BtnExtract_Click(object sender, EventArgs e)
        {
            try
            {
                btnExtract.Enabled = false;
                string inputFile = txtBoxInput.Text;

                List <string> publicDomainList = domainConfig.GetPublicDomainList();

                logger.AppendLog(string.Empty);
                logger.AppendLog("Input file: " + inputFile);

                string outputDir = appEnv.CreateOutputDirectory(Path.GetDirectoryName(inputFile));
                appEnv.InitLogFile(outputDir);

                logger.AppendLog("Public domain list from config..");

                foreach (string domainName in  publicDomainList)
                {
                    logger.AppendLog(domainName);
                }

                logger.AppendLog(string.Empty);

                PersonalInfoExtractor personalInfoExtractor = new PersonalInfoExtractor(inputFile, publicDomainList);
                DataTable             dt = personalInfoExtractor.GetPersonalInfoWithPublicDomain();

                string[]            fileData = personalInfoExtractor.GetDataFromCsvFile();
                PersonalInfoSummary summary  = new PersonalInfoSummary(fileData,
                                                                       NamedValue.PersonalInfoExtractor.CsvColumnDelimiter);

                List <DomainSummary> domainListSummary = summary.GetSummary();
                DisplaySummaryLog(outputDir, domainListSummary);

                logger.AppendLog("");

                string output = appEnv.GetOutputFileName(inputFile, outputDir, NamedValue.ExcelFileExtension);

                ExcelWriter excelWriter = new ExcelWriter(output);
                excelWriter.WriteData(dt);

                MessageBox.Show("Output generated.", "TuduBuddy Automation",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "TuduBuddy Automation",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                appEnv.SaveLogToFile();
                btnExtract.Enabled = true;
            }
        }
Ejemplo n.º 2
0
        public void Convert()
        {
            if (config.FileConversionOption == FileConversionOption.Single)
            {
                logger.AppendLog("Checking file path...");
                if (!File.Exists(config.Input))
                {
                    logger.AppendError("File not found.");
                    throw new FileNotFoundException();
                }

                logger.AppendLog("File found.");

                string outputDir = appEnv.CreateOutputDirectory(Path.GetDirectoryName(config.Input));
                appEnv.InitLogFile(outputDir);
                string outputFile = appEnv.GetOutputFileName(config.Input, outputDir, NamedValue.ExcelFileExtension);

                if (File.Exists(outputFile))
                {
                    if (config.OverwriteOutputFile == FileOverWriteFlag.no)
                    {
                        logger.AppendLog("Output file exists. Overwriting file is unselected.");
                        logger.AppendLog("Skipping file conversion.");
                        return;
                    }
                }

                ConvertFile(config.Input, outputFile);
            }
            else if (config.FileConversionOption == FileConversionOption.Multiple)
            {
                logger.AppendLog("Checking input directory path...");
                bool bResult = appEnv.ValidateDirectory(config.Input);
                logger.AppendLog("Input directory found.");

                if (bResult)
                {
                    string outputDir = appEnv.CreateOutputDirectory(config.Input);
                    appEnv.InitLogFile(outputDir);

                    logger.AppendLog("Selected input folder -" + config.Input);
                    logger.AppendLog("Looking for word documents in the selected folder...");
                    logger.AppendLog(string.Empty);
                    string[] files = Directory.GetFiles(config.Input, "*.docx");
                    if (files.Length == 0)
                    {
                        string errorMsg = "No matching files found. " +
                                          "Please ensure input file is available for conversion.";

                        logger.AppendError(errorMsg);
                        throw new Exception(errorMsg);
                    }

                    foreach (string file in files)
                    {
                        logger.AppendLog("FIle: " + file);
                        string outputFile = appEnv.GetOutputFileName(file, outputDir, NamedValue.ExcelFileExtension);

                        if (config.OverwriteOutputFile == FileOverWriteFlag.no && File.Exists(outputFile))
                        {
                            logger.AppendLog("Output file exists. Overwriting file is unselected.");
                            logger.AppendLog("Skipping file conversion.");
                            logger.AppendLog(outputFile);
                        }
                        else
                        {
                            ConvertFile(file, outputFile);
                            logger.AppendLog("***************************************");
                            logger.AppendLog(string.Empty);
                        }
                    }
                }
            }
            else
            {
                string errorMsg = "Incorrect File Conversion option selected." +
                                  " File conversion option should be Single or Multiple.";
                logger.AppendLog(errorMsg);
                throw new Exception(errorMsg);
            }

            logger.AppendLog(string.Empty);
        }