Example #1
0
        static Utils()
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);

            //string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            Assembly asm = Assembly.GetExecutingAssembly();

            Attribute[] ca = Attribute.GetCustomAttributes(asm, typeof(AssemblyCompanyAttribute));
            path = System.IO.Path.Combine(path, ((AssemblyCompanyAttribute)ca[0]).Company);

            Attribute[] pa = Attribute.GetCustomAttributes(asm, typeof(AssemblyProductAttribute));
            path = System.IO.Path.Combine(path, ((AssemblyProductAttribute)pa[0]).Product);

            DataLocation = path;

            path = System.IO.Path.Combine(path, "trace_log.txt");

            //Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Trace.Listeners.Add(new TextWriterTraceListener(path));
            Trace.AutoFlush = true;

            // This creates the special "Smoke Signal" user which allows commands to communicate with smoke signal. Things like "@SSignal:Help"
            CampfireState.UserInfo smokeSignalUser = new CampfireState.UserInfo(0, "Smoke Signal", "x", "y");
            Special_SmokeSignal_User = new List <CampfireState.UserInfo>();
            Special_SmokeSignal_User.Add(smokeSignalUser);
        }
Example #2
0
        static Utils()
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
 
            //string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            Assembly asm = Assembly.GetExecutingAssembly();
            Attribute[] ca = Attribute.GetCustomAttributes(asm, typeof(AssemblyCompanyAttribute));
            path = System.IO.Path.Combine(path, ((AssemblyCompanyAttribute)ca[0]).Company);

            Attribute[] pa = Attribute.GetCustomAttributes(asm, typeof(AssemblyProductAttribute));
            path = System.IO.Path.Combine(path, ((AssemblyProductAttribute)pa[0]).Product);

            DataLocation = path;

            path = System.IO.Path.Combine(path, "trace_log.txt");

            //Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Trace.Listeners.Add(new TextWriterTraceListener(path));
            Trace.AutoFlush = true;

            // This creates the special "Smoke Signal" user which allows commands to communicate with smoke signal. Things like "@SSignal:Help"
            CampfireState.UserInfo smokeSignalUser = new CampfireState.UserInfo(0, "Smoke Signal", "x", "y");
            Special_SmokeSignal_User = new List<CampfireState.UserInfo>();
            Special_SmokeSignal_User.Add(smokeSignalUser);
        }
Example #3
0
        public void SendSettings(CampfireState.UserInfo user, bool haveChanged)
        {
            if (user == null)
            {
                return;
            }

            try
            {
                MailMessage msg = new MailMessage();

                msg.To.Add(new MailAddress(user.EmailAddress));
                msg.BodyEncoding = Encoding.ASCII;
                msg.Subject      = string.Format(haveChanged ? "Your Smoke Signal settings have changed..." : "Your Smoke Signal settings");
                StringBuilder sb = new StringBuilder();

                AppendWithNewLine(sb, string.Format("Dear {0}", user.NickName));
                AppendWithNewLine(sb);

                AppendWithNewLine(sb, string.Format(haveChanged
                    ? "Your SmokeSignal settings have been changed per your request:"
                    : "Here are the Smoke Signal settings as requested:"));

                int  delay        = user.DelayInMinutes > 0 ? user.DelayInMinutes : SmokeSignalConfig.Instance.DelayBeforeSmokeSignalInMinutes;
                bool defaultDelay = user.DelayInMinutes < 1;

                AppendWithNewLine(sb, string.Format("    Campfire Email     : {0}", user.EmailAddress));
                AppendWithNewLine(sb, string.Format("    Smoke Signal Email : {0}", user.SmokeEmail));
                AppendWithNewLine(sb, string.Format("    Delay In Minutes   : {0}{1}", delay, defaultDelay ? " (default)" : ""));

                AppendWithNewLine(sb);
                AppendWithNewLine(sb, "Sincerely,");
                AppendWithNewLine(sb, "Smoke Signal");

                msg.Body = sb.ToString();

                SmtpClient smtp = ConfigSmtpClient();

                Utils.TraceInfoMessage(string.Format("Sending Settings email. {0}", user.EmailAddress));

                smtp.Send(msg);
            }
            catch (InvalidOperationException ex)
            {
                Utils.TraceException(TraceLevel.Error, ex, "Exception trying to send a help email");
            }
            catch (SmtpException ex)
            {
                Utils.TraceException(TraceLevel.Error, ex, "Exception trying to send a help email");
            }
        }
Example #4
0
        public static void TraceMessage(TraceLevel level, Message msg, string extraText)
        {
            CampfireState campState = CampfireState.Instance;
            IList <CampfireState.UserInfo> allUsers = campState.Users;

            CampfireState.UserInfo user = allUsers.FirstOrDefault(u => u.Id == msg.UserId);
            string userName             = (user != null) ? user.NickName : msg.UserId.ToString();

            CampfireState.RoomInfo room = campState.Rooms.FirstOrDefault(r => r.Id == msg.RoomId);
            string roomName             = (room != null) ? room.Name : msg.RoomId.ToString();

            TraceMessage(level, string.Format("At: {0}, User: {1}, Room: {2}, {3}{4}{5}",
                                              msg.PostedAt.ToString(), userName, roomName,
                                              (extraText ?? ""), (!string.IsNullOrEmpty(extraText)) ? ": " : "", msg.TrimmedBody));
        }
