Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
        private async Task AddNewSystem(SystemPosition ps)
        {
            StarSystem ss = new StarSystem();

            ss.Name = ps.Name;
            var sys = await _starSystemRepository.Insert(ss);

            LogText(string.Format("{0}: Adding system: {1}", DateTime.Now, ps.Name));
            var current = _systemPointer.Get <string>("currentObjectId");;

            _systemPointer["lastObjectId"]    = current;
            _systemPointer["currentObjectId"] = sys.ObjectId;
            _systemPointer = await _systemPointerRepository.Save(_systemPointer);
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        private async Task <int> ReadData(FileInfo fi, List <SystemPosition> visitedSystems, int count, StreamReader sr)
        {
            DateTime gammastart = new DateTime(2014, 11, 22, 13, 00, 00);

            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(fi.FullName))
            {
                nfi = netlogfiles[fi.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.
                        {
                            if (!visitedSystems.Contains(ps))
                            {
                                visitedSystems.Add(ps);
                                await AddNewSystem(ps);
                            }
                            count++;
                        }
                    }
                }
            }


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

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

            netlogfiles[nfi.FileName] = nfi;
            lastnfi = nfi;

            return(count);
        }