private void CrestronEnvironmentOnProgramStatusEventHandler(eProgramStatusEventType programEventType)
 {
     _programStopping = programEventType == eProgramStatusEventType.Stopping;
     if (_programStopping)
     {
         _updateFeedbackEvent.Set();
     }
 }
예제 #2
0
 public KiProRecorder(string ipAddress)
 {
     _ipAddress = ipAddress;
     _client    = new HttpClient()
     {
         Timeout = TimeSpan.FromSeconds(10)
     };
     CrestronEnvironment.ProgramStatusEventHandler += type =>
     {
         _programStopping = type == eProgramStatusEventType.Stopping;
         _connectionWait.Set();
     };
 }
예제 #3
0
        /// <summary>
        /// Adds (or returns) an object to the pool.
        /// </summary>
        /// <param name="obj"></param>
        public void AddToPool(T obj)
        {
            if (Interlocked.Increment(ref _currentCount) > MaxCapacity)
            {
                _queueReturnEvent.Wait();
            }

            if (_disposed)
            {
                return;
            }
            _objectPool.Enqueue(obj);
            _queueAddEvent.Set();
        }
예제 #4
0
 public SonyBravia(string name, string deviceAddress, string psk) : base(name)
 {
     _deviceAddress = deviceAddress;
     _psk           = psk;
     CrestronEnvironment.ProgramStatusEventHandler += type =>
     {
         _programStopping = type == eProgramStatusEventType.Stopping;
         if (_programStopping)
         {
             _checkWait.Set();
         }
     };
     _volumeControls.Add(new SonyBraviaVolumeControl(this, TargetVolumeDeviceType.Speaker));
     _volumeControls.Add(new SonyBraviaVolumeControl(this, TargetVolumeDeviceType.Headphone));
 }
예제 #5
0
        /// <summary>
        ///     Sets the event.
        /// </summary>
        public void Set()
        {
            // 1. Value = 1.
            // 2. Event = Global Event.
            // 3. Set Event.
            // 4. [Optional] Dereference the Global Event.

            if ((InterlockedEx.Or(ref _value, EventSet) & EventSet) != 0)
            {
                return;
            }

            RefEvent();

            // Do an update-to-date read.
            CEvent localEvent = _event;

            // Set the event if we had one.
            if (localEvent != null)
            {
                localEvent.Set();
            }

            // Note that at this point we don't need to worry about anyone
            // creating the event and waiting for it, because if they did
            // they would check the value first. It would be 1, so they
            // wouldn't wait at all.

            DerefEvent();
        }
예제 #6
0
        internal void Complete()
        {
            lock (_sync)
            {
                if (_completed)
                {
                    return;
                }

                _completed = true;
                if (_waitHandle != null)
                {
                    _waitHandle.Set();
                }

                if (_callback != null)
#if SSHARP
                { _callback.BeginInvokeEx(ar => _callback.EndInvokeEx(ar), null, this); }
#elif NETCF
                { ThreadPool.QueueUserWorkItem(o => _callback((IAsyncResult)o), this); }
#else
                { _callback.BeginInvoke(this, ar => _callback.EndInvoke(ar), null); }
#endif
            }
        }
예제 #7
0
        /// <summary>
        /// Create a CodecSshClient
        /// </summary>
        internal CiscoSshClient(string address, int port, string username, string password)
        {
            _address  = address;
            _port     = port;
            _username = username;
            _password = password;
            CrestronEnvironment.ProgramStatusEventHandler += type =>
            {
                _programRunning = type != eProgramStatusEventType.Stopping;
                if (_programRunning)
                {
                    return;
                }

                _threadWait.Set();
                _reconnect = false;

                if (!Connected)
                {
                    return;
                }

                CloudLog.Info("Program stopping, Sending bye to {0} at {1}", GetType().Name, _address);
                Send("bye");
            };
            _heartbeatId =
                CrestronEthernetHelper.GetEthernetParameter(
                    CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS,
                    CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter));
        }
