Beispiel #1
0
        public ActionResult Index(string folder)
        {
            string searchCatalog = folder;

            try
            {
                string[] filespatharray = System.IO.Directory.GetFiles(searchCatalog, "*.txt");
                foreach (string filepath in filespatharray)
                {
                    var result = System.IO.File.ReadAllLines(filepath, Encoding.Default)
                                 .AsParallel()
                                 .Select(s => WorkWithTxt.DevideByWords(s))
                                 .ToList();

                    FileTypes    ft  = WorkWithTxt.AddFileTypes(filepath);
                    Dirrectories dir = WorkWithTxt.AddDirrectories(filepath);
                    Files        f   = WorkWithTxt.AddFiles(filepath, ft, dir);
                    WorkWithTxt.AddFilesData(filepath, f);
                    List <Words> wordList = WorkWithTxt.AddWords(result, f);
                    WorkWithTxt.BulkInserting(wordList);
                }
            }
            catch { }

            return(RedirectToAction("Index", "Words"));
        }
        public static Files AddFiles(string filepath, FileTypes ft, Dirrectories dir)
        {
            Files f = new Files();

            f.FileTypes    = ft;
            f.FileName     = System.IO.Path.GetFileNameWithoutExtension(filepath);
            f.DateCreated  = DateTime.Now;
            f.Dirrectories = dir;
            db.Files.Add(f);
            db.SaveChanges();
            return(f);
        }
        public static Dirrectories AddDirrectories(string filepath)
        {
            Dirrectories dir = new Dirrectories();

            dir.DirrectoryName = System.IO.Path.GetDirectoryName(filepath);
            if (!db.Dirrectories.Any(x => x.DirrectoryName == dir.DirrectoryName))
            {
                db.Dirrectories.Add(dir);
            }
            else
            {
                dir = (Dirrectories)db.Dirrectories.FirstOrDefault(x => x.DirrectoryName == dir.DirrectoryName);
            }
            db.SaveChanges();
            return(dir);
        }