private int GetIndexOfPromo(Preferences.Promo cPromo) { int nProCount = _cPreferences.cVIP.aPromos.Count; int nRetVal = -1; for (ushort nIndx = 0; nProCount > nIndx; nIndx++) { if (_cPreferences.cVIP.aPromos[nIndx].nID == cPromo.nID) { nRetVal = nIndx; break; } } return(nRetVal); }
private Preferences.Promo GetNextPromo(Preferences.Promo cPromo, DateTime dtNow) { Preferences.Promo cRetVal = null; int nProCount = _cPreferences.cVIP.aPromos.Count; int nIndx = GetIndexOfPromo(cPromo); for (ushort i = 0; nProCount > i; i++) { nIndx = (nIndx == nProCount - 1 ? 0 : nIndx + 1); bool bIsInRange = _cPreferences.cVIP.aPromos[nIndx].aWeeklyRange[0].IsDateInRange(dtNow); if (bIsInRange && _cPreferences.cVIP.aPromos[nIndx].bEnabled) { cRetVal = _cPreferences.cVIP.aPromos[nIndx]; break; } } return(cRetVal); }
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); }