예제 #1
0
 public void RegisterParameter(string paramName)
 {
     if (_parameterInfo.ContainsKey(paramName))
     {
         try
         {
             var xTotal = int.Parse(_parameterInfo[paramName][0]);
             var yTotal = int.Parse(_parameterInfo[paramName][1]);
             for (int x = 0; x < xTotal; x++)
             {
                 for (int y = 0; y < yTotal; y++)
                 {
                     Send("get {0} {1} {2}", paramName, x, y);
                 }
             }
         }
         catch (Exception e)
         {
             CloudLog.Exception(e);
         }
     }
     else
     {
         throw new Exception(string.Format("Unknown parameter \"{0}\"", paramName));
     }
 }
예제 #2
0
        private object SendBufferProcess(object o)
        {
            while (true)
            {
                try
                {
                    var bytes = _txQueue.Dequeue();
                    if (bytes == null)
                    {
                        CloudLog.Notice("Exiting {0}", Thread.CurrentThread.Name);
                        return(null);
                    }
#if DEBUG
                    Debug.WriteInfo("Samsung Tx",
                                    Debug.AnsiPurple + Tools.GetBytesAsReadableString(bytes, 0, bytes.Length, false) +
                                    Debug.AnsiReset);
#endif
                    _comPort.Send(bytes, bytes.Length);
                    CrestronEnvironment.AllowOtherAppsToRun();
                    Thread.Sleep(10);
                }
                catch (Exception e)
                {
                    if (e.Message != "ThreadAbortException")
                    {
                        CloudLog.Exception(string.Format("{0} - Exception in tx buffer thread", GetType().Name), e);
                    }
                }
            }
        }
예제 #3
0
        protected virtual void OnDeviceConnect(int deviceCount)
        {
            CloudLog.Debug("{0} online deviceCount = {1}", Device, deviceCount);

            var oldCount = _deviceCount;

            _deviceCount = deviceCount;

            if (oldCount > 0)
            {
                return;
            }

            if (!System.Booted)
            {
                return;
            }

            if (Room != null && Room.Source != null)
            {
                UIShouldShowSource(Room.Source);
            }
            else
            {
                UIShouldShowHomePage(ShowHomePageEventType.OnDeviceConnect);
            }
        }
예제 #4
0
        internal ChristieComPortHandler(IComPortDevice comPort)
        {
            _comPort = comPort;

            var port = _comPort as CrestronDevice;

            if (port != null && !port.Registered)
            {
                var result = port.Register();
                if (result != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CloudLog.Error("Could not register {0}, {1}", port, result);
                }
            }

            _comPort.SetComPortSpec(new ComPort.ComPortSpec()
            {
                BaudRate          = ComPort.eComBaudRates.ComspecBaudRate115200,
                DataBits          = ComPort.eComDataBits.ComspecDataBits8,
                StopBits          = ComPort.eComStopBits.ComspecStopBits1,
                Parity            = ComPort.eComParityType.ComspecParityNone,
                Protocol          = ComPort.eComProtocolType.ComspecProtocolRS232,
                ReportCTSChanges  = false,
                HardwareHandShake = ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone,
                SoftwareHandshake = ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone,
            });

            _bytes     = new byte[1000];
            _byteIndex = 0;

            _comPort.SerialDataReceived += ComPortOnSerialDataReceived;
        }
예제 #5
0
        protected virtual void OnStatusChanged(TCPClient mytcpclient, SocketStatus clientsocketstatus)
        {
            var handler = StatusChanged;

            if (handler != null)
            {
                try
                {
#if DEBUG
                    if (clientsocketstatus == SocketStatus.SOCKET_STATUS_CONNECTED)
                    {
                        Debug.WriteSuccess(GetType().Name + " Connected", "IP: " + mytcpclient.AddressClientConnectedTo);
                    }
                    else
                    {
                        Debug.WriteWarn(GetType().Name, "Socket status = " + clientsocketstatus);
                    }
#endif
                    handler(mytcpclient, clientsocketstatus);
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e);
                }
            }
        }
