コード例 #1
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the OrderService.
              OrderService orderService = (OrderService) user.GetService(DfpService.v201302.OrderService);

              // Set the name of the advertiser (company) to get orders for.
              String advertiserId = _T("INSERT_ADVERTISER_COMPANY_ID_HERE");

              // Create a Statement to only select orders for a given advertiser.
              Statement statement = new StatementBuilder("WHERE advertiserId = :advertiserId LIMIT 500").
              AddValue("advertiserId", advertiserId).ToStatement();

              try {
            // Get orders by Statement.
            OrderPage page = orderService.getOrdersByStatement(statement);

            if (page.results != null && page.results.Length > 0) {
              int i = page.startIndex;
              foreach (Order order in page.results) {
            Console.WriteLine("{0}) Order with ID = '{1}', name = '{2}', and advertiser " +
                "ID = '{3}' was found.", i, order.id, order.name, order.advertiserId);
            i++;
              }
            }
            Console.WriteLine("Number of results found: " + page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get orders by Statement. Exception says \"{0}\"",
            ex.Message);
              }
        }
コード例 #2
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the CompanyService.
      CompanyService companyService =
          (CompanyService) user.GetService(DfpService.v201302.CompanyService);

      // Create a Statement to only select companies that are advertisers sorted
      // by name.
      Statement statement = new StatementBuilder("WHERE type = :advertiser ORDER BY name " +
          "LIMIT 500").AddValue("advertiser", CompanyType.ADVERTISER.ToString()).ToStatement();

      try {
        // Get companies by Statement.
        CompanyPage page = companyService.getCompaniesByStatement(statement);

        if (page.results != null) {
          int i = page.startIndex;
          foreach (Company company in page.results) {
            Console.WriteLine("{0}) Company with ID = {1}, name = {2} and type = {3} was found",
                i, company.id, company.name, company.type);
            i++;
          }
        }
        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get companies. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #3
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the LineItemService.
              LineItemService lineItemService =
              (LineItemService) user.GetService(DfpService.v201302.LineItemService);

              // Set the ID of the order to get line items from.
              long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

              // Create a statement to only select line items that need creatives from a
              // given order.
              Statement filterStatement =
              new StatementBuilder("WHERE orderId = :orderId AND status = :status LIMIT 500")
              .AddValue("orderId", orderId)
              .AddValue("status", ComputedStatus.NEEDS_CREATIVES.ToString())
              .ToStatement();

              try {
            // Get line items by Statement.
            LineItemPage page = lineItemService.getLineItemsByStatement(filterStatement);

            if (page.results != null && page.results.Length > 0) {
              int i = page.startIndex;
              foreach (LineItem lineItem in page.results) {
            Console.WriteLine("{0}) Line item with ID ='{1}', belonging to order ID = '{2}' and " +
                 "named '{3}' was found.", i, lineItem.id, lineItem.orderId, lineItem.name);
            i++;
              }
            }
            Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get line item by Statement. Exception says \"{0}\"",
            ex.Message);
              }
        }
コード例 #4
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the ThirdpartySlotService.
      ThirdPartySlotService thirdPartySlotService =
          (ThirdPartySlotService) user.GetService(DfpService.v201302.ThirdPartySlotService);

      // Sets defaults for page and filterStatement.
      ThirdPartySlotPage page = new ThirdPartySlotPage();
      Statement filterStatement = new StatementBuilder("WHERE status = :status LIMIT 500 ")
          .AddValue("status", ThirdPartySlotStatus.ARCHIVED.ToString()).ToStatement();

      try {
        // Get third party slots by statement.
        page = thirdPartySlotService.getThirdPartySlotsByStatement(filterStatement);

        if (page.results != null) {
          int i = page.startIndex;
          foreach (ThirdPartySlot thirdPartySlot in page.results) {
            Console.WriteLine("{0}) Third party slot with ID \"{1}\" was found.",
                i, thirdPartySlot.id);
            i++;
          }
        }

        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get third party slots. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #5
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the LineItemCreativeAssociationService.
              LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService)
              user.GetService(DfpService.v201302.LineItemCreativeAssociationService);

              // Set the line item to get LICAs by.
              long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE"));

              // Create a Statement to only select LICAs for the given lineItem ID.
              Statement statement = new StatementBuilder("WHERE lineItemId = :lineItemId LIMIT 500").
              AddValue("lineItemId", lineItemId).ToStatement();

              try {
            // Get LICAs by Statement.
            LineItemCreativeAssociationPage page =
            licaService.getLineItemCreativeAssociationsByStatement(statement);

            if (page.results != null && page.results.Length > 0) {
              int i = page.startIndex;
              foreach (LineItemCreativeAssociation lica in page.results) {
            Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " +
                "status ='{3}' was found.", i, lica.lineItemId, lica.creativeId,
                lica.status);
            i++;
              }
            }
            Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get LICAs. Exception says \"{0}\"", ex.Message);
              }
        }
