} // SendCampaign public void LoadClickStatsToDb() { McCampaign.Campaigns campaigns; int page = 0; const int campaignsPerPage = 50; const int maxNumOfPages = 1000 / campaignsPerPage; var campaignClickStats = new CampaignClickStats(); do { campaigns = m_oMcApi.Campaigns( new McCampaign.Filter { ListID = Constants.EzbobCustomersListId }, limit: campaignsPerPage, start: page); ms_oLog.Debug("num of campaigns {0} on page {1}", campaigns.Data.Count, page); foreach (MailChimp.Types.Campaign.CampaignsDataItem campaign in campaigns.Data) { try { //todo: for unsubscribers and opens: var stats = m_oMcApi.CampaignStats(campaign.ID); var clickStats = m_oMcApi.CampaignClickStats(campaign.ID); //ms_oLog.Debug("campaign {0},num of stats {1}", campaign.Title, clickStats.Count); foreach (string url in clickStats.Keys) { MailChimp.Types.Campaign.ReportData.ClickDetailAIM emails = m_oMcApi.CampaignClickDetailAIM(campaign.ID, url); MailChimp.Types.Campaign.Stats.ClickStats clicks = clickStats[url]; if (emails.Data.Count == 0) { // ms_oLog.Debug("campaign {0} with 0 clicks on url {1}", campaign.Title, url); campaignClickStats.AddStat( campaign.Title, url, "", campaign.SendTime.Value.ToString("yyyy-MM-dd"), campaign.EmailsSent, clicks.Clicks ); } // if foreach (var email in emails.Data) { //ms_oLog.Debug( // "{0} campaign: {1} sent mails: {2} num of clicks(stats): {3} num of clicks(email): {4} emails clicks: {5}", // url, campaign.Title, campaign.EmailsSent, clicks.Clicks, email.Clicks, email.Email); campaignClickStats.AddStat(campaign.Title, url, email.Email, campaign.SendTime.Value.ToString("yyyy-MM-dd"), campaign.EmailsSent, clicks.Clicks); } // for each } // for each } catch (Exception ex) { ms_oLog.Debug(ex, "can't load campaign stats for campaign {0}", campaign.ID); } // try } // for each page++; } while (campaigns.Data.Count > 0 && page < maxNumOfPages); /* * campaignClickStats.AddStat("test", "test", "test", DateTime.Now.ToString("yyyy-MM-dd"), 0, 0); * campaignClickStats.AddStat("test2", "test2", "test2", DateTime.Now.ToString("yyyy-MM-dd"), 0, 0); */ if (campaignClickStats.GetCampaignClickStatListCount() > 0) { try { SerializeToXml(campaignClickStats); } catch (Exception ex) { ms_oLog.Alert(ex, "Can't serialize to file."); } // try DbCmd.DeleteCampaignClickStatsTable(); var campaignClickStatsList = campaignClickStats.GetCampaignClickStatsList(); foreach (var campaignClickStat in campaignClickStatsList) { DbCmd.AddCampaignClickStat(campaignClickStat); } } // if } // LoadClickStatsToDb