Example #1
0
        /// <summary>
        /// Initializes the service before MakeApiCall.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="parameters">The method parameters.</param>
        protected override void InitForCall(string methodName, object[] parameters)
        {
            AdWordsAppConfig config = this.User.Config as AdWordsAppConfig;
            RequestHeader    header = GetRequestHeader();

            if (string.IsNullOrEmpty(header.developerToken))
            {
                throw new ArgumentNullException(AdWordsErrorMessages.DeveloperTokenCannotBeEmpty);
            }

            if (string.IsNullOrEmpty(header.clientCustomerId))
            {
                TraceUtilities.WriteGeneralWarnings(AdWordsErrorMessages.ClientCustomerIdIsEmpty);
            }

            string oAuthHeader = null;

            if (this.User.OAuthProvider != null)
            {
                oAuthHeader = this.User.OAuthProvider.GetAuthHeader();
            }
            else
            {
                throw new AdWordsApiException(null, AdWordsErrorMessages.OAuthProviderCannotBeNull);
            }
            ContextStore.AddKey("OAuthHeader", oAuthHeader);
            base.InitForCall(methodName, parameters);
        }
Example #2
0
 public void WriteGeneralWarnings()
 {
     VerifyLog(TraceUtilities.GENERAL_WARNING_MESSAGES_SOURCE, delegate()
     {
         // Ensure general warnings are logged at the warning level.
         TraceUtilities.WriteGeneralWarnings(TEST_LOG_MESSAGE);
     }, WARNING_MARKER);
 }
Example #3
0
        public void WriteGeneralWarnings()
        {
            using (var stream = new MemoryStream()) {
                enableLoggingToMemoryStream(TraceUtilities.GENERAL_WARNING_MESSAGES_SOURCE, stream);

                // Ensure general warnings are logged at the warning level.
                TraceUtilities.WriteGeneralWarnings(TEST_LOG_MESSAGE);
                StringAssert.Contains(WARNING_MARKER, getLogFromMemoryStream(stream));
            }
        }
Example #4
0
        /// <summary>
        /// Initializes the service before MakeApiCall.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="parameters">The method parameters.</param>
        protected override void InitForCall(string methodName, object[] parameters)
        {
            AdWordsAppConfig config = this.User.Config as AdWordsAppConfig;
            RequestHeader    header = GetRequestHeader();

            if (string.IsNullOrEmpty(header.developerToken))
            {
                throw new ArgumentNullException(AdWordsErrorMessages.DeveloperTokenCannotBeEmpty);
            }

            if (string.IsNullOrEmpty(header.clientCustomerId))
            {
                TraceUtilities.WriteGeneralWarnings(AdWordsErrorMessages.ClientCustomerIdIsEmpty);
            }

            // Validate Express business headers.
            if (this.Signature.ServiceName == "PromotionService")
            {
                if (header.expressBusinessIdSpecified && header.pageIdSpecified)
                {
                    throw new ArgumentException(AdWordsErrorMessages.OnlyOneExpressHeaderShouldBeSpecified);
                }
                else if (!header.expressBusinessIdSpecified && !header.pageIdSpecified)
                {
                    throw new ArgumentException(AdWordsErrorMessages.MissingExpressHeaders + ' ' +
                                                AdWordsErrorMessages.OnlyOneExpressHeaderShouldBeSpecified);
                }
            }
            else
            {
                if (header.expressBusinessIdSpecified || header.pageIdSpecified)
                {
                    throw new ArgumentException(AdWordsErrorMessages.ExpressHeadersShouldNotBeSpecified);
                }
            }

            header.userAgent = config.GetUserAgent();

            string oAuthHeader = null;

            if (this.User.OAuthProvider != null)
            {
                oAuthHeader = this.User.OAuthProvider.GetAuthHeader();
            }
            else
            {
                throw new AdWordsApiException(null, AdWordsErrorMessages.OAuthProviderCannotBeNull);
            }
            ContextStore.AddKey("OAuthHeader", oAuthHeader);
            base.InitForCall(methodName, parameters);
        }
 /// <summary>
 /// Gets the message body as a string.
 /// </summary>
 /// <returns>The message body.</returns>
 /// <param name="message">Message.</param>
 private string GetMessageBody(ref Message message)
 {
     using (MessageBuffer buffer = message.CreateBufferedCopy(Int32.MaxValue)) {
         // Message can only be read once, so replace it with a copy.
         message = buffer.CreateMessage();
         StringBuilder sb = new StringBuilder();
         try {
             using (XmlWriter xmlWriter = XmlWriter.Create(sb, xmlWriterSettings)) {
                 buffer.CreateMessage().WriteMessage(xmlWriter);
             }
             return(sb.ToString());
         } catch (Exception e) {
             TraceUtilities.WriteGeneralWarnings(string.Format(CommonErrorMessages.MalformedSoap, e));
             return("<soap />");
         }
     }
 }
Example #6
0
 private void Validate()
 {
     // TODO (cseeley): add real error messages
     if (RequestHeader == null)
     {
         throw new ArgumentNullException("Header is null");
     }
     if (this.User == null)
     {
         throw new ArgumentNullException("User is null");
     }
     if (string.IsNullOrEmpty(RequestHeader.developerToken))
     {
         throw new ArgumentNullException(AdWordsErrorMessages.DeveloperTokenCannotBeEmpty);
     }
     if (string.IsNullOrEmpty(RequestHeader.clientCustomerId))
     {
         TraceUtilities.WriteGeneralWarnings(AdWordsErrorMessages.ClientCustomerIdIsEmpty);
     }
 }