コード例 #6
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the OrderService.
      LineItemService lineItemService = (LineItemService) user.GetService(
          DfpService.v201302.LineItemService);

      long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

      try {
        // Create statement to only select line items for the given order that
        // have been modified in the last 3 days.
        DateTime threeDaysAgo = DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(-3));
        Statement filterStatement = new StatementBuilder(
            "WHERE lastModifiedDateTime >= :lastModifiedDateTime AND orderId = :orderId LIMIT 500").
            AddValue("lastModifiedDateTime", threeDaysAgo).
            AddValue("orderId", orderId).ToStatement();


        // Get line items by statement.
        LineItemPage page = lineItemService.getLineItemsByStatement(filterStatement);

        // Display results.
        if (page != null && page.results != null) {
          foreach (LineItem lineItem in page.results) {
            Console.WriteLine("Line item with id \"{0}\", belonging to order id \"{1}\" and " +
                "named \"{2}\" was found.", lineItem.id, lineItem.orderId, lineItem.name);
          }
          Console.WriteLine("Number of results found: {1}.", page.totalResultSetSize);
        } else {
          Console.WriteLine("No line items were found.");
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to get line items. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #7
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201302.InventoryService);

      Statement filterStatement = new StatementBuilder("WHERE targetPlatform = :targetPlatform").
          AddValue("targetPlatform", "WEB").ToStatement();

      try {
        // Get all ad unit sizes.
        AdUnitSize[] adUnitSizes = inventoryService.getAdUnitSizesByStatement(filterStatement);

        // Display results.
        if (adUnitSizes != null) {
          for (int i = 0; i < adUnitSizes.Length; i++) {
            AdUnitSize adUnitSize = adUnitSizes[i];
            Console.WriteLine("{0}) Ad unit size ({1}x{2}) was found.\n", i,
                adUnitSize.size.width, adUnitSize.size.height);
          }
        } else {
          Console.WriteLine("No ad unit sizes found.");
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to get ad unit sizes. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #8
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the TeamService.
              TeamService teamService = (TeamService) user.GetService(DfpService.v201302.TeamService);

              // Create a statement to order teams by name.
              Statement filterStatement = new StatementBuilder("ORDER BY name LIMIT 500").ToStatement();

              try {
              // Get teams by statement.
              TeamPage page = teamService.getTeamsByStatement(filterStatement);

              // Display results.
              if (page.results != null) {
            int i = page.startIndex;
            foreach (Team team in page.results) {
              Console.WriteLine("{0}) Team with ID \"{1}\" and name \"{2}\" was found.",
              i, team.id, team.name);
              i++;
            }
              }

              Console.WriteLine("Number of results found: " + page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get teams by statement. Exception says \"{0}\"", ex.Message);
              }
        }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the CreativeService.
      CustomTargetingService customTargetingService =
          (CustomTargetingService) user.GetService(DfpService.v201302.CustomTargetingService);

      try {
        // Create a statement to only select predefined custom targeting keys.
        Statement filterStatement = new StatementBuilder("WHERE type = :type LIMIT 500").AddValue(
            "type", CustomTargetingKeyType.PREDEFINED.ToString()).ToStatement();

        // Get custom targeting keys by statement.
        CustomTargetingKeyPage page =
            customTargetingService.getCustomTargetingKeysByStatement(filterStatement);

        if (page.results != null) {
          int i = page.startIndex;
          foreach (CustomTargetingKey customTargetingKey in page.results) {
            Console.WriteLine("{0}) Custom targeting key with ID \"{1}\", name \"{2}\", and " +
                "display name \"{3}\" was found.", i, customTargetingKey.id,
                customTargetingKey.name, customTargetingKey.displayName);
            i++;
          }
        }
        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get predefined custom targeting keys. Exception " +
            "says \"{0}\"", ex.Message);
      }
    }
コード例 #10
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the PlacementService.
              PlacementService placementService =
              (PlacementService) user.GetService(DfpService.v201302.PlacementService);

              // Create a Statement to only select active placements.
              Statement statement = new StatementBuilder("WHERE status = :status LIMIT 500").AddValue(
              "status", InventoryStatus.ACTIVE.ToString()).ToStatement();

              try {
            // Get placements by Statement.
            PlacementPage page = placementService.getPlacementsByStatement(statement);

            // Display results.
            if (page.results != null && page.results.Length > 0) {
              int i = page.startIndex;
              foreach (Placement placement in page.results) {
            Console.WriteLine("{0}) Placement with ID = '{1}', name ='{2}', and status = '{3}' " +
              "was found.", i, placement.id, placement.name, placement.status);
            i++;
              }
            }

            Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get placement by Statement. Exception says \"{0}\"",
            ex.Message);
              }
        }
