public StarSystem RetrieveNextStarSystem(FileInfo fileInfo)
        {
            if (fileInfo == null) throw new ArgumentNullException("fileInfo");
            var starSystem = new StarSystem();
            int count = 0, nrsystems = VisitedSystems.Count;
            _foundSystems = new List<StarSystem>();

            using (Stream fs = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                using (StreamReader sr = new StreamReader(fs)) {
                    DateTime gammastart = new DateTime(2014, 11, 22, 13, 00, 00);
                    string FirstLine = sr.ReadLine();
                    string line, str;
                    NetLogFileInfo nfi = null;
                    str = "20" + FirstLine.Substring(0, 8) + " " + FirstLine.Substring(9, 5);

                    DateTime filetime = DateTime.Parse(str);
                    if (_netlogfiles.ContainsKey(fileInfo.FullName)) {
                        nfi = _netlogfiles[fileInfo.FullName];
                        sr.BaseStream.Position = nfi.filePos;
                        sr.DiscardBufferedData();
                    }

                    while ((line = sr.ReadLine()) != null) {
                        if (line.Contains(" System:")) {
                            SystemPosition ps = SystemPosition.Parse(filetime, line);
                            if (ps != null) {
                                if (ps.Name.Equals("Training"))
                                    continue;
                                if (ps.Name.Equals("Destination"))
                                    continue;

                                filetime = ps.Time;

                                if (VisitedSystems.Count > 0)
                                    if (VisitedSystems[VisitedSystems.Count - 1].Name.Equals(ps.Name))
                                        continue;

                                if (ps.Time.Subtract(gammastart).TotalMinutes > 0) { // Ta bara med efter gamma.
                                    AddNewSystem(ps);
                                    count++;
                                }
                            }
                        }
                    }

                    if (nfi == null)
                        nfi = new NetLogFileInfo();

                    nfi.FileName = fileInfo.FullName;
                    nfi.lastchanged = File.GetLastWriteTimeUtc(nfi.FileName);
                    nfi.filePos = sr.BaseStream.Position;
                    nfi.fileSize = fileInfo.Length;

                    _netlogfiles[nfi.FileName] = nfi;
                    _lastnfi = nfi;
                }
            }
            if (_foundSystems.Count > 0) {
                starSystem = _foundSystems[_foundSystems.Count - 1];
                return starSystem;
            } else {
                return null;
            }
        }
