Beispiel #1
0
        public void Send(string eventId, string eventData)
        {
            dynamic e = new DynamicJson();

            e.id      = eventId;
            e.payload = eventData;

            //note, if there is no open socket, this isn't going to do anything, and
            //that's (currently) fine.
            lock (this)
            {
                foreach (var socket in _allSockets)
                {
                    socket.Send(e.ToString());
                }
            }
        }
Beispiel #2
0
        public void Send(string eventId, string eventData, string eventStyle = null)
        {
            dynamic e = new DynamicJson();

            e.id      = eventId;
            e.payload = eventData;
            if (!String.IsNullOrEmpty(eventStyle))
            {
                e.style = eventStyle;
            }

            //note, if there is no open socket, this isn't going to do anything, and
            //that's (currently) fine.
            lock (this)
            {
                // the ToArray() here gives us a copy so that if a socket
                // is removed while we're doing this, it will be ok
                foreach (var socket in _allSockets.ToArray())
                {
                    // see if it's been removed
                    if (_allSockets.Contains(socket))
                    {
                        // it could *still* be closed by the time we execute this,
                        // I don't know if Sending on a closed socket would throw, so we'll catch it in any case
                        try
                        {
                            socket?.Send(e.ToString());
                        }
                        catch (Exception error)
                        {
                            NonFatalProblem.Report(ModalIf.Alpha, PassiveIf.All, exception: error);
                        }
                    }
                }
            }
        }