/// <summary>
        /// Retrieves the lists.
        /// </summary>
        /// <returns></returns>
        public virtual NameValueCollection RetrieveLists()
        {
            var output = new NameValueCollection();
            try
            {

                // input parameters
                var listInput = new listsInput(_mailChimpSettings.ApiKey);

                // execute the request
                var cmd = new lists(listInput);
                listsOutput listOutput = cmd.Execute();

                if (listOutput != null && listOutput.result != null && listOutput.result.total > 0)
                {
                    foreach (listsResults.DataItem item in listOutput.result.data)
                    {
                        output.Add(item.name, item.id);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Debug(e.Message, e);
            }
            return output;
        }
        /// <summary>
        /// Retrieves the lists.
        /// </summary>
        /// <returns></returns>
        public virtual NameValueCollection RetrieveLists()
        {
            var output = new NameValueCollection();

            try
            {
                // input parameters
                var listInput = new listsInput(_mailChimpSettings.ApiKey);

                // execute the request
                var         cmd        = new lists(listInput);
                listsOutput listOutput = cmd.Execute();

                if (listOutput != null && listOutput.result != null && listOutput.result.total > 0)
                {
                    foreach (listsResults.DataItem item in listOutput.result.data)
                    {
                        output.Add(item.name, item.id);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Debug(e.Message, e);
            }
            return(output);
        }
        public ActionResult Lists()
        {
            listsInput listIn = new listsInput(apikey);
            PerceptiveMCAPI.Methods.lists li = new PerceptiveMCAPI.Methods.lists(listIn);
            listsOutput liOut = li.Execute();

            return View(liOut.result);
        }
    // A real simple request (using all default settings)
    public void lists_method()
    {
        // input parameters, using default apikey
        listsInput input = new listsInput(MCAPISettings.default_apikey);
        // execution
        lists cmd = new lists(input);
        listsOutput output = cmd.Execute();
        // format output (Assuming a User control named show_lists)

        //show_lists1.Display(output);
    }
Example #5
0
        /// <summary>
        /// Gets the mail chimp lists.
        /// </summary>
        /// <param name="apikey">The apikey.</param>
        /// <returns></returns>
        public List <listsResults.DataItem> GetMailChimpLists(string apikey)
        {
            //todo:pass
            listsInput  input  = new listsInput(apikey);
            lists       cmd    = new lists(input);
            listsOutput output = cmd.Execute();

            if (output.api_ErrorMessages.Count > 0)
            {
                StringBuilder sbErrDetail = new StringBuilder();
                foreach (var apiErrorMessage in output.api_ErrorMessages)
                {
                    sbErrDetail.AppendLine(string.Format("error code:{0},error msg:{1}", apiErrorMessage.code,
                                                         apiErrorMessage.error));
                }
                string errMsg = string.Format("apikey:{4}\r\n{0}{1}{2}{3}", output.api_Request, output.api_Response,     // raw data
                                              sbErrDetail.ToString(), output.api_ValidatorMessages, apikey);
                //int Event_id = 5011;
                //EventLog.WriteEntry(InfoHubEventLog.LogSource, errMsg, EventLogEntryType.Warning, Event_id, Category);
                return(new List <listsResults.DataItem>());
            }
            return(output.result.data);
        }
Example #6
0
        public Dictionary<String, String> getListsFromApi()
        {
            var listsInput = new listsInput(MailChimpSettings.ApiKey);
            var listsCmd = new lists(listsInput);

            var answer = listsCmd.Execute();

            var lists = new Dictionary<String, String>();
            foreach (var result in answer.result)
            {
                lists.Add(result.id, result.name);
            }

            return lists;
        }
        private void btnSync_Click(object sender, EventArgs e)
        {
            if (this.SelectedItems.Count == 0)
            {
                MessageBox.Show("請先選擇電子報名單。");
                return;
            }

            listsInput input = new listsInput(this.MailChimp_API_Key);
            lists cmd = new lists();
            listsOutput output = cmd.Execute(input);
            List<string> lists_duplicated = new List<string>();
            this.dicMailChimpLists.Clear();
            if (output != null)
            {
                if (output.result != null)
                {
                    foreach (var listsResult in output.result)
                    {
                        if (!dicMailChimpLists.ContainsKey(listsResult.name))
                        {
                            dicMailChimpLists.Add(listsResult.name, new McList()
                            {
                                ListId = listsResult.id,
                                ListName = listsResult.name,
                                MemberCount = listsResult.member_count,
                                UnsubscribeCount = listsResult.unsubscribe_count
                            });
                        }
                        else
                        {
                            if (this.SelectedItems.ContainsKey(listsResult.name))
                                lists_duplicated.Add(listsResult.name);
                        }
                    }
                }
            }
            lists_duplicated = lists_duplicated.Distinct().ToList();
            if (lists_duplicated.Count > 0)
            {
                MessageBox.Show(string.Format("下列 MailChimp Lists 名稱重覆,請先移除重覆之 MailChimp Lists:\n\n{0}", string.Join(",", lists_duplicated.Select(x => x))));
                return;
            }
            List<string> lists_NoneMailChimp = new List<string>();
            this.SelectedItems.Keys.ToList().ForEach((x) =>
            {
                if (!this.dicMailChimpLists.ContainsKey(x))
                    lists_NoneMailChimp.Add(x);
            });
            if (lists_NoneMailChimp.Count > 0)
            {
                MessageBox.Show(string.Format("下列電子報名單不存在於 MailChimp Lists,請先在 MailChimp 中建立:\n\n{0}", string.Join(",", lists_NoneMailChimp.Select(x => x))));
                return;
            }

            this.circularProgress.Visible = true;
            this.circularProgress.IsRunning = true;
            Task task = Task.Factory.StartNew(() =>
            {
                this.TeacherTags = this.GetTeacherTags();
                this.StudentTags = this.GetStudentTags();

                List<string> TeacherIDs = new List<string>();
                List<string> StudentIDs = new List<string>();
                this.TeacherTags.Values.ToList().ForEach(x => TeacherIDs.AddRange(x));
                this.StudentTags.Values.ToList().ForEach(x => StudentIDs.AddRange(x));

                this.dicTeachers = this.GetTeachersByIDs(TeacherIDs.Distinct().ToList());
                this.dicStudents = this.GetStudentsByIDs(StudentIDs.Distinct().ToList());

                foreach (string key in this.SelectedItems.Keys)
                {
                    listBatchSubscribe_method(this.SelectedItems[key]);
                }
            });
            task.ContinueWith((x) =>
            {
                if (x.Exception != null)
                    MessageBox.Show(x.Exception.InnerException.Message);
                else
                    MessageBox.Show("同步完成。");

                this.circularProgress.IsRunning = false;
                this.circularProgress.Visible = false;
            }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }