Esempio n. 1
0
        public void TestPushEventsDisposedEventIsRemoved() {
            var pushEndPoint = new PushEventsEndPoint();

            var genericEventArgs = new GenericEvent() {
                Message = "What up?"
            };

            pushEndPoint.Append(genericEventArgs);

            genericEventArgs.Dispose();

            Assert.AreEqual(0, pushEndPoint.EventsStream.Count);
        }
Esempio n. 2
0
        public void TestPushEventsAppendNonInclusiveEventNotPushed() {
            var pushEndPoint = new PushEventsEndPoint() {
                InclusiveNames = new List<String>() {
                    "EventName"
                }
            };

            pushEndPoint.Append(new GenericEvent() {
                Name = "DifferentEventName",
                Message = "Yo."
            });

            Assert.AreEqual(0, pushEndPoint.EventsStream.Count);
        }
Esempio n. 3
0
        public void TestPushEventsRequestFailCleanupOccurs() {
            var requestWait = new AutoResetEvent(false);
            var pushEndPoint = new PushEventsEndPoint() {
                InclusiveNames = new List<String>() {
                    "EventName"
                }
            };

            pushEndPoint.Append(new GenericEvent() {
                Name = "EventName",
                Message = "What up?"
            });

            pushEndPoint.PushCompleted += sender => requestWait.Set();

            pushEndPoint.Push();

            Assert.IsTrue(requestWait.WaitOne(10000));
            Assert.AreEqual(0, pushEndPoint.EventsStream.Count);
        }
Esempio n. 4
0
        /// <summary>
        /// Opens all of the database groups.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pushEventsGroupNames"></param>
        public void GroupedVariableListenerOnVariablesModified(GroupedVariableListener sender, List<String> pushEventsGroupNames) {
            foreach (String pushEventsGroupName in pushEventsGroupNames) {
                String pushUri = this.Shared.Variables.Get(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventsPushUri), String.Empty);

                // Make sure we have the available data to setup this end point.
                if (String.IsNullOrEmpty(pushUri) == false) {
                    if (this.EndPoints.ContainsKey(pushEventsGroupName) == false) {
                        IPushEventsEndPoint endPoint = new PushEventsEndPoint() {
                            // Deliberately done this way so two end points can't share identical credentials
                            // but share identical Uri's. Who knows what people might be doing?
                            Id = pushEventsGroupName,

                            // The password used to push data. Optional. Can be blank, null or garbage. It's just passed on to the server.
                            StreamKey = this.Shared.Variables.Get(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventPushStreamKey), String.Empty),

                            Uri = new Uri(this.Shared.Variables.Get(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventsPushUri), String.Empty)),

                            // Defaults to a 1 second interval
                            Interval = this.Shared.Variables.Get(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventPushIntervalSeconds), 1),

                            // Defaults to Xml serialization
                            ContentType = Mime.ToMimeType(this.Shared.Variables.Get(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventPushContentType), Mime.ApplicationJson), Mime.ApplicationJson),

                            // Defaults to empty list.
                            InclusiveNames = this.Shared.Variables.Variable(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventPushInclusiveNames)).ToList<String>()
                        };

                        // Now make sure we don't already push to this Uri with the same interval.
                        if (this.EndPoints.ContainsValue(endPoint) == false) {
                            this.EndPoints.Add(pushEventsGroupName, endPoint);
                        }
                    }
                    // Else, modify the existing end point.
                    else {
                        this.EndPoints[pushEventsGroupName].StreamKey = this.Shared.Variables.Get(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventPushStreamKey), String.Empty);
                        this.EndPoints[pushEventsGroupName].Uri = new Uri(this.Shared.Variables.Get(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventsPushUri), String.Empty));
                        this.EndPoints[pushEventsGroupName].Interval = this.Shared.Variables.Get(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventPushIntervalSeconds), 1);
                        this.EndPoints[pushEventsGroupName].ContentType = Mime.ToMimeType(this.Shared.Variables.Get(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventPushContentType), Mime.ApplicationJson), Mime.ApplicationJson);
                        this.EndPoints[pushEventsGroupName].InclusiveNames = this.Shared.Variables.Variable(VariableModel.NamespaceVariableName(pushEventsGroupName, CommonVariableNames.EventPushInclusiveNames)).ToList<String>();
                    }
                }
            }

            // Clear all tasks. We'll reestablish them again. Just easier than juggling what
            // has been added or not.
            this.Tasks.ForEach(task => task.Dispose());
            this.Tasks.Clear();

            foreach (var endPoint in this.EndPoints) {
                this.Tasks.Add(
                    new Timer(OnTick, endPoint.Value, TimeSpan.FromMilliseconds(0), TimeSpan.FromSeconds(endPoint.Value.Interval))
                );
            }
        }