Example #1
0
        private void getXLContent(FileSpecs fs)
        {
            //TODO: try blocks for error handling
            Excel.Application xlApp = new Excel.Application();
            Excel.Worksheet   wkSht = xlApp.Workbooks.Open(fs.Path).Worksheets[1];
            Excel.Range       ur    = wkSht.UsedRange;
            int columnEnd           = ur.Columns.Count + 1;
            int rowEnd = ur.Rows.Count + 1;

            //Console.WriteLine("columEnd: " + columnEnd);
            //Console.WriteLine("rowEnd: " + rowEnd);
            Excel.Range end = wkSht.Cells[rowEnd, columnEnd];
            ur = wkSht.Range["A1", end];
            List <string> line = new List <string>();

            fd = new FileData(fs.Name);
            for (int row = 1; row < ur.Rows.Count; row++)
            {
                line = new List <string>();
                for (int col = 1; col < ur.Columns.Count; col++)
                {
                    //Console.WriteLine("Row: " + row);
                    //Console.WriteLine("Col: " + col);
                    line.Add(Convert.ToString(
                                 (wkSht.Cells[row, col] as Excel.Range).Value2
                                 ));
                    //Console.WriteLine("Add: " + line[col - 1]);
                }
                fd.Add(line);
            }
            xlApp.Quit();
        }
Example #2
0
        private void GetFilePath(object o, RoutedEventArgs e)
        {
            Button    b  = (Button)e.Source;
            FileSpecs fs = (FileSpecs)b.DataContext;

            fs.Path = fps.GetFilePath();
        }
Example #3
0
        public void RepoFactory_get_data_first_element_equal_csharp()
        {
            FileSpecs fs = new FileSpecs {
                Name = "sysName", Path = @"C:\Users\leonardebarnes\Documents\AuditTestData1.xlsx"
            };
            var fdr = new RepositoryFactory().GetFileDataRepository(fs);
            var fd  = fdr.GetAllData();

            Assert.IsTrue(fd[0][0] == "csharp");
        }
        //NOT
        //public async Task<IActionResult> GetDocumentStats(string fileName)
        public IActionResult GetDocumentStats(string fileName)
        {
            //get the indicated file from the DICTIONARY using the DAO
            var file = dataAccessObject.GetFileAsString(fileName);

            //get the word count with the helper
            FileSpecs fileSpecs = new FileSpecs(fileName);

            //send the data back to the web page (SPA) as an Http response
            var obj  = fileSpecs.GetSpecsFromStringFile(file);
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);

            return(Ok(json));
        }
Example #5
0
        private void AddFileSpecs()
        {
            SystemNameDialogViewModel vm = new SystemNameDialogViewModel();
            FileSpecs fs = new FileSpecs();

            SystemNameRequest.Raise(
                new Notification
            {
                Title   = "Enter Systems Name",
                Content = new SystemNameDialogView(vm)
            },
                i => fs.Name = vm.FilePath
                );
            fs.Path = fps.GetFilePath();
            fileSpecs.Add(fs);
        }
Example #6
0
        private void getContent(FileSpecs fs)
        {
            string[] fileParts = fs.Path.Split('.');
            string   ext       = fileParts[fileParts.Length - 1];

            switch (ext)
            {
            case "csv":
            case "txt":
                getCSVContent(fs);
                break;

            default:     //excel file
                getXLContent(fs);
                break;
            }
        }
Example #7
0
        private void getCSVContent(FileSpecs fs)
        {
            string[]      fileContent;
            List <string> fileRow;
            FileData      fd = new FileData(fs.Name);
            int           row, col = 0;

            fileContent = System.IO.File.ReadAllLines(fs.Path);
            row         = fileContent.Length;

            if (row > 0)
            {
                col = fileContent[0].Split(',').Length;
            }

            for (int r = 0; r < row; r++)
            {
                fileRow = fileContent[r].Split(',').ToList <string>();
                fd.Add(fileRow);
            }
        }
Example #8
0
 public IFileDataRepository GetFileDataRepository(FileSpecs fileSpecs)
 {
     return(new FileDataRepository(fileSpecs));
 }
Example #9
0
 public FileDataRepository(FileSpecs fileSpecs)
 {
     getContent(fileSpecs);
 }
Example #10
0
        private void AddFilePath(object obj)
        {
            FileSpecs fs = (FileSpecs)obj;

            fs.Path = fps.GetFilePath();
        }
Example #11
0
 public void LoadData(FileSpecs fileSpecs)
 {
     fddr[fileSpecs.Name] = rf.GetFileDataRepository(fileSpecs);
 }