예제 #8
0
        /// <summary>
        /// Create an instance of a system for use on a CrestronControlSystem
        /// </summary>
        protected SystemBase(CrestronControlSystem controlSystem, Assembly appAssembly)
        {
            BootStatus = "Waiting for System.ctor()";

            _controlSystem = controlSystem;
            _appAssembly   = appAssembly;
            CrestronEnvironment.ProgramStatusEventHandler +=
                type =>
            {
                _programStopping = type == eProgramStatusEventType.Stopping;
                try
                {
                    _systemWait.Set();
                }
                catch (Exception e)
                {
                    CloudLog.Error("Error calling _systemWait.Set() on program stop", e.Message);
                }
                try
                {
                    _startupWait.Set();
                }
                catch (Exception e)
                {
                    CloudLog.Error("Error calling _startupWait.Set() on program stop", e.Message);
                }
            };
            Displays      = new DisplayCollection();
            Sources       = new SourceCollection();
            Rooms         = new RoomCollection();
            UIControllers = new UIControllerCollection(this);

            Debug.WriteInfo("Checking for new app version");

            AppIsNewVersion = CheckIfNewVersion(appAssembly);

            if (AppIsNewVersion)
            {
                Debug.WriteWarn("New Version", "version = {0}, running upgrade scripts...",
                                appAssembly.GetName().Version.ToString());
// ReSharper disable once DoNotCallOverridableMethodsInConstructor
                AppShouldRunUpgradeScripts();
            }

            CrestronConsole.AddNewConsoleCommand(parameters => FusionRVI.GenerateFileForAllFusionDevices(),
                                                 "RviGenerate", "Create RVI file for Fusion", ConsoleAccessLevelEnum.AccessOperator);
        }
예제 #9
0
        /// <summary>
        /// Retrieves an object from the pool.
        /// </summary>
        /// <returns>Pool object.</returns>
        public T GetFromPool()
        {
            if (_currentCount == 0)
            {
                _queueAddEvent.Wait();
            }

            if (_disposed)
            {
                return(null);
            }
            Interlocked.Decrement(ref _currentCount);
            var obj = _objectPool.Dequeue();

            _queueReturnEvent.Set();
            return(obj);
        }
예제 #10
0
        public bool Set()
        {
            lock (this)
            {
                CheckDisposed();

                return(ce.Set());
            }
        }
예제 #11
0
        public void Release()
        {
            Interlocked.Exchange(ref _value, 0);

            // Wake up a thread. Note that that thread might
            // not actually get to acquire the lock because
            // another thread may have acquired it already.
            if (_event != null)
            {
                _event.Set();
            }
        }
예제 #12
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;
            }
        }
예제 #13
0
파일: CloudLog.cs 프로젝트: uxav/lib2
        internal static void WriteLog(LoggingLevel level, string message, string process, string stack, bool printToConsole)
        {
            var now = DateTime.UtcNow;

            _idCount++;
            var id   = now.ToString("s") + "_" + _idCount;
            var m    = message;
            var info = string.Empty;

            if (message.Contains(CrestronEnvironment.NewLine))
            {
                var lines = message.Split(CrestronEnvironment.NewLine.ToCharArray());
                m    = lines.First();
                info = String.Join(CrestronEnvironment.NewLine, lines
                                   .Where(l => l.Length > 0)
                                   .Skip(1)
                                   .ToArray());
            }
            var entry = new LogEntry
            {
                Time    = now,
                Id      = id,
                Level   = level,
                Message = m,
                Info    = info,
                Process = process,
                Stack   = stack
            };

            InternalDictionaryLock.Enter();
            InternalDictionary[entry.Id] = entry;
            InternalDictionaryLock.Leave();
            if (CurrentLogFile != null)
            {
                if (!FileWriteQueue.TryToEnqueue(entry))
                {
                    Error("Could not enqueue log entry to file write queue!");
                }
            }

            try
            {
                UploadEvent.Set();
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error setting UploadEvent in WriteLog, {0}", e.Message);
            }

            if (!printToConsole)
            {
                return;
            }
            if (entry.Level >= LoggingLevel.Error)
            {
                Lib2.Debug.WriteError(entry.ToString(true));
            }
            else
            {
                switch (entry.Level)
                {
                case LoggingLevel.Warning:
                    Lib2.Debug.WriteWarn(entry.ToString(true));
                    break;

                case LoggingLevel.Notice:
                    Lib2.Debug.WriteInfo(entry.ToString(true));
                    break;

                case LoggingLevel.Info:
                    Lib2.Debug.WriteSuccess(entry.ToString(true));
                    break;

                default:
                    Lib2.Debug.WriteNormal(entry.ToString(true));
                    break;
                }
            }
        }
예제 #14
0
 /// <summary>
 /// Signals to other threads.
 /// </summary>
 /// <returns>True if successful, otherwise false.</returns>
 public bool Set()
 {
     return(_cEvent.Set());
 }