private void CreateTrayIcon(Akka.Configuration.Config config) { NotifyIcon = new System.Windows.Forms.NotifyIcon { Icon = BLUECATS.ToastNotifier.Properties.Resources.favicon, Text = "BLUE CATS Client" }; var menu = new System.Windows.Forms.ContextMenu(); NotifyIcon.ContextMenu = menu; NotifyIcon.Visible = true; var authority = AkkaHelper.ReadConfigurationFromHoconFile(Assembly.GetExecutingAssembly(), "conf") .WithFallback(ConfigurationFactory .FromResource <ConsumerSettings <object, object> >("Akka.Streams.Kafka.reference.conf")) .GetInt("ui.notification.authority-level"); menu.MenuItems.Add($"{_version} [{authority}]").Enabled = false; menu.MenuItems.Add(new System.Windows.Forms.MenuItem(@"&BLUE CATS", onClick: (_, __) => { var url = config.GetString("ui.server.url"); System.Diagnostics.Process.Start(url); })); menu.MenuItems.Add("-"); menu.MenuItems.Add(new System.Windows.Forms.MenuItem(@"&All Clear", onClick: (_, __) => { //notificationActor.Tell(new ClearAll()); Notifier.ClearMessages(new ClearAll()); })); menu.MenuItems.Add(new System.Windows.Forms.MenuItem(@"&Exit", onClick: (_, __) => { NotifyIcon.Visible = false; Shutdown(); })); }
protected override void OnStartup(StartupEventArgs e) { GUID = GetGUID(); _mtx = new Mutex(true, GUID, out var mtxSuccess); // 뮤텍스를 얻지 못하면 에러 if (!mtxSuccess) { MessageBox.Show("이미 실행중입니다."); Shutdown(); return; } try { var authority = AkkaHelper.ReadConfigurationFromHoconFile(Assembly.GetExecutingAssembly(), "conf") .WithFallback(ConfigurationFactory .FromResource <ConsumerSettings <object, object> >("Akka.Streams.Kafka.reference.conf")) .GetInt("ui.notification.authority-level"); if (authority < 1 || authority > 5) { MessageBox.Show("authority-level은 1~5까지 지정할 수 있습니다.", "Error"); Shutdown(); return; } var assembly = Assembly.GetExecutingAssembly(); var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); _version = fileVersionInfo.ProductVersion; var config = AkkaHelper.ReadConfigurationFromHoconFile(Assembly.GetExecutingAssembly(), "conf") .WithFallback(ConfigurationFactory.FromResource <ConsumerSettings <object, object> >("Akka.Streams.Kafka.reference.conf")); CreateTrayIcon(config); CreateNotifier(config); var system = ActorSystem.Create("BLUECATS-ToastNotifier", config); notificationActor = system.ActorOf(NotificationActor.Props(Notifier), nameof(NotificationActor)); var parserActor = system.ActorOf(ParserActor.Props(notificationActor), nameof(ParserActor)); var eventSubscribeActor = system.ActorOf(EventSubscribeActor.Props(notificationActor), nameof(EventSubscribeActor)); system.EventStream.Subscribe(eventSubscribeActor, typeof(Akka.Event.Error)); var bootStrapServers = GetBootStrapServers(config); var consumerSettings = ConsumerSettings <Null, string> .Create(system, null, Deserializers.Utf8) .WithBootstrapServers(bootStrapServers) .WithGroupId(GUID); notificationActor.Tell((NotificationLevel.Info, $"BLUE CATS: Client Start\n{GUID}")); RestartSource.WithBackoff(() => KafkaConsumer.PlainSource(consumerSettings, GetSubscription(config)), minBackoff: TimeSpan.FromSeconds(3), maxBackoff: TimeSpan.FromSeconds(30), randomFactor: 0.2) .RunForeach(result => { parserActor.Tell(result); }, system.Materializer()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); Current.Shutdown(); } base.OnStartup(e); }