Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 3
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);
            }));
        }