Inheritance: FuelSDK.Subscriber
 protected FuelReturn ProcessAddSubscriberToList(string EmailAddress, string SubscriberKey, List<int> ListIDs)
 {
     ET_Subscriber sub = new ET_Subscriber();
     sub.EmailAddress = EmailAddress;
     if (SubscriberKey != null)
         sub.SubscriberKey = SubscriberKey;
     List<ET_SubscriberList> lLists = new List<ET_SubscriberList>();
     foreach (int listID in ListIDs)
     {
         ET_SubscriberList feList = new ET_SubscriberList();
         feList.ID = listID;
         lLists.Add(feList);
     }
     sub.AuthStub = this;
     sub.Lists = lLists.ToArray();
     PostReturn prAddSub = sub.Post();
     if (!prAddSub.Status && prAddSub.Results.Length > 0 && prAddSub.Results[0].ErrorCode == 12014)
     {
         return sub.Patch();
     }
     else
     {
         return prAddSub;
     }
 }
        static void TestET_Subscriber()
        {
            ET_Client myclient = new ET_Client();

            Console.WriteLine("--- Testing Subscriber ---");
            string SubscriberTestEmail = "*****@*****.**";

            Console.WriteLine("\n Create Subscriber");
            ET_Subscriber postSub = new ET_Subscriber();
            postSub.AuthStub = myclient;
            postSub.EmailAddress = SubscriberTestEmail;
            postSub.Attributes = new FuelSDK.ET_ProfileAttribute[] {new ET_ProfileAttribute(){ Name= "First Name", Value = "ExactTarget Example"} };
            PostReturn postResponse = postSub.Post();
            Console.WriteLine("Post Status: " + postResponse.Status.ToString());
            Console.WriteLine("Message: " + postResponse.Message.ToString());
            Console.WriteLine("Code: " + postResponse.Code.ToString());
            Console.WriteLine("Results Length: " + postResponse.Results.Length);

            if (postResponse.Results.Length > 0)
            {
                Console.WriteLine("--NewID: " + postResponse.Results[0].NewID.ToString());
                foreach (ET_ProfileAttribute attr in ((ET_Subscriber)postResponse.Results[0].Object).Attributes) 
                {
                    Console.WriteLine("Name: " + attr.Name + ", Value: " + attr.Value);
                }
            }

            Console.WriteLine("\n Retrieve newly created Subscriber");
            ET_Subscriber getSub = new ET_Subscriber();
            getSub.AuthStub = myclient;
            getSub.Props = new string[] { "SubscriberKey", "EmailAddress", "Status" };
            getSub.SearchFilter = new SimpleFilterPart() { Property = "SubscriberKey", SimpleOperator = SimpleOperators.equals, Value = new string[] { SubscriberTestEmail } };
            GetReturn getResponse = getSub.Get();
            Console.WriteLine("Get Status: " + getResponse.Status.ToString());
            Console.WriteLine("Message: " + getResponse.Message.ToString());
            Console.WriteLine("Code: " + getResponse.Code.ToString());
            Console.WriteLine("Results Length: " + getResponse.Results.Length);

            foreach (ET_Subscriber sub in getResponse.Results) {
                Console.WriteLine("--EmailAddress: " + sub.EmailAddress + " Status: " + sub.Status.ToString());
            }


            Console.WriteLine("\n Update Subscriber");
            ET_Subscriber patchSub = new ET_Subscriber();
            patchSub.AuthStub = myclient;
            patchSub.EmailAddress = SubscriberTestEmail;
            patchSub.Status = SubscriberStatus.Unsubscribed;
            patchSub.Attributes = new FuelSDK.ET_ProfileAttribute[] { new ET_ProfileAttribute() { Name = "First Name", Value = "ExactTarget Example" } };
            PatchReturn pathResponse = patchSub.Patch();
            Console.WriteLine("Patch Status: " + pathResponse.Status.ToString());
            Console.WriteLine("Message: " + pathResponse.Message.ToString());
            Console.WriteLine("Code: " + pathResponse.Code.ToString());
            Console.WriteLine("Results Length: " + pathResponse.Results.Length);
            
            foreach (ResultDetail rd in pathResponse.Results){
                ET_Subscriber sub = (ET_Subscriber)rd.Object;
                Console.WriteLine("--EmailAddress: " + sub.EmailAddress + " Status: " + sub.Status.ToString());
            }

            Console.WriteLine("\n Retrieve Subscriber that should have status unsubscribed now");
            getResponse = getSub.Get();
            Console.WriteLine("Get Status: " + getResponse.Status.ToString());
            Console.WriteLine("Message: " + getResponse.Message.ToString());
            Console.WriteLine("Code: " + getResponse.Code.ToString());
            Console.WriteLine("Results Length: " + getResponse.Results.Length);

            foreach (ET_Subscriber sub in getResponse.Results)
            {
                Console.WriteLine("--EmailAddress: " + sub.EmailAddress + " Status: " + sub.Status.ToString());
            }

            Console.WriteLine("\n Delete Subscriber");
            ET_Subscriber deleteSub = new ET_Subscriber();
            deleteSub.AuthStub = myclient;
            deleteSub.EmailAddress = SubscriberTestEmail;
            DeleteReturn deleteResponse = deleteSub.Delete();
            Console.WriteLine("Delete Status: " + deleteResponse.Status.ToString());
            Console.WriteLine("Message: " + deleteResponse.Message.ToString());
            Console.WriteLine("Code: " + deleteResponse.Code.ToString());
            Console.WriteLine("Results Length: " + deleteResponse.Results.Length);

            Console.WriteLine("\n Retrieve Subscriber to confirm deletion");
            getResponse = getSub.Get();
            Console.WriteLine("Get Status: " + getResponse.Status.ToString());
            Console.WriteLine("Message: " + getResponse.Message.ToString());
            Console.WriteLine("Code: " + getResponse.Code.ToString());
            Console.WriteLine("Results Length: " + getResponse.Results.Length);

            foreach (ET_Subscriber sub in getResponse.Results)
            {
                Console.WriteLine("--EmailAddress: " + sub.EmailAddress + " Status: " + sub.Status.ToString());
            }           
        }
        // ------------------------------------------------------------
        // Name: SetBouncesToUnsubscribed
        // Abstract: Retrieve new customers
        // ------------------------------------------------------------
        public static void SetBouncesToUnsubscribed()
        {
            try
            {
                ET_Subscriber GetSubscriber = new ET_Subscriber();
                GetSubscriber.AuthStub = m_etcTDClient;
                GetSubscriber.Props = new string[] { "SubscriberKey", "EmailAddress", "Status" };
                //GetSubscriber.SearchFilter = new SimpleFilterPart() { Property = "EmailAddress", SimpleOperator = SimpleOperators.equals, Value = new string[] { "*****@*****.**" } };
                GetSubscriber.Attributes = new FuelSDK.ET_ProfileAttribute[] { new ET_ProfileAttribute() { Name = "Bounce Count", Value = "3" } };
                GetReturn GetResponse = GetSubscriber.Get();
                Console.WriteLine("Get Status: " + GetResponse.Status.ToString());
                Console.WriteLine("Message: " + GetResponse.Message.ToString());
                Console.WriteLine("Code: " + GetResponse.Code.ToString());
                Console.WriteLine("Results Length: " + GetResponse.Results.Length);

                foreach (ET_Subscriber sub in GetResponse.Results)
                {
                    Console.WriteLine("--EmailAddress: " + sub.EmailAddress + " Status: " + sub.Status.ToString());
                }
            }
            catch (Exception excError)
            {
                Console.WriteLine("Error: " + excError.ToString());
            }
        }
        static void TestET_ListSubscriber()
        {

            string NewListName = "CSharpSDKListSubscriber";
            string SubscriberTestEmail = "*****@*****.**";

            Console.WriteLine("--- Testing ListSubscriber ---");
            ET_Client myclient = new ET_Client();

            Console.WriteLine("\n Create List");
            ET_List postList = new ET_List();
            postList.AuthStub = myclient;
            postList.ListName = NewListName;
            PostReturn prList = postList.Post();

            if (prList.Status && prList.Results.Length > 0)
            {
                int newListID = prList.Results[0].Object.ID;

                Console.WriteLine("\n Create Subscriber on List");
                ET_Subscriber postSub = new ET_Subscriber();
                postSub.Lists = new ET_SubscriberList[] { new ET_SubscriberList() { ID = newListID } };
                postSub.AuthStub = myclient;
                postSub.EmailAddress = SubscriberTestEmail;
                postSub.Attributes = new FuelSDK.ET_ProfileAttribute[] { new ET_ProfileAttribute() { Name = "First Name", Value = "ExactTarget Example" } };
                PostReturn postResponse = postSub.Post();
                Console.WriteLine("Post Status: " + postResponse.Status.ToString());
                Console.WriteLine("Message: " + postResponse.Message.ToString());
                Console.WriteLine("Code: " + postResponse.Code.ToString());
                Console.WriteLine("Results Length: " + postResponse.Results.Length);


                if (!postResponse.Status)
                {
                    if (postResponse.Results.Length > 0 && postResponse.Results[0].ErrorCode == 12014)
                    {
                        // If the subscriber already exists in the account then we need to do an update.
                        //Update Subscriber On List 
                        Console.WriteLine("\n Update Subscriber to add to List");
                        PatchReturn patchResponse = postSub.Patch();
                        Console.WriteLine("Post Status: " + patchResponse.Status.ToString());
                        Console.WriteLine("Message: " + patchResponse.Message.ToString());
                        Console.WriteLine("Code: " + patchResponse.Code.ToString());
                        Console.WriteLine("Results Length: " + patchResponse.Results.Length);
                    }
                }

                Console.WriteLine("\n Retrieve all Subscribers on the List");
                ET_List_Subscriber getListSub = new ET_List_Subscriber();
                getListSub.AuthStub = myclient;
                getListSub.Props = new string[] { "ObjectID", "SubscriberKey", "CreatedDate", "Client.ID", "Client.PartnerClientKey", "ListID", "Status" };
                getListSub.SearchFilter = new SimpleFilterPart() { Property = "ListID", SimpleOperator = SimpleOperators.equals, Value = new string[] { newListID.ToString() } };
                GetReturn getResponse = getListSub.Get();
                Console.WriteLine("Get Status: " + getResponse.Status.ToString());
                Console.WriteLine("Message: " + getResponse.Message.ToString());
                Console.WriteLine("Code: " + getResponse.Code.ToString());
                Console.WriteLine("Results Length: " + getResponse.Results.Length);
                foreach (ET_List_Subscriber ResultListSub in getResponse.Results)
                {
                    Console.WriteLine("--ListID: " + ResultListSub.ID + ", SubscriberKey(EmailAddress): " + ResultListSub.SubscriberKey);
                }
            }


            //Console.WriteLine("Retrieve Filtered ListSubscribers with GetMoreResults");
            //ET_ListSubscriber oe = new ET_ListSubscriber();
            //oe.authStub = myclient;
            //oe.SearchFilter = new SimpleFilterPart() { Property = "EventDate", SimpleOperator = SimpleOperators.greaterThan, DateValue = new DateTime[] { filterDate } };
            //oe.props = new string[] { "ObjectID", "SubscriberKey", "CreatedDate", "Client.ID", "Client.PartnerClientKey", "ListID", "Status" };
            //GetReturn oeGet = oe.Get();

            //Console.WriteLine("Get Status: " + oeGet.Status.ToString());
            //Console.WriteLine("Message: " + oeGet.Message.ToString());
            //Console.WriteLine("Code: " + oeGet.Code.ToString());
            //Console.WriteLine("Results Length: " + oeGet.Results.Length);
            //Console.WriteLine("MoreResults: " + oeGet.MoreResults.ToString());
            //// Since this could potentially return a large number of results, we do not want to print the results
            ////foreach (ET_ListSubscriber ListSubscriber in oeGet.Results)
            ////{
            ////    Console.WriteLine("SubscriberKey: " + ListSubscriber.SubscriberKey + ", EventDate: " + ListSubscriber.EventDate.ToString());
            ////}

            //while (oeGet.MoreResults)
            //{
            //    Console.WriteLine("Continue Retrieve Filtered ListSubscribers with GetMoreResults");
            //    oeGet = oe.GetMoreResults();
            //    Console.WriteLine("Get Status: " + oeGet.Status.ToString());
            //    Console.WriteLine("Message: " + oeGet.Message.ToString());
            //    Console.WriteLine("Code: " + oeGet.Code.ToString());
            //    Console.WriteLine("Results Length: " + oeGet.Results.Length);
            //    Console.WriteLine("MoreResults: " + oeGet.MoreResults.ToString());
            //}


            //The following request could potentially bring back large amounts of data if run against a production account	
            //Console.WriteLine("Retrieve All ListSubscribers with GetMoreResults");
            //ET_ListSubscriber oe = new ET_ListSubscriber();
            //oe.authStub = myclient;
            //oe.props = new string[] { "SendID", "SubscriberKey", "EventDate", "Client.ID", "EventType", "BatchID", "TriggeredSendDefinitionObjectID", "PartnerKey" };
            //GetResponse oeGetAll = oe.Get();

            //Console.WriteLine("Get Status: " + oeGetAll.Status.ToString());
            //Console.WriteLine("Message: " + oeGetAll.Message.ToString());
            //Console.WriteLine("Code: " + oeGetAll.Code.ToString());
            //Console.WriteLine("Results Length: " + oeGetAll.Results.Length);
            //Console.WriteLine("MoreResults: " + oeGetAll.MoreResults.ToString());
            //// Since this could potentially return a large number of results, we do not want to print the results
            ////foreach (ET_ListSubscriber ListSubscriber in oeGet.Results)
            ////{
            ////    Console.WriteLine("SubscriberKey: " + ListSubscriber.SubscriberKey + ", EventDate: " + ListSubscriber.EventDate.ToString());
            ////}

            //while (oeGetAll.MoreResults)
            //{
            //    oeGetAll = oe.GetMoreResults();
            //    Console.WriteLine("Get Status: " + oeGetAll.Status.ToString());
            //    Console.WriteLine("Message: " + oeGetAll.Message.ToString());
            //    Console.WriteLine("Code: " + oeGetAll.Code.ToString());
            //    Console.WriteLine("Results Length: " + oeGetAll.Results.Length);
            //    Console.WriteLine("MoreResults: " + oeGetAll.MoreResults.ToString());
            //}
        }
        // ------------------------------------------------------------
        // Name: UpdateConvertedProspects
        // Abstract: Retrieve subscribers from a list
        // ------------------------------------------------------------
        public static Dictionary<string, string> GetDuplicateSubscribers()
        {
            Dictionary<string, string> dctDuplicateSubscribers = new Dictionary<string, string>();
            Dictionary<string, string> dctSubscribers = new Dictionary<string, string>();
            Dictionary<string, string> dctAllSubscribers = new Dictionary<string, string>();
            try
            {
                string strCustomerNumber = "";
                string strSubscriberKey = "";
                string strEmail = "";

                // Get subscriber dates
                ET_Subscriber getSub = new ET_Subscriber();
                getSub.AuthStub = m_etcTDClient;
                getSub.Props = new string[] { "SubscriberKey", "EmailAddress" };
                GetReturn getResponse = getSub.Get();
                Console.WriteLine("Get Status: " + getResponse.Status.ToString());
                Console.WriteLine("Message: " + getResponse.Message.ToString());
                Console.WriteLine("Code: " + getResponse.Code.ToString());
                Console.WriteLine("Results Length: " + getResponse.Results.Length);
                while (getResponse.MoreResults == true)
                {

                    foreach (ET_Subscriber sub in getResponse.Results)
                    {
                        Console.WriteLine("SubscriberKey: " + sub.SubscriberKey);

                        // Add to our list
                        dctAllSubscribers.Add(sub.SubscriberKey, sub.EmailAddress);
                    }

                    getResponse = getSub.GetMoreResults();
                }

                foreach (KeyValuePair<string, string> entry in dctAllSubscribers)
                {
                    strSubscriberKey = entry.Key;
                    strEmail = entry.Value;
                    // Add to duplicates if email already exists
                    if (dctSubscribers.ContainsValue(strEmail) == true)
                    {
                        // Get customer number from duplicate if duplicate hasn't been logged
                        if (dctDuplicateSubscribers.ContainsValue(strEmail) == false)
                        {
                            strCustomerNumber = dctSubscribers.FirstOrDefault(x => x.Value == strEmail).Key;

                            // Add (both) duplicate entries
                            dctDuplicateSubscribers.Add(strSubscriberKey, strEmail);
                            dctDuplicateSubscribers.Add(strCustomerNumber, strEmail);
                        }
                        else
                        {
                            dctDuplicateSubscribers.Add(strSubscriberKey, strEmail);
                        }
                    }
                    else
                    {
                        // Add to our list
                        dctSubscribers.Add(strSubscriberKey, strEmail);
                    }
                }

            }
            catch (Exception excError)
            {
                // Display Error
                Console.WriteLine("Error: " + excError.ToString());
            }

            return dctDuplicateSubscribers;
        }
        // ------------------------------------------------------------
        // Name: UpdateConvertedProspects
        // Abstract: Retrieve subscribers from a list
        // ------------------------------------------------------------
        public static void SetVerifiedEmailStatus()
        {
            Dictionary<string, string> dctAllSubscribers = new Dictionary<string, string>();
            Dictionary<string, string> dctDataExtensionSubscribers = new Dictionary<string, string>();
            Dictionary<string, string> dctNewsletterListSubscribers = new Dictionary<string, string>();
            Dictionary<string, string> dctDENewsletterSubscribers = new Dictionary<string, string>();
            Dictionary<string, string> dctRemindersListSubscribers = new Dictionary<string, string>();
            Dictionary<string, string> dctDERemindersSubscribers = new Dictionary<string, string>();

            List<string> alstrValidSubscriberKeys = new List<string>();

            try
            {
                string strSubscriberKey = "";
                string strEmail = "";
                string strCustomerNumber = "";
                string strStatus = "";
                string strDEStatus = "";
                int intUpdateRecordCount = 0;
                // Data
                DateTime dtmCreatedDate = DateTime.Now;

                
                // Get subscriber dates
                ET_Subscriber getSub = new ET_Subscriber();
                getSub.AuthStub = m_etcTDClientShared;
                getSub.Props = new string[] { "SubscriberKey", "EmailAddress", "Status", "CreatedDate" };
                GetReturn getResponse = getSub.Get();
                
                Console.WriteLine("Get Status: " + getResponse.Status.ToString());
                Console.WriteLine("Message: " + getResponse.Message.ToString());
                Console.WriteLine("Code: " + getResponse.Code.ToString());
                Console.WriteLine("Results Length: " + getResponse.Results.Length);
                int intResults = getResponse.Results.Length;

                // Get all subscriber keys associated with active subscribers
                while (getResponse.MoreResults == true || intResults > 0)
                {
                    foreach (ET_Subscriber sub in getResponse.Results)
                    {
                        strStatus = sub.Status.ToString();
                        dctAllSubscribers.Add(sub.SubscriberKey, strStatus);
                        Console.WriteLine("Added EmailAddress: " + sub.EmailAddress + " Status: " + strStatus);
                        
                    }

                    getResponse = getSub.GetMoreResults();
                    intResults = getResponse.Results.Length;
                }
                

                // Get all customers and their 'VerifiedEmail' field from CustomerBaseDatabase
                Console.WriteLine("\n Retrieve All Rows from DataExtension");
                ET_DataExtensionRow deRowGet = new ET_DataExtensionRow();
                deRowGet.AuthStub = m_etcTDClientShared;
                deRowGet.DataExtensionName = "CustomerDatabase";
                deRowGet.Props = new string[] { "SubscriberKey", "VerifiedEmail" };
                GetReturn grRow = deRowGet.Get();
                Console.WriteLine("Get Status: " + grRow.Status.ToString());
                Console.WriteLine("Message: " + grRow.Message.ToString());
                Console.WriteLine("Code: " + grRow.Code.ToString());
                Console.WriteLine("Results Length: " + grRow.Results.Length);
                intResults = grRow.Results.Length;
                string x;
                while (grRow.MoreResults == true || intResults > 0)
                {
                    foreach (ET_DataExtensionRow column in grRow.Results)
                    {
                        strSubscriberKey = column.ColumnValues["SubscriberKey"];
                        strStatus = column.ColumnValues["VerifiedEmail"];

                        if (dctAllSubscribers.TryGetValue(strSubscriberKey, out x) == true)
                        {
                            dctDataExtensionSubscribers.Add(strSubscriberKey, strStatus);
                            Console.WriteLine("Added customer: " + strSubscriberKey);
                        }

                    }

                    grRow = deRowGet.GetMoreResults();
                    intResults = grRow.Results.Length;
                }            

                // Update statuses
                ET_DataExtensionRow deRowPatch = null;
                foreach (KeyValuePair<string, string> entry in dctDataExtensionSubscribers)
                {
                    strSubscriberKey = entry.Key;
                    strDEStatus = entry.Value;

                    // if our status = active, set to true
                    strStatus = dctAllSubscribers[strSubscriberKey];
                    if (strStatus.Equals("Active") == true)
                    {
                        strStatus = "True";
                    }
                    else
                    {
                        strStatus = "False";
                    }

                    // Is the status of our subscriber the same on the All Subscribers list as it is on the Data Extension?
                    if (strDEStatus.Equals(strStatus) == false)
                    {
                        intUpdateRecordCount += 1;
                        // No, update the verified email field
                        deRowPatch = new ET_DataExtensionRow();
                        deRowPatch.AuthStub = m_etcTDClientShared;
                        deRowPatch.DataExtensionCustomerKey = "CustomerDBKey";
                        deRowPatch.ColumnValues.Add("SubscriberKey", strSubscriberKey);
                        deRowPatch.ColumnValues.Add("VerifiedEmail", strStatus);
                        PatchReturn patchRowResponse = deRowPatch.Patch();
                        Console.WriteLine("Post Status: " + patchRowResponse.Status.ToString());
                        Console.WriteLine("Count: " + intUpdateRecordCount.ToString());
                    }
                }

                Console.WriteLine("Done editing email statuses!");
   
            }
            catch (Exception excError)
            {
                // Display Error
                Console.WriteLine("Error: " + excError.ToString());
            }
        }
        // ------------------------------------------------------------
        // Name: UpdateConvertedProspects
        // Abstract: Retrieve subscribers from a list
        // ------------------------------------------------------------
        public static Dictionary<string, string> UpdateConvertedProspects(Dictionary<string, string> dctSubscriberList, Dictionary<string, string> dctSubscriberKeys,
                                                                          List<string> alstrConvertedKey, List<string> alstrConvertedEmail, List<string> alstrConvertedSubscriberKey)
        {
            Dictionary<string, string> dctSubscribers = new Dictionary<string, string>();

            try
            {
                string strSubscriberKey = "";
                string strEmail = "";
                string strCustomerNumber = "";

                // Loop through each converted prospect
                foreach (KeyValuePair<string, string> entry in dctSubscriberList)
                {
                    // Data
                    DateTime dtmCreatedDate = DateTime.Now;

                    // Get customer number and email
                    strCustomerNumber = entry.Key;
                    strEmail = entry.Value;

                    // Get subscriber key based on that email
                    strSubscriberKey = dctSubscriberKeys[strEmail];

                    // Get subscriber dates
                    ET_Subscriber getSub = new ET_Subscriber();
                    getSub.AuthStub = m_etcTDClient;
                    getSub.Props = new string[] { "SubscriberKey", "EmailAddress", "Status", "CreatedDate" };
                    getSub.SearchFilter = new SimpleFilterPart() { Property = "SubscriberKey", SimpleOperator = SimpleOperators.equals, Value = new string[] { strSubscriberKey } };
                    GetReturn getResponse = getSub.Get();
                    Console.WriteLine("Get Status: " + getResponse.Status.ToString());
                    Console.WriteLine("Message: " + getResponse.Message.ToString());
                    Console.WriteLine("Code: " + getResponse.Code.ToString());
                    Console.WriteLine("Results Length: " + getResponse.Results.Length);

                    foreach (ET_Subscriber sub in getResponse.Results)
                    {
                        Console.WriteLine("--EmailAddress: " + sub.EmailAddress + " Status: " + sub.Status.ToString());
                        dtmCreatedDate = sub.CreatedDate;
                    }

                    // Create subscriber with same information but correct SubscriberKey
                    Console.WriteLine("\n Create Subscriber");
                    ET_Subscriber postSub = new ET_Subscriber();
                    postSub.AuthStub = m_etcTDClient;
                    postSub.EmailAddress = strEmail;
                    postSub.SubscriberKey = strCustomerNumber;
                    postSub.CreatedDate = dtmCreatedDate;
                    PostReturn postResponse = postSub.Post();
                    Console.WriteLine("Post Status: " + postResponse.Status.ToString());
                    Console.WriteLine("Message: " + postResponse.Message.ToString());
                    Console.WriteLine("Code: " + postResponse.Code.ToString());
                    Console.WriteLine("Results Length: " + postResponse.Results.Length);

                    // Add Subscriber to Newsletter and Reminders List
                    // Newsletter ListID: 2726; Reminders ListID: 2727  
                    FuelReturn hrAddSub = m_etcTDClient.AddSubscribersToList(strEmail, strCustomerNumber, new List<int>() { 2726 });
                    Console.WriteLine("Helper Status: " + hrAddSub.Status.ToString());
                    Console.WriteLine("Message: " + hrAddSub.Message.ToString());
                    Console.WriteLine("Code: " + hrAddSub.Code.ToString());

                    hrAddSub = m_etcTDClient.AddSubscribersToList(strEmail, strCustomerNumber, new List<int>() { 2727 });
                    Console.WriteLine("Helper Status: " + hrAddSub.Status.ToString());
                    Console.WriteLine("Message: " + hrAddSub.Message.ToString());
                    Console.WriteLine("Code: " + hrAddSub.Code.ToString());

                    // Delete old subscriber
                    ET_Subscriber deleteSub = new ET_Subscriber();
                    deleteSub.AuthStub = m_etcTDClient;
                    deleteSub.EmailAddress = strEmail;
                    deleteSub.SubscriberKey = strSubscriberKey;
                    DeleteReturn deleteResponse = deleteSub.Delete();
                    Console.WriteLine("Delete Status: " + deleteResponse.Status.ToString());
                    Console.WriteLine("Message: " + deleteResponse.Message.ToString());
                    Console.WriteLine("Code: " + deleteResponse.Code.ToString());
                    Console.WriteLine("Results Length: " + deleteResponse.Results.Length);

                    // Add to array list
                    alstrConvertedKey.Add(strCustomerNumber);
                    alstrConvertedEmail.Add(strEmail);
                    alstrConvertedSubscriberKey.Add(strSubscriberKey);
                }

            }
            catch (Exception excError)
            {
                // Display Error
                Console.WriteLine("Error: " + excError.ToString());
            }

            return dctSubscribers;
        }
        // ------------------------------------------------------------
        // Name: RetrieveSubscribersFromList
        // Abstract: Retrieve subscribers from a list
        // ------------------------------------------------------------
        public static Dictionary<string, string> RetrieveSubscribersFromList()
        {
            Dictionary<string, string> dctSubscribers = new Dictionary<string, string>();

            try
            {
                int intIndex = 0;
                string strSubscriberKey = "";

                Console.WriteLine("\n Retrieve all Subscribers on the List");
                ET_List_Subscriber getListSub = new ET_List_Subscriber();
                getListSub.AuthStub = m_etcTDClient;
                getListSub.Props = new string[] { "ObjectID", "SubscriberKey", "CreatedDate", "Client.ID", "Client.PartnerClientKey", "ListID", "Status" };
                getListSub.SearchFilter = new SimpleFilterPart() { Property = "ListID", SimpleOperator = SimpleOperators.equals, Value = new string[] { "3075" } };
                GetReturn getResponse = getListSub.Get();
                Console.WriteLine("Get Status: " + getResponse.Status.ToString());
                Console.WriteLine("Message: " + getResponse.Message.ToString());
                Console.WriteLine("Code: " + getResponse.Code.ToString());
                Console.WriteLine("Results Length: " + getResponse.Results.Length);

                ET_Subscriber getSub = new ET_Subscriber();
                getSub.AuthStub = m_etcTDClient;
                getSub.Props = new string[] { "SubscriberKey", "EmailAddress", "Status" };

                // Loop through subscribers on the list and add their keys to our array
                foreach (ET_List_Subscriber ResultListSub in getResponse.Results)
                {
                    // Subscriber Key
                    strSubscriberKey = ResultListSub.SubscriberKey;

                    // Get information on that subscriber
                    getSub.SearchFilter = new SimpleFilterPart() { Property = "SubscriberKey", SimpleOperator = SimpleOperators.equals, Value = new string[] { strSubscriberKey } };
                    GetReturn getSubResponse = getSub.Get();

                    foreach (ET_Subscriber sub in getSubResponse.Results)
                    {
                        if (dctSubscribers.TryGetValue(sub.EmailAddress.ToUpper(), out strSubscriberKey) == false && dctSubscribers.ContainsKey(sub.EmailAddress.ToUpper()) == false)
                        {
                            intIndex += 1;
                            if (intIndex == 1323)
                            {
                                Console.WriteLine("EHY");
                            }
                            dctSubscribers.Add(sub.EmailAddress.ToUpper(), ResultListSub.SubscriberKey);
                            Console.WriteLine("Count: " + intIndex.ToString() + "; Subscriber Key: " + ResultListSub.SubscriberKey);
                        }
                    }
                }



            }
            catch (Exception excError)
            {
                // Display Error
                Console.WriteLine("Error: " + excError.ToString());
            }

            return dctSubscribers;
        }
        // ------------------------------------------------------------
        // Name: Test_AddSubscriberToList
        // Abstract: Test -- Add subscriber to list
        // ------------------------------------------------------------
        public static void Test_AddSubscriberToList()
        {

            string NewListName = "CSharpSDKAddSubscriberToList";
            string SubscriberTestEmail = "*****@*****.**";
            String strSubscriberKey = "TestTestTest";

            Console.WriteLine("--- Testing AddSubscriberToList ---");

            Console.WriteLine("\n Create List");
            ET_List postList = new ET_List();
            postList.AuthStub = m_etcTDClient;
            postList.ListName = NewListName;

            // Create the new list in ET
            PostReturn prList = postList.Post();

            if (prList.Status && prList.Results.Length > 0)
            {
                // Get List ID
                int newListID = prList.Results[0].Object.ID;

                Console.WriteLine("\n Create Subscriber on List");
                FuelReturn hrAddSub = m_etcTDClient.AddSubscribersToList(SubscriberTestEmail, strSubscriberKey, new List<int>() { newListID });
                Console.WriteLine("Helper Status: " + hrAddSub.Status.ToString());
                Console.WriteLine("Message: " + hrAddSub.Message.ToString());
                Console.WriteLine("Code: " + hrAddSub.Code.ToString());

                Console.WriteLine("\n Retrieve all Subscribers on the List");
                ET_List_Subscriber getListSub = new ET_List_Subscriber();
                getListSub.AuthStub = m_etcTDClient;
                getListSub.Props = new string[] { "ObjectID", "SubscriberKey", "CreatedDate", "Client.ID", "Client.PartnerClientKey", "ListID", "Status" };
                getListSub.SearchFilter = new SimpleFilterPart() { Property = "ListID", SimpleOperator = SimpleOperators.equals, Value = new string[] { newListID.ToString() } };
                GetReturn getResponse = getListSub.Get();
                Console.WriteLine("Get Status: " + getResponse.Status.ToString());
                Console.WriteLine("Message: " + getResponse.Message.ToString());
                Console.WriteLine("Code: " + getResponse.Code.ToString());
                Console.WriteLine("Results Length: " + getResponse.Results.Length);
                foreach (ET_List_Subscriber ResultListSub in getResponse.Results)
                {
                    Console.WriteLine("--ListID: " + ResultListSub.ListID + ", SubscriberKey(EmailAddress): " + ResultListSub.SubscriberKey);
                }

                Console.WriteLine("\n Delete List");
                postList.ID = newListID;

                // Deletes the list
                DeleteReturn drList = postList.Delete();
                Console.WriteLine("Delete Status: " + drList.Status.ToString());

                // Delete the subscriber
                ET_Subscriber deleteSubscriber = new ET_Subscriber();
                deleteSubscriber.AuthStub = m_etcTDClient;
                deleteSubscriber.EmailAddress = SubscriberTestEmail;
                deleteSubscriber.SubscriberKey = strSubscriberKey;
                //Console.WriteLine("Subscriber's Customer Key: " + deleteSubscriber.CustomerKey.ToString() + "; Subscriber Key: " + deleteSubscriber.SubscriberKey);
                DeleteReturn deleteResponse = deleteSubscriber.Delete();
                Console.WriteLine("Delete Status: " + deleteResponse.Status.ToString());
                Console.WriteLine("Message: " + deleteResponse.Message.ToString());
                Console.WriteLine("Code: " + deleteResponse.Code.ToString());
                Console.WriteLine("Results Length: " + deleteResponse.Results.Length);
            }
        }
        // ------------------------------------------------------------
        // Name: GetSubscriberEmails
        // Abstract: Get subscriber keys and emails
        // ------------------------------------------------------------
        public static Dictionary<string, string> GetSubscriberEmails()
        {
            Dictionary<string, string> dctAllSubscribers = new Dictionary<string, string>();

            try
            {
                ET_Subscriber getSub = new ET_Subscriber();
                getSub.AuthStub = m_etcTDClientShared;
                getSub.Props = new string[] { "SubscriberKey", "EmailAddress" };
                GetReturn getResponse = getSub.Get();

                Console.WriteLine("Get Status: " + getResponse.Status.ToString());
                Console.WriteLine("Message: " + getResponse.Message.ToString());
                Console.WriteLine("Code: " + getResponse.Code.ToString());
                Console.WriteLine("Results Length: " + getResponse.Results.Length);
                int intResults = getResponse.Results.Length;

                // Get all subscriber keys associated with active subscribers
                while (getResponse.MoreResults == true || intResults > 0)
                {
                    foreach (ET_Subscriber sub in getResponse.Results)
                    {
                        dctAllSubscribers.Add(sub.SubscriberKey, sub.EmailAddress);
                    }

                    getResponse = getSub.GetMoreResults();
                    intResults = getResponse.Results.Length;
                }
            }
            catch (Exception excError)
            {
                // Display Error
                Console.WriteLine("Error: " + excError.ToString());
            }

            return dctAllSubscribers;
        }
        public void Send()
        {
            ///////////////////////////////////////////////////////////////////
            //
            // setup the client stub, and add requisite
            // parameters to html body
            //
            ///////////////////////////////////////////////////////////////////

            ET_Client client = CreateClient();
            Body += "\r\nThis email was sent by:\r\n%%Member_Busname%%\r\n%%Member_Addr%%\r\n%%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%";

            ///////////////////////////////////////////////////////////////////
            //
            // use emails to setup the list of subscribers
            //
            ///////////////////////////////////////////////////////////////////

            List<ET_Subscriber> subscribers = new List<ET_Subscriber>();

            foreach (string recipient in To)
            {
                ET_Subscriber subscriber = new ET_Subscriber();
                subscriber.EmailAddress = recipient;
                subscriber.SubscriberKey = recipient;

                subscribers.Add(subscriber);
            }

            ///////////////////////////////////////////////////////////////////
            //
            // create email within ExactTarget email list
            //
            ///////////////////////////////////////////////////////////////////

            ET_Email email = new ET_Email();
            email.AuthStub = client;
            email.Name = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
            email.Subject = Subject;
            email.HTMLBody = Body.Replace("\r\n", "<br>");
            email.TextBody = Regex.Replace(Body, "<.*?>", string.Empty);
            email.EmailType = "html";

            PostReturn results = email.Post();

            ///////////////////////////////////////////////////////////////////
            //
            // create triggered email within ExactTarget triggered email list
            //
            ///////////////////////////////////////////////////////////////////

            ET_TriggeredSend create = new ET_TriggeredSend();
            create.AuthStub = client;
            create.Name = email.Name;
            create.AutoAddSubscribers = true;
            create.AutoAddSubscribersSpecified = true;
            create.List = new ET_List() { ID = 228 };
            create.CustomerKey = Convert.ToString(Guid.NewGuid());
            create.Email = new ET_Email() { ID = results.Results[0].NewID };
            create.SendClassification = new ET_SendClassification() { CustomerKey = "Default Commercial" };

            create.Post();

            ///////////////////////////////////////////////////////////////////
            //
            // patch triggered email (to set active)
            //
            ///////////////////////////////////////////////////////////////////

            ET_TriggeredSend update = new ET_TriggeredSend();
            update.AuthStub = client;
            update.CustomerKey = create.CustomerKey;
            update.TriggeredSendStatus = TriggeredSendStatusEnum.Active;

            update.Patch();

            ///////////////////////////////////////////////////////////////////
            //
            // send triggered email
            //
            ///////////////////////////////////////////////////////////////////

            ET_TriggeredSend send = new ET_TriggeredSend();
            send.AuthStub = client;
            send.CustomerKey = update.CustomerKey;
            send.Subscribers = subscribers.ToArray();

            send.Send();
        }