예제 #6
0
        object ReceiveBufferProcess(object obj)
        {
            var bytes     = new Byte[1000];
            var byteIndex = 0;

            while (true)
            {
                try
                {
                    var b = _rxQueue.Dequeue();

                    if (_programStopping)
                    {
                        return(null);
                    }

                    if (b == 'x')
                    {
                        var copiedBytes = new byte[byteIndex];
                        Array.Copy(bytes, copiedBytes, byteIndex);
#if DEBUG
                        //CrestronConsole.Print("LG Rx: ");
                        //Tools.PrintBytes(copiedBytes, 0, copiedBytes.Length, true);
#endif
                        if (ReceivedData != null)
                        {
                            try
                            {
                                ReceivedData(copiedBytes);
                            }
                            catch (Exception e)
                            {
                                CloudLog.Exception(e);
                            }
                        }

                        byteIndex = 0;
                    }
                    else
                    {
                        bytes[byteIndex] = b;
                        byteIndex++;
                    }
                }
                catch (Exception e)
                {
                    if (e.Message != "ThreadAbortException")
                    {
#if DEBUG
                        //CrestronConsole.Print("Error in Lg Rx Handler: ");
                        //Tools.PrintBytes(bytes, 0, byteIndex);
#endif
                        CloudLog.Exception(string.Format("{0} - Exception in rx thread", GetType().Name), e);
                    }
                }

                CrestronEnvironment.AllowOtherAppsToRun();
                Thread.Sleep(0);
            }
        }
예제 #7
0
파일: UITabBar.cs 프로젝트: uxav/lib2
        public UITabBar(UIControllerWithSmartObjects uiController, SmartObject smartObject)
        {
            _uiController = uiController;
            _smartObject = smartObject;

            CloudLog.Debug("{0}.ctor for SmartObject ID: {1}", GetType(), smartObject.ID);
            try
            {
                var count = 1U;
                while (true)
                {
                    var name = string.Format("Tab Button {0} Press", count);
                    if (_smartObject.BooleanOutput.Contains(name))
                    {
                        Buttons[count] = new UIButton(_smartObject, name, string.Format("Tab Button {0} Select", count));
                        count++;
                    }
                    else
                    {
                        break;
                    }
                }

                CloudLog.Debug("{0} for SmartObject ID: {1} contains {2} items", GetType(), smartObject.ID,
                    Buttons.Count);
            }
            catch (Exception e)
            {
                CloudLog.Exception(e, "Error in {0}.ctor, {1}", GetType().Name, e.Message);
            }
        }
예제 #8
0
파일: UIActionSheet.cs 프로젝트: uxav/lib2
        private void CountStep(object userSpecific)
        {
            _secondsCount++;

            if (_timeOutTime == 0)
            {
                return;
            }

            if (_secondsCount < _timeOutTime)
            {
                return;
            }

            _view.Hide();

            if (_callback == null)
            {
                return;
            }

            try
            {
                _callback(UIActionSheetResponseType.TimedOut, new UIActionSheetResponseArgs());
            }
            catch (Exception e)
            {
                CloudLog.Exception(e);
            }
        }
예제 #9
0
        private static void GetChannelsCallback(int requestId, HttpClientResponse response)
        {
            if (ChannelResponseCallbacks.ContainsKey(requestId))
            {
                var callback = ChannelResponseCallbacks[requestId];
                ChannelResponseLock.Enter();
                ChannelResponseCallbacks.Remove(requestId);
                ChannelResponseLock.Leave();

                if (response.Code != 200)
                {
                    callback(false, null);
                    return;
                }

                try
                {
                    var json     = JToken.Parse(response.ContentString);
                    var channels = json["result"].Select(item => new Channel(item));
                    callback(true, channels);
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e);
                    callback(false, null);
                }
            }
        }
예제 #10
0
        public override void SetInput(DisplayDeviceInput input)
        {
            if (_availableInputs.Contains(input))
            {
                switch (input)
                {
                case DisplayDeviceInput.HDMI1:
                    _requestedInputValue = "HDMI";
                    break;

                case DisplayDeviceInput.DVI:
                    _requestedInputValue = "D-RGB";
                    break;

                case DisplayDeviceInput.VGA:
                    _requestedInputValue = "A-RGB2";
                    break;

                case DisplayDeviceInput.HDBaseT:
                    _requestedInputValue = "HDBT";
                    break;
                }

                _socket.Send(string.Format("INPUT={0}", _requestedInputValue));
                _socket.Send("GET=INPUT");
            }
            else
            {
                CloudLog.Error("{0} does not have the option of input: {1}", this, input);
            }
        }
