Exemple #1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Cluster" /> class.
 /// </summary>
 /// <param name="brokers">
 ///     The set of active brokers.
 /// </param>
 public Cluster(IEnumerable <Broker> brokers) : this()
 {
     foreach (var broker in brokers)
     {
         Brokers.Add(broker.Id, broker);
     }
 }
Exemple #2
0
        public ConsumerSettingsTestEvents()
        {
            Brokers.Add("localhost:9092");
            Topic = "bruteflow-incoming-events";
            var dateTime = DateTime.Now;

            GroupId  = $"bruteflow-{dateTime:yyyyMMdd}-{dateTime:HH:mm:ss}";
            TestMode = true;
        }
Exemple #3
0
        public ConsumerSettingsProcessedEvents()
        {
            Brokers.Add("localhost:9092");
            Topic = "bruteflow-events-after-pipeline";
            var dateTime = DateTime.Now;

            GroupId  = $"bruteflow-{dateTime:yyyyMMdd}-{dateTime:HH:mm:ss}";
            TestMode = true;
        }
Exemple #4
0
        public void Push(string topicName, string message)
        {
            var broker = Brokers.FirstOrDefault(x => x.TopicName == topicName);

            if (broker is null)
            {
                broker = new Broker(topicName);
                Brokers.Add(broker);
            }

            broker.AddMessage(message);
            new Thread(() => MsgReceived(topicName, message))
            {
                IsBackground = true
            }.Start();
        }
 public ProducerSettingsTestEvents()
 {
     Brokers.Add("localhost:9092");
     Topic = "bruteflow-incoming-events";
 }
 public ProducerSettingsProcessedEvents()
 {
     Brokers.Add("localhost:9092");
     Topic = "bruteflow-events-after-pipeline";
 }
Exemple #7
0
        public void AddToQueue(string token, NotificationViewModel model, bool isTest)
        {
            lock (_notification)
            {
                _notification.IsTest = isTest;
                byte[] appleCertificate;
                string appleCertificatePassword;
                string gcmAuthorizationToken;
                using (var db = new ApplicationDbContext())
                {
                    var app = db.Apps.SingleOrDefault(p => p.AppToken == token);
                    if (app == null)
                    {
                        throw new UnauthorizedAccessException();
                    }
                    _notification.AppId      = app.Id;
                    gcmAuthorizationToken    = app.GcmAuthorizationToken;
                    appleCertificate         = app.AppleCertificate;
                    appleCertificatePassword = app.AppleCertificatePassword;
                }

                _notification.Json         = model.Json;
                _notification.DeviceTokens = new List <NotificationDeviceToken>();
                _notification.CreateDate   = DateTime.Now;

                foreach (var registrationId in model.AndroidRegistrationIds)
                {
                    _notification.DeviceTokens.Add(new NotificationDeviceToken()
                    {
                        DeviceToken = registrationId,
                        Device      = Device.Android
                    });
                }


                foreach (var deviceToken in model.AppleDeviceTokens)
                {
                    _notification.DeviceTokens.Add(new NotificationDeviceToken()
                    {
                        DeviceToken = deviceToken,
                        Device      = Device.iOS
                    });
                }

                if (gcmAuthorizationToken != null && _notification.DeviceTokens.Where(p => p.Device == Device.Android).Count() > 0)
                {
                    var itemsPerBulk       = 1000;
                    var totalAndroidTokens = _notification.DeviceTokens
                                             .Where(p => p.Device == Device.Android).Count();
                    var bulks = totalAndroidTokens <= itemsPerBulk ? 1 : Convert.ToInt32(Math.Ceiling((double)totalAndroidTokens / itemsPerBulk));
                    for (var bulk = 0; bulk < bulks; bulk++)
                    {
                        var broker = new PushBroker();
                        SetEvents(broker);
                        broker.RegisterGcmService(new GcmPushChannelSettings(gcmAuthorizationToken), new PushServiceSettings()
                        {
                            NotificationSendTimeout = 60000
                        });
                        var tokens = _notification.DeviceTokens
                                     .Where(p => p.Device == Device.Android).Skip(itemsPerBulk * bulk).Take(itemsPerBulk)
                                     .Select(p => p.DeviceToken).ToList();
#if DEBUG
                        // Set test mode, when google will return a response without really send the notifications
                        broker.QueueNotification(new GcmNotification()
                                                 .ForDeviceRegistrationId(tokens)
                                                 .WithJson(_notification.Json)
                                                 .WithDryRun());
#else
                        if (isTest)
                        {
                            broker.QueueNotification(new GcmNotification()
                                                     .ForDeviceRegistrationId(tokens)
                                                     .WithJson(_notification.Json)
                                                     .WithDryRun());
                        }
                        else
                        {
                            broker.QueueNotification(new GcmNotification()
                                                     .ForDeviceRegistrationId(tokens)
                                                     .WithJson(_notification.Json));
                        }
#endif
                        Brokers.Add(broker);
                    }
                }
                if (appleCertificate != null && _notification.DeviceTokens.Where(p => p.Device == Device.iOS).Count() > 0)
                {
                    var broker = new PushBroker();
                    SetEvents(broker);
                    broker.RegisterAppleService(new ApplePushChannelSettings(appleCertificate, appleCertificatePassword));

                    foreach (var deviceToken in _notification.DeviceTokens.Where(p => p.Device == Device.iOS).Select(d => d.DeviceToken))
                    {
                        broker.QueueNotification(new AppleNotification()
                                                 .ForDeviceToken(deviceToken)
                                                 .WithAlert(JObject.Parse(_notification.Json)["message"].Value <string>())
                                                 .WithSound("sound.caf")
                                                 .WithCustomItem("data", _notification.Json));
                    }
                    Brokers.Add(broker);
                }
            }
        }