Example #1
0
 /// <summary>
 /// Determines whether the exception thrown by the server matches a known
 /// error.
 /// </summary>
 /// <param name="ex">The exception.</param>
 /// <param name="errorMessage">The known error message.</param>
 /// <returns>True, if the server exception matches the known error, false
 /// otherwise.</returns>
 private static bool MatchesError(ReportsException ex, string[] errorMessages)
 {
     foreach (ReportDownloadError error in ex.Errors)
     {
         foreach (String errorMessage in errorMessages)
         {
             if (error.ErrorType.Contains(errorMessage))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #2
0
        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 !";
        }