Ejemplo n.º 1
0
        public KaTaLyzerWorker(PlatformDependencies platformDependencies)
        {
            if (!ConfigurationManager.GetInstance().HasConfiguration())
            {
                throw new InvalidOperationException("Can't start KaTaLyzer without configuration");
            }

            _platformDependencies = platformDependencies;

            _networkAdaptersStatistics = new List <NetworkAdapterStatistics>();
            _runningTasks = new List <Task>();


            _adapters = ConfigurationManager.GetInstance().GetNetworkAdapterConfiguration().Select(configuration =>
            {
                NetworkAdapter adapter = null;


                adapter = new NetworkAdapter(configuration, platformDependencies);
                adapter.PacketCaptured += ProcessPacket;
                adapter.ErrorOccured   += AdapterErrorOccured;

                return(adapter);
            }).ToList();

            ulong uploadedCount = 0;

            _timer = new Timer {
                Interval = ConfigurationManager.GetInstance().GetUploadInterval() * 1000
            };
            _timer.Elapsed += async(sender, eventArgs) =>
            {
                var statisticsRepository = new StatisticsRepository();

                try
                {
                    await statisticsRepository.PersistStatistics(TakeNetworkAdaptersStatistics());

                    uploadedCount++;

                    StatisticsPersisted?.Invoke(new StatisticsPersistedEventArgs(_capturingStartedAt, DateTime.Now, uploadedCount));
                }
                catch (Exception e)
                {
                    await KaTaLyzerLogger.Log(LogLevel.Error, e);

                    Error?.Invoke(this, e);
                }
            };
        }
Ejemplo n.º 2
0
 public NetworkAdapter(NetworkAdapterConfiguration configuration, PlatformDependencies dependencies)
 {
     _configuration = configuration;
     _dependencies  = dependencies;
 }
Ejemplo n.º 3
0
        public void ResolveArguments(string[] commandLineArguments, PlatformDependencies platform)
        {
            KaTaLyzerLogger.Log(LogLevel.Trace, "KaTaLyzer started", new KeyValuePair <string, object>("Arguments", commandLineArguments)).Wait();

            if (commandLineArguments.Length == 0)
            {
                ConsoleUi.ConsoleUi consoleUi = new ConsoleUi.ConsoleUi(platform);
                consoleUi.ShowMainMenu();
            }
            else
            {
                Parser parser = new Parser(settings => { settings.AutoHelp = false; });

                parser.ParseArguments <CommandLineOptions>(commandLineArguments).WithParsed(options =>
                {
                    if (options.Help)
                    {
                        ConsoleUi.ConsoleUi consoleUi = new ConsoleUi.ConsoleUi(platform);
                        consoleUi.ShowHelp();
                        Environment.Exit(0);
                    }

                    if (options.CreateConfigTemplate)
                    {
                        Settings templateSetting = new Settings()
                        {
                            DeviceName               = "<DeviceName>",
                            ServerAddress            = "<http://localhost:31311>",
                            MonitoredNetworkAdapters = platform.GetCurrentDevices().Select(x => new NetworkAdapterConfiguration {
                                CustomName = x.Interface.FriendlyName, InterfaceFriendlyName = x.Interface.FriendlyName
                            }).ToList(),
                            UploadInterval     = 60,
                            MonitoredProtocols = ProtocolsLists.AllProtocols.ToDictionary(x => x, x => true)
                        };

                        ConfigurationManager.GetInstance().SaveConfiguration(templateSetting, ConfigurationManager.DefaultConfigurationFilePath, true, null);

                        Console.WriteLine($"Configuration \"{ConfigurationManager.DefaultConfigurationFilePath}\" created successful");

                        Environment.Exit(0);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(options.PathToConfig))
                        {
                            ConfigurationManager.GetInstance().LoadConfiguration(options.PathToConfig);
                        }
                    }

                    if (options.RunInBackground)
                    {
                        platform.RunInBackground();
                    }
                    else
                    {
                        ConsoleUi.ConsoleUi consoleUi = new ConsoleUi.ConsoleUi(platform);
                        consoleUi.ShowMainMenu();
                    }
                }).WithNotParsed(errors =>
                {
                    ConsoleUi.ConsoleUi consoleUi = new ConsoleUi.ConsoleUi(platform);
                    consoleUi.InvalidArgumentsWerePassed();
                    consoleUi.ShowHelp();
                });
            }
        }
Ejemplo n.º 4
0
        public ConsoleUi(PlatformDependencies dependencies)
        {
            _dependencies = dependencies;

            _dialogs = new MainMenuDialogs();
        }
Ejemplo n.º 5
0
 public void RegisterTypes(IContainerRegistry containerRegistry)
 {
     //register platform dependencies
     PlatformDependencies.BuildDependencies();
 }