示例#1
0
文件: Join.cs 项目: bubbafat/TellHer
        protected override void PerformUnknownUser(Domain.IncomingSmsMessage message)
        {
            IDataStore store = DataStore.GetInstance();
            IConfiguration config = Configuration.GetInstance();

            if (store.Subscriptions.Count() < config.BetaLimit)
            {
                Subscription s = new Subscription
                {
                    Phone = message.From,
                    Next = DateTime.UtcNow,
                };

                store.Save(s);

                Say(message.From, SmsResponseStrings.Join_Created());
            }
            else
            {
                Say(message.From, SmsResponseStrings.Join_SorryBetaFull());
                Say(config.AdminNumber, SmsResponseStrings.Join_AdminBetaReject());
            }
        }
示例#2
0
        void IDataStore.Remove(Subscription sub)
        {
            if (sub != null)
            {
                foreach (Subscription s in Subscriptions.Where(s => s.Phone == sub.Phone))
                {
                    Subscriptions.Remove(s);
                }

                SaveChanges();
            }
        }
示例#3
0
        void IDataStore.ScheduleMessage(OutgoingSmsMessage msg, Subscription sub)
        {
            OutgoingMessages.Add(msg);
            Subscription toUpdate = Subscriptions.Where(s => s.Id == sub.Id).FirstOrDefault();
            if (toUpdate != null)
            {
                toUpdate.Next = DateTime.Today.AddDays(1).AddHours(4).ToUniversalTime();
            }

            SaveChanges();
        }
示例#4
0
        void IDataStore.Save(Subscription sub)
        {
            if (!Subscriptions.Any(s => s.Id == sub.Id))
            {
                Subscriptions.Add(sub);
            }

            SaveChanges();
        }
示例#5
0
 public void ScheduleMessage(OutgoingSmsMessage msg, Subscription sub)
 {
     lock (_lock)
     {
         Save(msg);
         Subscription toUpdate = Subscriptions.Where(s => s.Id == sub.Id).FirstOrDefault();
         if (toUpdate != null)
         {
             toUpdate.Next = DateTime.Today.AddDays(1).ToUniversalTime().AddHours(2);
         }
     }
 }
示例#6
0
        public void Save(Subscription sub)
        {
            lock (_lock)
            {
                if (sub.Id == 0)
                {
                    sub.Id = NextId();
                }

                _subscriptions[sub.Id] = sub;
            }
        }
示例#7
0
 public void Remove(Subscription sub)
 {
     lock (_lock)
     {
         _subscriptions.Remove(sub.Id);
     }
 }