예제 #11
0
        private void SourceButtonsOnButtonEvent(IButton button, ButtonEventArgs args)
        {
            if (args.EventType != ButtonEventType.Released)
            {
                return;
            }

            try
            {
                if (args.CollectionKey == 3 && Room.OtherRooms.Count > 0 && Room.OtherRooms.First().Source != null)
                {
                    Room.Source = Room.OtherRooms.First().Source;
                    return;
                }

                Room.Source = Room.Sources.ElementAt((int)args.CollectionKey - 1);
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            catch (Exception e)
            {
                CloudLog.Exception(e);
            }
        }
예제 #12
0
        public IEnumerable <Booking> GetBookings()
        {
            var cmd = new CodecCommand("Bookings", "List");

            cmd.Args.Add("Days", 1);
            cmd.Args.Add("DayOffset", 0);

            var bookings = new List <Booking>();

            var response = Codec.SendCommand(cmd);

            if (response.Code != 200)
            {
                CloudLog.Error("Error getting bookings search, Codec Responded with {0} code", response.Code);
                return(bookings);
            }

            var result = response.Xml.Element("Command").Element("BookingsListResult");

            Debug.WriteInfo("Bookings List");
            Debug.WriteNormal(Debug.AnsiPurple + result + Debug.AnsiReset);

            if (result.Attribute("status").Value == "Error")
            {
                var message = result.Element("Reason").Value;
                CloudLog.Error("Error getting bookings search: {0}", message);
                return(bookings);
            }

            bookings.AddRange(result.Elements("Booking").Select(data => new Booking(data)));

            return(bookings.ToArray());
        }
예제 #13
0
        public override void SetInput(DisplayDeviceInput input)
        {
            if (_availableInputs.Contains(input))
            {
                _requestedInput = input;

                switch (input)
                {
                case DisplayDeviceInput.HDMI1:
                    Send('x', 'b', 0x90);
                    break;

                case DisplayDeviceInput.HDMI2:
                    Send('x', 'b', 0x91);
                    break;

                case DisplayDeviceInput.HDMI3:
                    Send('x', 'b', 0x92);
                    break;

                case DisplayDeviceInput.HDMI4:
                    Send('x', 'b', 0x93);
                    break;
                }
            }
            else
            {
                CloudLog.Error("{0} does not have the option of input: {1}", this, input);
            }
        }
        protected override void WillShow()
        {
            base.WillShow();

            _inputListButtons.ButtonEvent   += InputListButtonsOnButtonEvent;
            _outputListButtons.ButtonEvent  += OutputListButtonsOnButtonEvent;
            _takeButton.ButtonEvent         += TakeButtonOnButtonEvent;
            _cancelButton.ButtonEvent       += CancelButtonOnButtonEvent;
            _switcher.Chassis.DMInputChange += ChassisOnDmInputChange;
            try
            {
                //UpdateSyncStatusFeedback();
            }
            catch (Exception e)
            {
                CloudLog.Exception(e);
            }

            UpdateLists(ConfigManager.Config.SwitcherConfig);

            if (_updateFeedbackThread != null && _updateFeedbackThread.ThreadState == Thread.eThreadStates.ThreadRunning)
            {
                return;
            }

            _updateFeedbackThread = new Thread(UpdateFeedbackProcess, null)
            {
                Priority = Thread.eThreadPriority.LowestPriority,
                Name     = "Routing UI Feedback Process"
            };
        }
예제 #15
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);
            }
        }
