Esempio n. 1
0
        protected virtual void OnSystemChanged(SystemChangedEventArgs eventArgs)
        {
            EventHandler <SystemChangedEventArgs> handler = SystemChanged;

            handler?.Invoke(this, eventArgs);
        }
Esempio n. 2
0
        /// <summary>
        /// Contains the logic for parsing chat log lines, and raises the relevant events.
        /// </summary>
        private void ParseChatLogLines(List <string> chatLines, LogFile chatLogFile)
        {
            try
            {
                // Check if file has never been opened, if so preform file initialization, raise relevant event
                SystemChangedEventArgs eventArgs = new SystemChangedEventArgs();
                if (chatLogFile.CurrentFileLength <= 0)
                {
                    // Get listener
                    if (ListenerRegex.IsMatch(chatLines[8]))
                    {
                        chatLogFile.CurrentListener = ListenerRegex.Match(chatLines[8]).Groups["Name"].Value;
                        eventArgs.Listener          = chatLogFile.CurrentListener;
                    }

                    // Get current system
                    foreach (var chatLine in chatLines)
                    {
                        if (!LocalSystemChange.IsMatch(chatLine))
                        {
                            continue;
                        }
                        var systemName = LocalSystemChange.Match(chatLine).Groups["NewSystemName"].Value;
                        // check if valid system
                        if (SolarSystems.SystemNameToIdDictionary.TryGetValue(systemName, out var systemId))
                        {
                            eventArgs.NewSystemName = systemName;
                            eventArgs.NewSystemId   = systemId;
                        }
                    }
                    OnSystemChanged(eventArgs);
                }
                // if its been analyzed before, parse the new lines for a system change.
                else
                {
                    eventArgs.Listener = chatLogFile.CurrentListener;

                    // Get current system
                    foreach (var chatLine in chatLines)
                    {
                        if (!LocalSystemChange.IsMatch(chatLine))
                        {
                            continue;
                        }
                        var systemName = LocalSystemChange.Match(chatLine).Groups["NewSystemName"].Value;
                        // check if valid system
                        if (SolarSystems.SystemNameToIdDictionary.TryGetValue(systemName, out var systemId))
                        {
                            eventArgs.NewSystemName = systemName;
                            eventArgs.NewSystemId   = systemId;
                        }
                    }
                    OnSystemChanged(eventArgs);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Log.Error(e);
                throw;
            }

            // Else, determine if its a system change
        }