예제 #1
0
 public LocationChangedEventArgs()
 {
     Changed     = enLogEvents.Location;
     System      = "";
     Location    = "";
     Position    = new Point3Dbl();
     TimeStamp   = new DateTime(1900, 1, 1, 0, 0, 0);
 }
예제 #2
0
        /// <summary>
        /// parses
        /// </summary>
        /// <param name="coordinateString"></param>
        internal static Boolean TryParse(string coordinateString, out Point3Dbl coordinate)
        {
            System.Globalization.CultureInfo customCulture = System.Globalization.CultureInfo.InvariantCulture;
            var       style            = System.Globalization.NumberStyles.Number | System.Globalization.NumberStyles.AllowDecimalPoint;
            Point3Dbl parsedCoordinate = new Point3Dbl();

            Boolean retValue = true;

            String[] parts = coordinateString.Split(new char[] { ',' });

            if ((parts.GetUpperBound(0) == 2))
            {
                for (int i = 0; i <= parts.GetUpperBound(0); i++)
                {
                    Double dblValue = 0.0;

                    if (Double.TryParse(parts[i], style, customCulture, out dblValue))
                    {
                        switch (i)
                        {
                        case 0:
                            parsedCoordinate.X = dblValue;
                            break;

                        case 1:
                            parsedCoordinate.Y = dblValue;
                            break;

                        case 2:
                            parsedCoordinate.Z = dblValue;
                            break;
                        }
                    }
                    else
                    {
                        retValue = false;
                    }
                }
            }
            else
            {
                retValue = false;
            }

            if (retValue)
            {
                coordinate = parsedCoordinate;
            }
            else
            {
                coordinate = new Point3Dbl();
            }

            return(retValue);
        }
예제 #3
0
        /// <summary>
        /// parses 
        /// </summary>
        /// <param name="coordinateString"></param>
        internal static Boolean TryParse(string coordinateString, out Point3Dbl coordinate)
        {
            System.Globalization.CultureInfo customCulture  = System.Globalization.CultureInfo.InvariantCulture;
            var style = System.Globalization.NumberStyles.Number | System.Globalization.NumberStyles.AllowDecimalPoint;
            Point3Dbl parsedCoordinate = new Point3Dbl();

            Boolean retValue = true;

            String[] parts = coordinateString.Split(new char[] {','});

            if((parts.GetUpperBound(0) == 2))
            {
                for (int i = 0; i <= parts.GetUpperBound(0); i++)
                {
                    Double dblValue = 0.0;

                    if(Double.TryParse(parts[i], style, customCulture, out dblValue))
                    { 
                        switch (i)
                        {
                            case 0:
                                parsedCoordinate.X = dblValue;
                                break;
                            case 1:
                                parsedCoordinate.Y = dblValue;
                                break;
                            case 2:
                                parsedCoordinate.Z = dblValue;
                                break;
                        }
                    }
                    else
                        retValue = false;
                }
            }
            else
                retValue = false;

            if(retValue)
            {
                coordinate = parsedCoordinate;
            }
            else
            {
                coordinate = new Point3Dbl();
            }

            return retValue;
        }
예제 #4
0
        /// <summary>
        /// returns the coordinates of the system
        /// </summary>
        /// <param name="systemName"></param>
        /// <returns></returns>
        internal Point3Dbl GetCoordinates(String systemName)
        {
            Point3Dbl retValue = new Point3Dbl();;
            String sqlString;
            DataTable data = new DataTable();

            try
            {
                sqlString = "select x, y, z from tbSystems where SystemName = " + DBConnector.SQLAEscape(systemName);

                Program.DBCon.Execute(sqlString, data);

                if(data.Rows.Count > 0)
                {
                    retValue.X = ((data.Rows[0]["x"] == DBNull.Value) ? null : (double?)data.Rows[0]["x"]);
                    retValue.Y = ((data.Rows[0]["y"] == DBNull.Value) ? null : (double?)data.Rows[0]["y"]);
                    retValue.Z = ((data.Rows[0]["z"] == DBNull.Value) ? null : (double?)data.Rows[0]["z"]);
                }

                return retValue;
            }
            catch (Exception ex)
            {
                throw new Exception("Error while retrieving system coordinates from database", ex);
            }
        }