コード例 #11
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the SuggestedAdUnitService.
      SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService) user.GetService(
          DfpService.v201302.SuggestedAdUnitService);

      // Set the number of requests to 50 or more.
      long NUMBER_OF_REQUESTS = 50L;

      // Create a statement to only select suggested ad units that have more
      // than 50 requests.
      Statement filterStatement = new StatementBuilder("WHERE numRequests > :numRequests LIMIT 500")
          .AddValue("numRequests", NUMBER_OF_REQUESTS).ToStatement();

      try {
        // Get suggested ad units by statement.
        SuggestedAdUnitPage page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(
            filterStatement);

        if (page.results != null) {
          int i = page.startIndex;
          foreach (SuggestedAdUnit suggestedAdUnit in page.results) {
            Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and number of requests " +
                "\"{2}\" was found.", i, suggestedAdUnit.id, suggestedAdUnit.numRequests);
            i++;
          }
        }
        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get suggested ad units. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #12
0
        public void TestAllStatementBuilderPartialFunctions()
        {
            StatementBuilder statementBuilder = new StatementBuilder()
              .Select("Name, Id")
              .From("Geo_Target")
              .Where("Targetable = :targetable")
              .OrderBy("Id DESC")
              .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
              .Offset(0)
              .AddValue("targetable", true)
              .IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT)
              .RemoveLimitAndOffset();
              Assert.AreEqual(null, statementBuilder.GetOffset());

              Statement expectedStatement = new Statement();
              expectedStatement.query = "SELECT Name, Id FROM Geo_Target"
              + " WHERE Targetable = :targetable ORDER BY Id DESC";
              String_ValueMapEntry targetableEntry = new String_ValueMapEntry();
              targetableEntry.key = "targetable";
              BooleanValue targetableValue = new BooleanValue();
              targetableValue.value = true;
              targetableEntry.value = targetableValue;
              expectedStatement.values = new String_ValueMapEntry[] {targetableEntry};
              Assert.True(StatementsAreEqual(expectedStatement, statementBuilder.ToStatement()));
        }
