/// <summary> /// Helper method to construct a single FeedAttribute. /// </summary> /// <param name="name">The name of the attribute to store.</param> /// <param name="type">The type represented by this attributed.</param> /// <returns>The newly created FeedAttribute instance.</returns> private FeedAttribute CreateFeedAttribute(string name, FeedAttributeType type) { return(new FeedAttribute() { Name = name, Type = type }); }
private void Download_Click(object sender, EventArgs e) { AdWordsAppConfig config = (AdWordsAppConfig)User.Config; string QUERY_REPORT_URL_FORMAT = "{0}/api/adwords/reportdownload/{1}?" + "__fmt={2}"; string reportVersion = "v201302"; string format = DownloadFormat.GZIPPED_CSV.ToString(); string downloadUrl = string.Format(QUERY_REPORT_URL_FORMAT, config.AdWordsApiServer, reportVersion, format); string query = this.AWQL_textBox.Text; string postData = string.Format("__rdquery={0}", HttpUtility.UrlEncode(query)); ClientReport retval = new ClientReport(); FeedAttributeType f = new FeedAttributeType(); ReportsException ex = null; this.response.Text += "\n Report download has started..."; int maxPollingAttempts = 30 * 60 * 1000 / 30000; string path = this.path.Text; for (int i = 0; i < 3; i++) { this.response.Text += "\n Attempt #1..."; try { using (FileStream fs = File.OpenWrite(path)) { fs.SetLength(0); bool isSuccess = DownloadReportToStream(downloadUrl, config, true, fs, postData, User); if (!isSuccess) { string errors = File.ReadAllText(path); } } } catch (Exception exception) { this.response.Text = exception.Message; } } this.response.Text += "\n DONE !"; }