public static SystemPosition Parse(DateTime lasttime, string line)
        {
            SystemPosition sp = new SystemPosition();

            try {
                if (line.Length < 15)
                    return null;

                if (line.StartsWith("<data>"))
                    return null;

                string str = line.Substring(1, 2);

                int hour = int.Parse(str);
                int min = int.Parse(line.Substring(4, 2));
                int sec = int.Parse(line.Substring(7, 2));

                sp.Time = new DateTime(lasttime.Year, lasttime.Month, lasttime.Day, hour, min, sec);

                if (sp.Time.Subtract(lasttime).TotalHours < -12)
                    sp.Time = sp.Time.AddDays(1);

                str = line.Substring(18, line.IndexOf(" Body:") - 19);

                sp.Nr = int.Parse(str.Substring(0, str.IndexOf("(")));
                sp.Name = str.Substring(str.IndexOf("(") + 1);
                return sp;
            } catch {
                return null;
            }
        }
Exemple #2
0
        private void AddNewSystem(SystemPosition ps)
        {
            if (ps == null)
            {
                throw new ArgumentNullException("ps");
            }
            var starSystem = new StarSystem {
                CreatedAt = DateTime.Now, Name = ps.Name
            };
            NetLogWatcherEventArgs args = new NetLogWatcherEventArgs();

            args.CurrentSystem = starSystem;
            OnNewPosition(this, args);
        }
        private void AddNewSystem(SystemPosition ps)
        {
            if (null == ps)
            {
                throw new ArgumentNullException("ps");
            }
            var now = DateTime.Now;

            if (null == VisitedSystems.Find(p => p.Name == ps.Name))
            {
                _foundSystems.Add(new StarSystem()
                {
                    CreatedAt  = now,
                    Expedition = _expedition,
                    Name       = ps.Name,
                    UpdatedAt  = now
                });
                VisitedSystems.Add(ps);
            }
        }
Exemple #4
0
        static public SystemPosition Parse(DateTime lasttime, string line)
        {
            SystemPosition sp = new SystemPosition();

            try {
                if (line.Length < 15)
                {
                    return(null);
                }

                if (line.StartsWith("<data>"))
                {
                    return(null);
                }

                string str = line.Substring(1, 2);

                int hour = int.Parse(str);
                int min  = int.Parse(line.Substring(4, 2));
                int sec  = int.Parse(line.Substring(7, 2));

                sp.Time = new DateTime(lasttime.Year, lasttime.Month, lasttime.Day, hour, min, sec);

                if (sp.Time.Subtract(lasttime).TotalHours < -12)
                {
                    sp.Time = sp.Time.AddDays(1);
                }

                str = line.Substring(18, line.IndexOf(" Body:") - 19);

                sp.Nr   = int.Parse(str.Substring(0, str.IndexOf("(")));
                sp.Name = str.Substring(str.IndexOf("(") + 1);
                return(sp);
            } catch {
                return(null);
            }
        }
 private void AddNewSystem(SystemPosition ps)
 {
     if (null == ps) throw new ArgumentNullException("ps");
     var now = DateTime.Now;
     if (null == VisitedSystems.Find(p => p.Name == ps.Name)) {
         _foundSystems.Add(new StarSystem() {
             CreatedAt = now,
             Expedition = _expedition,
             Name = ps.Name,
             UpdatedAt = now
         });
         VisitedSystems.Add(ps);
     }
 }
        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 #7
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);
        }
 private void AddNewSystem(SystemPosition ps)
 {
     if (ps == null) throw new ArgumentNullException("ps");
     var starSystem = new StarSystem { CreatedAt = DateTime.Now, Name = ps.Name };
     NetLogWatcherEventArgs args = new NetLogWatcherEventArgs();
     args.CurrentSystem = starSystem;
     OnNewPosition(this, args);
 }