コード例 #13
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the LabelService.
      LabelService labelService =
          (LabelService) user.GetService(DfpService.v201302.LabelService);

      // Create a statement to only select labels that are competitive
      // sorted by name.
      Statement filterStatement = new StatementBuilder("WHERE type = :type ORDER BY name LIMIT 500")
          .AddValue("type", LabelType.COMPETITIVE_EXCLUSION.ToString()).ToStatement();

      try {
        // Get labels by statement.
        LabelPage page = labelService.getLabelsByStatement(filterStatement);

        if (page.results != null) {
          int i = page.startIndex;
          foreach (Label label in page.results) {
            StringBuilder builder = new StringBuilder();
            foreach (LabelType labelType in label.types) {
              builder.AppendFormat("{0} | ", labelType);
            }

            Console.WriteLine("{0}) Label with ID '{1}', name '{2}'and type '{3}' was found.",
                i, label.id, label.name, builder.ToString().TrimEnd(' ', '|'));
            i++;
          }
        }
        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get labels. Exception says \"{0}\"", ex.Message);
      }
    }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the CreativeTemplateService.
      CreativeTemplateService creativeTemplateService =
          (CreativeTemplateService) user.GetService(DfpService.v201302.CreativeTemplateService);

      // Create a statement to only select system defined creative templates.
      Statement filterStatement =
          new StatementBuilder("WHERE type = :creativeTemplateType LIMIT 500").AddValue(
              "creativeTemplateType", CreativeTemplateType.SYSTEM_DEFINED.ToString()).ToStatement();

      try {
        // Get creative templates by statement.
        CreativeTemplatePage page = creativeTemplateService.getCreativeTemplatesByStatement(
            filterStatement);

        if (page.results != null) {
          int i = page.startIndex;
          foreach (CreativeTemplate creativeTemplate in page.results) {
            Console.WriteLine("{0}) Creative template with ID \"{1}\", name \"{2}\", and type " +
                "\"{3}\" was found.", i, creativeTemplate.id, creativeTemplate.name,
                creativeTemplate.type);
            i++;
          }
        }
        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get creative templates. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #15
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201302.CreativeService);

      // Create a Statement to only select image creatives.
      Statement statement = new StatementBuilder("WHERE creativeType = :creativeType LIMIT 500").
          AddValue("creativeType", "ImageCreative").ToStatement();

      try {
        // Get creatives by Statement.
        CreativePage page = creativeService.getCreativesByStatement(statement);

        if (page.results != null && page.results.Length > 0) {
          int i = page.startIndex;
          foreach (Creative creative in page.results) {
            Console.WriteLine("{0}) Creative with ID ='{1}', name ='{2}' and type ='{3}' " +
                "was found.", i, creative.id, creative.name, creative.CreativeType);
            i++;
          }
        }

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get creatives by Statement. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #16
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the LabelService.
              LabelService labelService =
              (LabelService) user.GetService(DfpService.v201302.LabelService);

              // Create statement text to select active labels.
              String statementText = "WHERE isActive = :isActive LIMIT 500";
              Statement filterStatement = new StatementBuilder("").AddValue("isActive", true).ToStatement();

              // Set defaults for page and offset.
              LabelPage page = new LabelPage();
              int offset = 0;
              List<string> labelIds = new List<string>();

              try {
            do {
              // Create a statement to page through active labels.
              filterStatement.query = statementText + " OFFSET " + offset;

              // Get labels by statement.
              page = labelService.getLabelsByStatement(filterStatement);

              if (page.results != null) {
            int i = page.startIndex;
            foreach (Label label in page.results) {
              Console.WriteLine("{0}) Label with ID '{1}', name '{2}' will be deactivated.",
                  i, label.id, label.name);
              labelIds.Add(label.id.ToString());
              i++;
            }
              }
              offset += 500;
            } while (offset < page.totalResultSetSize);

            Console.WriteLine("Number of labels to be deactivated: " + labelIds.Count);

            if (labelIds.Count > 0) {
              // Modify statement for action.
              filterStatement.query = "WHERE id IN (" + string.Join(", ", labelIds.ToArray()) + ")";

              // Create action.
              DeactivateLabels action = new DeactivateLabels();

              // Perform action.
              UpdateResult result = labelService.performLabelAction(action, filterStatement);

              // Display results.
              if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of labels deactivated: " + result.numChanges);
              } else {
            Console.WriteLine("No labels were deactivated.");
              }
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to deactivate labels. Exception says \"{0}\"", ex.Message);
              }
        }
コード例 #17
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the CreativeService.
              CustomTargetingService customTargetingService =
              (CustomTargetingService) user.GetService(DfpService.v201302.CustomTargetingService);

              // Set the ID of the predefined custom targeting key to get custom
              // targeting values for.
              long customTargetingKeyId = long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE"));

              // Create a statement to only select predefined custom targeting values
              // for a given key.
              Statement filterStatement =
              new StatementBuilder("WHERE customTargetingKeyId = :customTargetingKeyId LIMIT 500")
              .AddValue("customTargetingKeyId", customTargetingKeyId).ToStatement();

              try {
            // Get custom targeting values by statement.
            CustomTargetingValuePage page =
            customTargetingService.getCustomTargetingValuesByStatement(filterStatement);

            if (page.results != null) {
              CustomTargetingValue[] customTargetingValues = page.results;

              // Update each local custom targeting value object by changing its
              // display name.
              foreach (CustomTargetingValue customTargetingValue in customTargetingValues) {
            if (customTargetingValue.displayName == null) {
              customTargetingValue.displayName = customTargetingValue.displayName;
            }
            customTargetingValue.displayName = customTargetingValue.displayName + " (Deprecated)";
              }

              // Update the custom targeting values on the server.
              customTargetingValues =
              customTargetingService.updateCustomTargetingValues(customTargetingValues);

              if (customTargetingValues != null) {
            foreach (CustomTargetingValue customTargetingValue in customTargetingValues) {
              Console.WriteLine("Custom targeting value with ID \"{0}\", name \"{1}\", and " +
                  "display name \"{2}\" was updated.", customTargetingValue.id,
                  customTargetingValue.name, customTargetingValue.displayName);
            }
              } else {
            Console.WriteLine("No custom targeting values updated.");
              }
            } else {
              Console.WriteLine("No custom targeting values found to update.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update display names of custom targeting values. Exception " +
            "says \"{0}\"", ex.Message);
              }
        }
コード例 #18
0
        public void TestStatementBuilderBasicStatement()
        {
            StatementBuilder statementBuilder = new StatementBuilder()
              .Where("ID = 1");

              Statement expectedStatement = new Statement();
              expectedStatement.query = "WHERE ID = 1";
              expectedStatement.values = new String_ValueMapEntry[0];

              Assert.True(StatementsAreEqual(expectedStatement,
                                     statementBuilder.ToStatement()));
        }