예제 #5
0
        /// <summary>
        /// Checks if the system is existing and adds it, if not.
        /// Also sets the visited-flag if not set.
        /// </summary>
        /// <param name="newSystemName"></param>
        /// <param name="newStationName"></param>
        /// <param name="setVisitedFlag"></param>
        /// <param name="name"></param>
        public void checkPotentiallyNewSystemOrStation(String newSystemName, String newStationName, Point3Dbl coordinates = null, Boolean setVisitedFlag = true)
        {
            String sqlString;
            Int32 systemID = 0;
            Int32 stationID = 0;
            Boolean systemFirstTimeVisited = false;
            Boolean stationFirstTimeVisited = false;
            DataTable Data = new DataTable();
            Boolean Visited;
            PerformanceTimer pt = new PerformanceTimer();

            try
            {
                pt.startMeasuring();

                newSystemName = newSystemName.Trim();
                newStationName = newStationName.Trim();

                if (!String.IsNullOrEmpty(newSystemName))
                {
                    sqlString = "select id, visited from tbSystems where Systemname = " + DBConnector.SQLAEscape(newSystemName);
                    if (Program.DBCon.Execute(sqlString, Data) > 0)
                    {
                        // system is existing, check or update the visited-flag
                        systemID    = (Int32)(Data.Rows[0]["ID"]);
                        Visited     = (Boolean)(Data.Rows[0]["visited"]);

                        if (!Visited && setVisitedFlag)
                        {
                            sqlString = String.Format("update tbSystems set visited = 1 where id = {0};" +
                                                      "insert ignore into tbVisitedSystems(system_id, time) values" +
                                                      " ({0},{1});", 
                                                      systemID.ToString(), 
                                                      DBConnector.SQLDateTime(DateTime.UtcNow));

                            Program.DBCon.Execute(sqlString);

                            // set flag in the memory table
                            var system = Program.Data.BaseData.tbsystems.FindByid(systemID);
                            if(system != null)
                                system.visited = setVisitedFlag;

                            systemFirstTimeVisited = setVisitedFlag;
                        }

                        if((coordinates != null) && (coordinates.Valid))
                        {
                            var system = Program.Data.BaseData.tbsystems.FindByid(systemID);
                            if(system != null)
                            {
                                if((system.x == null) || (Math.Abs(system.x - coordinates.X.Value) > 0.001) ||
                                   (system.y == null) || (Math.Abs(system.y - coordinates.Y.Value) > 0.001) ||
                                   (system.z == null) || (Math.Abs(system.z - coordinates.Z.Value) > 0.001))
                                {
                                    sqlString = String.Format("update tbSystems set x={0}, y={1}, z={2}, updated_at = UTC_TIMESTAMP()" +
                                                              " where ((ABS(x-{0}) > 0.001) or (ABS(y-{1}) > 0.001) or (ABS(z-{2}) > 0.001)) and id = {3}", 
                                                              DBConnector.SQLDecimal(coordinates.X.Value), 
                                                              DBConnector.SQLDecimal(coordinates.Y.Value), 
                                                              DBConnector.SQLDecimal(coordinates.Z.Value), 
                                                              systemID);

                                    if(Program.DBCon.Execute(sqlString)>0)
                                    {
                                        system.x = coordinates.X.Value;
                                        system.y = coordinates.Y.Value;
                                        system.z = coordinates.Z.Value;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // add a new system
                        Program.DBCon.TransBegin();

                        try
                        {
                            systemID = Program.DBCon.Execute<Int32>("select min(ID)-1 from tbsystems");
                        
                            sqlString = String.Format("insert into tbSystems(id, systemname, x, y, z, updated_at, visited) values ({0},{1},{2},{3},{4},{5},{6});" +
                                                      "insert ignore into tbVisitedsystems(system_id, time) values ({0},{5});",
                                                      systemID, 
                                                      DBConnector.SQLAEscape(newSystemName), 
                                                      coordinates.Valid ? DBConnector.SQLDecimal(coordinates.X.Value) : "null", 
                                                      coordinates.Valid ? DBConnector.SQLDecimal(coordinates.Y.Value) : "null", 
                                                      coordinates.Valid ? DBConnector.SQLDecimal(coordinates.Z.Value) : "null",
                                                      DBConnector.SQLDateTime(DateTime.UtcNow), 
                                                      "1"); 
                            Program.DBCon.Execute(sqlString);
                            Program.DBCon.TransCommit();
                        }
                        catch (Exception ex)
                        {
                                Program.DBCon.TransRollback();
                                throw new Exception("Error while inserting a new system");
                        }


                        systemFirstTimeVisited = setVisitedFlag;

                        dsEliteDB.tbsystemsRow newSystemRow = (dsEliteDB.tbsystemsRow)Program.Data.BaseData.tbsystems.NewRow();

                        newSystemRow.id         = systemID;
                        newSystemRow.systemname = DBConnector.SQLAEscape(newSystemName);
                        if(coordinates.Valid)
                        {
                            newSystemRow.x          = coordinates.X.Value;
                            newSystemRow.y          = coordinates.X.Value;
                            newSystemRow.z          = coordinates.X.Value;
                        }
                        newSystemRow.updated_at = DateTime.UtcNow;
                        newSystemRow.visited    = setVisitedFlag;

                        Program.Data.BaseData.tbsystems.Rows.Add(newSystemRow);
                    }

                    /////////////////////////////////////////////////////////////////////////////////////////////////////

                    if (!String.IsNullOrEmpty(newStationName))
                    {
                        Data.Clear();

                        sqlString = "select St.ID, St.visited from tbSystems Sy, tbStations St" +
                                       " where Sy.ID = St. System_ID" +
                                       " and   Sy.ID          = " + systemID +
                                       " and   St.Stationname = " + DBConnector.SQLAEscape(newStationName);

                        if (Program.DBCon.Execute(sqlString, Data) > 0)
                        {
                            // station is existing, check or update the visited-flag
                            stationID = (Int32)(Data.Rows[0]["ID"]);
                            Visited = (Boolean)(Data.Rows[0]["visited"]);

                            if (!Visited && setVisitedFlag)
                            {
                                sqlString = String.Format("update tbStations set visited = 1 where id = {0};" +
                                                          "insert ignore into tbVisitedStations(station_id, time) values" +
                                                          " ({0},{1});", stationID.ToString(), DBConnector.SQLDateTime(DateTime.UtcNow));
                                Program.DBCon.Execute(sqlString);

                                // set flag in the memory table
                                var station = Program.Data.BaseData.tbstations.FindByid(stationID);
                                if(station != null)
                                    station.visited = setVisitedFlag;

                                stationFirstTimeVisited = setVisitedFlag;
                            }
                        }
                        else
                        {
                            // add a new station
                            Program.DBCon.TransBegin();
                            try
                            {
                                stationID = Program.DBCon.Execute<Int32>("select min(ID)-1 from tbStations");

                                sqlString = String.Format("insert into tbStations(id, stationname, system_id, updated_at, visited) values ({0},{1},{2},{3},{4});" +
                                                          "insert ignore into tbVisitedstations(station_id, time) values ({0},{3});",
                                                          stationID, 
                                                          DBConnector.SQLAEscape(newSystemName), 
                                                          systemID, 
                                                          DBConnector.SQLDateTime(DateTime.UtcNow), 
                                                          "1"); 
                                Program.DBCon.Execute(sqlString);
                                Program.DBCon.TransCommit();
                            }
                            catch (Exception ex)
                            {
                                Program.DBCon.TransRollback();
                                throw new Exception("Error while inserting a new station");
                            }

                            stationFirstTimeVisited = setVisitedFlag;

                            dsEliteDB.tbstationsRow newStationRow = (dsEliteDB.tbstationsRow)Program.Data.BaseData.tbstations.NewRow();

                            newStationRow.id            = stationID;
                            newStationRow.system_id     = systemID;
                            newStationRow.stationname   = DBConnector.SQLAEscape(newStationName);
                            newStationRow.updated_at    = DateTime.UtcNow;
                            newStationRow.visited       = setVisitedFlag;

                            Program.Data.BaseData.tbstations.Rows.Add(newStationRow);

                        }
                    }


                    if(systemFirstTimeVisited && (Program.Data.BaseData.tbvisitedsystems.Select("System_ID = " + systemID).Count() == 0))
                    {
                        dsEliteDB.tbvisitedsystemsRow newVisSystemRow = (dsEliteDB.tbvisitedsystemsRow)Program.Data.BaseData.tbvisitedsystems.NewRow();
                        newVisSystemRow.system_id   = systemID;
                        newVisSystemRow.time        = DateTime.UtcNow;
                        Program.Data.BaseData.tbvisitedsystems.Rows.Add(newVisSystemRow);
                    }
                    if(stationFirstTimeVisited && (Program.Data.BaseData.tbvisitedstations.Select("Station_ID = " + stationID).Count() == 0))
                    {
                        dsEliteDB.tbvisitedstationsRow newVisStationRow = (dsEliteDB.tbvisitedstationsRow)Program.Data.BaseData.tbvisitedstations.NewRow();
                        newVisStationRow.station_id  = stationID;
                        newVisStationRow.time        = DateTime.UtcNow;
                        Program.Data.BaseData.tbvisitedstations.Rows.Add(newVisStationRow);
                    }

                    if (((systemFirstTimeVisited) || (stationFirstTimeVisited)) && 
                        (stationID != 0) && 
                        (Program.Data.BaseData.visystemsandstations.Select("SystemID = " + systemID + " and StationID = " + stationID).Count() == 0))
                    {
                        dsEliteDB.visystemsandstationsRow newVisStationRow = (dsEliteDB.visystemsandstationsRow)Program.Data.BaseData.visystemsandstations.NewRow();
                        newVisStationRow.SystemName = newSystemName;
                        newVisStationRow.SystemID = systemID;
                        newVisStationRow.StationName = newStationName;
                        newVisStationRow.StationID = stationID;
                        Program.Data.BaseData.visystemsandstations.Rows.Add(newVisStationRow);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error while checking for potentially new system or station", ex);
            }
        }
예제 #6
0
파일: Form1.cs 프로젝트: Duke-Jones/ED-IBE
        /// <summary>
        /// shows location data like system/station/ccordinates on gui
        /// </summary>
        private void ShowLocationData()
        {
            try
            {
                if(this.InvokeRequired)
                    this.Invoke(new MethodInvoker(ShowLocationData));
                else
                {
                    Point3Dbl coords        = new Point3Dbl();
                    String currentSystem    = Program.actualCondition.System;
                    String currentLocation  = Program.actualCondition.Station;

                    this.tbCurrentSystemFromLogs.Text       = currentSystem;
                    this.tbCurrentStationinfoFromLogs.Text  = currentLocation;
                    this.tbCurrentBodyinfoFromLogs.Text = Program.actualCondition.Body;
                    if(!String.IsNullOrWhiteSpace(Program.actualCondition.BodyType))
                    {
                        this.tbCurrentBodyinfoFromLogs.Text += "      (" + Program.actualCondition.BodyType + ")";
                    }

                    coords = Program.actualCondition.Coordinates;
                    if(coords.Valid)
                    {
                        txtPosition_X.Text = coords.X.Value.ToString("f3");
                        txtPosition_Y.Text = coords.Y.Value.ToString("f3");
                        txtPosition_Z.Text = coords.Z.Value.ToString("f3");
                    }
                    else
                    {
                        txtPosition_X.Text = "n/a";
                        txtPosition_Y.Text = "n/a";
                        txtPosition_Z.Text = "n/a";
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error while showing location infos", ex);
            }
        }
예제 #7
0
 public LocationInfoEventArgs()
 {
     System      = "";
     Location    = "";
     Position    = new Point3Dbl();
     TimeStamp   = new DateTime(1900, 1, 1, 0, 0, 0);
 }
예제 #8
0
        private void UpdateSystemNameFromLogFile_worker()
        {
            SingleThreadLogger logger           = new SingleThreadLogger(ThreadLoggerType.FileScanner);
            Regex RegExTest_FindBestIsland      = new Regex(String.Format("FindBestIsland:.+:.+:.+:.+", Regex.Escape(Program.DBCon.getIniValue<String>(IBE.IBESettingsView.DB_GROUPNAME, "PilotsName"))), RegexOptions.IgnoreCase);
            Regex RegExTest_Island_Claimed      = new Regex(String.Format("vvv------------ ISLAND .+ CLAIMED ------------vvv"), RegexOptions.IgnoreCase);

            do
            {
                try
                {
                    Boolean EndNow = false;
                    string Systemname = "";
                    string Locationname = "";
                    string currentLogString;
                    Match m = null;
                    Boolean Got_Jump = false;
                    List<String> PossibleLocations      = new List<string>();
                    List<LogEvent> LoggedEvents         = new List<LogEvent>();  
                    DateTime TimestampCurrentLine       = DateTime.MinValue;
                    String InfoCurrentLine              = "";
                    //DateTime Timestamp_YoungestLine     = DateTime.MaxValue;
                    Int32 LineCountRaw                  = 0;
                    Int32 LineCount                     = 0;
                    DateTime TimestampLastScanCandidate = DateTime.MinValue;
                    String InfoLastScanCandidate        = "";

                    #if extScanLog
                        logger.Log("start, RegEx = <" + String.Format("FindBestIsland:.+:.+:.+:.+", Regex.Escape(Program.RegulatedNoiseSettings.PilotsName)) + ">");
                    #endif

                    var appConfigPath = Program.DBCon.getIniValue("Settings", "GamePath");

                    if (Directory.Exists(appConfigPath))
                    {
                        //var versions = Directory.GetDirectories(appConfigPath).Where(x => x.Contains("FORC-FDEV")).ToList().OrderByDescending(x => x).ToList();
                        var versions = new String[] {appConfigPath};

                        if (versions.Count() == 0)
                        {
#if extScanLog
                                logger.Log("no dirs with <FORC-FDEV> found");
                                var versions2 = Directory.GetDirectories(appConfigPath).ToList().OrderByDescending(x => x).ToList();
                                foreach (string SubPath in versions2)
                                {
                                    logger.Log("but found <" +  SubPath + ">");   
                                }
#endif
                        }
                        else
                        {
#if extScanLog
                                logger.Log("lookin' for files in <" + versions[0] + ">");
#endif

                            // We'll just go right ahead and use the latest log...
                            var netLogs =
                                Directory.GetFiles(versions[0] + "\\Logs", "netLog*.log")
                                    .OrderByDescending(File.GetLastWriteTime)
                                    .ToArray();

                            if (netLogs.Length != 0)
                            {
                                Systemname          = "";
                                Locationname         = "";
                                LoggedEvents.Clear();
                                var newestNetLog    = netLogs[0];

                                if(!m_currentLogFile.Equals(newestNetLog, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    // new logfile -> ignore the first jump again, it's simpply the "startjump" of ED, not a real jump
                                    m_InitialJumpFound = false;
                                    m_currentLogFile   = newestNetLog;

                                    Program.DBCon.setIniValue(DB_GROUPNAME, "CurrentLogfile",    m_currentLogFile);
                                    Program.DBCon.setIniValue(DB_GROUPNAME, "InitialJumpFound",  m_InitialJumpFound.ToString());

                                    m_TimestampLastScan = DateTime.MinValue;
                                    m_InfoLastScan      = "";
                                    Program.DBCon.setIniValue(DB_GROUPNAME, "TimestampLastScan", m_TimestampLastScan.ToString());
                                    Program.DBCon.setIniValue(DB_GROUPNAME, "InfoLastScan",      m_InfoLastScan);      
                                }

                                #if extScanLog
                                    Debug.Print("File opened : <" + newestNetLog + ">");
                                    logger.Log("File opened : <" + newestNetLog + ">");
                                #endif

                                FileStream Datei = new FileStream(newestNetLog, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                                Byte[] ByteBuffer = new Byte[1];
                                Byte[] LineBuffer = new Byte[SEARCH_MAXLENGTH];

                                Datei.Seek(0, SeekOrigin.End);

                                while (!EndNow && (Datei.Position >= 2))
                                {
                                    long StartPos   = -1;
                                    long EndPos     = -1;

                                    do
                                    {
                                        Datei.Read(ByteBuffer, 0, ByteBuffer.Length);
                                        //Debug.Print(ByteBuffer[0].ToString("x") + " ");
                                        if ((ByteBuffer[0] == 0x0A) || (ByteBuffer[0] == 0x0D))
                                            if (EndPos == -1)
                                            {
                                                if (ByteBuffer[0] == 0x0D)
                                                    EndPos = Datei.Position + 1;
                                                else
                                                    EndPos = Datei.Position;

                                                Datei.Seek(-3, SeekOrigin.Current);
                                            }
                                            else
                                            {
                                                if (ByteBuffer[0] == 0x0D)
                                                    StartPos = Datei.Position + 1;
                                                else
                                                    StartPos = Datei.Position;
                                            }
                                        else
                                        {
                                            if((LineCountRaw == 0) && (EndPos == -1))
                                            { 
                                                EndPos = Datei.Position;
                                            }

                                            Datei.Seek(-3, SeekOrigin.Current);
                                        }
                                            

                                    } while (StartPos == -1 && Datei.Position >= 3);

                                    LineCountRaw++;

                                    if((StartPos == -1) && ((EndPos - StartPos) > SEARCH_MINLENGTH))
                                        StartPos = 0;

                                    if ((StartPos >= 0) && ((EndPos - StartPos) <= SEARCH_MAXLENGTH))
                                    {
                                        // found a line and it's not too long
                                        // read
                                        Datei.Read(LineBuffer, 0, (int)(EndPos - StartPos));
                                        // and convert to string
                                        currentLogString = Encoding.ASCII.GetString(LineBuffer, 0, (int)(EndPos - StartPos) );

                                        Debug.Print("log - scanning :" + currentLogString);

                                        if (currentLogString != null)
                                        {

                                            // *********************************************
                                            // check the timestamp of the current line to avoid to re-analyse older data
                                            if(TryGetTimeFromLine(currentLogString, ref TimestampCurrentLine, ref InfoCurrentLine))
                                            { 
                                                if(TimestampCurrentLine < m_TimestampLastScan)
                                                { 
                                                    // everything is coming now is older
                                                    EndNow = true;
                                                }
                                                else if ((TimestampCurrentLine == m_TimestampLastScan) && (InfoCurrentLine.Equals(m_InfoLastScan)))
                                                {
                                                    // everything is coming now is older
                                                    EndNow = true;
                                                }

                                                // if it's the first line we have to save the "new youngest line" 
                                                // to avoid to re-analyse the same lines lines next scan
                                                if(LineCount == 0)
                                                {
                                                    TimestampLastScanCandidate = TimestampCurrentLine;
                                                    InfoLastScanCandidate      = InfoCurrentLine;
                                                }

                                                LineCount++;

                                                if(!EndNow)
                                                {
                                                    // first: check if we've jumped
                                                    m = RegExTest_Island_Claimed.Match(currentLogString);
                                                    if (m.Success)
                                                    {
                                                        if(!Got_Jump)
                                                        { 
                                                            LoggedEvents.Add(new LogEvent() { EventType = enLogEvents.Jump, Value = "", Time = TimestampCurrentLine});
                                                            Got_Jump = true;
                                                        }

                                                        #if extScanLog
                                                            Debug.Print("Jump Recognized");
                                                            logger.Log("Jump Recognized : " + currentLogString.Replace("\n", "").Replace("\r", ""));
                                                        #endif
                                                    }

                                                    // *********************************************
                                                    // second: looking for the systemname
                                                    if(String.IsNullOrEmpty(Systemname))
                                                    {
                                                        if (currentLogString.Contains("System:"))
                                                        {
                                                            #if extScanLog
                                                                Debug.Print("Systemstring:" + currentLogString);
                                                                logger.Log("Systemstring:" + currentLogString.Replace("\n", "").Replace("\r", ""));
                                                            #endif

                                                            // before 2.1 :
                                                            // Systemname = currentLogString.Substring(currentLogString.IndexOf("(", StringComparison.Ordinal) + 1);
                                                            // Systemname = Systemname.Substring(0, Systemname.IndexOf(")", StringComparison.Ordinal));

                                                            // since 2.1 :
                                                            currentLogString = currentLogString.Replace("\r", "").Replace("\n", "").Replace(@"\\", "");
                                                            MatchCollection matchCollection = Regex.Matches(currentLogString, @"(?<match>[^""\s]+)|\""(?<match>[^""]*)""");
                                                            Point3Dbl systemPosition = new Point3Dbl();

                                                            for (int i = 0; i < matchCollection.Count; i++)
                                                            {
                                                                if ((matchCollection[i].ToString().Equals("System:")) && (matchCollection.Count > i))
                                                                {
                                                                    Systemname = matchCollection[i+1].ToString().Replace("\"", "");
                                                                }
                                                                else if ((matchCollection[i].ToString().StartsWith("System:")) && (matchCollection[i].ToString().Length > "System:".Length))
                                                                {
                                                                    Systemname = matchCollection[i].ToString().Substring("System:".Length).Replace("\"", "");
                                                                }
                                                                else if (matchCollection[i].ToString().StartsWith("StarPos:("))
                                                                {
                                                                    try
                                                                    {
                                                                        var posParts = matchCollection[i].ToString().Replace("StarPos:(", "").Replace(")ly", "").Replace(")", "").Split(new char[] {','});    

                                                                        systemPosition.X = Double.Parse(posParts[0], System.Globalization.CultureInfo.InvariantCulture);
                                                                        systemPosition.Y = Double.Parse(posParts[1], System.Globalization.CultureInfo.InvariantCulture);
                                                                        systemPosition.Z = Double.Parse(posParts[2], System.Globalization.CultureInfo.InvariantCulture);
                                                                    }
                                                                    catch (Exception)
                                                                    {
                                                                    }
                                                                }

                                                            }


                                                            LoggedEvents.Add(new LogEvent() { EventType = enLogEvents.System, Value = Systemname, Time = TimestampCurrentLine, Position = systemPosition});

                                                            #if extScanLog
                                                                Debug.Print("System: " + systemName);
                                                                logger.Log("System: " + systemName);
                                                            #endif

                                                            // preparing search for location info
                                                            RegExTest_FindBestIsland = new Regex(String.Format("FindBestIsland:.+:.+:.+:{0}", Regex.Escape(Systemname)), RegexOptions.IgnoreCase);

                                                            #if extScanLog
                                                                logger.Log("new Regex : <" + String.Format("FindBestIsland:.+:.+:.+:{0}", Regex.Escape(systemName)) + ">");
                                                            #endif

                                                            // we may have candidates, check them and if nothing found search from the current position
                                                            foreach (string candidate in PossibleLocations)
                                                            {
                                                                #if extScanLog
                                                                    Debug.Print("check candidate : " + candidate);
                                                                    logger.Log("check candidate : " + candidate.Replace("\n", "").Replace("\r", ""));
                                                                #endif

                                                                m = RegExTest_FindBestIsland.Match(candidate);
                                                                //Debug.Print(currentLogString);
                                                                //if (currentLogString.Contains("Duke Jones"))
                                                                //    Debug.Print("Stop");
                                                                if (m.Success)
                                                                {
                                                                    #if extScanLog
                                                                        Debug.Print("locationstring from candidate : " + candidate);
                                                                        logger.Log("locationstring from candidate : " + candidate.Replace("\n", "").Replace("\r", ""));
                                                                    #endif

                                                                    getLocation(ref Locationname, m);

                                                                    DateTime CurrentTimestamp = new DateTime();
                                                                    String   CurrentInfo      = "";
                                                                    TryGetTimeFromLine(currentLogString, ref CurrentTimestamp, ref CurrentInfo);
                                                                    LoggedEvents.Add(new LogEvent() { EventType = enLogEvents.Location, Value = Locationname, Time = CurrentTimestamp});

                                                                    EndNow = true;
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                        else 
                                                        {
                                                            m = RegExTest_FindBestIsland.Match(currentLogString);
                                                            if (m.Success)
                                                            {
                                                                #if extScanLog
                                                                    Debug.Print("Candidate : " + currentLogString);
                                                                    logger.Log("Candidate added : " + currentLogString.Replace("\n", "").Replace("\r", ""));
                                                                #endif

                                                                PossibleLocations.Add(currentLogString);
                                                            }
                                                        }
                                                    }
                                                }

                                                if(!EndNow)
                                                {
                                                    // if we have the systemname we're looking for the locationname
                                                    if (!string.IsNullOrEmpty(Systemname) && string.IsNullOrEmpty(Locationname))
                                                    {
                                                        m = RegExTest_FindBestIsland.Match(currentLogString);
                                                        //Debug.Print(currentLogString);
                                                        //if (currentLogString.Contains("Duke Jones"))
                                                        //    Debug.Print("Stop");
                                                        if (m.Success)
                                                        {
                                                            #if extScanLog
                                                                Debug.Print("locationstring (direct) : " + currentLogString);
                                                                logger.Log("locationstring (direct) : " + currentLogString.Replace("\n", "").Replace("\r", ""));
                                                            #endif

                                                            getLocation(ref Locationname, m);
                                                            LoggedEvents.Add(new LogEvent() { EventType = enLogEvents.Location, Value = Locationname, Time = TimestampCurrentLine});

                                                            EndNow = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if(!EndNow)
                                    { 
                                        if (StartPos >= 3)
                                        {
                                            Datei.Seek(StartPos-1, SeekOrigin.Begin);
                                        }
                                        else
                                            Datei.Seek(0, SeekOrigin.Begin);
                                    }
                                }


                                if((!m_TimestampLastScan.Equals(TimestampLastScanCandidate)) || (!m_InfoLastScan.Equals(InfoLastScanCandidate)))
                                {
                                    // save only if changed
                                    m_TimestampLastScan = TimestampLastScanCandidate;
                                    m_InfoLastScan      = InfoLastScanCandidate;

                                    Program.DBCon.setIniValue(DB_GROUPNAME, "TimestampLastScan", m_TimestampLastScan.ToString());
                                    Program.DBCon.setIniValue(DB_GROUPNAME, "InfoLastScan",      m_InfoLastScan);      
                                }

                                Datei.Close();
                                Datei.Dispose();

                                #if extScanLog
                                    Debug.Print("Datei geschlossen");
                                    logger.Log("File closed");
                                #endif

                                processingLocationInfo(LoggedEvents);

                                LoggedEvents.Clear();

                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.Print("AnalyseError");
                    logger.Log(ex.Message + "\n" + ex.StackTrace + "\n\n");
                }

                #if extScanLog
                    logger.Log("sleeping...");
                    logger.Log("\n\n\n");
                    Debug.Print("\n\n\n");
                #endif

                m_LogfileScanner_ARE.WaitOne();

                #if extScanLog
                    logger.Log("awake...");
                #endif

            }while (!m_Closing);

            #if extScanLog
                Debug.Print("out");
            #endif

        }
예제 #9
0
 public BasedataEventArgs()
 {
     EventType   = JournalEvent.Undefined;
     Coordinates = new Point3Dbl();
 }