コード例 #1
0
        private void SocketOnResponseReceived(QsysSocket socket, QsysResponse response)
        {
#if DEBUG
            //CloudLog.Debug("{0}.SocketOnResponseReceived(), ID = {1}{2}", GetType().Name, response.Id,
            //    response.IsError ? string.Format(", Error: {0}", response.ErrorMessage) : " OK");
#endif
            if (_awaitingEvents.ContainsKey(response.Id))
            {
#if DEBUG
                //CrestronConsole.PrintLine("Found awaiting CEvent for response ID {0}", response.Id);
#endif
                _awaitingResponsesLocked.Enter();
                _awaitingResponses[response.Id] = response;
                _awaitingResponsesLocked.Leave();
                _awaitingEvents[response.Id].Set();
                return;
            }
            if (!_awaitingAsyncRequests.ContainsKey(response.Id))
            {
                return;
            }
            try
            {
                _awaitingAsyncRequests[response.Id](response);
            }
            catch (Exception e)
            {
                CloudLog.Exception(e);
            }
            _awaitingAsyncRequestsLocked.Enter();
            _awaitingAsyncRequests.Remove(response.Id);
            _awaitingAsyncRequestsLocked.Leave();
        }
コード例 #2
0
        private void SocketOnRequestReceived(QsysSocket socket, QsysRequest request)
        {
            //CloudLog.Debug("{0}.SocketOnRequestReceived()\r\n{1}", GetType().Name, request);

            switch (request.Method)
            {
            case "EngineStatus":
                ReceivedEngineStatusUpdate(request);
                break;

            case "ChangeGroup.Poll":
                var groupId = request.Args["Id"].Value <string>();

                if (_changeGroups.ContainsKey(groupId))
                {
                    var changes = request.Args["Changes"];
                    foreach (var change in changes.Where(change => change["Component"] != null))
                    {
                        this[change["Component"].Value <string>()][change["Name"].Value <string>()].UpdateFromData
                            (change);
                    }
                }
                break;
            }
        }
コード例 #3
0
        /// <summary>
        /// Create an instance of a QsysCore
        /// </summary>
        /// <param name="deviceAddresses">The hostnames or ip addresses of the core(s)</param>
        /// <param name="port">Override the default TCP port of 1710</param>
        /// <param name="name"></param>
        public QsysCore(IList <string> deviceAddresses, string name, int port)
        {
            _name = name;
            try
            {
                _socket = new QsysSocket(deviceAddresses, port, name);
                _socket.StatusChanged += (client, status) =>
                {
                    _initialized        = status != SocketStatus.SOCKET_STATUS_CONNECTED;
                    DeviceCommunicating = status == SocketStatus.SOCKET_STATUS_CONNECTED;
                };

                _socket.RequestReceived  += SocketOnRequestReceived;
                _socket.ResponseReceived += SocketOnResponseReceived;
                CloudLog.Debug("{0} instance created with address(es) \"{1}\" port {2}", GetType().Name,
                               String.Join(",", deviceAddresses.ToArray()), port);
                CrestronConsole.AddNewConsoleCommand(parameters => DefaultChangeGroup.Invalidate(), "QSysUpdateAll",
                                                     "Invalidate the default change group in the core",
                                                     ConsoleAccessLevelEnum.AccessOperator);
            }
            catch (Exception e)
            {
                CloudLog.Error("Error in {0}.ctor(), {1}", GetType().Name, e.Message);
            }
        }
コード例 #4
0
 internal QsysRequest(QsysSocket socket, string method, object args)
 {
     Socket = socket;
     Id     = socket.GetNextId();
     Method = method;
     if (args != null)
     {
         Args = JToken.FromObject(args);
     }
 }
コード例 #5
0
        protected virtual void OnResponseReceived(QsysSocket socket, QsysResponse response)
        {
#if DEBUG
            //Debug.WriteSuccess(string.Format("{0}.OnResponseReceived()", GetType().Name));
            //Debug.WriteNormal(Debug.AnsiBlue + response + Debug.AnsiReset);
#endif
            var handler = ResponseReceived;
            if (handler != null)
            {
                handler(socket, response);
            }
        }