示例#1
0
        private async void _SendFile(bool scoring, string filePath, int emailAddressColumn, SendFileOptions options,
                                     Action <ZBSendFileResponse> successCallback, Action <string> failureCallback)
        {
            if (InvalidApiKey(failureCallback))
            {
                return;
            }

            try
            {
                var content = new MultipartFormDataContent();
                var file    = File.OpenRead(filePath);
                content.Add(new StreamContent(file), "file", Path.GetFileName(filePath));

                content.Add(new StringContent(_apiKey), "api_key");
                content.Add(new StringContent(emailAddressColumn.ToString()), "email_address_column");

                if (options != null)
                {
                    if (options.ReturnUrl != null)
                    {
                        content.Add(new StringContent(options.ReturnUrl), "return_url");
                    }
                    if (options.HasHeaderRow)
                    {
                        content.Add(new StringContent("true"), "has_header_row");
                    }
                    if (options.FirstNameColumn > 0)
                    {
                        content.Add(new StringContent(options.FirstNameColumn.ToString()), "first_name_column");
                    }
                    if (options.LastNameColumn > 0)
                    {
                        content.Add(new StringContent(options.LastNameColumn.ToString()), "last_name_column");
                    }
                    if (options.GenderColumn > 0)
                    {
                        content.Add(new StringContent(options.GenderColumn.ToString()), "gender_column");
                    }
                    if (options.IpAddressColumn > 0)
                    {
                        content.Add(new StringContent(options.IpAddressColumn.ToString()), "ip_address_column");
                    }
                }

                var url    = BulkApiBaseUrl + (scoring ? "/scoring" : "") + "/sendFile";
                var result = await _client.PostAsync(url, content);

                var responseString = await result.Content.ReadAsStringAsync();

                var response = JsonConvert.DeserializeObject <ZBSendFileResponse>(responseString);
                successCallback(response);
            }
            catch (Exception e)
            {
                failureCallback(e.Message);
            }
        }
示例#2
0
 /// <summary>
 /// The sendfile API allows user to send a file for bulk email validation
 /// <param name="successCallback"> The success callback function, called with a ZBSendFileResponse object</param>
 /// <param name="failureCallback"> The failure callback function, called with a string error message</param>
 /// </summary>
 public void SendFile(string filePath, int emailAddressColumn, SendFileOptions options,
                      Action <ZBSendFileResponse> successCallback, Action <string> failureCallback)
 {
     _SendFile(false, filePath, emailAddressColumn, options, successCallback, failureCallback);
 }