Exemple #2
0
        private int ReadData(FileInfo fileInfo, StreamReader sr)
        {
            if (fileInfo == null)
            {
                throw new ArgumentNullException("fileInfo");
            }
            if (sr == null)
            {
                throw new ArgumentNullException("sr");
            }

            DateTime       gammastart = new DateTime(2014, 11, 22, 13, 00, 00);
            var            count = 0;
            DateTime       filetime = DateTime.Now.AddDays(-500);
            string         FirstLine = sr.ReadLine();
            string         line, str;
            NetLogFileInfo nfi = null;

            str = "20" + FirstLine.Substring(0, 8) + " " + FirstLine.Substring(9, 5);

            filetime = DateTime.Parse(str);

            if (_netlogfiles.ContainsKey(fileInfo.FullName))
            {
                nfi = _netlogfiles[fileInfo.FullName];
                sr.BaseStream.Position = nfi.filePos;
                sr.DiscardBufferedData();
            }

            while ((line = sr.ReadLine()) != null)
            {
                if (line.Contains(" System:"))
                {
                    SystemPosition ps = SystemPosition.Parse(filetime, line);
                    if (ps != null)
                    {
                        if (ps.Name.Equals("Training"))
                        {
                            continue;
                        }
                        if (ps.Name.Equals("Destination"))
                        {
                            continue;
                        }

                        filetime = ps.Time;

                        if (VisitedSystems.Count > 0)
                        {
                            if (VisitedSystems[VisitedSystems.Count - 1].Name.Equals(ps.Name))
                            {
                                continue;
                            }
                        }

                        if (ps.Time.Subtract(gammastart).TotalMinutes > 0)   // Ta bara med efter gamma.
                        {
                            AddNewSystem(ps);
                            count++;
                        }
                    }
                }
            }


            if (nfi == null)
            {
                nfi = new NetLogFileInfo();
            }

            nfi.FileName    = fileInfo.FullName;
            nfi.lastchanged = File.GetLastWriteTimeUtc(nfi.FileName);
            nfi.filePos     = sr.BaseStream.Position;
            nfi.fileSize    = fileInfo.Length;

            _netlogfiles[nfi.FileName] = nfi;
            _lastnfi = nfi;

            return(count);
        }
        public StarSystem RetrieveNextStarSystem(FileInfo fileInfo)
        {
            if (fileInfo == null)
            {
                throw new ArgumentNullException("fileInfo");
            }
            var starSystem = new StarSystem();
            int count = 0, nrsystems = VisitedSystems.Count;

            _foundSystems = new List <StarSystem>();

            using (Stream fs = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                using (StreamReader sr = new StreamReader(fs)) {
                    DateTime       gammastart = new DateTime(2014, 11, 22, 13, 00, 00);
                    string         FirstLine = sr.ReadLine();
                    string         line, str;
                    NetLogFileInfo nfi = null;
                    str = "20" + FirstLine.Substring(0, 8) + " " + FirstLine.Substring(9, 5);

                    DateTime filetime = DateTime.Parse(str);
                    if (_netlogfiles.ContainsKey(fileInfo.FullName))
                    {
                        nfi = _netlogfiles[fileInfo.FullName];
                        sr.BaseStream.Position = nfi.filePos;
                        sr.DiscardBufferedData();
                    }

                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.Contains(" System:"))
                        {
                            SystemPosition ps = SystemPosition.Parse(filetime, line);
                            if (ps != null)
                            {
                                if (ps.Name.Equals("Training"))
                                {
                                    continue;
                                }
                                if (ps.Name.Equals("Destination"))
                                {
                                    continue;
                                }

                                filetime = ps.Time;

                                if (VisitedSystems.Count > 0)
                                {
                                    if (VisitedSystems[VisitedSystems.Count - 1].Name.Equals(ps.Name))
                                    {
                                        continue;
                                    }
                                }

                                if (ps.Time.Subtract(gammastart).TotalMinutes > 0)   // Ta bara med efter gamma.
                                {
                                    AddNewSystem(ps);
                                    count++;
                                }
                            }
                        }
                    }


                    if (nfi == null)
                    {
                        nfi = new NetLogFileInfo();
                    }

                    nfi.FileName    = fileInfo.FullName;
                    nfi.lastchanged = File.GetLastWriteTimeUtc(nfi.FileName);
                    nfi.filePos     = sr.BaseStream.Position;
                    nfi.fileSize    = fileInfo.Length;

                    _netlogfiles[nfi.FileName] = nfi;
                    _lastnfi = nfi;
                }
            }
            if (_foundSystems.Count > 0)
            {
                starSystem = _foundSystems[_foundSystems.Count - 1];
                return(starSystem);
            }
            else
            {
                return(null);
            }
        }
        private int ReadData(FileInfo fileInfo, StreamReader sr)
        {
            if (fileInfo == null) throw new ArgumentNullException("fileInfo");
            if (sr == null) throw new ArgumentNullException("sr");

            DateTime gammastart = new DateTime(2014, 11, 22, 13, 00, 00);
            var count = 0;
            DateTime filetime = DateTime.Now.AddDays(-500);
            string FirstLine = sr.ReadLine();
            string line, str;
            NetLogFileInfo nfi = null;

            str = "20" + FirstLine.Substring(0, 8) + " " + FirstLine.Substring(9, 5);

            filetime = DateTime.Parse(str);

            if (_netlogfiles.ContainsKey(fileInfo.FullName)) {
                nfi = _netlogfiles[fileInfo.FullName];
                sr.BaseStream.Position = nfi.filePos;
                sr.DiscardBufferedData();
            }

            while ((line = sr.ReadLine()) != null) {
                if (line.Contains(" System:")) {
                    SystemPosition ps = SystemPosition.Parse(filetime, line);
                    if (ps != null) {
                        if (ps.Name.Equals("Training"))
                            continue;
                        if (ps.Name.Equals("Destination"))
                            continue;

                        filetime = ps.Time;

                        if (VisitedSystems.Count > 0)
                            if (VisitedSystems[VisitedSystems.Count - 1].Name.Equals(ps.Name))
                                continue;

                        if (ps.Time.Subtract(gammastart).TotalMinutes > 0) { // Ta bara med efter gamma.
                             AddNewSystem(ps);
                            count++;
                        }
                    }
                }
            }

            if (nfi == null)
                nfi = new NetLogFileInfo();

            nfi.FileName = fileInfo.FullName;
            nfi.lastchanged = File.GetLastWriteTimeUtc(nfi.FileName);
            nfi.filePos = sr.BaseStream.Position;
            nfi.fileSize = fileInfo.Length;

            _netlogfiles[nfi.FileName] = nfi;
            _lastnfi = nfi;

            return count;
        }