Ejemplo n.º 1
0
        public static string CreateWelcomeMail (Person person, Organization organization)
        {
            // for this person, iterate over all applicable geographies and organizations

            Organizations orgLine = organization.GetLine();
            Geographies geoLine = person.Geography.GetLine();

            orgLine.Reverse(); // Start at the most local org

            Dictionary<int,bool> orgMailedLookup = new Dictionary<int, bool>();

            int delay = 0;
            string result = string.Empty;
            Random random = new Random();

            foreach (Organization org in orgLine)
            {
                foreach (Geography geo in geoLine) // but at the top geography
                {
                    AutoMail autoMail = AutoMail.FromTypeOrganizationAndGeography(AutoMailType.Welcome, org, geo);

                    if (autoMail == null)
                    {
                        continue;
                    }

                    Person lead = null;
                    string geoName = geo.Name;

                    try
                    {
                        lead = Roles.GetLocalLead(org, geo);
                        orgMailedLookup[org.Identity] = true; // Make sure that the chairman doesn't mail at a lower level
                    }
                    catch (ArgumentException)
                    {
                    }

                    if (lead == null && !orgMailedLookup.ContainsKey(org.Identity))
                    {
                        // If we get here, there is a mail template at the highest possible geo for this org, but no local lead.
                        // That's usually the case with board-centric organizations rather than executive-centric.
                        // Try to mail from chairman rather than the local lead.
                       
                        try
                        {
                            orgMailedLookup[org.Identity] = true;
                            lead = Roles.GetChairman(org);
                            geoName = "Chairman";
                        }
                        catch (ArgumentException)
                        {
                        }
                    }

                    if (lead == null)
                    {
                        // ok, give up if there isn't a chairman either or if we've already mailed this org from the chairman
                        continue;
                    }

                    // TODO: fetch lead from roles
                    WelcomeMail welcomemail = new WelcomeMail();

                    welcomemail.pOrgName = org.MailPrefixInherited;

                    welcomemail.pGeographyName = "";
                    if (geo.Identity != Geography.RootIdentity)
                    {
                        welcomemail.pGeographyName = geo.Name;
                    }

                    welcomemail.pBodyContent = autoMail.Body;
                    welcomemail.pSubject = autoMail.Title;
                    
                    OutboundMail newMail = welcomemail.CreateOutboundMail (lead, OutboundMail.PriorityNormal,
                                                                            org, geo, DateTime.Now.AddMinutes(delay));
                    newMail.AddRecipient(person.Identity, false);
                    newMail.SetRecipientCount(1);
                    newMail.SetResolved();
                    newMail.SetReadyForPickup();
                    
                    result += String.Format(" - {0}/{1} by {2} (",
                                            org.NameShort, geoName, lead.Canonical);
                    if (delay == 0)
                    {
                        result += "sent now";
                        delay += 37;
                    }
                    else
                    {
                        result += "sending at " + DateTime.Now.AddMinutes(delay).ToString("HH:mm");
                        delay += 31 + random.Next(52);
                    }
                    result += ")\r\n";
                }
            }

            if (result.Length < 4)
            {
                result = "none\r\n";
            }

            return result;
        }
Ejemplo n.º 2
0
        public static string CreateWelcomeMail(Person person, Organization organization)
        {
            // for this person, iterate over all applicable geographies and organizations

            Organizations orgLine = organization.GetLine();
            Geographies   geoLine = person.Geography.GetLine();

            orgLine.Reverse(); // Start at the most local org

            Dictionary <int, bool> orgMailedLookup = new Dictionary <int, bool>();

            int    delay  = 0;
            string result = string.Empty;
            Random random = new Random();

            foreach (Organization org in orgLine)
            {
                foreach (Geography geo in geoLine) // but at the top geography
                {
                    AutoMail autoMail = AutoMail.FromTypeOrganizationAndGeography(AutoMailType.Welcome, org, geo);

                    if (autoMail == null)
                    {
                        continue;
                    }

                    Person lead    = null;
                    string geoName = geo.Name;

                    try
                    {
                        lead = Roles.GetLocalLead(org, geo);
                        orgMailedLookup[org.Identity] = true;
                        // Make sure that the chairman doesn't mail at a lower level
                    }
                    catch (ArgumentException)
                    {
                    }

                    if (lead == null && !orgMailedLookup.ContainsKey(org.Identity))
                    {
                        // If we get here, there is a mail template at the highest possible geo for this org, but no local lead.
                        // That's usually the case with board-centric organizations rather than executive-centric.
                        // Try to mail from chairman rather than the local lead.

                        try
                        {
                            orgMailedLookup[org.Identity] = true;
                            lead    = Roles.GetChairman(org);
                            geoName = "Chairman";
                        }
                        catch (ArgumentException)
                        {
                        }
                    }

                    if (lead == null)
                    {
                        // ok, give up if there isn't a chairman either or if we've already mailed this org from the chairman
                        continue;
                    }

                    // TODO: fetch lead from roles
                    WelcomeMail welcomemail = new WelcomeMail();

                    welcomemail.pOrgName = org.MailPrefixInherited;

                    welcomemail.pGeographyName = "";
                    if (geo.Identity != Geography.RootIdentity)
                    {
                        welcomemail.pGeographyName = geo.Name;
                    }

                    welcomemail.pBodyContent = autoMail.Body;
                    welcomemail.pSubject     = autoMail.Title;

                    OutboundMail newMail = welcomemail.CreateOutboundMail(lead, OutboundMail.PriorityNormal,
                                                                          org, geo, DateTime.Now.AddMinutes(delay));
                    newMail.AddRecipient(person.Identity, false);
                    newMail.SetRecipientCount(1);
                    newMail.SetResolved();
                    newMail.SetReadyForPickup();

                    result += String.Format(" - {0}/{1} by {2} (",
                                            org.NameShort, geoName, lead.Canonical);
                    if (delay == 0)
                    {
                        result += "sent now";
                        delay  += 37;
                    }
                    else
                    {
                        result += "sending at " + DateTime.Now.AddMinutes(delay).ToString("HH:mm");
                        delay  += 31 + random.Next(52);
                    }
                    result += ")\r\n";
                }
            }

            if (result.Length < 4)
            {
                result = "none\r\n";
            }

            return(result);
        }