示例#1
0
 public static NotificationPipeline CreatePipleline(Random random, out string triggerIdentifier, NotificationCondition condition = null, NotificationActor actor = null)
 {
     triggerIdentifier = random.GetAlphanumericString();
     return(CreatePipleline(random, triggerIdentifier, condition, actor));
 }
示例#2
0
        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);
        }
示例#3
0
        public static NotificationPipeline CreatePipleline(Random random, string triggerIdentifier, NotificationCondition condition = null, NotificationActor actor = null)
        {
            NotificationActorCreateModel actorCreateModel = new NotificationActorCreateModel
            {
                Typename            = random.GetAlphanumericString(),
                PropertiesAndValues = new Dictionary <String, String>(),
            };

            NotificationConditionCreateModel conditionCreateModel = new NotificationConditionCreateModel
            {
                Typename            = random.GetAlphanumericString(),
                PropertiesAndValues = new Dictionary <String, String>(),
            };

            Mock <INotificationConditionFactory> conditionFactoryMock = new Mock <INotificationConditionFactory>(MockBehavior.Strict);

            conditionFactoryMock.Setup(x => x.Initilize(conditionCreateModel)).Returns(condition ?? DummyNotificationCondition.AllErrors).Verifiable();

            Mock <INotificationActorFactory> actorFactoryMock = new Mock <INotificationActorFactory>(MockBehavior.Strict);

            actorFactoryMock.Setup(x => x.Initilize(actorCreateModel)).Returns(actor ?? DummyNotificationActor.AllErrors).Verifiable();

            Guid id = random.NextGuid();

            var pipeline = new NotificationPipeline(id, conditionFactoryMock.Object,
                                                    actorFactoryMock.Object, Mock.Of <ILogger <NotificationPipeline> >());

            pipeline.Load(new[] { new NotificationPipelineCreatedEvent
                                  {
                                      Id                  = id,
                                      Description         = random.GetAlphanumericString(),
                                      Name                = random.GetAlphanumericString(),
                                      TriggerIdentifier   = triggerIdentifier,
                                      ActorCreateInfo     = actorCreateModel,
                                      ConditionCreateInfo = conditionCreateModel,
                                  } });

            return(pipeline);
        }