コード例 #19
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the LineItemService.
              LineItemService lineItemService =
              (LineItemService) user.GetService(DfpService.v201302.LineItemService);

              // Set the ID of the order to get line items from.
              long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

              // Create a Statement to get line items with even delivery rates.
              Statement statement = new StatementBuilder("WHERE deliveryRateType = :deliveryRateType and " +
              "orderId = :orderId LIMIT 500").AddValue("deliveryRateType",
              DeliveryRateType.EVENLY.ToString()).AddValue("orderId", orderId).ToStatement();

              try {
            // Get line items by Statement.
            LineItemPage page = lineItemService.getLineItemsByStatement(statement);

            if (page.results != null && page.results.Length > 0) {
              LineItem[] lineItems = page.results;
              List<LineItem> lineItemsToUpdate = new List<LineItem>();

              // Update each local line item object by changing its delivery rate.
              foreach (LineItem lineItem in lineItems) {
            // Archived line items cannot be updated.
            if (!lineItem.isArchived) {
              lineItem.deliveryRateType = DeliveryRateType.AS_FAST_AS_POSSIBLE;
              lineItemsToUpdate.Add(lineItem);
            }
              }

              // Update the line items on the server.
              lineItems = lineItemService.updateLineItems(lineItemsToUpdate.ToArray());

              if (lineItems != null) {
            foreach (LineItem lineItem in lineItems) {
              Console.WriteLine("A line item with ID = '{0}', belonging to order ID = '{1}', " +
                  "named '{2}', and having delivery rate = '{3}' was updated.",
                  lineItem.id, lineItem.orderId, lineItem.name, lineItem.deliveryRateType);
            }
              } else {
            Console.WriteLine("No line items updated.");
              }
            } else {
              Console.WriteLine("No line items found to update.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update line items. Exception says \"{0}\"",
            ex.Message);
              }
        }
