Beispiel #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.ScriptTimeout = 300;

        Label3.Text = "";
        Label4.Text = "";

        if (Label1.Text == "" && Label2.Text == "")
        {
            Label1.Text                    = "1";
            Label2.Text                    = "0";
            Session["Memberships"]         = Memberships.ForOrganization(Organization.PPSE);
            Session["memberAccountLookup"] = new Dictionary <int, bool>();
            Button1.Text                   = "Press OK to converting Person forumaccountIDs to new forum";
        }
        else if (Label1.Text == "1")
        {
            IForumDatabase         forumDatabase       = SwedishForumDatabase.GetDatabase(2, TextBox1.Text);
            Dictionary <int, bool> memberAccountLookup = Session["memberAccountLookup"] as Dictionary <int, bool>;
            Memberships            memberships         = Session["Memberships"] as Memberships;
            int startRec = int.Parse(Label2.Text);

            SetMembers(startRec, forumDatabase, memberAccountLookup, memberships);
            Button1.Text = "continuing setting memberships";
        }

        else if (Label1.Text == "2")
        {
            IForumDatabase forumDatabase = SwedishForumDatabase.GetDatabase(2, TextBox1.Text);
            Session["accountIds"] = forumDatabase.GetAccountList();

            Label1.Text  = "3";
            Label2.Text  = "0";
            Button1.Text = "removing memberships";
        }
        else if (Label1.Text == "3")
        {
            IForumDatabase         forumDatabase       = SwedishForumDatabase.GetDatabase(2, TextBox1.Text);
            Dictionary <int, bool> memberAccountLookup = Session["memberAccountLookup"] as Dictionary <int, bool>;
            int[] accountIds = Session["accountIds"] as int[];

            int startRec = int.Parse(Label2.Text);

            RemoveMembers(startRec, forumDatabase, memberAccountLookup, accountIds);

            Button1.Text = "removing memberships";
        }

        if (Label1.Text == "4")
        {
            Button1.Text = "DONE!";
        }

        if (Label1.Text != "4" && Label1.Text != "" && Label3.Text == "")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "reloadscript", "document.getElementById('" + Button1.ClientID + "').click();", true);
        }
    }
Beispiel #2
0
    protected void Button2_Click(object sender, EventArgs e)
    {
        IForumDatabase db  = SwedishForumDatabase.GetDatabase(2, TextBox1.Text);
        int            pid = int.Parse(TextBox2.Text);
        Person         p   = Person.FromIdentity(pid);
        int            acc = db.GetAccountId(p.Handle);

        Label2.Text = p.Handle + ":" + acc.ToString();
        db.SetPartyNonmember(acc);
        Label1.Text = db.IsPartyMember(acc).ToString();
    }
Beispiel #3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        IForumDatabase db = SwedishForumDatabase.GetDatabase(2, TextBox1.Text);

        int[]         accounts = db.GetAccountList();
        StringBuilder sb       = new StringBuilder();

        foreach (int i in accounts)
        {
            sb.Append("," + i);
        }
        TextBox2.Text = sb.ToString();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            IForumDatabase forum = SwedishForumDatabase.GetDatabase();

            forum.TestMode = true;

            int forumPostId = forum.CreateNewPost(0, Person.FromIdentity(7838),
                                                  "Nyhetsbrev " + DateTime.Today.ToString("yyyy-MM-dd"),
                                                  "TestTitle", "TestContenttext");

            Response.Write(forumPostId);
        }
        catch (Exception ex)
        {
            if (!System.Diagnostics.Debugger.IsAttached)
            {   // ignore when debugging
                throw ex;
            }
        }
    }