예제 #16
0
        internal virtual void UpdateProperties(Dictionary <string, Dictionary <string, string> > properties)
        {
            try
            {
                foreach (var property in properties["gen"])
                {
                    switch (property.Key)
                    {
                    case "model":
                        Model = property.Value;
                        break;

                    case "state":
                        State = (DeviceState)Enum.Parse(typeof(DeviceState), property.Value, true);
                        break;

                    case "name":
                        Name = property.Value;
                        break;

                    case "uptime":
                        var timeMatch = Regex.Match(property.Value, @"(\d+)d:(\d+)h:(\d+)m:(\d+)s");
                        UpTime = TimeSpan.FromDays(int.Parse(timeMatch.Groups[1].Value))
                                 + TimeSpan.FromHours(int.Parse(timeMatch.Groups[2].Value))
                                 + TimeSpan.FromMinutes(int.Parse(timeMatch.Groups[3].Value))
                                 + TimeSpan.FromSeconds(int.Parse(timeMatch.Groups[4].Value));
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                CloudLog.Error("Error processing property values in {0}, {1}", GetType().Name, e.Message);
            }
        }
예제 #17
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();
        }
        private object UpdateFeedback(OneBeyond selectedProcessor)
        {
            if (selectedProcessor == null)
            {
                return(null);
            }

            try
            {
                selectedProcessor.GetRoomConfigs();
                selectedProcessor.GetCurrentRoomConfig();
                selectedProcessor.GetAutoSwitchStatus();
                selectedProcessor.GetLayouts();
                selectedProcessor.GetCurrentLayout();
                selectedProcessor.GetAutoSwitchStatus();
                selectedProcessor.GetCameraStatus();
                selectedProcessor.GetRecordStatus();
                selectedProcessor.GetRecordingSpace();
                selectedProcessor.GetStreamStatus();
                selectedProcessor.GetIsoRecordStatus();
            }
            catch (Exception e)
            {
                CloudLog.Exception(e);
            }

            return(null);
        }
예제 #19
0
        internal SnapshotController(QsysCore core, JToken data)
            : base(core, data)
        {
            var count = 10;

            try
            {
                count = int.Parse(Properties["dataset_count"]);
            }
            catch (Exception e)
            {
                CloudLog.Warn("Error in Snapshot Controller ctor, {0}, defaulting to size of 10", e.Message);
            }

            for (var i = 1; i <= count; i++)
            {
                var control = RegisterControl(string.Format("load.{0}", i));
                if (control == null)
                {
                    break;
                }
                RegisterControl(string.Format("match.{0}", i)).ValueChange += OnValueChange;
                RegisterControl(string.Format("last.{0}", i)).ValueChange  += OnValueChange;
            }
        }
예제 #20
0
파일: UIKeypad.cs 프로젝트: uxav/lib2
        private void OnButtonEvent(IButton button, ButtonEventArgs args)
        {
            var    type = (UIKeypadButtonType)args.CollectionKey;
            string stringValue;

            switch (type)
            {
            case UIKeypadButtonType.Star:
                stringValue = "*";
                break;

            case UIKeypadButtonType.Hash:
                stringValue = "#";
                break;

            default:
                stringValue = args.CollectionKey.ToString(CultureInfo.InvariantCulture);
                break;
            }

            if (_buttonEvent == null)
            {
                return;
            }

            CloudLog.Debug("{0} {1}: {2}", GetType().Name, args.EventType, (UIKeypadButtonType)args.CollectionKey);

            _buttonEvent(this, new UIKeypadButtonEventArgs()
            {
                EventType        = args.EventType,
                KeypadButtonType = (UIKeypadButtonType)args.CollectionKey,
                StringValue      = stringValue,
                Value            = args.CollectionKey
            });
        }
예제 #21
0
        internal override void UpdateProperties(Dictionary <string, Dictionary <string, string> > properties)
        {
            base.UpdateProperties(properties);

            try
            {
                if (properties.ContainsKey("hdmiInput"))
                {
                    HdmiInput.UpdateFromProperties(properties["hdmiInput"]);
                }
            }
            catch (Exception e)
            {
                CloudLog.Error("Error processing property values in {0}, {1}", GetType().Name, e.Message);
            }

#if DEBUG
            CrestronConsole.PrintLine("Updated {0}, \"{1}\": State: {2}", GetType().Name, Name, State);
            if (State != DeviceState.Up)
            {
                return;
            }
            CrestronConsole.PrintLine("   Uptime: {0}", UpTime.ToPrettyFormat());
            CrestronConsole.PrintLine("   HdmiInput: {0}{1}{2}",
                                      HdmiInput.Connected ? "Connected" : "Disconnected",
                                      HdmiInput.Connected ? " " + HdmiInput.Format : "",
                                      HdmiInput.Connected ? " HDCP: " + HdmiInput.Hdcp : "",
                                      HdmiInput.Connected ? " HDMI 2.0: " + HdmiInput.Hdmi2Point0 : "");
#endif
        }
예제 #22
0
        private void AmOnOnlineStatusChange(GenericBase currentDevice, OnlineOfflineEventArgs args)
        {
            if (!args.DeviceOnLine)
            {
                CloudLog.Warn("{0} is offline!", currentDevice.ToString());
            }

            if (args.DeviceOnLine && currentDevice is AmX00)
            {
                try
                {
                    ((AmX00)currentDevice).DisplayControl.DisableAutomaticRouting();
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e);
                }
            }

            try
            {
                if (DeviceCommunicatingChange != null)
                {
                    DeviceCommunicatingChange(this, args.DeviceOnLine);
                }
            }
            catch (Exception e)
            {
                CloudLog.Exception(e);
            }
        }