コード例 #20
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the InventoryService.
      PublisherQueryLanguageService pqlService =
          (PublisherQueryLanguageService) user.GetService(
              DfpService.v201302.PublisherQueryLanguageService);

      int pageSize = 500;
      // Create statement to select all targetable cities.
      String selectStatement = "SELECT * FROM City WHERE targetable = true LIMIT " + pageSize;
      int offset = 0;
      int resultSetSize = 0;
      List<Row> allRows = new List<Row>();
      ResultSet resultSet;

      try {
        do {
          // For criteria that do not have a "targetable" property, that predicate
          // may be left off, i.e. just "SELECT * FROM Browser_Groups LIMIT 500"
          StatementBuilder statementBuilder =
              new StatementBuilder(selectStatement + " OFFSET " + offset);

          // Get all cities.
          resultSet = pqlService.select(statementBuilder.ToStatement());

          // Collect all cities from each page.
          allRows.AddRange(resultSet.rows);

          // Display results.
          Console.WriteLine(PqlUtilities.ResultSetToString(resultSet));

          offset += pageSize;
          resultSetSize = resultSet.rows == null ? 0 : resultSet.rows.Length;
        } while (resultSetSize == pageSize);

        Console.WriteLine("Number of results found: " + allRows.Count);

        // Optionally, save all rows to a CSV.
        // Get a string array representation of the data rows.
        resultSet.rows = allRows.ToArray();
        List<String[]> rows = PqlUtilities.ResultSetToStringArrayList(resultSet);

        // Write the contents to a csv file.
        CsvFile file = new CsvFile();
        file.Headers.AddRange(rows[0]);
        file.Records.AddRange(rows.GetRange(1, rows.Count - 1).ToArray());
        file.Write("cities.csv");
      } catch (Exception ex) {
        Console.WriteLine("Failed to get all cities. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #21
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="dfpUser">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the UserTeamAssociationService.
              UserTeamAssociationService userTeamAssociationService =
              (UserTeamAssociationService) user.GetService(
              DfpService.v201302.UserTeamAssociationService);

              // Set the user to set to read only access within its teams.
              long userId = long.Parse(_T("INSERT_USER_ID_HERE"));

              // Create filter text to select user team associations by the user ID.
              String statementText = "WHERE userId = :userId LIMIT 500";
              Statement filterStatement = new StatementBuilder(statementText).
              AddValue("userId", userId).ToStatement();

              try {
            // Get user team associations by statement.
            UserTeamAssociationPage page =
            userTeamAssociationService.getUserTeamAssociationsByStatement(filterStatement);

            if (page.results != null) {
              UserTeamAssociation[] userTeamAssociations = page.results;

              // Update each local user team association to read only access.
              foreach (UserTeamAssociation userTeamAssociation in userTeamAssociations) {
            userTeamAssociation.overriddenTeamAccessType = TeamAccessType.READ_ONLY;
              }

              // Update the user team associations on the server.
              userTeamAssociations =
              userTeamAssociationService.updateUserTeamAssociations(userTeamAssociations);

              if (userTeamAssociations != null) {
            foreach (UserTeamAssociation userTeamAssociation in userTeamAssociations) {
              Console.WriteLine("User team association between user with ID \"{0}\" and team " +
                  "with ID \"{1}\" was updated to access type \"{2}\".", userTeamAssociation.userId,
                  userTeamAssociation.teamId, userTeamAssociation.overriddenTeamAccessType);
            }
              } else {
            Console.WriteLine("No user team associations updated.");
              }
            } else {
              Console.WriteLine("No user team associations found to update.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update user team associations. Exception says \"{0}\"",
            ex.Message);
              }
        }
コード例 #22
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the TeamService.
              TeamService teamService = (TeamService) user.GetService(DfpService.v201302.TeamService);

              // Set the ID of the ad unit to add to the teams.
              String adUnitId = _T("INSERT_AD_UNIT_ID_HERE");

              // Create a statement to select first 5 teams that aren't built-in.
              Statement filterStatement = new StatementBuilder("WHERE id > 0 LIMIT 5").ToStatement();

              try {
            // Get the teams by statement.
            TeamPage page = teamService.getTeamsByStatement(filterStatement);

            if (page.results != null) {
              Team[] teams = page.results;

              // Update each local team object by adding the ad unit to it.
              foreach (Team team in teams) {
            // Don't add ad unit if the team has all inventory already.
            if (!team.hasAllInventory) {
              List<String> adUnitIds = new List<String>();
              if (team.adUnitIds != null) {
                adUnitIds.AddRange(team.adUnitIds);
              }
              adUnitIds.Add(adUnitId);
              team.adUnitIds = adUnitIds.ToArray();
            }
              }

              // Update the teams on the server.
              teams = teamService.updateTeams(teams);

              if (teams != null) {
            foreach (Team team in teams) {
              Console.WriteLine("A team with ID \"{0}\" and name \"{1}\" was updated.",
                  team.id, team.name);
            }
              } else {
            Console.WriteLine("No teams updated.");
              }
            } else {
              Console.WriteLine("No teams found to update.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update teams. Exception says \"{0}\"", ex.Message);
              }
        }
コード例 #23
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the SuggestedAdUnitService.
              SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService) user.GetService(
              DfpService.v201302.SuggestedAdUnitService);

              // Create statement to select all suggested ad units with 50 or more
              // requests.
              string statementText = "WHERE numRequests >= 50";
              Statement filterStatement = new StatementBuilder(statementText).ToStatement();

              try {
            // Get suggested ad units by statement.
            SuggestedAdUnitPage page =
            suggestedAdUnitService.getSuggestedAdUnitsByStatement(filterStatement);

            int i = 0;
            if (page != null && page.results != null) {
              foreach (SuggestedAdUnit suggestedAdUnit in page.results) {
            Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and \"{2}\" will be " +
                "approved.", i, suggestedAdUnit.id, suggestedAdUnit.numRequests);
            i++;
              }

              Console.WriteLine("Number of suggested ad units to be approved: " +
              page.totalResultSetSize);

              // Create action.
              ApproveSuggestedAdUnit action = new ApproveSuggestedAdUnit();

              // Perform action.
              SuggestedAdUnitUpdateResult result = suggestedAdUnitService.performSuggestedAdUnitAction(
              action, filterStatement);

              // Display results.
              if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of suggested ad units approved: " + result.numChanges);
              } else {
            Console.WriteLine("No suggested ad units were approved.");
              }
            } else {
              Console.WriteLine("No suggested ad units were approved.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to approve suggested ad units. Exception says \"{0}\"",
            ex.Message);
              }
        }
コード例 #24
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the CreativeService.
              CreativeService creativeService =
              (CreativeService) user.GetService(DfpService.v201302.CreativeService);

              // Create a Statement to get all image creatives.
              Statement statement = new StatementBuilder("WHERE creativeType = :creativeType LIMIT 500").
              AddValue("creativeType", "ImageCreative").ToStatement();

              try {
            // Get creatives by Statement.
            CreativePage page = creativeService.getCreativesByStatement(statement);

            if (page.results != null && page.results.Length > 0) {
              Creative[] creatives = page.results;

              // Update each local creative object by changing its destination URL.
              foreach (Creative creative in creatives) {
            if (creative is ImageCreative) {
              ImageCreative imageCreative = (ImageCreative) creative;
              imageCreative.destinationUrl = "http://news.google.com";
            }
              }

              // Update the creatives on the server.
              creatives = creativeService.updateCreatives(creatives);

              if (creatives != null) {
            foreach (Creative creative in creatives) {
              if (creative is ImageCreative) {
                ImageCreative imageCreative = (ImageCreative) creative;
                Console.WriteLine("An image creative with ID = '{0}' and destination URL ='{1}' " +
                    "was updated.", imageCreative.id, imageCreative.destinationUrl);
              }
            }
              } else {
            Console.WriteLine("No creatives updated.");
              }
            } else {
              Console.WriteLine("No creatives found to update.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update creatives. Exception says \"{0}\"", ex.Message);
              }
        }
