Esempio n. 1
0
        public void Prepare()
        {
            try
            {
                (new Logger()).WriteDebug2("prepare_in");
                _cDBI       = new DBInteract();
                _cPLCurrent = null;
                _nPLID      = _cDBI.TryToGetIDFromCommands();
                (new Logger()).WriteDebug2("pl_id=" + _nPLID);
                _ahVideoBinds = new Dictionary <Video, helpers.replica.cues.plugins.PlaylistItem>();

                _cPlaylist                 = new btl.Playlist();
                _cPlaylist.stArea          = _cPreferences.stArea;
                _cPlaylist.stMergingMethod = _cPreferences.stMerging;
                _cPlaylist.nLayer          = _cPreferences.nLayer;
                _cPlaylist.bOpacity        = false;
                _cPlaylist.bStopOnEmpty    = true;
                _cPlaylist.aChannelsAudio  = new byte[] { 0, 1 };
                _cPlaylist.EffectStarted  += _cPlaylist_EffectStarted;
                _cPlaylist.EffectStopped  += _cPlaylist_EffectStopped;
                _cPlaylist.EffectFailed   += _cPlaylist_EffectFailed;
                _cPlaylist.Stopped        += _cPlaylist_Stopped;
                _cPlaylist.Prepare();


                Video cVideo;
                _cPLCurrent = _cDBI.AdvancedPlaylistGet(_nPLID > 0 ? _nPLID : _cPreferences.nPlaylistID);
                (new Logger()).WriteDebug2("pl_id=" + (_nPLID > 0 ? _nPLID : _cPreferences.nPlaylistID));
                helpers.replica.cues.plugins.PlaylistItem cPLI = _cPLCurrent.aItems[0];
                cVideo           = new Video(cPLI.oAsset.cFile.sFile);
                cVideo.nDuration = (ulong)(cPLI.nFramesQty == long.MaxValue || cPLI.nFramesQty < 1 ? cPLI.oAsset.nFramesQty : cPLI.nFramesQty);
                cVideo.Prepare();
                _cPlaylist.VideoAdd(cVideo);
                _ahVideoBinds.Add(cVideo, cPLI);

                if (null != Prepared)
                {
                    Plugin.EventSend(Prepared, this);
                }
                (new Logger()).WriteDebug2("prepare_ok");
            }
            catch (Exception ex)
            {
                (new Logger()).WriteError(ex);
                Stop();
            }
        }
