Example #1
0
        public void LogSuccessfullyWithValue()
        {
            //Act
            var eventToLog = new Event {
                key = "Key1", eventTypeId = "testEventType", trafficTypeName = "testTrafficType", timestamp = 7000, value = 12.34
            };

            _eventLog.Log(new WrappedEvent
            {
                Event = eventToLog,
                Size  = 1024
            });

            //Assert
            WrappedEvent element = null;

            while (element == null)
            {
                element = _queue.Dequeue();
            }
            Assert.IsNotNull(element);
            Assert.AreEqual("Key1", element.Event.key);
            Assert.AreEqual("testEventType", element.Event.eventTypeId);
            Assert.AreEqual("testTrafficType", element.Event.trafficTypeName);
            Assert.AreEqual(7000, element.Event.timestamp);
            Assert.AreEqual(12.34, element.Event.value);
        }
Example #2
0
        public void GivenDiscountChangedThenVerifyUpdateDiscount()
        {
            var priceSaver = Substitute.For <IPriceSaver>();
            var handler    = new UpdatePricesHandler(priceSaver);
            var evt        = new DiscountChanged(1000, 0, 0.3m);
            var wrap       = new WrappedEvent(Guid.NewGuid(), evt);

            handler.Handle(wrap, evt);

            priceSaver.Received().Update(new Price(wrap.StreamId, evt.Price, evt.Discount, evt.Profit));
        }
Example #3
0
            public static BaseEvent CreateWrapper(BaseEvent original, Action <BaseEvent, bool> passthrough, bool ignore_delay)
            {
                ConfigNode cn = new ConfigNode();

                original.OnSave(cn);
                Wrapper   wrapper   = new Wrapper(original, passthrough, ignore_delay);
                BaseEvent new_event = new WrappedEvent(original, original.listParent, original.name, wrapper.Invoke);

                new_event.OnLoad(cn);

                return(new_event);
            }
Example #4
0
        public void Log(WrappedEvent wrappedEvent)
        {
            _wrappedEventsCache.AddItems(new List <WrappedEvent> {
                wrappedEvent
            });

            _acumulateSize += wrappedEvent.Size;

            if (_wrappedEventsCache.HasReachedMaxSize() || _acumulateSize >= MAX_SIZE_BYTES)
            {
                SendBulkEvents();
            }
        }
        public EventListViewItem(EventInfo _event)
        {
            this.wrappedEvent = new WrappedEvent(_event);
            this.Tag          = this.wrappedEvent;

            this.Text = wrappedEvent.Event.ToString();
            this.SubItems.Add(wrappedEvent.Accessibility.ToString());
            this.SubItems.Add(wrappedEvent.Virtual.ToString());
            this.SubItems.Add(wrappedEvent.Interface);

            this.wrappedEvent.AccessibilityChanged += this.OnAccessibilityChanged;
            this.wrappedEvent.VirtualChanged       += this.OnVirtualChanged;
            this.wrappedEvent.InterfaceChanged     += this.OnInterfaceChanged;
        }
Example #6
0
        public void Log(WrappedEvent wrappedEvent)
        {
            var dropped = _wrappedEventsCache.AddItems(new List <WrappedEvent> {
                wrappedEvent
            });

            if (dropped == 0)
            {
                _acumulateSize += wrappedEvent.Size;
            }

            RecordStats(dropped);

            if (_wrappedEventsCache.HasReachedMaxSize() || _acumulateSize >= MAX_SIZE_BYTES)
            {
                SendBulkEvents();
            }
        }
Example #7
0
        public void LogSuccessfully()
        {
            //Arrange
            var eventToLog = new Event {
                key = "Key1", eventTypeId = "testEventType", trafficTypeName = "testTrafficType", timestamp = 7000, value = 12.34
            };

            var wrappedEvent = new WrappedEvent
            {
                Event = eventToLog,
                Size  = 1024
            };

            //Act
            _redisEventsLog.Log(wrappedEvent);

            //Assert
            _eventsCacheMock.Verify(mock => mock.AddItems(It.IsAny <IList <WrappedEvent> >()), Times.Once());
        }
Example #8
0
            public static BaseEvent CreateWrapper(BaseEvent original, Action <BaseEvent, bool> passthrough, bool ignoreDelay, KSPEvent kspEvent)
            {
                // Create a new configuration node and fill this node with the original base event with the values
                ConfigNode cn = new ConfigNode();

                original.OnSave(cn);

                // create the wrapper (used solely for its Invoke() method)
                // this class keeps the:
                // * pass through event (leading to the ModuleSPU.InvokeEvent() method)
                // * the original event (button click event)
                // * the ignore delay boolean value (true if the event ignore delay, false otherwise)
                EventWrapper wrapper = new EventWrapper(original, passthrough, ignoreDelay);
                // Create a new event, its main features are:
                // 1. It retains its original base event invokable method: invokable directly through its InvokeOriginalEvent() method [useful for other mods, e.g. kOS]
                // 2. Its new invoke() method which is in this wrapper class and decorated with and new KSPEvent category, namely "skip_control" (meaning we have already seen this event).
                BaseEvent newEvent = new WrappedEvent(original, original.listParent, original.name, wrapper.Invoke, kspEvent);

                // load the original base event values into the new base event
                newEvent.OnLoad(cn);

                return(newEvent);
            }
