Beispiel #1
0
        /// <summary>
        /// Attempts to discover a walmart project based on content and contacts in the email
        /// </summary>
        /// <param name="message">Microsoft.Exchange.WebServices.Data.EmailMessage</param>
        /// <param name="category">Contains the category string if function returns true.
        /// <para>If function returns false this value will be String.Empty</para></param>
        /// <param name="store">System.Collections.Generic.List&lt; Entity.Store &gt;</param>
        /// <returns>RfiCoder.Enum.QuestionTypes</returns>
        public Enum.QuestionTypes DiscoverProject(Microsoft.Exchange.WebServices.Data.EmailMessage message, out string category, out System.Collections.Generic.List <Entity.Store> store)
        {
            // step one try to get the city, state combination from the email.
            var parser = new Parser();

            var search = String.Format("{0} {1}", message.Subject, message.Body);

            System.Collections.Generic.List <System.Collections.Generic.Dictionary <string, string> > matches;

            var isMatch = parser.TryCityState(search, out matches);

            if (isMatch)
            {
                // let's try to find some stores
                var connector = new Data.DatabaseConnector();

                var stores = new System.Collections.Generic.List <Entity.Store>();

                foreach (var match in matches)
                {
                    var storeList = connector.GetAllStoresByCityState(match["city"], match["state"]);

                    if (storeList.Count != 0)
                    {
                        stores.AddRange(storeList);
                    }
                }
            }

            // get email contacts
            var contacts = message.CcRecipients;

            contacts.Add(message.Sender);

            // some (actually alot) email are automatically forwarded from Amy.  These email
            // don't have any CC recipients.  They are listed in the body of the email.
            // what we'll do is check the message to see if it was sent from Amy but only
            // to the RFI inbox.

            if (message.Sender.Address == "*****@*****.**" &&
                message.ToRecipients[0].Address == "*****@*****.**")
            {
                // becuase this message is an autoforward we need to clear the email addresses we've stored
                contacts.Clear();
            }

            store = new System.Collections.Generic.List <Entity.Store>();

            category = "";

            return(Enum.QuestionTypes.RequestForInformation);
        }