예제 #23
0
        private string Get(string paramId)
        {
            var uri = new UriBuilder("http", _ipAddress, 80, string.Format("config"))
            {
                Query = string.Format("action=get&paramid={0}", paramId)
            };

#if true
            CloudLog.Debug("Request to KiPro: GET {0}", uri.Uri.ToString());
#endif
            var task     = _client.GetAsync(uri.Uri);
            var response = task.Await();
#if true
            CloudLog.Debug("Response from KiPro: Code {0}", response.StatusCode);
#endif
            response.EnsureSuccessStatusCode();

            var readTask = response.Content.ReadAsStringAsync();
            var content  = readTask.Await();
#if true
            CloudLog.Debug("Response content:\r\n{0}", content);
#endif
            var json = JToken.Parse(content);

            return(json["value"].Value <string>());
        }
예제 #24
0
        void OnReceive(string receivedString)
        {
            var match = Regex.Match(receivedString, @"^mute near (off|on)");

            if (!match.Success)
            {
                return;
            }
            var muted = match.Groups[1].Value == "on";

            if (_muted == muted)
            {
                return;
            }

            _muted = muted;

            if (MuteChange == null)
            {
                return;
            }
            try
            {
                MuteChange(_muted);
            }
            catch (Exception e)
            {
                CloudLog.Exception(e);
            }
        }
예제 #25
0
        protected virtual void OnSourceChange(SourceBase source)
        {
            CloudLog.Debug("{0} set to Source: {1}", this, source != null ? source.ToString() : "None");

            if (source == null || _displayDevice == null)
            {
                return;
            }
            if (!_displayDevice.Power)
            {
                CloudLog.Debug("{0} Power set to On!", this);
                _displayDevice.Power = true;
            }
            try
            {
                if (Room != null && Room.GetDisplayInputOverrideForSource(this, source) != DisplayDeviceInput.Unknown)
                {
                    RouteSourceDisplayDeviceInput(Room.GetDisplayInputOverrideForSource(this, source));
                }
                else if (source.DisplayDeviceInput != DisplayDeviceInput.Unknown)
                {
                    RouteSourceDisplayDeviceInput(source.DisplayDeviceInput);
                }
            }
            catch (Exception e)
            {
                CloudLog.Exception(e, "Error setting input for display");
            }
        }
예제 #26
0
        private void AssetCommsAlertTimerProcess(object userSpecific)
        {
            var itemsToRemove = new List <FusionStaticAsset>();

            foreach (var kvp in _assetCommsStatus)
            {
                var asset = kvp.Key;
                var info  = kvp.Value;

                if (!info.ShouldRaiseAlert)
                {
                    continue;
                }

                if (info.Communicating)
                {
                    CloudLog.Info("Notifying Fusion asset \"{0}\" is back online", asset.ParamAssetName);
                }
                else
                {
                    CloudLog.Warn("Notifying Fusion asset \"{0}\" is now offline", asset.ParamAssetName);
                }

                itemsToRemove.Add(asset);
                asset.Connected.InputSig.BoolValue    = info.Communicating;
                asset.AssetError.InputSig.StringValue = !info.Communicating ? "3:Device is offline" : "0:Device is online";
            }

            foreach (var assetKey in itemsToRemove)
            {
                _assetCommsStatus.Remove(assetKey);
            }
        }
