Disabled or removed tons of hardcoded functionality - needs to be generalized and localized or removed entirely
This commit is contained in:
@@ -10,8 +10,11 @@ namespace Swarmops.Utility.BotCode
|
||||
{
|
||||
public class ActivityMailer
|
||||
{
|
||||
[Obsolete("Disabled/Deprecated for Swarmops", true)]
|
||||
public static void Run()
|
||||
{
|
||||
/* Nope. Disable this.
|
||||
|
||||
// PPSE only, for now
|
||||
|
||||
ExternalActivities activities = ExternalActivities.ForOrganization(Organization.PPSE);
|
||||
@@ -90,7 +93,7 @@ namespace Swarmops.Utility.BotCode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@ namespace Swarmops.Utility.BotCode
|
||||
{
|
||||
// This entire class could use a tune-up. More event types will come, too.
|
||||
|
||||
[Obsolete("Deprecated for Swarmops. Way too much hardcoded. Rewrite, generalize, or scrap.", true)]
|
||||
public static void Run ()
|
||||
{
|
||||
/*
|
||||
BasicPWEvent[] events = PWEvents.GetTopUnprocessedEvents();
|
||||
|
||||
foreach (BasicPWEvent newEvent in events)
|
||||
@@ -201,7 +203,7 @@ namespace Swarmops.Utility.BotCode
|
||||
|
||||
}
|
||||
PWEvents.SetEventProcessed(newEvent.EventId);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +219,7 @@ namespace Swarmops.Utility.BotCode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
internal static void ProcessAddedRole (BasicPWEvent newPwEvent)
|
||||
{
|
||||
// This function handles the case when a new role has been added to a point in the organization.
|
||||
@@ -421,17 +423,6 @@ namespace Swarmops.Utility.BotCode
|
||||
"\r\nTo add an automatic welcome mail for your organization and geography, " +
|
||||
"go to PirateWeb, Communications, Triggered Automails, Automail type \"Welcome\".\r\n\r\n";
|
||||
|
||||
// Add some hardcoded things for UP
|
||||
|
||||
/*
|
||||
if (organization.Inherits(2))
|
||||
{
|
||||
int membersTotal = Organization.FromIdentity(2).GetTree().GetMemberCount();
|
||||
int membersHere = organization.GetMemberCount();
|
||||
|
||||
body += "Member count for Ung Pirat SE: " + membersTotal.ToString("#,##0") + "\r\n" +
|
||||
"Member count for " + organization.Name + ": " + membersHere.ToString("#,##0") + "\r\n";
|
||||
}*/
|
||||
|
||||
string orgSubjectLine = string.Empty;
|
||||
|
||||
@@ -1410,29 +1401,6 @@ namespace Swarmops.Utility.BotCode
|
||||
MailServerDatabase.AddAccount(newAddress, password, 1024);
|
||||
newMailPerson.PartyEmail = newAddress;
|
||||
|
||||
/** -- COMMENTED OUT -- OLD EXCHANGE-FACING CODE -- KEEP AS COMMENT FOR REFERENCE --
|
||||
|
||||
// Create AD account
|
||||
|
||||
ActiveDirectoryCode.AddUser(newMailPerson, organization, password);
|
||||
|
||||
// Add to security group
|
||||
|
||||
ActiveDirectoryCode.AddUserToPirateSecurityGroup(newMailPerson, organization);
|
||||
|
||||
// Mail enable
|
||||
|
||||
ExchangeCode.CreateMailbox(newMailPerson);
|
||||
|
||||
// Add internal mail addresses
|
||||
|
||||
ActiveDirectoryCode.AddEmailAddress(newMailPerson, adAccountName + "@internal.pirateweb.net", false);
|
||||
ActiveDirectoryCode.AddEmailAddress(newMailPerson, adAccountName + "@pirateweb.net", false);
|
||||
|
||||
// Add primary mail address
|
||||
|
||||
ActiveDirectoryCode.AddEmailAddress(newMailPerson, newAddress, true); -- */
|
||||
|
||||
|
||||
// Send notice to person that the account has been created
|
||||
|
||||
@@ -1449,7 +1417,7 @@ namespace Swarmops.Utility.BotCode
|
||||
"Försök att börja läsa mail från den adressen så snart som möjligt; i vissa roller kan " +
|
||||
"det hända att du redan står som lokal kontaktperson, när medlemmar letar.\r\n\r\n" +
|
||||
MailConnectionExplanation(newAddress) +
|
||||
/* Fix for Ticket #50 */
|
||||
// Fix for Ticket #50 --
|
||||
"Du kan också hitta bra information här: http://forum.piratpartiet.se/Topic131505-56-1.aspx\r\n\r\n" +
|
||||
"Hör av dig om du har några frågor!\r\n" +
|
||||
"Piratpartiet medlemsservice (automatbrev)\r\n";
|
||||
@@ -1563,12 +1531,6 @@ namespace Swarmops.Utility.BotCode
|
||||
string password = Formatting.GeneratePassword(16);
|
||||
MailServerDatabase.SetNewPassword(mailAddress, password);
|
||||
|
||||
/* COMMENTED OUT -- AD DEACTIVATED
|
||||
|
||||
// Update AD Account with new password
|
||||
|
||||
ActiveDirectoryCode.SetUserPassword (mailPerson, password); */
|
||||
|
||||
// Send notice to person about the new password
|
||||
|
||||
string noticeBody =
|
||||
@@ -2146,6 +2108,6 @@ namespace Swarmops.Utility.BotCode
|
||||
new MailTransmitter(Strings.MailSenderName, Strings.MailSenderAddress,
|
||||
"Activism Logged: [" + geo.Name + "]",
|
||||
string.Empty, officers, true).Send();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ namespace Swarmops.Utility.BotCode
|
||||
foreach (int personId in recipients)
|
||||
{
|
||||
Person.FromIdentity(personId).SendNotice(
|
||||
subject, body, Organization.PPSEid);
|
||||
subject, body, poll.OrganizationId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,14 +96,6 @@ namespace Swarmops.Utility.BotCode
|
||||
|
||||
Dictionary<int, bool> decliners = new Dictionary<int, bool>();
|
||||
|
||||
//HACK: invitation to member meeting should be sent out to ALL members for PPSE
|
||||
if (mail.Author.PartyEmail.ToLower() != "motespresidiet@piratpartiet.se"
|
||||
|| mail.GeographyId != Geography.RootIdentity
|
||||
|| mail.OrganizationId != Organization.PPSEid)
|
||||
{
|
||||
decliners = Optimizations.GetPeopleWhoDeclineLocalMail(personIdList.ToArray());
|
||||
}
|
||||
|
||||
int declineCount = decliners.Count;
|
||||
|
||||
if (declineCount > 0)
|
||||
|
||||
@@ -13,8 +13,12 @@ namespace Swarmops.Utility.BotCode
|
||||
{
|
||||
public class Mappery
|
||||
{
|
||||
[Obsolete("Too specialized for Swarmops. Plugin or generalize.", true)]
|
||||
public static void CreateUngPiratUptakeMap()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
/*
|
||||
string svg = string.Empty;
|
||||
string legendTemplate = string.Empty;
|
||||
|
||||
@@ -32,7 +36,7 @@ namespace Swarmops.Utility.BotCode
|
||||
}
|
||||
|
||||
Organizations effectiveOrgs = new Organizations();
|
||||
Organizations possibleOrgs = Organization.FromIdentity(2).GetTree();
|
||||
Organizations possibleOrgs = Organization.FromIdentity(Organization.UPSEid).GetTree();
|
||||
|
||||
foreach (Organization org in possibleOrgs)
|
||||
{
|
||||
@@ -99,12 +103,12 @@ namespace Swarmops.Utility.BotCode
|
||||
|
||||
MatchEvaluator matchEvaluator = new MatchEvaluator(mappery.UPUptakeLookupReplacer);
|
||||
|
||||
Persistence.Key["OrgUptakeMap-2"] = regex.Replace(svg, matchEvaluator);
|
||||
Persistence.Key["OrgUptakeMap-2"] = regex.Replace(svg, matchEvaluator);*/
|
||||
}
|
||||
|
||||
|
||||
public Dictionary<int, string> OrgColorLookup; // ugly way to transfer data to delegate
|
||||
|
||||
/*
|
||||
public string UPUptakeLookupReplacer (Match match)
|
||||
{
|
||||
string resultColor = "#000000";
|
||||
@@ -120,7 +124,7 @@ namespace Swarmops.Utility.BotCode
|
||||
|
||||
return match.Groups["start"].Value + resultColor + match.Groups["middle"].Value + id +
|
||||
match.Groups["end"].Value;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
public static Color ColorFromAhsb (int a, float h, float s, float b)
|
||||
@@ -182,7 +186,7 @@ namespace Swarmops.Utility.BotCode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public static void CreatePiratpartietOrganizationStrengthCircuitMap()
|
||||
{
|
||||
string svg = string.Empty;
|
||||
@@ -432,7 +436,6 @@ namespace Swarmops.Utility.BotCode
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
try
|
||||
{
|
||||
if (lookup.ContainsKey(id))
|
||||
@@ -515,13 +518,12 @@ namespace Swarmops.Utility.BotCode
|
||||
// Ignore - color will be black
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
return match.Groups["start"].Value + resultColorString + match.Groups["middle"].Value + id +
|
||||
match.Groups["end"].Value;
|
||||
}
|
||||
|
||||
private Dictionary<int, bool> volunteerCache;
|
||||
private Dictionary<int, bool> volunteerCache;*/
|
||||
}
|
||||
}
|
||||
@@ -22,16 +22,18 @@ namespace Swarmops.Utility.BotCode
|
||||
{ }
|
||||
}
|
||||
static Dictionary<string, DateTime> feedErrorSignaled = new Dictionary<string, DateTime>();
|
||||
public static void Run ()
|
||||
{
|
||||
|
||||
[Obsolete("Too specialized for Swarmops. Plugin or generalize.", true)]
|
||||
public static void Run()
|
||||
{/*
|
||||
//TODO: This list should reside in database/by organisation and possibly geography.
|
||||
|
||||
CheckOneBlog("http://rickfalkvinge.se/feed", 1);
|
||||
CheckOneBlog("http://christianengstrom.wordpress.com/feed", 5);
|
||||
CheckOneBlog("http://opassande.se/index.php/feed/", 367);
|
||||
CheckOneBlog("http://www.annatroberg.com/feed/", 11443);
|
||||
CheckOneBlog("http://www.annatroberg.com/feed/", 11443);*/
|
||||
}
|
||||
|
||||
/*
|
||||
private static void CheckOneBlog (string readerFeedUrl, int personId)
|
||||
{
|
||||
try
|
||||
@@ -151,18 +153,7 @@ namespace Swarmops.Utility.BotCode
|
||||
recipients = People.FromNewsletterFeed(NewsletterFeed.TypeID.ChairmanBlog);
|
||||
}
|
||||
|
||||
/*
|
||||
* Disabled sending to activists -- this was done leading up to the election in 2009
|
||||
*/
|
||||
// Add activists (HACK)
|
||||
// Should probably be better to select by organization, not geography.
|
||||
|
||||
/*
|
||||
People activists = Activists.FromGeography(Country.FromCode("SE").Geography).People;
|
||||
|
||||
recipients = recipients.LogicalOr(activists);*/
|
||||
|
||||
|
||||
|
||||
// OVERRIDE: If this is a TEST newsletter, send ONLY to the originator
|
||||
|
||||
if (testMode)
|
||||
@@ -245,6 +236,6 @@ namespace Swarmops.Utility.BotCode
|
||||
Replace("’", "'").
|
||||
Replace("—", "--").
|
||||
Replace("…", "...");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -12,12 +12,17 @@ namespace Swarmops.Utility.BotCode
|
||||
{
|
||||
public class PressReleaseChecker
|
||||
{
|
||||
[Obsolete("Do not call this function until it's been generalized. Don't delete, though - generalize it.", true)]
|
||||
public static void Run ()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
//TODO: This list should reside in database/by organisation and possibly geography.
|
||||
|
||||
/*
|
||||
CheckOneFeed("http://press.piratpartiet.se/feed", "PPSE", Organization.PPSEid);
|
||||
CheckOneFeed("http://presscenter.ungpirat.se/feed", "UPSE", Organization.UPSEid);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using Swarmops.Basic.Enums;
|
||||
using Swarmops.Basic.Types;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Communications;
|
||||
using Swarmops.Logic.DataObjects;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Support;
|
||||
@@ -81,21 +82,28 @@ namespace Swarmops.Utility.BotCode
|
||||
|
||||
public static void RemindAllExpiries ()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
// needs generalization and localization.
|
||||
|
||||
/*
|
||||
RemindExpiriesMail(); // Send on ALL days, but only if DayOfWeek == OrganizationId % 7. This scatters reminder mails.
|
||||
|
||||
//RemindExpiriesSms(DateTime.Now.AddDays(7).Date,
|
||||
// "Piratpartiet: Ditt medlemskap går ut om bara ett par dagar. Svara på detta SMS med texten \"PP IGEN\" för att förnya (5 kr).");
|
||||
RemindExpiriesSms(DateTime.Now.AddDays(7).Date,
|
||||
"Piratpartiet: Ditt medlemskap går ut om bara ett par dagar. Svara på detta SMS med texten \"PP IGEN\" för att förnya (5 kr).");
|
||||
RemindExpiriesSms(DateTime.Now.AddDays(1).Date,
|
||||
"Piratpartiet: Ditt medlemskap går ut vid midnatt ikväll. Svara på detta SMS med texten \"PP IGEN\" för att förnya.");
|
||||
"Piratpartiet: Ditt medlemskap går ut vid midnatt ikväll. Svara på detta SMS med texten \"PP IGEN\" för att förnya.");*/
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Generalize and localize this function.", true)]
|
||||
public static void RemindExpiriesMail ()
|
||||
{
|
||||
// Get expiring
|
||||
|
||||
Console.WriteLine("Inside RemindExpiriesMail()");
|
||||
|
||||
Organizations orgs = Organization.Root.GetTree();
|
||||
Organizations orgs = Organizations.GetAll();
|
||||
|
||||
Dictionary<int, bool> personLookup = new Dictionary<int, bool>();
|
||||
Dictionary<string, int> dateLookup = new Dictionary<string, int>();
|
||||
@@ -189,7 +197,8 @@ namespace Swarmops.Utility.BotCode
|
||||
Console.WriteLine("none.");
|
||||
}
|
||||
|
||||
Person.FromIdentity(1).SendOfficerNotice("Reminders sent today", notifyBody, 1);
|
||||
/* no. just no. we should do a global search for "FromIdentity(1)"
|
||||
Person.FromIdentity(1).SendOfficerNotice("Reminders sent today", notifyBody, 1); */
|
||||
}
|
||||
|
||||
|
||||
@@ -197,13 +206,11 @@ namespace Swarmops.Utility.BotCode
|
||||
|
||||
public static void ChurnExpiredMembers ()
|
||||
{
|
||||
// For the time being, use org 1 as master.
|
||||
Organizations organizations = Organizations.GetAll();
|
||||
|
||||
int[] organizationIds = new int[] { Organization.PPSEid };
|
||||
|
||||
foreach (int organizationId in organizationIds)
|
||||
foreach (Organization organization in organizations)
|
||||
{
|
||||
Memberships memberships = Memberships.GetExpired(Organization.FromIdentity(organizationId));
|
||||
Memberships memberships = Memberships.GetExpired(organization);
|
||||
// Mail each expiring member
|
||||
|
||||
foreach (Membership membership in memberships)
|
||||
@@ -256,7 +263,7 @@ namespace Swarmops.Utility.BotCode
|
||||
string expiredMemberships = "";
|
||||
foreach (Membership personMembership in membershipsToDelete)
|
||||
{
|
||||
if (personMembership.OrganizationId != organizationId)
|
||||
if (personMembership.OrganizationId != organization.Identity)
|
||||
{
|
||||
expiredMemberships += ", " + personMembership.Organization.Name;
|
||||
}
|
||||
@@ -275,9 +282,9 @@ namespace Swarmops.Utility.BotCode
|
||||
"&MID=" + membershipsIds;
|
||||
|
||||
expiredmail.pStdRenewLink = stdLink;
|
||||
expiredmail.pOrgName = Organization.FromIdentity(organizationId).MailPrefixInherited;
|
||||
expiredmail.pOrgName = organization.MailPrefixInherited;
|
||||
|
||||
person.SendNotice(expiredmail, organizationId);
|
||||
person.SendNotice(expiredmail, organization.Identity);
|
||||
|
||||
person.DeleteSubscriptionData();
|
||||
|
||||
@@ -296,10 +303,10 @@ namespace Swarmops.Utility.BotCode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Generalize and localize this functionality.", true)]
|
||||
internal static void RemindExpiries (DateTime dateExpiry)
|
||||
{
|
||||
Organizations orgs = Organization.Root.GetTree();
|
||||
Organizations orgs = Organizations.GetAll();
|
||||
|
||||
foreach (Organization org in orgs)
|
||||
{
|
||||
@@ -325,8 +332,13 @@ namespace Swarmops.Utility.BotCode
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Requires move to plugin or similar, or at least rearch into a hook", true)]
|
||||
internal static void RemindExpiriesSms (DateTime dateExpiry, string message)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
/*
|
||||
|
||||
// For the time being, only remind for org 1.
|
||||
|
||||
int[] organizationIds = new int[] { Organization.PPSEid };
|
||||
@@ -359,7 +371,7 @@ namespace Swarmops.Utility.BotCode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
@@ -380,8 +392,10 @@ namespace Swarmops.Utility.BotCode
|
||||
return result;
|
||||
}
|
||||
|
||||
[Obsolete("Generalize and localize this function.", true)]
|
||||
public static void SendReminderMail (Membership membership)
|
||||
{
|
||||
/*
|
||||
// First, determine the organization template to use. Prioritize a long ancestry.
|
||||
|
||||
// This is a hack for the Swedish structure.
|
||||
@@ -465,12 +479,6 @@ namespace Swarmops.Utility.BotCode
|
||||
|
||||
remindermail.pTerminateLink = terminateLink;
|
||||
|
||||
//mailBody += "[a href=\"" + stdLink + "\"]" + stdLink + "[/a]\r\n\r\n" +
|
||||
// "[br]Välkommen att vara med oss i [b]ett år till![/b]\r\n\r\n" +
|
||||
// "Hälsningar,[br]Medlemsservice\r\n\r\n"; // +
|
||||
/*"PS: [b]Du fick ett likadant mail alldeles nyss. Om du har å, ä eller ö i ditt namn fungerade " +
|
||||
"inte länken i det mailet. Tack till alla som hörde av sig om det; felet är fixat nu och länken ovan ska fungera.[/b]\r\n\r\n";*/
|
||||
|
||||
//OutboundMail mail = remindermail.CreateOutboundMail(sender, OutboundMail.PriorityNormal, topOrg, Geography.Root);
|
||||
OutboundMail mail = remindermail.CreateFunctionalOutboundMail(MailAuthorType.MemberService, OutboundMail.PriorityNormal, membership.Organization, Geography.Root);
|
||||
if (mail.Body.Trim() == "")
|
||||
@@ -483,7 +491,7 @@ namespace Swarmops.Utility.BotCode
|
||||
mail.SetRecipientCount(2);
|
||||
mail.SetResolved();
|
||||
mail.SetReadyForPickup();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public static void TimeoutVolunteers ()
|
||||
@@ -497,12 +505,14 @@ namespace Swarmops.Utility.BotCode
|
||||
{
|
||||
// timed out
|
||||
|
||||
OfficerChain officers = OfficerChain.FromOrganizationAndGeography(Organization.PPSE,
|
||||
/* -- wtf, Volunteer doesn't have an Org component? Well, will change anyway with Swarmops role structure
|
||||
|
||||
OfficerChain officers = OfficerChain.FromOrganizationAndGeography(volunteer.,
|
||||
volunteer.Geography);
|
||||
|
||||
new MailTransmitter(Strings.MailSenderName, Strings.MailSenderAddress,
|
||||
"Volunteer Timed Out: [" + volunteer.Geography.Name + "]",
|
||||
String.Empty, officers, true).Send();
|
||||
String.Empty, officers, true).Send(); */
|
||||
|
||||
volunteer.Close("Timed out");
|
||||
}
|
||||
@@ -510,334 +520,7 @@ namespace Swarmops.Utility.BotCode
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handle UP special: Monthly reminder to members that are in wrong organisation
|
||||
* (member in an org that no longer accepts members) or member of an org where a "better fit" exists geographically
|
||||
*
|
||||
*/
|
||||
private class ChangeOrgReport
|
||||
{
|
||||
public Organization FromOrg = null;
|
||||
public Organization ToOrg = null;
|
||||
}
|
||||
|
||||
public static void RemindChangeOrg ()
|
||||
{
|
||||
HeartBeater.Instance.Beat();
|
||||
|
||||
// Get expiring
|
||||
DateTime starttime = DateTime.Now;
|
||||
Organizations orgs = Organization.FromIdentity(Organization.UPSEid).GetTree();
|
||||
Dictionary<int, Person> personLookup = new Dictionary<int, Person>();
|
||||
Dictionary<int, Memberships> personMembershipsLookup = new Dictionary<int, Memberships>();
|
||||
Dictionary<int, Organization> orgLookup = new Dictionary<int, Organization>();
|
||||
Dictionary<int, Organization> mostLocalOrganizationCache = new Dictionary<int, Organization>();
|
||||
List<ChangeOrgReport> report = new List<ChangeOrgReport>();
|
||||
|
||||
foreach (Organization org in orgs)
|
||||
{
|
||||
orgLookup[org.OrganizationId] = org;
|
||||
}
|
||||
|
||||
Memberships allMemberships = Memberships.ForOrganizations(orgs);
|
||||
foreach (Membership ms in allMemberships)
|
||||
{
|
||||
//Handle defunct Memberships.ForOrganizations
|
||||
if (orgLookup.ContainsKey(ms.OrganizationId))
|
||||
{
|
||||
if (!personLookup.ContainsKey(ms.PersonId))
|
||||
{
|
||||
personLookup[ms.PersonId] = null;
|
||||
personMembershipsLookup[ms.PersonId] = new Memberships();
|
||||
|
||||
}
|
||||
personMembershipsLookup[ms.PersonId].Add(ms);
|
||||
}
|
||||
}
|
||||
allMemberships = null;
|
||||
|
||||
People peeps = People.FromIdentities((new List<int>(personLookup.Keys)).ToArray());
|
||||
foreach (Person p in peeps)
|
||||
{
|
||||
personLookup[p.PersonId] = p;
|
||||
}
|
||||
|
||||
|
||||
if (Debugger.IsAttached)
|
||||
Console.WriteLine("Found " + personLookup.Count + " people");
|
||||
|
||||
int processedCounter = 0;
|
||||
int sentCounter = 0;
|
||||
int failCounter = 0;
|
||||
|
||||
DateTime lastDisplay = DateTime.Now;
|
||||
|
||||
foreach (Person person in personLookup.Values)
|
||||
{
|
||||
++processedCounter;
|
||||
if ((processedCounter % 50) == 0)
|
||||
{
|
||||
HeartBeater.Instance.Beat();
|
||||
if (Debugger.IsAttached)
|
||||
Console.WriteLine("Processed " + processedCounter + " t=" + DateTime.Now.Subtract(lastDisplay).TotalSeconds);
|
||||
lastDisplay = DateTime.Now;
|
||||
}
|
||||
|
||||
int geoid = person.GeographyId;
|
||||
|
||||
//check for error, geography broken.
|
||||
if (person.GeographyId == 0)
|
||||
{
|
||||
geoid = person.Geography.GeographyId; //Will force resolve Geography
|
||||
if (geoid != 0)
|
||||
person.Geography = person.Geography; ; //repair person.
|
||||
}
|
||||
|
||||
if (geoid == 0)
|
||||
continue; //give up on that...
|
||||
|
||||
Organization expectedLowOrg = null;
|
||||
|
||||
if (mostLocalOrganizationCache.ContainsKey(geoid))
|
||||
{
|
||||
expectedLowOrg = mostLocalOrganizationCache[geoid];
|
||||
}
|
||||
else
|
||||
{
|
||||
expectedLowOrg = Organizations.GetMostLocalOrganization(geoid, Organization.UPSEid);
|
||||
mostLocalOrganizationCache[geoid] = expectedLowOrg;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
Dictionary<int, Membership> personMS = new Dictionary<int, Membership>();
|
||||
|
||||
foreach (Membership ms in personMembershipsLookup[person.PersonId])
|
||||
{
|
||||
if (orgLookup.ContainsKey(ms.OrganizationId))
|
||||
{ //Its an UP org
|
||||
personMS[ms.OrganizationId] = ms;
|
||||
}
|
||||
if (ms.OrganizationId == expectedLowOrg.Identity)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found == false)
|
||||
{
|
||||
//OK we didnt find the recommended org. Find out why.
|
||||
|
||||
// loop thru the persons up orgs to find an inactive
|
||||
List<Organization> foundInactiveOrg = new List<Organization>();
|
||||
List<Organization> foundActiveOrg = new List<Organization>();
|
||||
Membership membership = null;
|
||||
try
|
||||
{
|
||||
Organization org = null;
|
||||
|
||||
foreach (Membership ms in personMS.Values)
|
||||
{
|
||||
org = orgLookup[ms.OrganizationId];
|
||||
if (org.AcceptsMembers == false)
|
||||
{
|
||||
foundInactiveOrg.Add(org);
|
||||
}
|
||||
else if (org.AutoAssignNewMembers == true)
|
||||
{
|
||||
foundActiveOrg.Add(org);
|
||||
}
|
||||
}
|
||||
|
||||
if (foundInactiveOrg.Count > 0)
|
||||
{
|
||||
//inactive
|
||||
membership = personMS[foundInactiveOrg[0].Identity];
|
||||
|
||||
}
|
||||
else if (foundActiveOrg.Count > 0)
|
||||
{
|
||||
//change
|
||||
membership = personMS[foundActiveOrg[0].Identity];
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//already a member but not of an autoassign org
|
||||
if (Debugger.IsAttached)
|
||||
Console.WriteLine("Debug:nochange " + person.Name + ";" + person.Geography.Name + ";" + (org != null ? org.Name : "UnknownOrg") + ";" + expectedLowOrg.Name);
|
||||
continue;
|
||||
}
|
||||
DateTime lastReminder = PWLog.CheckLatest(PWLogItem.Person, membership.PersonId, PWLogAction.MembershipRenewReminder);
|
||||
|
||||
if (DateTime.Now.Subtract(lastReminder).TotalDays > 25)
|
||||
{
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
Console.Write("Debug:" + person.Name + ";" + person.Geography.Name + ";" + membership.Organization.Name + ";" + expectedLowOrg.Name);
|
||||
foreach (var o in foundActiveOrg)
|
||||
Console.Write(";" + o.Name);
|
||||
Console.WriteLine("");
|
||||
}
|
||||
|
||||
SendChangeOrgMail(person, membership, expectedLowOrg);
|
||||
report.Add(new ChangeOrgReport { FromOrg = membership.Organization, ToOrg = expectedLowOrg });
|
||||
++sentCounter;
|
||||
PWLog.Write(PWLogItem.Person, membership.PersonId,
|
||||
PWLogAction.MembershipRenewReminder,
|
||||
"Mail was sent to " + membership.Person.Mail +
|
||||
" for recommendation of organisation change in " + membership.Organization.Name + ".",
|
||||
membership.Organization.Identity.ToString() + "/" + expectedLowOrg.Identity.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
++failCounter;
|
||||
string logText = "FAILED sending mail to " + membership.Person.Mail +
|
||||
" for recommendation of organisation change in " + membership.Organization.Name + ".";
|
||||
PWLog.Write(PWLogItem.Person, membership.PersonId,
|
||||
PWLogAction.MembershipRenewReminder,
|
||||
logText, string.Empty);
|
||||
ExceptionMail.Send(new Exception(logText, x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<Organization, Dictionary<Organization, int>> fromdict = new Dictionary<Organization, Dictionary<Organization, int>>();
|
||||
StringBuilder fromOrgReport = new StringBuilder();
|
||||
report.ForEach(delegate(ChangeOrgReport r)
|
||||
{
|
||||
if (!fromdict.ContainsKey(r.FromOrg))
|
||||
fromdict[r.FromOrg] = new Dictionary<Organization, int>();
|
||||
if (!fromdict[r.FromOrg].ContainsKey(r.ToOrg))
|
||||
fromdict[r.FromOrg][r.ToOrg] = 0;
|
||||
fromdict[r.FromOrg][r.ToOrg]++;
|
||||
});
|
||||
foreach (var fd in fromdict.Keys)
|
||||
{
|
||||
StringBuilder tmp = new StringBuilder();
|
||||
int cnt = 0;
|
||||
foreach (var td in fromdict[fd].Keys)
|
||||
{
|
||||
tmp.Append(", " + td.Name);
|
||||
cnt += fromdict[fd][td];
|
||||
}
|
||||
fromOrgReport.Append("\r\nFrån " + fd.Name + " (" + cnt + " st) till " + tmp.ToString().Substring(2));
|
||||
}
|
||||
|
||||
Dictionary<Organization, Dictionary<Organization, int>> todict = new Dictionary<Organization, Dictionary<Organization, int>>();
|
||||
StringBuilder toOrgReport = new StringBuilder();
|
||||
report.ForEach(delegate(ChangeOrgReport r)
|
||||
{
|
||||
if (!todict.ContainsKey(r.ToOrg))
|
||||
todict[r.ToOrg] = new Dictionary<Organization, int>();
|
||||
if (!todict[r.ToOrg].ContainsKey(r.FromOrg))
|
||||
todict[r.ToOrg][r.FromOrg] = 0;
|
||||
todict[r.ToOrg][r.FromOrg]++;
|
||||
});
|
||||
foreach (var td in todict.Keys)
|
||||
{
|
||||
StringBuilder tmp = new StringBuilder();
|
||||
int cnt = 0;
|
||||
foreach (var fd in todict[td].Keys)
|
||||
{
|
||||
tmp.Append(", " + fd.Name);
|
||||
cnt += todict[td][fd];
|
||||
}
|
||||
toOrgReport.Append("\r\nTill " + td.Name + " (" + cnt + " st) från " + tmp.ToString().Substring(2));
|
||||
}
|
||||
|
||||
|
||||
string reportMessage = string.Format(
|
||||
"Result from running recommendation to change org mails:\r\n"
|
||||
+ "Time: {0,10:#0.0} minutes. \r\n"
|
||||
+ "Checked: {1,10:g}\r\n"
|
||||
+ "Sent: {2,10:g}\r\n"
|
||||
+ "Failed: {3,10:g}\r\n",
|
||||
DateTime.Now.Subtract(starttime).TotalMinutes, processedCounter, sentCounter, failCounter)
|
||||
+ fromOrgReport + "\r\n"
|
||||
+ toOrgReport;
|
||||
|
||||
BasicPersonRole[] UPSecretary = SwarmDb.GetDatabaseForReading().GetPeopleWithRoleType(RoleType.OrganizationSecretary,
|
||||
new int[] { Organization.UPSEid },
|
||||
new int[] { });
|
||||
if (UPSecretary.Length > 0)
|
||||
{
|
||||
Person.FromIdentity(UPSecretary[0].PersonId).SendOfficerNotice("ChangeOrg Mails Job report", reportMessage, Organization.UPSEid);
|
||||
}
|
||||
|
||||
Person.FromIdentity(7838).SendOfficerNotice("ChangeOrgMails run", reportMessage, Organization.UPSEid);//Debug
|
||||
}
|
||||
|
||||
public static void SendChangeOrgMail (Person person, Membership membership, Organization newOrg)
|
||||
{
|
||||
// HACK for UPSE
|
||||
// This is a hack for the Swedish structure.
|
||||
|
||||
ChangeOrgMail changeorgmail = new ChangeOrgMail();
|
||||
|
||||
Organization topOrg = Organization.FromIdentity(Organization.UPSEid);
|
||||
Organization lowOrg = membership.Organization;
|
||||
DateTime currentExpiry = membership.Expires;
|
||||
|
||||
|
||||
DateTime newExpiry = DateTime.Today.AddYears(1);
|
||||
|
||||
|
||||
changeorgmail.pCurrentOrg = lowOrg.Name;
|
||||
changeorgmail.pCurrentGeo = person.Geography.Name;
|
||||
changeorgmail.pNextDate = newExpiry;
|
||||
|
||||
string tokenBase = person.PasswordHash + "-" + membership.Identity.ToString() + "-" + currentExpiry.Year.ToString();
|
||||
|
||||
if (newOrg.AnchorGeographyId == Geography.RootIdentity && newOrg.AutoAssignNewMembers)
|
||||
{//Fallback org
|
||||
changeorgmail.pNoLocalOrg = newOrg.Name;
|
||||
changeorgmail.pChangeOrg = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
changeorgmail.pNoLocalOrg = "";
|
||||
changeorgmail.pChangeOrg = newOrg.Name;
|
||||
}
|
||||
|
||||
if (lowOrg.AcceptsMembers)
|
||||
{
|
||||
changeorgmail.pInactiveOrg = "";
|
||||
changeorgmail.pInactiveEnding = " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
changeorgmail.pInactiveOrg = newOrg.Name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
changeorgmail.pStdRenewLink = "https://pirateweb.net/Pages/Public/SE/People/MemberRenew.aspx?PersonId=" +
|
||||
person.Identity.ToString() + "&Transfer=" + lowOrg.Identity.ToString() + "," +
|
||||
newOrg.Identity.ToString() +
|
||||
"&MembershipId=" + membership.Identity.ToString() +
|
||||
"&SecHash=" + SHA1.Hash(tokenBase + "-Transfer" + lowOrg.Identity.ToString() + "/" +
|
||||
newOrg.Identity.ToString()).Replace(" ", "").Substring(0, 8);
|
||||
|
||||
OutboundMail mail = changeorgmail.CreateFunctionalOutboundMail(MailAuthorType.MemberService, OutboundMail.PriorityNormal, topOrg, Geography.Root);
|
||||
string test = mail.RenderHtml(person, person.PreferredCulture);
|
||||
test = mail.RenderText(person, person.PreferredCulture);
|
||||
|
||||
if (mail.Body.Trim() == "")
|
||||
{
|
||||
throw new InvalidOperationException("Failed to create a mailBody");
|
||||
}
|
||||
else
|
||||
{
|
||||
//mail.AddRecipient(7838, true);
|
||||
mail.AddRecipient(person.Identity, false);
|
||||
mail.SetRecipientCount(1);
|
||||
mail.SetResolved();
|
||||
mail.SetReadyForPickup();
|
||||
}
|
||||
}
|
||||
|
||||
// Deleted a ton of special cases here, see file history if you need to copy code for reminding people to change org
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,12 @@ namespace Swarmops.Utility.BotCode
|
||||
{
|
||||
public class TurnaroundTracker
|
||||
{
|
||||
[Obsolete("This is dependent on a specific support system. Should move to plugin.", true)]
|
||||
public static void Run()
|
||||
{
|
||||
throw new NotImplementedException("Disabled for Swarmops");
|
||||
|
||||
/*
|
||||
const string persistenceKey = "PPSE-LastSupportDeltaId";
|
||||
|
||||
string lastDeltaIdString = Persistence.Key[persistenceKey];
|
||||
@@ -80,9 +84,9 @@ namespace Swarmops.Utility.BotCode
|
||||
}
|
||||
}
|
||||
|
||||
Persistence.Key[persistenceKey] = lastDeltaId.ToString();
|
||||
Persistence.Key[persistenceKey] = lastDeltaId.ToString();*/
|
||||
}
|
||||
|
||||
/*
|
||||
public static void Housekeeping()
|
||||
{
|
||||
CommunicationTurnarounds turnarounds = CommunicationTurnarounds.ForOrganization(Organization.PPSE);
|
||||
@@ -100,6 +104,6 @@ namespace Swarmops.Utility.BotCode
|
||||
SwarmDb.GetDatabaseForWriting().SetCommunicationTurnaroundClosed(Organization.PPSEid, 1, turnaround.CommunicationId, (DateTime) dateTimeClosed, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user