Exemplo n.º 1
0
 public void show_list_details()
 {
     Console.WriteLine("Connecting to: " + this.api.getUrl());
     MCList[] lists = this.api.lists();
     foreach (MCList list in lists)
     {
         Console.WriteLine("\tID: " + list.id + " - " + list.name);
         Console.WriteLine("\tList Size: " + list.member_count);
         MCMergeVar[] vars = this.api.listMergeVars(list.id);
         Console.WriteLine("\tMerge Vars:");
         foreach (MCMergeVar var in vars)
         {
             Console.WriteLine("\t\t" + var.name + " - " + var.tag + " - " + var.req);
         }
         Console.WriteLine("\tInterest Groups:");
         try {
             MCInterestGroups ig = this.api.listInterestGroups(list.id);
             Console.WriteLine("\t\t" + ig.name + " - " + ig.form_field);
             foreach (string group in ig.groups)
             {
                 Console.WriteLine("\t\t\t" + group);
             }
         }catch (Exception) {
             Console.WriteLine("\t\tInterest Groups not or not configured.");
         }
         Console.WriteLine("\n");
     }
 }            //show_list_details
        /// <summary>
        /// Used when binding the lists to the MailChimp actual subscribers.  It will use the
        /// API to dynamically query each potential subscriber against each configured list.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void dlLists_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                MailChimpLookup item = new MailChimpLookup(e.Item.DataItem as Lookup);

                if (item.ImageUrl != string.Empty)
                {
                    Image image = e.Item.FindControl("imgBG") as Image;
                    image.ImageUrl = item.ImageUrl;
                }
                else
                {
                    Literal itemName = e.Item.FindControl("liListName") as Literal;
                    itemName.Text = item.Name;
                }

                ImageButton btnSubscribe = e.Item.FindControl("btnSubscribe") as ImageButton;
                btnSubscribe.CommandName     = "Subscribe";
                btnSubscribe.CommandArgument = item.ListID;

                ImageButton btnUnsubscribe = e.Item.FindControl("btnUnsubscribe") as ImageButton;
                btnUnsubscribe.CommandName     = "Unsubscribe";
                btnUnsubscribe.CommandArgument = item.ListID;

                LinkButton lbSaveGroups = e.Item.FindControl("lbSaveGroups") as LinkButton;
                lbSaveGroups.CommandName     = "SaveGroups";
                lbSaveGroups.CommandArgument = item.ListID;

                CheckBoxList cblGroups = e.Item.FindControl("cblGroups") as CheckBoxList;

                try
                {
                    // Create a checkbox for each Interest group if MC Groups is enabled.
                    if (EnableMCGroupsSetting)
                    {
                        lbSaveGroups.Visible = false;
                        try
                        {
                            MCInterestGroups mcGroups = api.listInterestGroups(item.ListID);
                            cblGroups.Visible       = true;
                            cblGroups.RepeatColumns = (MaxColumnsSetting) ? NumRowsColsSetting : (mcGroups.groups.Count() + NumRowsColsSetting - 1) / NumRowsColsSetting;
                            cblGroups.DataSource    = mcGroups.groups;
                            cblGroups.DataBind();
                        }
                        catch (XmlRpcFaultException ex)
                        {
                            if (ex.FaultCode != MailChimpErrorCodes.List_InterestGroups_NotEnabled)
                            {
                                AddMsg(string.Format(" {0}: {1} (err:{2})", item.Name, ex.FaultString, ex.FaultCode));
                            }
                        }
                    }

                    // Try to determine if the email address is subscribed/unsubscribed from the MailChimp list
                    MCMemberInfo info = api.listMemberInfo(item.ListID, GetPerson().Emails.FirstActive);

                    // Set the user's groups if "MailChimp groups" is enabled.
                    if (EnableMCGroupsSetting)
                    {
                        lbSaveGroups.Visible = true;
                        // now check the interests that are selected for this user
                        string interests = (from m in info.merges where m.tag == "INTERESTS" select m).FirstOrDefault().val;
                        if (!string.IsNullOrEmpty(interests))
                        {
                            foreach (ListItem interestCheckbox in cblGroups.Items)
                            {
                                if (interests.Contains(interestCheckbox.Value))
                                {
                                    interestCheckbox.Selected = true;
                                }
                            }
                        }
                    }

                    string hoverInfo = string.Format(" {0}: {1} on {2} EST/EDT", item.Name, info.status, info.timestamp);
                    if ("subscribed".Equals(info.status))
                    {
                        btnUnsubscribe.ToolTip = hoverInfo;
                        btnUnsubscribe.Visible = true;
                    }
                    else
                    {
                        btnSubscribe.ToolTip = hoverInfo;
                        btnSubscribe.Visible = true;
                    }
                }
                catch (XmlRpcFaultException ex)
                {
                    if (ex.FaultCode == MailChimpErrorCodes.Email_NotExists)
                    {
                        btnSubscribe.Visible = true;
                    }
                    else if (ex.FaultCode == MailChimpErrorCodes.List_NotSubscribed)
                    {
                        btnSubscribe.ToolTip = "Person no longer subscribed.";
                        btnSubscribe.Visible = true;
                    }
                    else
                    {
                        AddMsg(string.Format(" {0}: {1} (err:{2})", item.Name, ex.FaultString, ex.FaultCode));
                    }
                }
            }
        }