Beispiel #1
0
        void CommandReceivedCallback(string data)
        {
            _responseTimer.Reset(_subscriptionTimerMs * 2);
            if (IsResponding != true)
            {
                IsResponding = true;
                TrigRespondingEvent(true);
            }

            var evIc = IncomingCommand;

            if (evIc != null)
            {
                var args = new SscIncomingCommandEventArgs(data);
                evIc(this, args);
                if (args.Handled)
                {
                    return;
                }
            }
            // There is a bug in some of the error responses from Sennheiser that genereates an invalid json
            // This is a workaround to not crash the json parser.
            if (data.Contains("\"error\":"))
            {
                var ev = Errors;
                if (ev != null)
                {
                    ev(this, new SscErrorEventArgs(data.Trim('\0', '\r', '\n')));
                }

                return;
            }

            var json     = JObject.Parse(data);
            var property = ((JProperty)json.First).Name;

            ABaseHandler handler = null;

            if (Handlers.TryGetValue(property, out handler))
            {
                if (json.First.First.HasValues)
                {
                    handler.HandleResponse((JObject)json.First.Children().First());
                }
                else
                {
                    handler.HandleResponse(json);
                }
            }
        }
Beispiel #2
0
 internal void AddHandler(string property, ABaseHandler handler)
 {
     Handlers[property] = handler;
 }