Example #5
0
        private static void FindUserReferencesViaPrefix(string text, IList <CampfireState.UserReference> references, IList <CampfireState.UserInfo> allUsers,
                                                        string prefix, bool smokeSignalCommands)
        {
            IList <string> atWords = WordsStartingWithPrefix(text, prefix, smokeSignalCommands);

            foreach (string reference in atWords)
            {
                CampfireState.UserInfo referencedUser = SingleMatch(reference, allUsers, smokeSignalCommands);

                // The extra/second check is to prevent adding the same User multiple times to the list
                if (referencedUser != null && (smokeSignalCommands || !references.Any(ri => ri.TargetUser.Id == referencedUser.Id)))
                {
                    references.Add(InitReferenceInfo(text, reference, referencedUser, smokeSignalCommands));
                }
            }
        }
        private static void ProcessTextMessage(CampfireState campfireInfo, Message msg, ICampfireAPI api)
        {
            // The person that posted this message... If they have a pending notification in the room... then cancel it... they've spoken
            campfireInfo.RemovePendingNotification(msg.UserId, msg.RoomId, msg.PostedAt, true);

            IList <CampfireState.UserInfo> allUsers = campfireInfo.Users;

            IList <CampfireState.UserReference> lazyNotificationUsers;
            IList <CampfireState.UserReference> immediateNotificationUsers;
            IList <CampfireState.UserReference> smokeSignalReferences;

            Utils.FindUserReferences(msg.Body, allUsers, out lazyNotificationUsers, out immediateNotificationUsers, out smokeSignalReferences);

            CampfireState.UserInfo source = allUsers.FirstOrDefault(u => u.Id == msg.UserId);
            CampfireState.RoomInfo room   = CampfireState.Instance.Rooms.FirstOrDefault(r => r.Id == msg.RoomId);

            // special smoke signal commands only make sense if a legitimate user issued them
            if (source != null)
            {
                foreach (CampfireState.UserReference ri in smokeSignalReferences)
                {
                    ri.SourceUser = source;
                    ri.Room       = room;
                    ProcessSmokeSignalCommands(source.Id, ri);
                }
            }

            foreach (CampfireState.UserReference ri in immediateNotificationUsers)
            {
                ri.SourceUser = source;
                ri.Room       = room;
                campfireInfo.AddPendingNotification(ri, msg.PostedAt.AddSeconds(0));
            }
            foreach (CampfireState.UserReference ri in lazyNotificationUsers)
            {
                ri.SourceUser = source;
                ri.Room       = room;

                int delay = ri.TargetUser.DelayInMinutes > 0 ? ri.TargetUser.DelayInMinutes : SmokeSignalConfig.Instance.DelayBeforeSmokeSignalInMinutes;
                campfireInfo.AddPendingNotification(ri, msg.PostedAt.AddSeconds(delay * 60));
            }
        }
Example #7
0
        private static CampfireState.UserInfo SingleMatch(string target, IList <CampfireState.UserInfo> allUsers, bool smokeSignalCommands)
        {
            // trim off trailing periods so taht references can be at the end of a sentance: "... @Peter."
            string lowered = target.Trim('.').ToLowerInvariant();

            try
            {
                // For reference... if there's only one user who matches... we have a HIT!
                CampfireState.UserInfo referencedUser = allUsers.SingleOrDefault(
                    ui => smokeSignalCommands ? ui.PossibleAbbreviations.Any(abbrv => lowered.StartsWith(abbrv)) : ui.PossibleAbbreviations.Contains(lowered));
                if (referencedUser != null)
                {
                    return(referencedUser);
                }
            }
            catch (InvalidOperationException ex)
            {
                // this means we have multiple people that can match the reference found in the text. Oh well... just skip it
            }
            return(null);
        }
 public UserReference(string text, CampfireState.UserInfo target)
 {
     this.TargetUser = target;
     this.NearByText = text;
 }
Example #9
0
        private static CampfireState.UserReference InitReferenceInfo(string text, string target, CampfireState.UserInfo user, bool smokeSignalCommands)
        {
            string refText;

            if (smokeSignalCommands)
            {
                refText = target;
            }
            else if (text.Length < 80)
            {
                refText = text;
            }
            else
            {
                try
                {
                    refText = FindSentenceContaining(text, target);
                }
                catch (ArgumentException ex)
                {
                    refText = string.Empty;
                }
            }

            return(new CampfireState.UserReference(refText, user));
        }
 public void NickName_MiddleInitial_Test()
 {
     string name = string.Empty;
     CampfireState.UserInfo target = new CampfireState.UserInfo(0, "George W. Bush", "x", "x");
     Assert.AreEqual("GeorgeB", target.NickName);
 }
 public void NickName_NoLastName_Test()
 {
     string name = string.Empty;
     CampfireState.UserInfo target = new CampfireState.UserInfo(0, "Cher", "x", "x");
     Assert.AreEqual("Cher", target.NickName);
 }
 public void NickName_Basic_Test()
 {
     string name = string.Empty;
     CampfireState.UserInfo target = new CampfireState.UserInfo(0, "Jack Nicklaus", "x", "x");
     Assert.AreEqual("JackN", target.NickName);
 }
 public void NickName_TwoMiddleNames_Test()
 {
     string name = string.Empty;
     CampfireState.UserInfo target = new CampfireState.UserInfo(0, "Peter John Paul Frank", "x", "x");
     Assert.AreEqual("PeterF", target.NickName);
 }