Exemple #1
0
 // -- command --
 public Event Call(AnyEvent evt)
 {
     return(new Event(
                evt.Step,
                GetFactory(evt.Val).From(evt.Val)
                ));
 }
Exemple #2
0
        // -- IJob --
        public void Execute(int ci)
        {
            DataStreamReader stream;

            Assert.IsTrue(mConnections[ci].IsCreated);

            NetworkEvent.Type cmd;
            while ((cmd = mDriver.PopEventForConnection(mConnections[ci], out stream)) != NetworkEvent.Type.Empty)
            {
                switch (cmd)
                {
                case NetworkEvent.Type.Data: {
                    // read number of events
                    var n = stream.ReadByte();
                    Log.D($"Host - received {n} events from client {ci}");

                    // read events out of stream
                    var events = new AnyEvent[n];

                    for (var i = 0; i < n; i++)
                    {
                        events[i] = new AnyEvent(
                            step: stream.ReadUInt(),
                            new AnyEvent.Value(
                                type: (EventType)stream.ReadByte()
                                )
                            );
                    }

                    // route events back to every client
                    for (var i = 0; i < mConnections.Length; i++)
                    {
                        var writer = mDriver.BeginSend(mConnections[i]);

                        // write the number of events
                        writer.WriteByte(n);

                        // write each event
                        foreach (var evt in events)
                        {
                            writer.WriteUInt(evt.Step);
                            writer.WriteByte((byte)evt.Val.Type);
                        }

                        mDriver.EndSend(writer);
                    }

                    break;
                }

                case NetworkEvent.Type.Disconnect: {
                    Log.I($"Host - client {ci} disconnected");
                    mConnections[ci] = default;
                    break;
                }
                }
            }
        }
        private bool HandleMessage(BrokeredMessage message)
        {
            MessageReceived?.Invoke(message);

            object eventName;

            if (!message.Properties.TryGetValue("eventName", out eventName))
            {
                throw new EventNameMissingException();
            }

            FlrEvents flrEvent;

            if (!Enum.TryParse((string)eventName, out flrEvent))
            {
                throw new UnknownFlrEventNameException((string)eventName);
            }

            var eventHandle    = EventHandlers[flrEvent];
            var eventInfo      = eventHandle.EventInfo;
            var bodyObjectType = eventHandle.Type;
            var eventDelegate  = GetType().GetField(eventInfo.Name, BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(this) as MulticastDelegate;

            if (eventDelegate == null && AnyEvent == null)
            {
                return(false);
            }

            object bodyObject = null;

            if (bodyObjectType != null)
            {
                // Deserialize body object
                var stream     = message.GetBody <Stream>();
                var serializer = Serializers[bodyObjectType];
                var reader     = XmlDictionaryReader.CreateTextReader(stream, XmlDictionaryReaderQuotas.Max);
                bodyObject = serializer.ReadObject(reader);
            }

            // Fire event handlers
            AnyEvent?.Invoke(flrEvent, bodyObject, message.Properties);

            if (eventDelegate != null)
            {
                var args = bodyObject == null
                    ? new object[] { message.Properties }
                    : new[] { bodyObject, message.Properties };

                foreach (var handler in eventDelegate.GetInvocationList())
                {
                    handler.Method.Invoke(handler.Target, args);
                }
            }

            return(true);
        }
        public virtual void ActionCallback(MediaSessionEventData eventData)
        {
            Console.WriteLine("MS_" + eventData.ActionType);
            if (string.Equals(eventData.ActionType, "Play", StringComparison.InvariantCultureIgnoreCase))
            {
                Play?.Invoke(this, eventData);
            }
            else if (string.Equals(eventData.ActionType, "Pause", StringComparison.InvariantCultureIgnoreCase))
            {
                Pause?.Invoke(this, eventData);
            }
            else if (string.Equals(eventData.ActionType, "Stop", StringComparison.InvariantCultureIgnoreCase))
            {
                Stop?.Invoke(this, eventData);
            }
            else if (string.Equals(eventData.ActionType, "SeekBackward", StringComparison.InvariantCultureIgnoreCase))
            {
                SeekBackward?.Invoke(this, eventData);
            }
            else if (string.Equals(eventData.ActionType, "SeekForward", StringComparison.InvariantCultureIgnoreCase))
            {
                SeekForward?.Invoke(this, eventData);
            }
            else if (string.Equals(eventData.ActionType, "SeekTo", StringComparison.InvariantCultureIgnoreCase))
            {
                SeekTo?.Invoke(this, eventData);
            }
            else if (string.Equals(eventData.ActionType, "PreviousTrack", StringComparison.InvariantCultureIgnoreCase))
            {
                PreviousTrack?.Invoke(this, eventData);
            }
            else if (string.Equals(eventData.ActionType, "NextTrack", StringComparison.InvariantCultureIgnoreCase))
            {
                NextTrack?.Invoke(this, eventData);
            }
            else if (string.Equals(eventData.ActionType, "SkipAd", StringComparison.InvariantCultureIgnoreCase))
            {
                SkipAd?.Invoke(this, eventData);
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }

            AnyEvent?.Invoke(this, eventData);
        }
            public void TestToEventData()
            {
                var expectedEventType = typeof(string);
                var anyEvent = new AnyEvent (new AnyEventHeader {
                    EventId = "eventId"
                }, new AnyEventBody {
                    EventType = expectedEventType,
                    EventData = "hi"
                });

                var subject = new EventDataConverter ();

                var actual = subject.ToEventData (anyEvent);

                actual.EventId.Should ().NotBeEmpty ();
                actual.IsJson.Should ().BeTrue ();
                actual.Type.Should ().Be (expectedEventType.AssemblyQualifiedName);
                actual.Metadata.Should ().NotBeNull ();
                actual.Metadata.Should ().NotBeEmpty ();
                actual.Data.Should ().NotBeNull ();
                actual.Data.Should ().NotBeEmpty ();
            }
Exemple #6
0
        public Frame(bool isSimple, string frameType, Frame parent, float x, float y, int level)
        {
            _context = GetStoredInteger(_gc, frameType, "0");
            var storedInt = GetStoredInteger(_gc, frameType, $"{_context}");

            StoreInteger(_gc, frameType, "0", storedInt == 0 ? _context + 1 : storedInt);

            _parent   = parent;
            _children = new List <Frame>();
            _isSimple = isSimple;

            _frame             = _isSimple ? BlzCreateSimpleFrame(frameType, DefaultFrame.Game, _context) : BlzCreateFrame(frameType, DefaultFrame.Game, 0, _context);
            _mainTexture       = GetSubFrame(frameType + "Texture");
            _disabledTexture   = GetSubFrame(frameType + "Disabled");
            _highlightTexture  = GetSubFrame(frameType + "Highlight");
            _pushedTexture     = GetSubFrame(frameType + "Pushed");
            _backgroundTexture = GetSubFrame(frameType + "Background");
            _borderTexture     = GetSubFrame(frameType + "Border");
            _textFrame         = GetSubFrame(frameType + "Text");
            _modelFrame        = GetSubFrame(frameType + "Model");

            _inheritScale       = true;
            _inheritOpacity     = true;
            _inheritVisibility  = true;
            _inheritEnableState = true;
            _inheritPosition    = true;
            _inheritLevel       = true;
            _scalePosition      = true;

            var temp = Util.ReferenceDpi2Pixels;

            _unscaledWidth  = BlzFrameGetWidth(_frame) * temp;
            _unscaledHeight = BlzFrameGetHeight(_frame) * temp;
            _name           = $"{frameType}{_context}";
            Level           = level;
            _visibleSelf    = true;
            _enabledSelf    = true;
            _fontType       = @"Fonts\FRIZQT__.TTF";
            _fontSize       = 0.013f;
            _fontFlags      = 0;
            Value           = 0f;
            LocalScale      = 1f;
            _anchorX        = 0f;
            _anchorY        = 0f;
            _pivotX         = 0f;
            _pivotY         = 0f;
            Opacity         = 255;

            _mainTextureFile       = string.Empty;
            _disabledTextureFile   = string.Empty;
            _pushedTextureFile     = string.Empty;
            _highlightTextureFile  = string.Empty;
            _backgroundTextureFile = string.Empty;
            _borderTextureFile     = string.Empty;
            _modelFile             = string.Empty;

            Move(x, y);
            SetMinMaxValue(0f, 1f);
            Refresh();
            _frames.Add(this);
            _dict.Add(_frame, this);

            var eventTrigger = CreateTrigger();

            for (var i = 1; i <= 16; i++)
            {
                BlzTriggerRegisterFrameEvent(eventTrigger, _frame, ConvertFrameEventType(i));
            }

            TriggerAddCondition(eventTrigger, Condition(() =>
            {
                AnyEvent?.Invoke(this, null);
                return(false);
            }));
        }