Exemplo n.º 1
0
        /// <summary>
        /// Parses the error response into an exception.
        /// </summary>
        /// <param name="errorsXml">The errors XML.</param>
        /// <param name="e">The original exception.</param>
        /// <returns>An AdWords Reports exception that represents the error.</returns>
        private AdWordsReportsException ParseException(Exception e, string contents)
        {
            List <ReportDownloadError> errorList = new List <ReportDownloadError>();

            try {
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(contents);
                XmlNodeList errorNodes = xDoc.DocumentElement.SelectNodes("ApiError");
                foreach (XmlElement errorNode in errorNodes)
                {
                    ReportDownloadError downloadError = new ReportDownloadError();
                    downloadError.ErrorType = errorNode.SelectSingleNode("type").InnerText;
                    downloadError.FieldPath = errorNode.SelectSingleNode("fieldPath").InnerText;
                    downloadError.Trigger   = errorNode.SelectSingleNode("trigger").InnerText;

                    errorList.Add(downloadError);
                }
            } catch {
            }
            AdWordsReportsException ex = new AdWordsReportsException(
                "Report download errors occurred.", e);

            ex.Errors = errorList.ToArray();
            return(ex);
        }
        /// <summary>
        /// Parses the error response into an exception.
        /// </summary>
        /// <param name="exception">The original exception.</param>
        /// <param name="contents">The errors XML.</param>
        /// <returns>An AdWords Reports exception that represents the error.</returns>
        private AdWordsReportsException ParseException(Exception exception, string contents)
        {
            List <ReportDownloadError> errorList = new List <ReportDownloadError>();

            try
            {
                XmlDocument xDoc       = XmlUtilities.CreateDocument(contents);
                XmlNodeList errorNodes = xDoc.DocumentElement.SelectNodes("ApiError");
                foreach (XmlElement errorNode in errorNodes)
                {
                    ReportDownloadError downloadError = new ReportDownloadError();
                    downloadError.ErrorType = errorNode.SelectSingleNode("type").InnerText;
                    downloadError.FieldPath = errorNode.SelectSingleNode("fieldPath").InnerText;
                    downloadError.Trigger   = errorNode.SelectSingleNode("trigger").InnerText;
                    errorList.Add(downloadError);
                }
            }
            catch
            {
            }

            AdWordsReportsException retval = new AdWordsReportsException(this.reportVersion,
                                                                         AdWordsErrorMessages.ReportingExceptionOccurred, exception);

            retval.Errors = errorList.ToArray();
            return(retval);
        }
        /// <summary>
        /// Parses the error response into an exception.
        /// </summary>
        /// <param name="exception">The original exception.</param>
        /// <param name="contents">The errors XML.</param>
        /// <returns>An AdWords Reports exception that represents the error.</returns>
        private AdWordsReportsException ParseException(Exception exception, string contents)
        {
            List<ReportDownloadError> errorList = new List<ReportDownloadError>();
              try {
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(contents);
            XmlNodeList errorNodes = xDoc.DocumentElement.SelectNodes("ApiError");
            foreach (XmlElement errorNode in errorNodes) {
              ReportDownloadError downloadError = new ReportDownloadError();
              downloadError.ErrorType = errorNode.SelectSingleNode("type").InnerText;
              downloadError.FieldPath = errorNode.SelectSingleNode("fieldPath").InnerText;
              downloadError.Trigger = errorNode.SelectSingleNode("trigger").InnerText;

              errorList.Add(downloadError);
            }
              } catch {
              }
              AdWordsReportsException retval = new AdWordsReportsException(
              "Report download errors occurred.", exception);
              retval.Errors = errorList.ToArray();
              return retval;
        }
 /// <summary>
 /// Determines whether the exception thrown by the server matches a known
 /// error.
 /// </summary>
 /// <param name="exception">The exception.</param>
 /// <param name="errorMessages">The known error message.</param>
 /// <returns>True, if the server exception matches the known error, false
 /// otherwise.</returns>
 private static bool MatchesError(AdWordsReportsException exception, string[] errorMessages) {
   foreach (ReportDownloadError error in exception.Errors) {
     foreach (String errorMessage in errorMessages) {
       if (error.ErrorType.Contains(errorMessage)) {
         return true;
       }
     }
   }
   return false;
 }