Exemple #1
0
        private void ReadDataFile()
        {
            string path           = PathHelper.AbsolutePath(DataFile.Name);
            int    lastLine       = DataFile.LastLine;
            var    currentStatus  = StatusHelper.Processing;
            var    hasBeenStopped = false;

            try {
                using (EntitiesContext _context = (new EntityObjectContext()).GetContext()) {
                    DataFile     df   = _context.Files.First(x => x.Id == DataFile.Id);
                    StreamReader file = new StreamReader(path);
                    string       line;
                    int          counter = 0;
                    while ((line = file.ReadLine()) != null)
                    {
                        if (_shouldStop)
                        {
                            hasBeenStopped = true;
                            break;
                        }
                        if (counter >= lastLine)
                        {
                            InsertLine(line, df, _context);
                            lastLine++;
                            UpdateLastLineAndStatus(df, _context, lastLine);
                            _context.SaveChanges();
                        }
                        counter++;
                    }

                    /*foreach (string line in File.ReadAllLines(path).Skip(lastLine)) {
                     *  InsertLine(line, df, _context);
                     *  lastLine++;
                     *  UpdateLastLineAndStatus(df, _context, lastLine);
                     *  _context.SaveChanges();
                     * }*/
                }
                if (!hasBeenStopped)
                {
                    currentStatus = StatusHelper.Finished;
                }
                else
                {
                    currentStatus = StatusHelper.Waiting;
                }
            } catch (OutOfMemoryException e) {
                currentStatus = StatusHelper.OutOfMemory;
                Console.WriteLine(e);
            } catch (Exception e) {
                currentStatus = StatusHelper.Waiting;
                Console.WriteLine(e);
            }
            using (EntitiesContext _context = (new EntityObjectContext()).GetContext()) {
                DataFile df = _context.Files.First(x => x.Id == DataFile.Id);
                UpdateLastLineAndStatus(df, _context, lastLine, currentStatus);
                _context.SaveChanges();
            }
            _shouldStop = true;
        }
Exemple #2
0
 public CodesetData(string xmlFilePath)
 {
     Check.Require(!string.IsNullOrEmpty(xmlFilePath), "xmlFilePath must not be null or empty.");
     _termDocument = new Lazy <XPathDocument>(delegate()
     {
         return(new XPathDocument(PathHelper.AbsolutePath(xmlFilePath)));
     });
 }