public bool Reset()
        {
            /* This needs locking since another thread could dispose the handle */
            lock (this)
            {
                CheckDisposed();

                return(ce.Reset());
            }
        }
示例#2
0
        private void TestEventCmd(string parameters)
        {
            switch (parameters.ToUpper())
            {
            case "SET":
                myEvent.Set();
                break;

            case "RESET":
                myEvent.Reset();
                break;

            case "CLOSE":
                myEvent.Close();
                break;

            case "CREATE":
                killThreads();
                myEvent = new CEvent();
                createTestCEventThreads();
                break;

            case "CREATE FALSE FALSE":
                killThreads();
                myEvent = new CEvent(false, false);
                createTestCEventThreads();
                break;

            case "CREATE FALSE TRUE":
                killThreads();
                myEvent = new CEvent(false, true);
                createTestCEventThreads();
                break;

            case "CREATE TRUE FALSE":
                killThreads();
                myEvent = new CEvent(true, false);
                createTestCEventThreads();
                break;

            case "CREATE TRUE TRUE":
                killThreads();
                myEvent = new CEvent(true, true);
                createTestCEventThreads();
                break;

            default:
                break;
            }
        }
 /// <summary>
 /// Resets the signal for other threads forcing them to wait.
 /// </summary>
 /// <returns>True if successful, otherwise false.</returns>
 public bool Reset()
 {
     return(_cEvent.Reset());
 }
示例#4
0
        public void ConnectionStart()
        {
            if (_connectionId > 0 || (_connectionThread != null && _connectionThread.ThreadState == Thread.eThreadStates.ThreadRunning))
            {
                return;
            }
            _connectionActive = true;
            _connectionWait.Reset();
            CloudLog.Notice("{0} Initialize() called", GetType().Name);
            _connectionThread = new Thread(specific =>
            {
                while (_connectionActive && !_programStopping)
                {
                    var suppressErrors = false;

                    UriBuilder uri;
                    Task <HttpResponseMessage> task;
                    HttpResponseMessage response;
                    Task <string> readTask;
                    string content;
                    JToken json;

                    while (_connectionId == 0)
                    {
                        try
                        {
                            uri = new UriBuilder("http", _ipAddress, 80, string.Format("config"))
                            {
                                Query = "action=connect"
                            };

                            Debug.WriteInfo("Trying to connect to " + uri.Uri);

                            task     = _client.GetAsync(uri.Uri);
                            response = task.Await();

                            response.EnsureSuccessStatusCode();

                            readTask = response.Content.ReadAsStringAsync();
                            content  = readTask.Await();
#if DEBUG
                            Debug.WriteInfo("Response content:\r\n" + content);
#endif
                            json = JToken.Parse(content);

                            _connectionId = int.Parse(json["connectionid"].Value <string>());
                            CloudLog.Debug("{0} connected and received conenction id of \"{1}\"", GetType().Name,
                                           _connectionId);

                            try
                            {
                                var eventInfo   = json["configevents"].First;
                                _currentClip    = eventInfo["eParamID_CurrentClip"].Value <string>();
                                _transportState =
                                    (ETransportState)int.Parse(eventInfo["eParamID_TransportState"].Value <string>());
                                OnTransportModeChanged(this);
                            }
                            catch (Exception e)
                            {
                                Debug.WriteWarn("Could not parse configevents on connect, {0}", e.Message);
                            }
                        }
                        catch (Exception e)
                        {
                            if (!suppressErrors)
                            {
                                suppressErrors = true;
                                CloudLog.Error("Error trying to connect to {0}, {1}", GetType().Name, e.Message);
                                CloudLog.Warn("{0} will try again in 5 seconds", GetType().Name);
                            }

                            _connectionWait.Wait(5000);

                            DeviceCommunicating = false;
                        }
                    }

                    DeviceCommunicating = true;

                    uri = new UriBuilder("http", _ipAddress, 80, string.Format("config"))
                    {
                        Query = "action=get&paramid=eParamID_TransportState"
                    };

                    Debug.WriteInfo("Trying to connect to " + uri.Uri);

                    task     = _client.GetAsync(uri.Uri);
                    response = task.Await();

                    response.EnsureSuccessStatusCode();
                    readTask = response.Content.ReadAsStringAsync();
                    content  = readTask.Await();
#if DEBUG
                    Debug.WriteWarn("Response content:\r\n" + content);
#endif
                    json = JToken.Parse(content);

                    TransportState = (ETransportState)int.Parse(json["value"].Value <string>());

                    while (_connectionActive)
                    {
                        var timeStamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

                        uri = new UriBuilder("http", _ipAddress, 80, string.Format("config"))
                        {
                            Query =
                                string.Format("action=wait_for_config_events&connectionid={0}&_={1}", _connectionId,
                                              timeStamp)
                        };

                        Debug.WriteInfo("Trying to connect to " + uri.Uri);

                        task     = _client.GetAsync(uri.Uri);
                        response = task.Await();

                        if (response.StatusCode == HttpStatusCode.Gone)
                        {
                            _connectionId = 0;
                            break;
                        }

                        response.EnsureSuccessStatusCode();
                        readTask = response.Content.ReadAsStringAsync();
                        content  = readTask.Await();
#if DEBUG
                        Debug.WriteWarn("Response content:\r\n" + content);
#endif
                        json = JToken.Parse(content);

                        foreach (var item in json)
                        {
                            var paramId = item["param_id"].Value <string>();
                            switch (paramId)
                            {
                            case "eParamID_DisplayTimecode":
                                _timeCode = item["str_value"].Value <string>();
                                break;

                            case "eParamID_CurrentClip":
                                _currentClip = item["str_value"].Value <string>();
                                break;

                            case "eParamID_TransportState":
                                _transportState = (ETransportState)item["int_value"].Value <int>();
                                break;
                            }
                        }

                        OnTransportModeChanged(this);

                        CrestronEnvironment.AllowOtherAppsToRun();

                        _connectionWait.Wait(100);
                    }
                }

                _connectionId = 0;

                return(null);
            }, null);
        }