/// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="businessId">The AdWords Express business id.</param>
    /// <param name="promotionId">The promotion id.</param>
    public void Run(AdWordsUser user, long businessId, long promotionId) {
      // Get the ExpressBusinessService.
      ExpressBusinessService businessService = (ExpressBusinessService)
          user.GetService(AdWordsService.v201509.ExpressBusinessService);

      // Get the PromotionService
      PromotionService promotionService = (PromotionService)
          user.GetService(AdWordsService.v201509.PromotionService);

      // Set the business ID to the service.
      promotionService.RequestHeader.expressBusinessId = businessId;

      // Update the budget for the promotion
      Promotion promotion = new Promotion();
      promotion.id = promotionId;
      Money newBudget = new Money();
      newBudget.microAmount = 2000000;
      promotion.budget = newBudget;

      PromotionOperation operation = new PromotionOperation();
      operation.@operator = Operator.SET;
      operation.operand = promotion;

      try {
        Promotion[] updatedPromotions = promotionService.mutate(
            new PromotionOperation[] { operation });

        Console.WriteLine("Promotion ID {0} for business ID {1} now has budget micro " +
            "amount {2}.", promotionId, businessId,
            updatedPromotions[0].budget.microAmount);
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to update promotions.", e);
      }
    }
Beispiel #2
0
        /// <summary>
        /// Tries to unify the constraints of a method call
        /// </summary>
        /// <param name="methodAnalyzed">The method that is being analyzed when the operation is performed.</param>
        /// <param name="actualImplicitObject">Only suitable in an assignment constraint. It represents the actual object used to pass the message.</param>
        /// <param name="showInvocationMessage">To show the invocation line and column in case an error exists</param>
        /// <param name="activeSortOfUnification">The active sort of unification used (Equivalent is the default
        /// one and Incremental is used in the SSA bodies of the while, for and do statements)</param>
        /// <param name="location">Location of the method call</param>
        /// <returns>If the unification has been satisfied</returns>
        public override TypeExpression Check(MethodType methodAnalyzed, TypeExpression actualImplicitObject, bool showInvocationMessage, SortOfUnification activeSortOfUnification, Location location)
        {
            TypeExpression result;

            if (this.op != null)
            {
                //result = this.FirstOperand.Promotion(this.SecondOperand, (Enum)this.Operator, methodAnalyzed, this.Location);
                result = (TypeExpression)this.FirstOperand.AcceptOperation(PromotionOperation.Create(this.SecondOperand, (Enum)this.Operator, methodAnalyzed, this.Location, showInvocationMessage), null);
            }
            else
            {
                result = (TypeExpression)this.FirstOperand.AcceptOperation(PromotionOperation.Create(this.SecondOperand, methodAnalyzed, this.Location, showInvocationMessage), null);
            }
            if (result == null && showInvocationMessage)
            {
                ErrorManager.Instance.NotifyError(new ConstraintError(location));
                return(null);
            }
            // * If no error exists, we return the supertype
            return(this.SecondOperand);
        }
