private static void TriggerNotification(CampfireState campfireInfo, CampfireState.UserReference userRef)
        {
            if ((userRef.TargetUser != null) && (userRef.Room != null))
            {
                string email = userRef.TargetUser.SmokeEmail;

                Utils.TraceVerboseMessage(string.Format("Sending notification: User: {0}, Room: {1}, SmokeEmail: {2}",
                                                        userRef.TargetUser.Name, userRef.Room.Name, userRef.TargetUser.SmokeEmail));

                string userName = (userRef.SourceUser != null) ? userRef.SourceUser.Name : "guest";

                campfireInfo.Notifier.Doit(userRef.TargetUser.Name, userRef.Room.Name, userRef.Room.Id, email,
                                           SmokeSignalConfig.Instance.CampfireName, userName, userRef.NearByText);
            }
        }
        public void AddPendingNotification_EarlierTimeTest()
        {
            CampfireState_Accessor target = new CampfireState_Accessor();
            int userId = 11;
            int roomId = 51;
            DateTime triggerTime = DateTime.Now.AddHours(1);
            CampfireState.UserReference ri = new CampfireState.UserReference("", new CampfireState.UserInfo(userId, "Fake User", "*****@*****.**", ""));
            ri.Room = new CampfireState.RoomInfo("fake room", roomId, 0);

            target.AddPendingNotification(ri, triggerTime);
            Assert.AreEqual(1, target.PendingNotifications.Count);
            Assert.AreEqual(triggerTime, target.PendingNotifications[0].TriggerTime);
            DateTime earlierTrigger = triggerTime.AddMinutes(-1);

            // Trying to add a notification for a same user/room, but with a earlier time will cause the pending trigger time to adjust
            target.AddPendingNotification(ri, earlierTrigger);
            Assert.AreEqual(1, target.PendingNotifications.Count);
            Assert.AreEqual(earlierTrigger, target.PendingNotifications[0].TriggerTime);
        }
        private static void ProcessSmokeSignalCommands(int userId, CampfireState.UserReference ri)
        {
            // ??? Should a syntax error generate an email to the user explaining the problem?

            int pos = ri.NearByText.IndexOf(':');

            if (pos < 0)
            {
                return;
            }

            string cmd = ri.NearByText.Remove(0, pos + 1);

            string[] args = cmd.Split('=');

            switch (args[0].ToLowerInvariant())
            {
            case "help":
                CampfireState.Instance.Notifier.SendHelp(ri.SourceUser.Name, ri.SourceUser.EmailAddress);
                break;

            case "settings":
                CampfireState.Instance.Notifier.SendSettings(ri.SourceUser, false);
                break;

            case "delay":
                int    newDelay;
                string newDelayStr = "";
                if (args.Length > 2)
                {
                    return;
                }
                if (args.Length == 2)
                {
                    newDelayStr = args[1];
                }
                if (string.IsNullOrEmpty(newDelayStr))
                {
                    newDelayStr = "-1";
                }

                if (Int32.TryParse(newDelayStr, out newDelay))
                {
                    ri.SourceUser = CampfireState.Instance.UpdateUser(userId, newDelay);
                    CampfireState.Instance.Notifier.SendSettings(ri.SourceUser, true);
                }
                break;

            case "altemail":
                string newEmail = null;
                if (args.Length > 2)
                {
                    return;
                }
                if (args.Length == 2)
                {
                    newEmail = args[1];
                }

                if (!string.IsNullOrEmpty(newEmail) && !IsValidEmail(newEmail))
                {
                    return;
                }

                ri.SourceUser = CampfireState.Instance.UpdateAltEmail(ri.SourceUser.Id, newEmail);
                CampfireState.Instance.Notifier.SendSettings(ri.SourceUser, true);
                break;

            default:
                break;
            }
        }