Beispiel #5
0
        public static void Run()
        {
            BotLog.Write(1, "SeForumCheck", "Entering");

            Memberships    memberships   = Memberships.ForOrganization(Organization.PPSE);
            IForumDatabase forumDatabase = SwedishForumDatabase.GetDatabase();

            int[] accountIds;
            try
            {
                accountIds = forumDatabase.GetAccountList();
            }
            catch (Exception e)
            {
                ExceptionMail.Send(new Exception("Failed to connect to vBulletin", e), true);
                BotLog.Write(1, "SeForumCheck", "Failed to connect -- exiting");

                return;
            }

            BotLog.Write(1, "SeForumCheck", "Primed db - entering promotion cycle");

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

            // This is kind of suboptimal, but hey, it only runs once a night in the wolf hour.

            Person currentMember = null;

            foreach (Membership membership in memberships)
            {
                if (!membership.Active)
                {
                    continue;
                }

                currentMember = membership.Person;

                try
                {
                    if (currentMember.SwedishForumAccountId != 0)
                    {
                        if (!forumDatabase.IsPartyMember(currentMember.SwedishForumAccountId))
                        {
                            // This guy is not listed as a party member, but should be.

                            BotLog.Write(2, "SeForumCheck", "Promoting " + currentMember.Name);
                            forumDatabase.SetPartyMember(currentMember.SwedishForumAccountId);
                        }

                        memberAccountLookup[currentMember.SwedishForumAccountId] = true;
                    }
                }
                catch (Exception e)
                {
                    // The forum account probably doesn't exist. Just remove it from the profile.

                    BotLog.Write(2, "SeForumCheck", "Exception reading " + currentMember.Name + ": " + e.ToString());

                    try
                    {
                        currentMember.SwedishForumAccountId = 0;
                    }
                    catch (Exception e2)
                    {
                        string logMessage = "Exception removing " + currentMember.Name + "'s forum account: " + e2.ToString();
                        BotLog.Write(2, "SeForumCheck", logMessage);
                        ExceptionMail.Send(new Exception(logMessage, e2));
                    }
                }
            }

            // Now that we have flagged all member accounts as member accounts, flag the rest as
            // non-party members.

            BotLog.Write(1, "SeForumCheck", "Promotion cycle done - entering demotion cycle");

            foreach (int accountId in accountIds)
            {
                if (!memberAccountLookup.ContainsKey(accountId))
                {
                    if (forumDatabase.IsPartyMember(accountId))
                    {
                        BotLog.Write(2, "SeForumCheck", "Demoting forum account " + forumDatabase.GetAccountName(accountId));
                        forumDatabase.SetPartyNonmember(accountId);
                    }
                }
            }
            BotLog.Write(1, "SeForumCheck", "Demotion cycle complete -- exiting");
        }
        private static void CheckOneBlog(string readerFeedUrl, int personId)
        {
            try
            {
                Person sender = Person.FromIdentity(personId);

                string senderName    = sender.Name + " (Piratpartiet)";
                string senderAddress = sender.PartyEmail;


                if (personId == 5)
                {
                    senderName = "=?utf-8?Q?Christian_Engstr=C3=B6m_(Piratpartiet)?="; // compensate for Mono bug
                }
                if (personId == 1)
                {
                    senderAddress = "*****@*****.**";
                }

                RssReader reader     = new RssReader(readerFeedUrl);
                People    recipients = null;

                DateTime highWaterMark  = DateTime.MinValue;
                string   persistenceKey = "Newsletter-Highwater-" + personId.ToString();

                string highWaterMarkString = Persistence.Key[persistenceKey];

                try
                {
                    highWaterMark = DateTime.Parse(highWaterMarkString);
                }
                catch (FormatException)
                {
                    highWaterMark = DateTime.MinValue;
                }
                catch (Exception e)
                {
                    throw new ReaderException("feed:" + readerFeedUrl, e);
                }

                try
                {
                    Rss rss = reader.Read();

                    // TODO: Read the high water mark from db

                    foreach (RssChannelItem item in rss.Channel.Items)
                    {
                        // Ignore any items older than the highwater mark.

                        if (item.PubDate < highWaterMark)
                        {
                            continue;
                        }

                        // For each item, look for the "Nyhetsbrev" category.

                        bool publish = false;

                        foreach (RssCategory category in item.Categories)
                        {
                            if (category.Name.ToLowerInvariant() == "nyhetsbrev")
                            {
                                publish = true;
                            }
                        }


                        if (publish)
                        {
                            // Set highwater datetime mark. We do this first as a defense against mail floods, should something go wrong.

                            Persistence.Key[persistenceKey] = item.PubDate.AddMinutes(5).ToString();

                            // Verify that it was written correctly to database. This is defensive programming to avoid a mail flood.

                            if (DateTime.Parse(Persistence.Key[persistenceKey]) < item.PubDate)
                            {
                                throw new Exception(
                                          "Unable to commit new highwater mark to database in NewsletterChecker.Run()");
                            }

                            bool testMode = false;

                            if (item.Title.ToLower().Contains("test"))
                            {
                                // Newsletter blog entry contains "test" in title -> testmode
                                testMode = true;
                            }

                            // Post to forum

                            string forumText   = Blog2Forum(item.Content);
                            string mailText    = Blog2Mail(item.Content);
                            int    forumPostId = 0;
                            try
                            {
                                forumPostId = SwedishForumDatabase.GetDatabase().CreateNewPost(
                                    testMode ? ForumIdTestPost : ForumIdNewsletter, sender,
                                    "Nyhetsbrev " + DateTime.Today.ToString("yyyy-MM-dd"),
                                    item.Title, forumText);
                            }
                            catch (Exception ex)
                            {
                                if (!System.Diagnostics.Debugger.IsAttached)
                                {   // ignore when debugging
                                    throw ex;
                                }
                            }


                            // Establish people to send to, if not already done.

                            if (recipients == null || recipients.Count == 1)
                            {
                                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)
                            {
                                recipients  = People.FromSingle(sender);
                                item.Title += " [TEST MODE]";
                            }

                            //TODO: hardcoded Org & geo ... using PP & World
                            Organization org = Organization.PPSE;
                            Geography    geo = Geography.Root;


                            NewsletterMail newslettermail = new NewsletterMail();

                            newslettermail.pSubject      = item.Title;
                            newslettermail.pDate         = DateTime.Now;
                            newslettermail.pForumPostUrl =
                                String.Format("http://vbulletin.piratpartiet.se/showthread.php?t={0}", forumPostId);
                            newslettermail.pBodyContent = Blog2Mail(item.Content);
                            newslettermail.pOrgName     = org.MailPrefixInherited;


                            OutboundMail newMail = newslettermail.CreateOutboundMail(sender, OutboundMail.PriorityLow, org, geo);

                            int recipientCount = 0;
                            foreach (Person recipient in recipients)
                            {
                                if (!Formatting.ValidateEmailFormat(recipient.Mail) ||
                                    recipient.MailUnreachable ||
                                    recipient.NeverMail)
                                {
                                    continue;
                                }
                                ++recipientCount;
                                newMail.AddRecipient(recipient, false);
                            }

                            newMail.SetRecipientCount(recipientCount);
                            newMail.SetResolved();
                            newMail.SetReadyForPickup();
                        }
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                lock (feedErrorSignaled)
                {
                    if (!feedErrorSignaled.ContainsKey(readerFeedUrl) || feedErrorSignaled[readerFeedUrl].AddMinutes(60) < DateTime.Now)
                    {
                        feedErrorSignaled[readerFeedUrl] = DateTime.Now;
                        throw new ReaderException("NewsletterChecker got error " + ex.Message + "\n when checking feed:" + readerFeedUrl + "\n(feed will be continually checked, bu will not signal error again for an hour)", ex);
                    }
                }
            }
        }