Example #9
0
        public static void WrapPartActionEventItem(Part part, Action <BaseEvent, bool> passthrough)
        {
            var controller = UIPartActionController.Instance;

            if (!controller)
            {
                return;
            }

            // get the part action window corresponding to the part
            var window = controller.GetItem(part);

            if (window == null)
            {
                return;
            }

            // get all the items that makes this window (toggle buttons, sliders, etc.)
            var partActionItems = window.ListItems;

            // loop through all of those UI components
            for (var i = 0; i < partActionItems.Count(); i++)
            {
                // check that the part action item is actually a UIPartActionFieldItem (it could be a UIPartActionEventItem)
                var uiPartActionEventItem = (partActionItems[i] as UIPartActionEventItem);
                if (uiPartActionEventItem == null)
                {
                    continue;
                }

                // get event from button
                BaseEvent originalEvent = uiPartActionEventItem.Evt;

                // Search for the BaseEventDelegate (BaseEvent.onEvent) field defined for the current BaseEvent type.
                // Note that 'onEvent' is protected, so we have to go through reflection.
                FieldInfo partEventFieldInfo = typeof(BaseEvent).GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                                               .First(fi => fi.FieldType == typeof(BaseEventDelegate));

                // Get the actual value of the 'onEvent' field
                BaseEventDelegate partEvent = (BaseEventDelegate)partEventFieldInfo.GetValue(originalEvent);

                // Gets the method represented by the delegate and from this method returns an array of custom attributes applied to this member.
                // Simply put, we want all [KSPEvent] attributes applied to the BaseEventDelegate.Method field.
                object[] customAttributes = partEvent.Method.GetCustomAttributes(typeof(KSPEvent), true);

                // Look for the custom attribute skip_control
                bool skipControl = customAttributes.Any(a => ((KSPEvent)a).category.Contains("skip_control"));
                if (skipControl)
                {
                    continue;
                }

                /*
                 * Override the old BaseEvent with our BaseEvent to the button
                 */

                // fix problems with other mods (behavior not seen with KSP) when the customAttributes list is empty.
                KSPEvent kspEvent = !customAttributes.Any() ? WrappedEvent.KspEventFromBaseEvent(originalEvent) : (KSPEvent)customAttributes[0];

                // Look for the custom attribute skip_delay
                bool ignoreDelay = customAttributes.Any(a => ((KSPEvent)a).category.Contains("skip_delay"));

                // create the new BaseEvent
                BaseEvent hookedEvent = EventWrapper.CreateWrapper(originalEvent, passthrough, ignoreDelay, kspEvent);

                // get the original event index in the event list
                BaseEventList eventList = originalEvent.listParent;
                int           listIndex = eventList.IndexOf(originalEvent);

                // remove the original event in the event list and add our hooked event
                eventList.RemoveAt(listIndex);
                eventList.Add(hookedEvent);

                // get the baseEvent field from UIPartActionEventItem (note: this is uiPartActionEventItem.Evt, but we can't set its value...)
                FieldInfo baseEventField = typeof(UIPartActionEventItem).GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                                           .First(fi => fi.FieldType == typeof(BaseEvent));

                // replace the button baseEvent value with our hooked event
                baseEventField.SetValue(uiPartActionEventItem, hookedEvent);
            }
        }
Example #10
0
 public void Log(WrappedEvent wrappedEvent)
 {
     _eventsCache.AddItems(new List <WrappedEvent> {
         wrappedEvent
     });
 }
            public static BaseEvent CreateWrapper(BaseEvent original, Action<BaseEvent, bool> passthrough, bool ignore_delay)
            {
                ConfigNode cn = new ConfigNode();
                original.OnSave(cn);
                Wrapper wrapper = new Wrapper(original, passthrough, ignore_delay);
                BaseEvent new_event = new WrappedEvent(original, original.listParent, original.name, wrapper.Invoke);
                new_event.OnLoad(cn);

                return new_event;
            }
Example #12
0
 public void Handle(WrappedEvent wrapper, PriceDeleted evt)
 {
     priceSaver.Delete(wrapper.StreamId);
 }
Example #13
0
 public void Handle(WrappedEvent wrapper, DiscountChanged evt)
 {
     priceSaver.Update(new Price(wrapper.StreamId, evt.Price, evt.Discount, evt.Profit));
 }
            public static BaseEvent CreateWrapper(BaseEvent original, Action<BaseEvent, bool> passthrough, bool ignoreDelay, KSPEvent kspEvent)
            {
                // Create a new configuration node and fill this node with the original base event with the values
                ConfigNode cn = new ConfigNode();
                original.OnSave(cn);

                // create the wrapper (used solely for its Invoke() method)
                // this class keeps the:
                // * pass through event (leading to the ModuleSPU.InvokeEvent() method)
                // * the original event (button click event)
                // * the ignore delay boolean value (true if the event ignore delay, false otherwise)
                EventWrapper wrapper = new EventWrapper(original, passthrough, ignoreDelay);
                // Create a new event, its main features are:
                // 1. It retains its original base event invokable method: invokable directly through its InvokeOriginalEvent() method [useful for other mods, e.g. kOS]
                // 2. Its new invoke() method which is in this wrapper class and decorated with and new KSPEvent category, namely "skip_control" (meaning we have already seen this event).
                BaseEvent newEvent = new WrappedEvent(original, original.listParent, original.name, wrapper.Invoke, kspEvent);

                // load the original base event values into the new base event
                newEvent.OnLoad(cn);

                return newEvent;
            }