예제 #27
0
        private void SocketOnReceivedString(string receivedString)
        {
            DeviceCommunicating = true;
            var match = Regex.Match(receivedString, @"^([\w-]+) ([\w/]+)(?:(\.|:| )(.+))?$");

            if (!match.Success)
            {
                CloudLog.Error("Error processing line from lightware: \"{0}\"", receivedString);
                return;
            }
            var prefix  = match.Groups[1].Value;
            var path    = match.Groups[2].Value;
            var context = match.Groups[4].Value;

            Debug.WriteNormal(Debug.AnsiBlue + prefix + " " + Debug.AnsiPurple + path + Debug.AnsiCyan +
                              match.Groups[3].Value + Debug.AnsiGreen + context + Debug.AnsiReset);

            switch (prefix)
            {
            case "CHG":
                OnReceiveChange(path, context);
                break;

            case "pr":
                OnReceiveProperty(path, context, true);
                break;

            case "pw":
                OnReceiveProperty(path, context, false);
                break;
            }
        }
예제 #28
0
        internal QsysResponse Request(string method, object args)
        {
            if (Thread.CurrentThread.ThreadType == Thread.eThreadType.SystemThread)
            {
                throw new Exception("Cannot call QsysCore.Request synchronously in system thread!");
            }
            var request = new QsysRequest(_socket, method, args);

            //CloudLog.Debug("{0}.Request(), ID = {1}", GetType().Name, request.Id);
            _awaitingEventsLocked.Enter();
            _awaitingEvents[request.Id] = new CEvent(true, false);
            _awaitingEventsLocked.Leave();
            _socket.SendRequest(request);
            var result = _awaitingEvents[request.Id].Wait(30000);

            _awaitingEvents[request.Id].Dispose();
            _awaitingEventsLocked.Enter();
            _awaitingEvents.Remove(request.Id);
            _awaitingEventsLocked.Leave();
            if (!result)
            {
                CloudLog.Error("{0} Request Time Out, Request: {1}, ID {2}", GetType().Name, request.Method, request.Id);
                throw new TimeoutException("Request did not process a response in suitable time");
            }
            var response = _awaitingResponses[request.Id];

            _awaitingResponsesLocked.Enter();
            _awaitingResponses.Remove(request.Id);
            _awaitingResponsesLocked.Leave();
            return(response);
        }
예제 #29
0
        protected virtual void OnRoomSourceChange(RoomBase room, RoomSourceChangeEventArgs args)
        {
            if (room != Room || !System.Booted)
            {
                return;
            }

            try
            {
                if (SourceChange != null)
                {
                    SourceChange(room, args);
                }
            }
            catch (Exception e)
            {
                CloudLog.Exception(e);
            }

            if (args.NewSource != null)
            {
                UIShouldShowSource(args.NewSource);
            }
            else
            {
                UIShouldShowHomePage(ShowHomePageEventType.OnClearingSource);
            }
        }
예제 #30
0
        public void Connect()
        {
            if (_client != null && _client.IsConnected)
            {
                CloudLog.Warn("{0} already connected", GetType().Name);
                return;
            }

            _reconnect = true;

            var info = new KeyboardInteractiveConnectionInfo(_address, 22, _username);

            info.AuthenticationPrompt += OnPasswordPrompt;

            _client = new SshClient(info);
            _client.ErrorOccurred   += (sender, args) => CrestronConsole.PrintLine("ErrorOccurred: {0}", args.Exception.Message);
            _client.HostKeyReceived +=
                (sender, args) => CrestronConsole.PrintLine("HostKeyReceived: {1}, can trust = {0}", args.CanTrust,
                                                            args.HostKeyName);

            _sshProcess = new Thread(SshCommsProcess, null, Thread.eThreadStartOptions.CreateSuspended)
            {
                Name     = "Tesira SSH Comms Handler",
                Priority = Thread.eThreadPriority.HighPriority
            };

            _sshProcess.Start();
        }