コード例 #25
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            ReportService reportService = (ReportService) user.GetService(
              DfpService.v201302.ReportService);

              long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

              // Create statement object to filter for an order.
              Statement filterStatement = new StatementBuilder("WHERE ORDER_ID = :id").AddValue(
              "id", orderId).ToStatement();

              // Create report job.
              ReportJob reportJob = new ReportJob();
              reportJob.reportQuery = new ReportQuery();
              reportJob.reportQuery.dimensions = new Dimension[] {Dimension.ORDER_ID, Dimension.ORDER_NAME};
              reportJob.reportQuery.dimensionAttributes = new DimensionAttribute[] {
              DimensionAttribute.ORDER_TRAFFICKER, DimensionAttribute.ORDER_START_DATE_TIME,
              DimensionAttribute.ORDER_END_DATE_TIME};
              reportJob.reportQuery.columns = new Column[] {Column.AD_SERVER_IMPRESSIONS,
              Column.AD_SERVER_CLICKS, Column.AD_SERVER_CTR, Column.AD_SERVER_CPM_AND_CPC_REVENUE,
              Column.AD_SERVER_WITHOUT_CPD_AVERAGE_ECPM};
              reportJob.reportQuery.dateRangeType = DateRangeType.LAST_MONTH;
              reportJob.reportQuery.statement = filterStatement;

              try {
            // Run report.
            reportJob = reportService.runReportJob(reportJob);
            // Wait for report to complete.
            while (reportJob.reportJobStatus == ReportJobStatus.IN_PROGRESS) {
              Console.WriteLine("Report job with id = '{0}' is still running.", reportJob.id);
              Thread.Sleep(30000);
              // Get report job.
              reportJob = reportService.getReportJob(reportJob.id);
            }

            if (reportJob.reportJobStatus == ReportJobStatus.COMPLETED) {
              Console.WriteLine("Report job with id = '{0}' completed successfully.", reportJob.id);
            } else if (reportJob.reportJobStatus == ReportJobStatus.FAILED) {
              Console.WriteLine("Report job with id = '{0}' failed to complete successfully.",
              reportJob.id);
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to run delivery report. Exception says \"{0}\"",
            ex.Message);
              }
        }
コード例 #26
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the ActivityService.
              ActivityService activityService =
              (ActivityService) user.GetService(DfpService.v201302.ActivityService);

              // Set the ID of the activity group these activities are associated with.
              long activityGroupId = long.Parse(_T("INSERT_ACTIVITY_GROUP_ID_HERE"));

              // Statement parts to help build a statement that only selects active
              // activities.
              Statement filterStatement = new StatementBuilder("").
              AddValue("activityGroupId", activityGroupId).
              AddValue("status", ActivityStatus.ACTIVE.ToString()).
              ToStatement();

              int offset = 0;
              ActivityPage page;

              try {
            do {
              filterStatement.query = "WHERE activityGroupId = :activityGroupId and status = :status " +
              "ORDER BY id LIMIT 500 OFFSET " + offset;

              page = activityService.getActivitiesByStatement(filterStatement);

              // Display results.
              if (page.results != null) {
            int i = page.startIndex;
            foreach (Activity activity in page.results) {
              Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\", and type \"{3}\" " +
                  "was found.", i, activity.id, activity.name, activity.type);
              i++;
            }
              }

              offset += 500;
            } while (offset < page.totalResultSetSize);

            Console.WriteLine("Number of results found: {0}.", page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get activities. Exception says \"{0}\"", ex.Message);
              }
        }
