Пример #1
0
        public override DataTableStore GetDataTable(DataTableStore dt)
        {
            dt.AddIdentifierColumn(typeof(string));

            var uriHelper = new MailChimpUriHelper(APIKey);
            var mapping   = new DataSchemaMapping(SchemaMap, Side);
            var schema    = MailChimpDataSchema.MailChimpListSchema();

            helper.SetAuthorizationHeader(APIKey);
            var result = helper.GetRequestAsJson(uriHelper.ListServiceUrl);

            if (result["lists"] != null)
            {
                foreach (var item_row in result["lists"])
                {
                    var newRow = dt.NewRow();

                    foreach (DataSchemaItem item in SchemaMap.GetIncludedColumns())
                    {
                        string columnName = mapping.MapColumnToDestination(item);

                        var schemaItem = schema[columnName];

                        if (schemaItem.IsSubValue)
                        {
                            foreach (var six in item_row[schemaItem.ObjectName])
                            {
                                foreach (var sub_item in item_row[schemaItem.ObjectName].Children <JProperty>())
                                {
                                    if (sub_item.Name.Equals(schemaItem.FieldName))
                                    {
                                        newRow[item.ColumnName] = DataSchemaTypeConverter.ConvertTo(sub_item.Value, item.DataType);
                                    }
                                }
                            }
                        }
                        else
                        {
                            newRow[item.ColumnName] = DataSchemaTypeConverter.ConvertTo(item_row[schemaItem.FieldName], item.DataType);
                        }
                    }

                    if (dt.Rows.AddWithIdentifier(newRow, DataSchemaTypeConverter.ConvertTo <string>(item_row["id"])) == DataTableStore.ABORT)
                    {
                        break;
                    }
                }
            }

            return(dt);
        }
        public override DataTableStore GetDataTable(DataTableStore dt, DataTableKeySet keyset)
        {
            dt.AddIdentifierColumn(typeof(string));

            var uriHelper        = new MailChimpUriHelper(APIKey);
            var mapping          = new DataSchemaMapping(SchemaMap, Side);
            var schema           = MailChimpDataSchema.MailChimpMemberSchema();
            var hash_helper      = new HashHelper(HashHelper.HashType.MD5);
            var included_columns = SchemaMap.GetIncludedColumns();

            helper.SetAuthorizationHeader(APIKey);

            var target_index = mapping.MapColumnToDestination(keyset.KeyColumn);

            foreach (var key in keyset.KeyValues)
            {
                var index = key;
                if (target_index.Equals("email_address"))
                {
                    index = hash_helper.GetHashAsString(DataSchemaTypeConverter.ConvertTo <string>(key)).ToLower();
                }

                try
                {
                    var result = helper.GetRequestAsJson($"{uriHelper.ListServiceUrl}/{ListId}/members/{index}");

                    var newRow = dt.NewRow();
                    var id     = ProcessRow(mapping, schema, included_columns, result, newRow);

                    if (dt.Rows.AddWithIdentifier(newRow, id) == DataTableStore.ABORT)
                    {
                        break;
                    }
                }
                catch (WebException e)
                {
                    var response = e.Response as HttpWebResponse;
                    if (response.StatusCode == HttpStatusCode.NotFound)
                    {
                        continue;
                    }

                    throw;
                }
            }


            return(dt);
        }
        public Dictionary <string, string> GetMailChimpLists()
        {
            var lists = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            var uriHelper = new MailChimpUriHelper(APIKey);

            helper.SetAuthorizationHeader(APIKey);

            var result = helper.GetRequestAsJson(uriHelper.ListServiceUrl);

            if (result["lists"] != null)
            {
                foreach (var item_row in result["lists"])
                {
                    lists[item_row["id"].ToObject <string>()] = item_row["name"].ToObject <string>();
                }
            }

            return(lists);
        }
        public override DataTableStore GetDataTable(DataTableStore dt)
        {
            dt.AddIdentifierColumn(typeof(string));

            var uriHelper        = new MailChimpUriHelper(APIKey);
            var mapping          = new DataSchemaMapping(SchemaMap, Side);
            var schema           = MailChimpDataSchema.MailChimpMemberSchema();
            var included_columns = SchemaMap.GetIncludedColumns();

            int  total_items = 0;
            int  count       = 0;
            bool abort       = false;

            helper.SetAuthorizationHeader(APIKey);

            do
            {
                var result = helper.GetRequestAsJson($"{uriHelper.ListServiceUrl}/{ListId}/members?count={PageSize}&offset={count}");

                total_items = result["total_items"].ToObject <int>();

                if (result["members"] != null)
                {
                    foreach (var item_row in result["members"])
                    {
                        count++;

                        var newRow = dt.NewRow();
                        var id     = ProcessRow(mapping, schema, included_columns, item_row, newRow);

                        if (dt.Rows.AddWithIdentifier(newRow, id) == DataTableStore.ABORT)
                        {
                            abort = true;
                            break;
                        }
                    }
                }
            } while (!abort && count < total_items);

            return(dt);
        }