Beispiel #3
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="businessId">The AdWords Express business id.</param>
        /// <param name="promotionId">The promotion id.</param>
        public void Run(AdWordsUser user, long businessId, long promotionId)
        {
            // Get the ExpressBusinessService.
            ExpressBusinessService businessService = (ExpressBusinessService)
                                                     user.GetService(AdWordsService.v201506.ExpressBusinessService);

            // Get the PromotionService
            PromotionService promotionService = (PromotionService)
                                                user.GetService(AdWordsService.v201506.PromotionService);

            // Set the business ID to the service.
            promotionService.RequestHeader.expressBusinessId = businessId;

            // Update the budget for the promotion
            Promotion promotion = new Promotion();

            promotion.id = promotionId;
            Money newBudget = new Money();

            newBudget.microAmount = 2000000;
            promotion.budget      = newBudget;

            PromotionOperation operation = new PromotionOperation();

            operation.@operator = Operator.SET;
            operation.operand   = promotion;

            try {
                Promotion[] updatedPromotions = promotionService.mutate(
                    new PromotionOperation[] { operation });

                Console.WriteLine("Promotion ID {0} for business ID {1} now has budget micro " +
                                  "amount {2}.", promotionId, businessId,
                                  updatedPromotions[0].budget.microAmount);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to update promotions.", ex);
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="businessId">The AdWords Express business id.</param>
        public void Run(AdWordsUser user, long businessId)
        {
            // Get the PromotionService
            PromotionService promotionService = (PromotionService)
                                                user.GetService(AdWordsService.v201605.PromotionService);

            // Set the business ID to the service.
            promotionService.RequestHeader.expressBusinessId = businessId;

            // First promotion
            Promotion marsTourPromotion = new Promotion();
            Money     budget            = new Money();

            budget.microAmount                    = 1000000L;
            marsTourPromotion.name                = "Mars Tour Promotion " + ExampleUtilities.GetShortRandomString();
            marsTourPromotion.status              = PromotionStatus.PAUSED;
            marsTourPromotion.destinationUrl      = "http://www.example.com";
            marsTourPromotion.budget              = budget;
            marsTourPromotion.callTrackingEnabled = true;

            // Criteria

            // Criterion - Travel Agency product service
            ProductService productService = new ProductService();

            productService.text = "Travel Agency";

            // Criterion - English language
            // The ID can be found in the documentation:
            // https://developers.google.com/adwords/api/docs/appendix/languagecodes
            Language language = new Language();

            language.id = 1000L;

            // Criterion - State of California
            Location location = new Location();

            location.id = 21137L;

            marsTourPromotion.criteria = new Criterion[] { productService, language, location };

            // Creative
            Creative creative = new Creative();

            creative.headline = "Standard Mars Trip";
            creative.line1    = "Fly coach to Mars";
            creative.line2    = "Free in-flight pretzels";

            marsTourPromotion.creatives = new Creative[] { creative };

            PromotionOperation operation = new PromotionOperation();

            operation.@operator = Operator.ADD;
            operation.operand   = marsTourPromotion;

            try {
                Promotion[] addedPromotions = promotionService.mutate(
                    new PromotionOperation[] { operation });

                Console.WriteLine("Added promotion ID {0} with name {1} to business ID {2}.",
                                  addedPromotions[0].id, addedPromotions[0].name, businessId);
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to add promotions.", e);
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="businessId">The AdWords Express business id.</param>
        public void Run(AdWordsUser user, long businessId)
        {
            // Get the ExpressBusinessService.
            ExpressBusinessService businessService = (ExpressBusinessService)
                                                     user.GetService(AdWordsService.v201409.ExpressBusinessService);

            // Get the PromotionService
            PromotionService promotionService = (PromotionService)
                                                user.GetService(AdWordsService.v201409.PromotionService);

            // Get the business for the businessId. We will need its geo point to
            // create a Proximity criterion for the new Promotion.
            Selector businessSelector = new Selector();

            Predicate predicate = new Predicate();

            predicate.field             = "Id";
            predicate.@operator         = PredicateOperator.EQUALS;
            predicate.values            = new string[] { businessId.ToString() };
            businessSelector.predicates = new Predicate[] { predicate };

            businessSelector.fields = new string[] { "Id", "GeoPoint" };

            ExpressBusinessPage businessPage = businessService.get(businessSelector);

            if (businessPage == null || businessPage.entries == null ||
                businessPage.entries.Length == 0)
            {
                Console.WriteLine("No business was found.");
                return;
            }

            // Set the business ID to the service.
            promotionService.RequestHeader.expressBusinessId = businessId;

            // First promotion
            Promotion marsTourPromotion = new Promotion();
            Money     budget            = new Money();

            budget.microAmount                    = 1000000L;
            marsTourPromotion.name                = "Mars Tour Promotion " + ExampleUtilities.GetShortRandomString();
            marsTourPromotion.status              = PromotionStatus.PAUSED;
            marsTourPromotion.destinationUrl      = "http://www.example.com";
            marsTourPromotion.budget              = budget;
            marsTourPromotion.callTrackingEnabled = true;

            // Criteria

            // Criterion - Travel Agency product service
            ProductService productService = new ProductService();

            productService.text = "Travel Agency";

            // Criterion - English language
            // The ID can be found in the documentation:
            // https://developers.google.com/adwords/api/docs/appendix/languagecodes
            Language language = new Language();

            language.id = 1000L;

            // Criterion - Within 15 miles
            Proximity proximity = new Proximity();

            proximity.geoPoint            = businessPage.entries[0].geoPoint;
            proximity.radiusDistanceUnits = ProximityDistanceUnits.MILES;
            proximity.radiusInUnits       = 15;

            marsTourPromotion.criteria = new Criterion[] { productService, language, proximity };

            // Creative
            Creative creative = new Creative();

            creative.headline = "Standard Mars Trip";
            creative.line1    = "Fly coach to Mars";
            creative.line2    = "Free in-flight pretzels";

            marsTourPromotion.creatives = new Creative[] { creative };

            PromotionOperation operation = new PromotionOperation();

            operation.@operator = Operator.ADD;
            operation.operand   = marsTourPromotion;

            try {
                Promotion[] addedPromotions = promotionService.mutate(
                    new PromotionOperation[] { operation });

                Console.WriteLine("Added promotion ID {0} with name {1} to business ID {2}.",
                                  addedPromotions[0].id, addedPromotions[0].name, businessId);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to add promotions.", ex);
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="businessId">The AdWords Express business id.</param>
        public void Run(AdWordsUser user, long businessId)
        {
            // Get the PromotionService
              PromotionService promotionService = (PromotionService)
              user.GetService(AdWordsService.v201601.PromotionService);

              // Set the business ID to the service.
              promotionService.RequestHeader.expressBusinessId = businessId;

              // First promotion
              Promotion marsTourPromotion = new Promotion();
              Money budget = new Money();
              budget.microAmount = 1000000L;
              marsTourPromotion.name = "Mars Tour Promotion " + ExampleUtilities.GetShortRandomString();
              marsTourPromotion.status = PromotionStatus.PAUSED;
              marsTourPromotion.destinationUrl = "http://www.example.com";
              marsTourPromotion.budget = budget;
              marsTourPromotion.callTrackingEnabled = true;

              // Criteria

              // Criterion - Travel Agency product service
              ProductService productService = new ProductService();
              productService.text = "Travel Agency";

              // Criterion - English language
              // The ID can be found in the documentation:
              // https://developers.google.com/adwords/api/docs/appendix/languagecodes
              Language language = new Language();
              language.id = 1000L;

              // Criterion - State of California
              Location location = new Location();
              location.id = 21137L;

              marsTourPromotion.criteria = new Criterion[] { productService, language, location };

              // Creative
              Creative creative = new Creative();
              creative.headline = "Standard Mars Trip";
              creative.line1 = "Fly coach to Mars";
              creative.line2 = "Free in-flight pretzels";

              marsTourPromotion.creatives = new Creative[] { creative };

              PromotionOperation operation = new PromotionOperation();
              operation.@operator = Operator.ADD;
              operation.operand = marsTourPromotion;

              try {
            Promotion[] addedPromotions = promotionService.mutate(
            new PromotionOperation[] { operation });

            Console.WriteLine("Added promotion ID {0} with name {1} to business ID {2}.",
            addedPromotions[0].id, addedPromotions[0].name, businessId);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to add promotions.", e);
              }
        }
    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="businessId">The AdWords Express business id.</param>
    public void Run(AdWordsUser user, long businessId) {
      // Get the ExpressBusinessService.
      ExpressBusinessService businessService = (ExpressBusinessService)
          user.GetService(AdWordsService.v201509.ExpressBusinessService);

      // Get the PromotionService
      PromotionService promotionService = (PromotionService)
          user.GetService(AdWordsService.v201509.PromotionService);

      // Get the business for the businessId. We will need its geo point to
      // create a Proximity criterion for the new Promotion.
      Selector businessSelector = new Selector() {
        fields = new string[] {
          ExpressBusiness.Fields.Id, ExpressBusiness.Fields.GeoPoint
        },
        predicates = new Predicate[] {
          Predicate.Equals(ExpressBusiness.Fields.Id, businessId.ToString())
        }
      };

      ExpressBusinessPage businessPage = businessService.get(businessSelector);

      if (businessPage == null || businessPage.entries == null ||
          businessPage.entries.Length == 0) {
        Console.WriteLine("No business was found.");
        return;
      }

      // Set the business ID to the service.
      promotionService.RequestHeader.expressBusinessId = businessId;

      // First promotion
      Promotion marsTourPromotion = new Promotion();
      Money budget = new Money();
      budget.microAmount = 1000000L;
      marsTourPromotion.name = "Mars Tour Promotion " + ExampleUtilities.GetShortRandomString();
      marsTourPromotion.status = PromotionStatus.PAUSED;
      marsTourPromotion.destinationUrl = "http://www.example.com";
      marsTourPromotion.budget = budget;
      marsTourPromotion.callTrackingEnabled = true;

      // Criteria

      // Criterion - Travel Agency product service
      ProductService productService = new ProductService();
      productService.text = "Travel Agency";

      // Criterion - English language
      // The ID can be found in the documentation:
      // https://developers.google.com/adwords/api/docs/appendix/languagecodes
      Language language = new Language();
      language.id = 1000L;

      // Criterion - Within 15 miles
      Proximity proximity = new Proximity();
      proximity.geoPoint = businessPage.entries[0].geoPoint;
      proximity.radiusDistanceUnits = ProximityDistanceUnits.MILES;
      proximity.radiusInUnits = 15;

      marsTourPromotion.criteria = new Criterion[] { productService, language, proximity };

      // Creative
      Creative creative = new Creative();
      creative.headline = "Standard Mars Trip";
      creative.line1 = "Fly coach to Mars";
      creative.line2 = "Free in-flight pretzels";

      marsTourPromotion.creatives = new Creative[] { creative };

      PromotionOperation operation = new PromotionOperation();
      operation.@operator = Operator.ADD;
      operation.operand = marsTourPromotion;

      try {
        Promotion[] addedPromotions = promotionService.mutate(
            new PromotionOperation[] { operation });

        Console.WriteLine("Added promotion ID {0} with name {1} to business ID {2}.",
        addedPromotions[0].id, addedPromotions[0].name, businessId);
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to add promotions.", e);
      }
    }
Beispiel #8
0
        // Loop Detection

        // Helper Methods

        #region methodCall()

        /// <summary>
        /// This method does the type inference in a method call including unification.
        /// It requires that a) the method to be invoked has been previously analyzed with this visitor
        /// b) The formalMethod parameter is the result of the overload resolution
        /// </summary>
        /// <param name="actualImplicitObject">The actual implicit object</param>
        /// <param name="formalMethod">The formal method to be called</param>
        /// <param name="args">The ordered types of the actual parameters</param>
        /// <param name="methodAnalyzed">The method that is being analyzed when the operation is performed.</param>
        /// <param name="activeSortOfUnification">The active sort of unification used (Equivalent is the default
        /// one and Incremental is used in the SSA bodies of the while, for and do statements)</param>
        /// <param name="fileName">File name.</param>
        /// <param name="line">Line number.</param>
        /// <param name="column">Column number.</param>
        /// <returns>The type expression of the returned value</returns>
        public static TypeExpression methodCall(TypeExpression actualImplicitObject, MethodType formalMethod, TypeExpression[] args,
                                                MethodType methodAnalyzed, SortOfUnification activeSortOfUnification, Location location)
        {
            UserType   userType     = formalMethod.MemberInfo.Class;
            MethodType actualMethod = null;
            // * We must create a new type with type variables for the object's attributes (the formal implicit object)
            IDictionary <TypeVariable, TypeVariable> typeVariableMappings = new Dictionary <TypeVariable, TypeVariable>();

            // * If the method is an instance one and the actual object is not this, we create a new implicit object to unify
            if (!formalMethod.MemberInfo.hasModifier(Modifier.Static) && actualImplicitObject != null && actualImplicitObject != methodAnalyzed.memberInfo.Class)
            {
                // * Unifies the implicit objects (actual and formal)
                UserType formalImplicitObject = (UserType)userType.CloneType(typeVariableMappings);
                if (!actualImplicitObject.Unify(formalImplicitObject, SortOfUnification.Equivalent, new List <Pair <TypeExpression, TypeExpression> >()))
                {
                    // * If the formal implicit object already has substitution (fields declararion with assignments), we override it with a union type
                    formalImplicitObject.Unify(actualImplicitObject, SortOfUnification.Override, new List <Pair <TypeExpression, TypeExpression> >());
                }
                actualImplicitObject.ValidTypeExpression = false;
            }

            // * If "this" is the actual implicit object, the return type is the original return type of the method
            TypeExpression originalReturnType = formalMethod.Return;

            if (formalMethod.HasTypeVariables() || formalMethod.Constraints.Count > 0)
            {
                // * We must also generate a method with fresh variables (formal method)
                //   when it has parameters with type variables or constraints
                formalMethod = formalMethod.CloneMethodType(typeVariableMappings);
            }

            // * If the method has type variables...
            if (formalMethod.HasTypeVariables())
            {
                // * We create the actual method:
                //   1.- The actual return type
                TypeVariable actualReturnType = TypeVariable.NewTypeVariable;
                //   2.- The actual method
                actualMethod = new MethodType(actualReturnType);
                //   3.- The actual parameters
                foreach (TypeExpression arg in args)
                {
                    actualMethod.AddParameter(arg);
                }

                // * Unifies both methods
                if (!actualMethod.Unify(formalMethod, SortOfUnification.Equivalent, new List <Pair <TypeExpression, TypeExpression> >()))
                {
                    ErrorManager.Instance.NotifyError(new UnificationError(actualMethod.FullName, location));
                    return(null);
                }
            }
            // * Otherwise, arguments promotion must be checked
            else
            {
                if (args.Length != formalMethod.ParameterListCount)
                {
                    ErrorManager.Instance.NotifyError(new ArgumentNumberError(formalMethod.FullName, args.Length, location));
                    return(null);
                }
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].AcceptOperation(PromotionOperation.Create(formalMethod.paramList[i], methodAnalyzed, location), null) == null)
                    {
                        return(null);
                    }
                }
            }

            // * Method constraints satisfaction
            if (formalMethod.Constraints.Count > 0)
            {
                formalMethod.Constraints.Check(methodAnalyzed, actualImplicitObject, true, activeSortOfUnification, location);
            }

            // * The returned type is the the actual method if there has been a unification and
            //   in case the method is a instance method, a concrete object has been used (not this) or
            //   a different implicit object (the this reference is changed in the SSA algorithm)
            if (actualMethod != null && (formalMethod.MemberInfo.hasModifier(Modifier.Static) ||
                                         ClassType.IsConcreteType(actualImplicitObject) != null ||
                                         actualImplicitObject != formalMethod.MemberInfo.Class))
            {
                TypeVariable returnType = (TypeVariable)actualMethod.Return;
                if (returnType.Substitution != null)
                {
                    return(returnType.EquivalenceClass.Substitution);
                }
                return(returnType);
            }
            // * The original returned type if there has been no unification or the implicit object is "this"
            return(originalReturnType);
        }