コード例 #27
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the CompanyService.
              CompanyService companyService =
              (CompanyService) user.GetService(DfpService.v201302.CompanyService);

              // Create a Statement to only select companies that are advertisers.
              Statement statement = new StatementBuilder("WHERE type = :advertiser LIMIT 500").AddValue(
              "advertiser", CompanyType.ADVERTISER.ToString()).ToStatement();

              try {
            // Get the companies by Statement.
            CompanyPage page = companyService.getCompaniesByStatement(statement);

            if (page.results != null && page.results.Length > 0) {
              Company[] companies = page.results;

              // Update each local company object by appending LLC. to its name.
              foreach (Company company in companies) {
            company.name = company.name + " LLC.";
              }

              // Update the companies on the server.
              companies = companyService.updateCompanies(companies);

              if (companies != null && companies.Length > 0) {
            int i = 0;
            foreach (Company company in companies) {
              Console.WriteLine("{0}) Company with ID = {1}, name = {2} was updated",
                  i, company.id, company.name, company.type);
              i++;
            }
              } else {
            Console.WriteLine("No companies updated.");
              }
            } else {
              Console.WriteLine("No companies found to update.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update companies. Exception says \"{0}\"", ex.Message);
              }
        }
コード例 #28
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the LabelService.
              LabelService labelService =
              (LabelService) user.GetService(DfpService.v201302.LabelService);

              // Create a statement to only select labels that are competitive
              // exclusion.
              Statement filterStatement = new StatementBuilder("WHERE isActive = :isActive LIMIT 500").
              AddValue("isActive", true).ToStatement();

              try {
            // Get the labels by statement.
            LabelPage page = labelService.getLabelsByStatement(filterStatement);

            if (page.results != null) {
              Label[] labels = page.results;

              // Update each local label object by updating its description.
              foreach (Label label in labels) {
            label.description = "These labels are still competiting with each other.";
              }

              // Update the labels on the server.
              labels = labelService.updateLabels(labels);

              if (labels != null) {
            foreach (Label label in labels) {
              Console.WriteLine("A label with ID '{0}' and name '{1}' was updated.",
                  label.id, label.name);
            }
              } else {
            Console.WriteLine("No labels updated.");
              }
            } else {
              Console.WriteLine("No labels found to update.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update labels. Exception says \"{0}\"", ex.Message);
              }
        }
コード例 #29
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the ActivityService.
              ActivityService activityService =
              (ActivityService) user.GetService(DfpService.v201302.ActivityService);

              int totalResultsCounter = 0;

              try {
            long[] activityGroupIds = getAllActivityGroupIds(user);

            foreach (long activityGroupId in activityGroupIds) {
              Statement filterStatement = new StatementBuilder("").AddValue(
              "activityGroupId", activityGroupId).ToStatement();

              ActivityPage page = new ActivityPage();
              int offset = 0;

              do {
            filterStatement.query = "WHERE activityGroupId = :activityGroupId ORDER BY id " +
                "LIMIT 500 OFFSET " + offset;
            // Get activities by statement.
            page = activityService.getActivitiesByStatement(filterStatement);

            // Display results.
            if (page.results != null) {
              foreach (Activity activity in page.results) {
                Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\", type \"{3}\", " +
                    "and activity group ID \"{4}\" was found.\n", totalResultsCounter,
                    activity.id, activity.name, activity.type, activityGroupId);
                totalResultsCounter++;
              }
            }
            offset += 500;
              } while (offset < page.totalResultSetSize);
            }
            Console.WriteLine("Number of results found: {0}.", totalResultsCounter);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get contacts. Exception says \"{0}\"", ex.Message);
              }
        }
コード例 #30
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Create the CreativeWrapperService.
              CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService(
              DfpService.v201302.CreativeWrapperService);

              long labelId = long.Parse(_T("INSERT_CREATIVE_WRAPPER_LABEL_ID_HERE"));

              try {
            // Create a query to select the active creative wrapper for the given
            // label.
            Statement statement = new StatementBuilder("WHERE status = :status AND labelId = :labelId")
            .AddValue("labelId", labelId)
            .AddValue("status", CreativeWrapperStatus.ACTIVE.ToString())
            .ToStatement();
            CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statement);
            CreativeWrapper[] creativeWrappers = page.results;
            if (creativeWrappers != null) {
              foreach (CreativeWrapper wrapper in creativeWrappers) {
            Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " +
                "status \'{2}\' will be deactivated.", wrapper.id, wrapper.labelId, wrapper.status);
              }
              Console.WriteLine("Number of creative wrappers to be deactivated: {0}",
              creativeWrappers.Length);

              // Perform action.
              CreativeWrapperAction action = new DeactivateCreativeWrappers();
              UpdateResult result =
              creativeWrapperService.performCreativeWrapperAction(action, statement);

              // Display results.
              if (result.numChanges > 0) {
            Console.WriteLine("Number of creative wrappers deactivated: {0}", result.numChanges);
              } else {
            Console.WriteLine("No creative wrappers were deactivated.");
              }
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to create creative wrappers. Exception says \"{0}\"", ex.Message);
              }
        }