Esempio n. 2
0
 private bool FillHistoryQueue()
 {
     if (_aqHistorySMSs.IsNullOrEmpty())
     {
         DBInteract cDBI      = new DBInteract();
         Message[]  aMessages = cDBI.MessagesHistoryGet(_cPreferences.cRoll.nUseHistorySMS, _cPreferences.cRoll.cExceptions.sWhere);
         if (!aMessages.IsNullOrEmpty())
         {
             Queue <SMS> aqSMS = new Queue <SMS>();
             Message     cMessage;
             SMS         cSMS;
             for (int nI = 0; nI < aMessages.Length; nI++)
             {
                 cMessage   = aMessages[nI];
                 cSMS       = new SMS();
                 cSMS.ID    = cMessage.nID;
                 cSMS.sText = cMessage.sText.ToString();
                 if (cSMS.sText.StartsWith(_cPreferences.cVIP.sPrefix))
                 {
                     cSMS.sText = cSMS.sText.Remove(0, _cPreferences.cVIP.sPrefix.Length);
                 }
                 else if (cSMS.sText.StartsWith(_cPreferences.sPhotoPrefix))
                 {
                     continue;
                 }
                 cSMS.eType        = SMS.Type.Repeat;
                 cSMS.cPreferences = _cPreferences.cRoll.cSMSCommon;
                 if (_cPreferences.cRoll.cSMSCommon.bToUpper)
                 {
                     cSMS.sText = cSMS.sText.ToUpper();
                 }
                 cSMS.Phone = "+" + cMessage.nSourceNumber;
                 aqSMS.Enqueue(cSMS);
             }
             if (!aqSMS.IsNullOrEmpty())
             {
                 _aqHistorySMSs = aqSMS;
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 3
0
        private void MessagesRelease()
        {
            try
            {
                if (null != _cSMSChat)
                {
                    long[] aMessageIDsDisplayed = _cSMSChat.MessageIDsDisplayed;
                    if (null == aMessageIDsDisplayed || 1 > aMessageIDsDisplayed.Length)
                    {
                        return;
                    }

                    (new Logger()).WriteDebug3("MessagesRelease: " + aMessageIDsDisplayed.Length);
                    List <long> aIDs = new List <long>();
                    foreach (long nId in aMessageIDsDisplayed)
                    {
                        if (-109 == nId)
                        {
                            _nPromoReleased = 1;
                        }
                        else if (-123456 != nId)
                        {
                            aIDs.Add(nId);
                        }
                    }
                    DBInteract cDBI = new DBInteract();
                    if (_cPreferences.eBroadcastType == Preferences.BroadcastType.live && !cDBI.IsThereAnyStartedLiveBroadcast())
                    {
                        return;
                    }
                    if (_cPreferences.bMessagesRelease)
                    {
                        cDBI.MessagesDisplaySet(aIDs.ToArray());
                    }
                }
            }
            catch (Exception ex)
            {
                (new Logger()).WriteError(ex);
            }
        }
Esempio n. 4
0
		private void MessagesRelease()
		{
			try
			{
				if (null != _cSMSChat)
				{
					long[] aMessageIDsDisplayed = _cSMSChat.MessageIDsDisplayed;
					if (null == aMessageIDsDisplayed || 1 > aMessageIDsDisplayed.Length)
						return;

					(new Logger()).WriteDebug3("MessagesRelease: " + aMessageIDsDisplayed.Length);
					List<long> aIDs = new List<long>();
					foreach (long nId in aMessageIDsDisplayed)
					{
						if (-109 == nId)
							_nPromoReleased = 1;
						else if (-123456 != nId)
							aIDs.Add(nId);
					}
					DBInteract cDBI = new DBInteract();
					if (_cPreferences.eBroadcastType == Preferences.BroadcastType.live && !cDBI.IsThereAnyStartedLiveBroadcast())
						return; 
                    if (_cPreferences.bMessagesRelease)
						cDBI.MessagesDisplaySet(aIDs.ToArray());
				}
			}
			catch (Exception ex)
			{
				(new Logger()).WriteError(ex);
			}
		}
Esempio n. 5
0
		private Queue<SMS> GetSMSs(int nQtty)
        {
			Queue<SMS> aRetVal = new Queue<SMS>();
			try
            {
				Queue<Message> aqMessages = null;
				Message cMessage = null;
                SMS cSMS = null;
                DBInteract cDBI = new DBInteract();
                try
                {
                    if (_cPreferences.eBroadcastType == Preferences.BroadcastType.linear && cDBI.IsThereAnyStartedLiveBroadcast())
                    {
                        cSMS = new SMS() { cPreferences = _cPreferences.cRoll.cSMSVIP };

                        //cSMS.Color = null;
                        //cSMS.Color = Color.FromArgb(0, 0, 0, 0);
                        cSMS.ID = -123456;
                        cSMS.sText = "По техническим причинам SMS-чат временно заблокирован! Приносим извинения за причиненные неудобства! :)";
                        cSMS.Phone = "+70000000003";
                        cSMS.eType = SMS.Type.Promo;
						aRetVal.Enqueue(cSMS);
                        return aRetVal;
                    }
                }
                catch (Exception ex)
                {
                    (new Logger()).WriteError(ex);
                }

                Preferences.Promo cPromo;
                Preferences.Promo cPromoLast = _cPromoLast;
                if (null != cPromoLast)
                {
					aqMessages = new Queue<Message>();
					DateTime dtNow = DateTime.Now;
                    if (dtNow >= cPromoLast.dtLastShow.Add(_cPreferences.cVIP.tsPromoPeriod) && null != (cPromo = GetNextPromo(cPromoLast, dtNow)))
					{
						cMessage = new Message(-109, "-109", null, 1, 70000000002, 0, "PROMO " + cPromo.sText, null, dtNow, dtNow);
						cPromo.dtLastShow = dtNow;
                        _cPromoLast = cPromo;
						aqMessages.Enqueue(cMessage);
					}
					if (1 > aqMessages.Count)
						aqMessages = null;
                }

				if (null == aqMessages)
				{
					aqMessages = cDBI.MessagesQueuedGet(_cPreferences.cVIP.sPrefix);
					if (null == aqMessages || 1 > aqMessages.Count)
						aqMessages = cDBI.MessagesQueuedGet();
				}

				while (null != aqMessages && 0 < aqMessages.Count)
				{
                    try
                    {
						cMessage = aqMessages.Dequeue();
						cSMS = new SMS();
						cSMS.ID = cMessage.nID;
						cSMS.sText = cMessage.sText.ToString();
                        if (cSMS.sText.StartsWith(_cPreferences.cVIP.sPrefix))
                        {
                            //if (bRemovePrefix)
                            cSMS.sText = cSMS.sText.Remove(0, _cPreferences.cVIP.sPrefix.Length);
                            cSMS.eType = SMS.Type.VIP;
                            cSMS.cPreferences = _cPreferences.cRoll.cSMSVIP;
							if (_cPreferences.cRoll.cSMSVIP.bToUpper)
								cSMS.sText = cSMS.sText.ToUpper();
						}
                        else if (cSMS.sText.StartsWith(_cPreferences.sPhotoPrefix))
                        {
                            cSMS.eType = SMS.Type.Photo;
                            cSMS.cPreferences = _cPreferences.cRoll.cSMSPhoto;
							if (_cPreferences.cRoll.cSMSPhoto.bToUpper)
								cSMS.sText = cSMS.sText.ToUpper();
                        }
                        else if (cSMS.sText.StartsWith("PROMO "))
                        {
                            cSMS.sText = cSMS.sText.Remove(0, ("PROMO ").Length);
                            cSMS.eType = SMS.Type.Promo;
							cSMS.cPreferences = _cPreferences.cRoll.cSMSPromo;
							if (_cPreferences.cRoll.cSMSPromo.bToUpper)
								cSMS.sText = cSMS.sText.ToUpper();
						}
                        else
                        {
                            cSMS.eType = SMS.Type.Common;
                            cSMS.cPreferences = _cPreferences.cRoll.cSMSCommon;
							if (_cPreferences.cRoll.cSMSCommon.bToUpper)
								cSMS.sText = cSMS.sText.ToUpper();
						}
						cSMS.Phone = "+" + cMessage.nSourceNumber;
						aRetVal.Enqueue(cSMS);
                    }
                    catch (Exception ex)
                    {
						if (null == _cSMSChat)
							break;
						(new Logger()).WriteWarning("[msgsc:" + aqMessages.Count + "]");
                        (new Logger()).WriteWarning("ERROR:" + ex.Message + ex.StackTrace.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                (new Logger()).WriteError(ex);
            }
            return aRetVal;
        }
Esempio n. 6
0
        private void Worker(object cState)
        {
            _bStopped = false;
			_bWorkerEnd = false;
            try
            {
				(new Logger()).WriteDebug3("chat started");
				if (null == _cSMSChat)
				{
					_bWorkerEnd = true;
					return;
				}
                Queue<ChatInOut> aqChatInOuts = null;
                DateTime dtBase = DateTime.Now;
                DBInteract cDBI = null;
                PlaylistItem cCurrentPLI = null;
                Queue<PlaylistItem> aqCU = null;
                try
                {
                    cDBI = new DBInteract();

                    while (!_bStopped && null == cCurrentPLI)
                    {
						//if (DateTime.Now > dtNextTimeLog_Worker)
						//{
						//    (new Logger()).WriteNotice("Worker: I'm HERE! [hash:" + this.GetHashCode() + "]");
						//    dtNextTimeLog_Worker = DateTime.Now.AddMinutes(1);
						//}
                        aqCU = cDBI.ComingUpGet(0, 1);
                        if (0 < aqCU.Count)
                        {
                            cCurrentPLI = aqCU.Dequeue();
                            aqChatInOuts = cDBI.ChatInOutsGet(cCurrentPLI.cAsset);
//							aqChatInOuts = cDBI.ChatInOutsGet(helpers.replica.mam.Asset.Load(3261));
                            if (0 < aqChatInOuts.Count)
                                dtBase = cCurrentPLI.dtStartReal;
                            else
                                aqChatInOuts = null;
                        }
                        else
                            Thread.Sleep(300);
                    }
                }
                catch (Exception ex)
                {
                    (new Logger()).WriteError(ex);
                }


				// ==========================================================================================================
				//dtBase = DateTime.Now;
				//aqChatInOuts = new Queue<ChatInOut>();
				//aqChatInOuts.Enqueue(new ChatInOut(1176, new TimeRange(400, 900)));
				//aqChatInOuts.Enqueue(new ChatInOut(1176, new TimeRange(1300, 1600)));
				//aqChatInOuts.Enqueue(new ChatInOut(1176, new TimeRange(2200, 3500)));
				// ==========================================================================================================


                if (null == aqChatInOuts)
                {
                    aqChatInOuts = new Queue<ChatInOut>();
					aqChatInOuts.Enqueue(new ChatInOut(-1, 1, int.MaxValue));
                }

				ChatInOut cChatInOut;
                DateTime dtStop;
                int nMSStartDelay;

				ThreadPool.QueueUserWorkItem(WorkerSMS);

				while (!_bStopped && 0 < aqChatInOuts.Count)
                {
					//if (DateTime.Now > dtNextTimeLog_Worker)
					//{
					//    (new Logger()).WriteNotice("Worker: I'm HERE! [hash:" + this.GetHashCode() + "]");
					//    dtNextTimeLog_Worker = DateTime.Now.AddMinutes(1);
					//}
                    cChatInOut = aqChatInOuts.Dequeue();
                    if (TimeSpan.MaxValue > cChatInOut.cTimeRange.tsOut)
						dtStop = dtBase.Add(cChatInOut.cTimeRange.tsOut);
                    else
                        dtStop = DateTime.MaxValue;

                    if (DateTime.Now > dtStop.AddSeconds(-20))
                        continue;

					if (_cSMSChat.bReleased)
					{
						_cSMSChat.Init();
					}
					nMSStartDelay = (int)dtBase.Add(cChatInOut.cTimeRange.tsIn).Subtract(DateTime.Now).TotalMilliseconds;
                    if (0 < nMSStartDelay)
                        Thread.Sleep(nMSStartDelay);
                    _cSMSChat.Start();

//#if UNLIMIT
    //while (!_bStopped)
//#else
    //while (!_cSMSChat.IsChatTerminating)
//#endif
					while (ChatMustGoOn()) 
                    {
						//if (DateTime.Now > dtNextTimeLog_Worker)
						//{
						//    (new Logger()).WriteNotice("Worker: I'm HERE! [hash:" + this.GetHashCode() + "]");
						//    dtNextTimeLog_Worker = DateTime.Now.AddMinutes(1);
						//}
                        if (_cPreferences.eBroadcastType == Preferences.BroadcastType.linear && DateTime.Now > dtStop)
                            break;
                        if (4 > _cSMSChat.QueueLength)   //  4>
						{
							lock (_aqSMSs)
							{
								if (0 < _aqSMSs.Count)
								{
									_cSMSChat.MessagesAdd(_aqSMSs);
									_aqSMSs.Clear();
								}
							}
						}
                        Thread.Sleep(500);
                    }
					(new Logger()).WriteDebug3("chat stopped" + (DateTime.MaxValue > dtStop ? ":" + dtStop.ToStr() : ""));
					_cSMSChat.Stop();
                    _cSMSChat.Release();     // ушла в stop()
                    (new Logger()).WriteDebug4("return");
                }
            }
            catch (Exception ex)
            {
                (new Logger()).WriteError(ex);
                try
                {
                    _cSMSChat.Stop();
					//_cSMSChat.Release();    ушла в stop()
                }
                catch (Exception ex1)
                {
                    (new Logger()).WriteError(ex1);
                }
            }
			_bWorkerEnd = true;
			try
			{
				if (!_bStopped)
					Stop();
				//if (!_bStopped && null != Stopped)
				//    Stopped(this);                     ушла в stop()
				//_bStopped = true;                      ушла в stop()
				(new Logger()).WriteNotice("chat worker stopped");
			}
			catch (Exception ex)
			{
				(new Logger()).WriteError(ex);
			}
		}
Esempio n. 7
0
        private Queue <SMS> GetSMSs(int nQtty)
        {
            Queue <SMS> aRetVal = new Queue <SMS>();

            try
            {
                List <Message>  aM         = null;
                Queue <Message> aqMessages = null;
                Message         cMessage   = null;
                SMS             cSMS       = null;
                DBInteract      cDBI       = new DBInteract();
                try
                {
                    if (_cPreferences.eBroadcastType == Preferences.BroadcastType.linear && cDBI.IsThereAnyStartedLiveBroadcast())
                    {
                        if (_cPreferences.bAnotherAirError)
                        {
                            (new Logger()).WriteError("there is another broadcast on air. chat is off. see DB scr.shifts");
                        }
                        else
                        {
                            (new Logger()).WriteNotice("there is another broadcast on air. chat is off. see DB scr.shifts");
                        }
                        System.Threading.Thread.Sleep(6000);
                        return(aRetVal);  // do not display errors to people



                        cSMS = new SMS()
                        {
                            cPreferences = _cPreferences.cRoll.cSMSVIP
                        };

                        //cSMS.Color = null;
                        //cSMS.Color = Color.FromArgb(0, 0, 0, 0);
                        cSMS.ID    = -123456;
                        cSMS.sText = "По техническим причинам SMS-чат временно заблокирован! Приносим извинения за причиненные неудобства! :)";
                        cSMS.Phone = "+70000000003";
                        cSMS.eType = SMS.Type.Promo;
                        aRetVal.Enqueue(cSMS);
                        Preferences.nUndisplayedMessages = 1;
                        return(aRetVal);
                    }
                }
                catch (Exception ex)
                {
                    (new Logger()).WriteError(ex);
                }

                Preferences.nUndisplayedMessages = cDBI.MessagesUndisplayedCountGet();
                Preferences.Promo cPromo;
                Preferences.Promo cPromoLast = _cPromoLast;
                aM = new List <Message>();

                if (null != cPromoLast)
                {
                    DateTime dtNow = DateTime.Now;
                    if (dtNow >= cPromoLast.dtLastShow.Add(_cPreferences.cVIP.tsPromoPeriod) && null != (cPromo = GetNextPromo(cPromoLast, dtNow)))
                    {
                        cMessage          = new Message(-109, "-109", null, 1, 70000000002, 0, "PROMO " + cPromo.sText, null, dtNow, dtNow);
                        cPromo.dtLastShow = dtNow;
                        _cPromoLast       = cPromo;
                        aM.Add(cMessage);
                    }
                }
                if (aM.Count < nQtty)
                {
                    aqMessages = cDBI.MessagesQueuedGet(_cPreferences.cVIP.sPrefix);
                    if (!aqMessages.IsNullOrEmpty())
                    {
                        aM.AddRange(aqMessages.ToArray());
                    }
                }

                if (aM.Count < nQtty)
                {
                    aqMessages = cDBI.MessagesQueuedGet();
                    if (!aqMessages.IsNullOrEmpty())
                    {
                        aM.AddRange(aqMessages.ToArray());
                    }
                }

                for (int nI = 0; nI < aM.Count; nI++)
                {
                    try
                    {
                        cMessage   = aM[nI];
                        cSMS       = new SMS();
                        cSMS.ID    = cMessage.nID;
                        cSMS.sText = cMessage.sText.ToString();
                        if (cSMS.sText.StartsWith(_cPreferences.cVIP.sPrefix))
                        {
                            //if (bRemovePrefix)
                            cSMS.sText        = cSMS.sText.Remove(0, _cPreferences.cVIP.sPrefix.Length);
                            cSMS.eType        = SMS.Type.VIP;
                            cSMS.cPreferences = _cPreferences.cRoll.cSMSVIP;
                            if (_cPreferences.cRoll.cSMSVIP.bToUpper)
                            {
                                cSMS.sText = cSMS.sText.ToUpper();
                            }
                        }
                        else if (cSMS.sText.StartsWith(_cPreferences.sPhotoPrefix))
                        {
                            cSMS.eType        = SMS.Type.Photo;
                            cSMS.cPreferences = _cPreferences.cRoll.cSMSPhoto;
                            if (_cPreferences.cRoll.cSMSPhoto.bToUpper)
                            {
                                cSMS.sText = cSMS.sText.ToUpper();
                            }
                        }
                        else if (cSMS.sText.StartsWith("PROMO "))
                        {
                            cSMS.sText        = cSMS.sText.Remove(0, ("PROMO ").Length);
                            cSMS.eType        = SMS.Type.Promo;
                            cSMS.cPreferences = _cPreferences.cRoll.cSMSPromo;
                            if (_cPreferences.cRoll.cSMSPromo.bToUpper)
                            {
                                cSMS.sText = cSMS.sText.ToUpper();
                            }
                        }
                        else
                        {
                            cSMS.eType        = SMS.Type.Common;
                            cSMS.cPreferences = _cPreferences.cRoll.cSMSCommon;
                            if (_cPreferences.cRoll.cSMSCommon.bToUpper)
                            {
                                cSMS.sText = cSMS.sText.ToUpper();
                            }
                        }
                        cSMS.Phone = "+" + cMessage.nSourceNumber;
                        aRetVal.Enqueue(cSMS);
                        if (aRetVal.Count >= nQtty)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (null == _cSMSChat)
                        {
                            break;
                        }
                        (new Logger()).WriteWarning("[msgsc:" + aM.Count + "][msg:" + aM[nI]?.sText + "]");
                        (new Logger()).WriteWarning("ERROR:" + ex.Message + ex.StackTrace.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                (new Logger()).WriteError(ex);
            }
            return(aRetVal);
        }
Esempio n. 8
0
        public void Stop()
        {
            lock (_oLockStop)
            {
                if (_bStopped)
                {
                    return;
                }
                _bStopped = true;
            }
            try
            {
                _cSMSChat.IsChatTerminating = true;
                (new Logger()).WriteNotice("Stop: IsChatTerminating = true");
                DateTime dtNow = DateTime.Now.AddSeconds(5);
                while ((_cSMSChat.IsChatTerminating || _cSMSChat.IsInfoOnAir) && DateTime.Now < dtNow)
                {
                    Thread.Sleep(50);
                }

                while (!_bWorkerSMSEnd && !_bWorkerEnd)
                {
                    Thread.Sleep(50);
                }

                _cSMSChat.Stop();
                _cSMSChat.Release();
                (new Logger()).WriteNotice("Stop: after _cSMSChat.Release();");
                lock (_oLock)
                {
                    _cSMSChat = null;
                }
            }
            catch (Exception ex)
            {
                (new Logger()).WriteError(ex);
            }
            finally
            {
                try
                {
                    DBInteract cDBI   = new DBInteract();
                    bool       bIsAir = cDBI.IsThereAnyStartedLiveBroadcast();
                    (new Logger()).WriteDebug2("ChatLogStopAdd [isair=" + bIsAir + "][type=" + _cPreferences.eBroadcastType + "][release=" + _cPreferences.bMessagesRelease + "]");
                    if (_cPreferences.bMessagesRelease && !(_cPreferences.eBroadcastType == Preferences.BroadcastType.linear && bIsAir) && !(_cPreferences.eBroadcastType == Preferences.BroadcastType.live && !bIsAir))
                    {
                        bool bOk = cDBI.ChatLogStopAdd(DateTime.Now.AddSeconds(4));
                        (new Logger()).WriteNotice("ChatLogStopAdd - " + bOk);
                    }
                    else if (_bChatWasAddedToLogsOnStart)
                    {
                        bool bOk = cDBI.ChatLogStopAdd(DateTime.Now.AddSeconds(4));
                        (new Logger()).WriteNotice("ChatLogStopAdd-2 - " + bOk);
                    }
                    _bChatWasAddedToLogsOnStart = false;
                    _eStatus         = BTL.EffectStatus.Stopped;
                    _dtStatusChanged = DateTime.Now;
                    _cPreferences    = null;
                    if (null != Stopped)
                    {
                        Plugin.EventSend(Stopped, this);
                    }
                }
                catch (Exception ex)
                {
                    (new Logger()).WriteError("Stop: ", ex);
                }
            }
        }
Esempio n. 9
0
        private void Worker(object cState)
        {
            _bStopped   = false;
            _bWorkerEnd = false;
            try
            {
                (new Logger()).WriteDebug3("chat started");
                if (null == _cSMSChat)
                {
                    _bWorkerEnd = true;
                    return;
                }
                Logger.Timings       cTimings     = new helpers.Logger.Timings("chat:Worker");
                Queue <ChatInOut>    aqChatInOuts = null;
                DateTime             dtBase       = DateTime.Now;
                DBInteract           cDBI         = null;
                PlaylistItem         cCurrentPLI  = null;
                Queue <PlaylistItem> aqCU         = null;
                try
                {
                    cDBI = new DBInteract();

                    while (!_bStopped && null == cCurrentPLI)
                    {
                        //if (DateTime.Now > dtNextTimeLog_Worker)
                        //{
                        //    (new Logger()).WriteNotice("Worker: I'm HERE! [hash:" + this.GetHashCode() + "]");
                        //    dtNextTimeLog_Worker = DateTime.Now.AddMinutes(1);
                        //}
                        aqCU = cDBI.ComingUpGet(0, 1);
                        if (0 < aqCU.Count)
                        {
                            cCurrentPLI  = aqCU.Dequeue();
                            aqChatInOuts = cDBI.ChatInOutsGet(cCurrentPLI.cAsset);
                            //							aqChatInOuts = cDBI.ChatInOutsGet(helpers.replica.mam.Asset.Load(3261));
                            if (0 < aqChatInOuts.Count)
                            {
                                dtBase = cCurrentPLI.dtStartReal;
                            }
                            else
                            {
                                aqChatInOuts = null;
                            }
                        }
                        else
                        {
                            Thread.Sleep(300);
                        }
                    }
                }
                catch (Exception ex)
                {
                    (new Logger()).WriteError(ex);
                }


                // ==========================================================================================================
                //dtBase = DateTime.Now;
                //aqChatInOuts = new Queue<ChatInOut>();
                //aqChatInOuts.Enqueue(new ChatInOut(1176, new TimeRange(400, 900)));
                //aqChatInOuts.Enqueue(new ChatInOut(1176, new TimeRange(1300, 1600)));
                //aqChatInOuts.Enqueue(new ChatInOut(1176, new TimeRange(2200, 3500)));
                // ==========================================================================================================


                if (null == aqChatInOuts)
                {
                    aqChatInOuts = new Queue <ChatInOut>();
                    aqChatInOuts.Enqueue(new ChatInOut(-1, 1, int.MaxValue));
                }

                ChatInOut cChatInOut;
                DateTime  dtStop;
                int       nMSStartDelay;
                bool      bIsAir = cDBI.IsThereAnyStartedLiveBroadcast();
                (new Logger()).WriteDebug2("ChatLogStartAdd [isair=" + bIsAir + "][type=" + _cPreferences.eBroadcastType + "][release=" + _cPreferences.bMessagesRelease + "]");
                if (_cPreferences.bMessagesRelease && !(_cPreferences.eBroadcastType == Preferences.BroadcastType.linear && bIsAir) && !(_cPreferences.eBroadcastType == Preferences.BroadcastType.live && !bIsAir))
                {
                    bool bOk = cDBI.ChatLogStartAdd(DateTime.Now.AddSeconds(4));
                    (new Logger()).WriteNotice("ChatLogStartAdd - " + bOk);
                    _bChatWasAddedToLogsOnStart = true;
                }
                else
                {
                    _bChatWasAddedToLogsOnStart = false;
                }

                ThreadPool.QueueUserWorkItem(WorkerSMS);

                while (!_bStopped && 0 < aqChatInOuts.Count)
                {
                    //if (DateTime.Now > dtNextTimeLog_Worker)
                    //{
                    //    (new Logger()).WriteNotice("Worker: I'm HERE! [hash:" + this.GetHashCode() + "]");
                    //    dtNextTimeLog_Worker = DateTime.Now.AddMinutes(1);
                    //}
                    cChatInOut = aqChatInOuts.Dequeue();
                    if (TimeSpan.MaxValue > cChatInOut.cTimeRange.tsOut)
                    {
                        dtStop = dtBase.Add(cChatInOut.cTimeRange.tsOut);
                    }
                    else
                    {
                        dtStop = DateTime.MaxValue;
                    }

                    if (DateTime.Now > dtStop.AddSeconds(-20))
                    {
                        continue;
                    }

                    if (_cSMSChat.bReleased)
                    {
                        _cSMSChat.Init();
                    }
                    nMSStartDelay = (int)dtBase.Add(cChatInOut.cTimeRange.tsIn).Subtract(DateTime.Now).TotalMilliseconds;
                    if (0 < nMSStartDelay)
                    {
                        Thread.Sleep(nMSStartDelay);
                    }
                    _cSMSChat.Start();

                    //#if UNLIMIT
                    //while (!_bStopped)
                    //#else
                    //while (!_cSMSChat.IsChatTerminating)
                    //#endif
                    bool bNotFirst = false;
                    while (ChatMustGoOn())
                    {
                        //if (DateTime.Now > dtNextTimeLog_Worker)
                        //{
                        //    (new Logger()).WriteNotice("Worker: I'm HERE! [hash:" + this.GetHashCode() + "]");
                        //    dtNextTimeLog_Worker = DateTime.Now.AddMinutes(1);
                        //}
                        if (_cPreferences.eBroadcastType == Preferences.BroadcastType.linear && DateTime.Now > dtStop)
                        {
                            break;
                        }
                        if (4 > _cSMSChat.QueueLength)   //  4>
                        {
                            lock (_aqSMSs)
                            {
                                if (0 < _aqSMSs.Count)
                                {
                                    bNotFirst = true;
                                    _cSMSChat.MessagesAdd(_aqSMSs);
                                    _aqSMSs.Clear();
                                }
                                if (bNotFirst && 4 > _cSMSChat.QueueLength && _cPreferences.cRoll.nUseHistorySMS > 0)
                                {
                                    _cSMSChat.MessagesAdd(GetHistorySMSs(5));
                                }
                            }
                        }

                        //GC.Collect
                        Thread.Sleep(500);
                    }
                    (new Logger()).WriteDebug3("chat stopped" + (DateTime.MaxValue > dtStop ? ":" + dtStop.ToStr() : ""));
                    lock (_oLock)
                    {
                        if (null != _cSMSChat)
                        {
                            _cSMSChat.Stop();
                            _cSMSChat.Release();     // ушла в stop()
                        }
                    }
                    (new Logger()).WriteDebug4("return");
                }
            }
            catch (Exception ex)
            {
                (new Logger()).WriteError(ex);
                try
                {
                    _cSMSChat.Stop();
                    //_cSMSChat.Release();    ушла в stop()
                }
                catch (Exception ex1)
                {
                    (new Logger()).WriteError("catch: ", ex1);
                }
            }
            finally
            {
                _bWorkerEnd = true;
                try
                {
                    Stop();
                    //if (!_bStopped && null != Stopped)
                    //    Stopped(this);                     ушла в stop()
                    //_bStopped = true;                      ушла в stop()
                    (new Logger()).WriteNotice("chat worker stopped");
                }
                catch (Exception ex)
                {
                    (new Logger()).WriteError("finally: ", ex);
                }
            }
        }