示例#1
0
        /// <summary>
        /// EslClient constructor.
        /// Initiates service classes that can be used by the client.
        /// </summary>
        /// <param name="apiKey">The client's api key.</param>
        /// <param name="baseUrl">The staging or production url.</param>
        public EslClient(string apiKey, string baseUrl)
        {
            Asserts.NotEmptyOrNull(apiKey, "apiKey");
            Asserts.NotEmptyOrNull(baseUrl, "baseUrl");
            this.baseUrl = AppendServicePath(baseUrl);

            configureJsonSerializationSettings();

            RestClient restClient = new RestClient(apiKey);

            packageService      = new PackageService(restClient, this.baseUrl, jsonSerializerSettings);
            sessionService      = new SessionService(apiKey, this.baseUrl);
            fieldSummaryService = new FieldSummaryService(new FieldSummaryApiClient(apiKey, this.baseUrl));
            auditService        = new AuditService(apiKey, this.baseUrl);

            eventNotificationService     = new EventNotificationService(new EventNotificationApiClient(restClient, this.baseUrl, jsonSerializerSettings));
            customFieldService           = new CustomFieldService(new CustomFieldApiClient(restClient, this.baseUrl, jsonSerializerSettings));
            groupService                 = new GroupService(new GroupApiClient(restClient, this.baseUrl, jsonSerializerSettings));
            accountService               = new AccountService(new AccountApiClient(restClient, this.baseUrl, jsonSerializerSettings));
            approvalService              = new ApprovalService(new ApprovalApiClient(restClient, this.baseUrl, jsonSerializerSettings));
            reminderService              = new ReminderService(new ReminderApiClient(restClient, this.baseUrl, jsonSerializerSettings));
            templateService              = new TemplateService(new TemplateApiClient(restClient, this.baseUrl, jsonSerializerSettings), packageService);
            authenticationTokenService   = new AuthenticationTokenService(restClient, this.baseUrl);
            attachmentRequirementService = new AttachmentRequirementService(new AttachmentRequirementApiClient(restClient, this.baseUrl, jsonSerializerSettings));
            layoutService                = new LayoutService(new LayoutApiClient(restClient, this.baseUrl, jsonSerializerSettings));
            qrCodeService                = new QRCodeService(new QRCodeApiClient(restClient, this.baseUrl, jsonSerializerSettings));
        }
示例#2
0
 private void init(RestClient restClient, String apiKey)
 {
     packageService            = new PackageService(restClient, this.baseUrl, jsonSerializerSettings);
     reportService             = new ReportService(restClient, this.baseUrl, jsonSerializerSettings);
     systemService             = new SystemService(restClient, this.baseUrl, jsonSerializerSettings);
     signingService            = new SigningService(restClient, this.baseUrl, jsonSerializerSettings);
     signingStyleService       = new SigningStyleService(restClient, this.baseUrl, jsonSerializerSettings);
     signerVerificationService = new SignerVerificationService(restClient, this.baseUrl, jsonSerializerSettings);
     signatureImageService     = new SignatureImageService(restClient, this.baseUrl, jsonSerializerSettings);
     sessionService            = new SessionService(apiKey, this.baseUrl);
     fieldSummaryService       = new FieldSummaryService(new FieldSummaryApiClient(apiKey, this.baseUrl));
     auditService                 = new AuditService(apiKey, this.baseUrl);
     eventNotificationService     = new EventNotificationService(new EventNotificationApiClient(restClient, this.baseUrl, jsonSerializerSettings));
     customFieldService           = new CustomFieldService(new CustomFieldApiClient(restClient, this.baseUrl, jsonSerializerSettings));
     groupService                 = new GroupService(new GroupApiClient(restClient, this.baseUrl, jsonSerializerSettings));
     accountService               = new AccountService(new AccountApiClient(restClient, this.baseUrl, jsonSerializerSettings));
     approvalService              = new ApprovalService(new ApprovalApiClient(restClient, this.baseUrl, jsonSerializerSettings));
     reminderService              = new ReminderService(new ReminderApiClient(restClient, this.baseUrl, jsonSerializerSettings));
     templateService              = new TemplateService(new TemplateApiClient(restClient, this.baseUrl, jsonSerializerSettings), packageService);
     authenticationTokenService   = new AuthenticationTokenService(restClient, this.baseUrl);
     attachmentRequirementService = new AttachmentRequirementService(restClient, this.baseUrl, jsonSerializerSettings);
     layoutService                = new LayoutService(new LayoutApiClient(restClient, this.baseUrl, jsonSerializerSettings));
     qrCodeService                = new QRCodeService(new QRCodeApiClient(restClient, this.baseUrl, jsonSerializerSettings));
     authenticationService        = new AuthenticationService(this.webpageUrl);
     dataRetentionSettingsService = new DataRetentionSettingsService(restClient, this.baseUrl);
 }
示例#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 CustomFieldService.
            CustomFieldService customFieldService = (CustomFieldService)user.GetService(
                DfpService.v201403.CustomFieldService);

            // Create a statement to get all custom fields.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

            // Sets default for page.
            CustomFieldPage page = new CustomFieldPage();

            try {
                do
                {
                    // Get custom fields by statement.
                    page = customFieldService.getCustomFieldsByStatement(statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        int i = page.startIndex;
                        foreach (CustomField customField in page.results)
                        {
                            if (customField is DropDownCustomField)
                            {
                                List <String>       dropDownCustomFieldStrings = new List <String>();
                                DropDownCustomField dropDownCustomField        = (DropDownCustomField)customField;
                                if (dropDownCustomField.options != null)
                                {
                                    foreach (CustomFieldOption customFieldOption in dropDownCustomField.options)
                                    {
                                        dropDownCustomFieldStrings.Add(customFieldOption.displayName);
                                    }
                                }
                                Console.WriteLine("{0}) Drop-down custom field with ID \"{1}\", name \"{2}\", " +
                                                  "and options {{{3}}} was found.", i, customField.id, customField.name,
                                                  string.Join(", ", dropDownCustomFieldStrings.ToArray()));
                            }
                            else
                            {
                                Console.WriteLine("{0}) Custom field with ID \"{1}\" and  name \"{2}\" was found.",
                                                  i, customField.id, customField.name);
                            }
                            i++;
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                Console.WriteLine("Number of results found: " + page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get all custom fields. 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 CustomFieldService.
            CustomFieldService customFieldService = (CustomFieldService)user.GetService(
                DfpService.v201311.CustomFieldService);

            // Sets defaults for page and filter.
            CustomFieldPage page            = new CustomFieldPage();
            Statement       filterStatement = new Statement();
            int             offset          = 0;

            try {
                do
                {
                    // Create a statement to get all custom fields.
                    filterStatement.query = "LIMIT 500 OFFSET " + offset;

                    // Get custom fields by statement.
                    page = customFieldService.getCustomFieldsByStatement(filterStatement);

                    if (page.results != null)
                    {
                        int i = page.startIndex;
                        foreach (CustomField customField in page.results)
                        {
                            if (customField is DropDownCustomField)
                            {
                                List <String>       dropDownCustomFieldStrings = new List <String>();
                                DropDownCustomField dropDownCustomField        = (DropDownCustomField)customField;
                                if (dropDownCustomField.options != null)
                                {
                                    foreach (CustomFieldOption customFieldOption in dropDownCustomField.options)
                                    {
                                        dropDownCustomFieldStrings.Add(customFieldOption.displayName);
                                    }
                                }
                                Console.WriteLine("{0}) Drop-down custom field with ID \"{1}\", name \"{2}\", " +
                                                  "and options {{{3}}} was found.", i, customField.id, customField.name,
                                                  string.Join(", ", dropDownCustomFieldStrings.ToArray()));
                            }
                            else
                            {
                                Console.WriteLine("{0}) Custom field with ID \"{1}\" and  name \"{2}\" was found.",
                                                  i, customField.id, customField.name);
                            }
                            i++;
                        }
                    }

                    offset += 500;
                } while (page.results != null && page.results.Length == 500);

                Console.WriteLine("Number of results found: " + page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get all custom fields. Exception says \"{0}\"", ex.Message);
            }
        }
示例#5
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (CustomFieldService customFieldService =
                       (CustomFieldService)user.GetService(DfpService.v201805.CustomFieldService))
            {
                // Create custom fields.
                CustomField customField1 = new CustomField();
                customField1.name       = "Customer comments #" + GetTimeStamp();
                customField1.entityType = CustomFieldEntityType.LINE_ITEM;
                customField1.dataType   = CustomFieldDataType.STRING;
                customField1.visibility = CustomFieldVisibility.FULL;

                CustomField customField2 = new CustomField();
                customField2.name       = "Internal approval status #" + GetTimeStamp();
                customField2.entityType = CustomFieldEntityType.LINE_ITEM;
                customField2.dataType   = CustomFieldDataType.DROP_DOWN;
                customField2.visibility = CustomFieldVisibility.FULL;

                try
                {
                    // Add custom fields.
                    CustomField[] customFields = customFieldService.createCustomFields(
                        new CustomField[]
                    {
                        customField1,
                        customField2
                    });

                    // Display results.
                    if (customFields != null)
                    {
                        foreach (CustomField customField in customFields)
                        {
                            Console.WriteLine(
                                "Custom field with ID \"{0}\" and name \"{1}\" was created.",
                                customField.id, customField.name);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No custom fields created.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to create custom fields. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (CustomFieldService customFieldService =
                       (CustomFieldService)user.GetService(DfpService.v201802.CustomFieldService))
            {
                // Set the ID of the drop-down custom field to create options for.
                long customFieldId = long.Parse(_T("INSERT_DROP_DOWN_CUSTOM_FIELD_ID_HERE"));

                // Create custom field options.
                CustomFieldOption customFieldOption1 = new CustomFieldOption();
                customFieldOption1.displayName   = "Approved";
                customFieldOption1.customFieldId = customFieldId;

                CustomFieldOption customFieldOption2 = new CustomFieldOption();
                customFieldOption2.displayName   = "Unapproved";
                customFieldOption2.customFieldId = customFieldId;

                try
                {
                    // Add custom field options.
                    CustomFieldOption[] customFieldOptions =
                        customFieldService.createCustomFieldOptions(new CustomFieldOption[]
                    {
                        customFieldOption1,
                        customFieldOption2
                    });

                    // Display results.
                    if (customFieldOptions != null)
                    {
                        foreach (CustomFieldOption customFieldOption in customFieldOptions)
                        {
                            Console.WriteLine(
                                "Custom field option with ID \"{0}\" and name \"{1}\" was " +
                                "created.", customFieldOption.id, customFieldOption.displayName);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No custom field options created.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(
                        "Failed to create custom field options. Exception says \"{0}\"", e.Message);
                }
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (CustomFieldService customFieldService =
                       (CustomFieldService)user.GetService(DfpService.v201802.CustomFieldService))
            {
                // Set the ID of the custom field to update.
                long customFieldId = long.Parse(_T("INSERT_CUSTOM_FIELD_ID_HERE"));

                try
                {
                    // Get the custom field.
                    StatementBuilder statementBuilder = new StatementBuilder()
                                                        .Where("id = :id")
                                                        .OrderBy("id ASC")
                                                        .Limit(1)
                                                        .AddValue("id", customFieldId);

                    CustomFieldPage page =
                        customFieldService.getCustomFieldsByStatement(
                            statementBuilder.ToStatement());
                    CustomField customField = page.results[0];

                    customField.description = (customField.description == null
                        ? ""
                        : customField.description + " Updated");

                    // Update the custom field on the server.
                    CustomField[] customFields = customFieldService.updateCustomFields(
                        new CustomField[]
                    {
                        customField
                    });

                    // Display results
                    foreach (CustomField updatedCustomField in customFields)
                    {
                        Console.WriteLine(
                            "Custom field with ID \"{0}\", name \"{1}\", and description " +
                            "\"{2}\" was updated.", updatedCustomField.id, updatedCustomField.name,
                            updatedCustomField.description);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to update custom fields. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
示例#8
0
 public ServiceList(string url, ResponseToken token)
 {
     this.eventService       = new EventService(url, token);
     this.categoryService    = new CategoryService(url, token);
     this.clubService        = new ClubService(url, token);
     this.userService        = new UserService(url, token);
     this.ticketService      = new TicketService(url, token);
     this.meetingService     = new MeetingService(url, token);
     this.invoiceService     = new InvoiceService(url, token);
     this.groupService       = new GroupService(url, token);
     this.expenseService     = new ExpenseService(url, token);
     this.emailService       = new EmailService(url, token);
     this.depositService     = new DepositService(url, token);
     this.customFieldService = new CustomFieldService(url, token);
     this.taskService        = new TaskService(url, token);
     this.contactService     = new ContactService(url, token);
 }
示例#9
0
 public ServiceList(string url, ResponseToken token)
 {
     this.eventService = new EventService(url, token);
     this.categoryService = new CategoryService(url, token);
     this.clubService = new ClubService(url, token);
     this.userService = new UserService(url, token);
     this.ticketService = new TicketService(url, token);
     this.meetingService = new MeetingService(url, token);
     this.invoiceService = new InvoiceService(url, token);
     this.groupService = new GroupService(url, token);
     this.expenseService = new ExpenseService(url, token);
     this.emailService = new EmailService(url, token);
     this.depositService = new DepositService(url, token);
     this.customFieldService = new CustomFieldService(url, token);
     this.taskService = new TaskService(url, token);
     this.contactService = new ContactService(url, token);
 }
        /// <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 CustomFieldService.
            CustomFieldService customFieldService = (CustomFieldService)user.GetService(
                DfpService.v201311.CustomFieldService);

            // Set the ID of the custom field to update.
            long customFieldId = long.Parse(_T("INSERT_CUSTOM_FIELD_ID_HERE"));

            try {
                // Get the custom field.
                CustomField customField = customFieldService.getCustomField(customFieldId);

                if (customField != null)
                {
                    customField.description =
                        (customField.description == null ? "" : customField.description + " Updated");

                    // Update the custom field on the server.
                    CustomField[] customFields =
                        customFieldService.updateCustomFields(new CustomField[] { customField });

                    // Display results
                    if (customFields != null)
                    {
                        foreach (CustomField updatedCustomField in customFields)
                        {
                            Console.WriteLine("Custom field with ID \"{0}\", name \"{1}\", and description " +
                                              "\"{2}\" was updated.", updatedCustomField.id, updatedCustomField.name,
                                              updatedCustomField.description);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No custom fields were updated.");
                    }
                }
                else
                {
                    Console.WriteLine("No custom fields found to update.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to update custom fields. Exception says \"{0}\"", ex.Message);
            }
        }
示例#11
0
        /// <summary>
        /// EslClient constructor.
        /// Initiates service classes that can be used by the client.
        /// </summary>
        /// <param name="apiKey">The client's api key.</param>
        /// <param name="baseUrl">The staging or production url.</param>
        public EslClient(string apiKey, string baseUrl)
        {
            Asserts.NotEmptyOrNull(apiKey, "apiKey");
            Asserts.NotEmptyOrNull(baseUrl, "baseUrl");
            this.baseUrl = AppendServicePath(baseUrl);

            RestClient restClient = new RestClient(apiKey);

            packageService           = new PackageService(restClient, this.baseUrl);
            sessionService           = new SessionService(apiKey, this.baseUrl);
            fieldSummaryService      = new FieldSummaryService(apiKey, this.baseUrl);
            auditService             = new AuditService(apiKey, this.baseUrl);
            eventNotificationService = new EventNotificationService(restClient, this.baseUrl);
            customFieldService       = new CustomFieldService(restClient, this.baseUrl);
            groupService             = new GroupService(restClient, this.baseUrl);
            accountService           = new AccountService(restClient, this.baseUrl);
            reminderService          = new ReminderService(restClient, this.baseUrl);
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            CustomFieldService customFieldService =
                (CustomFieldService)user.GetService(DfpService.v201605.CustomFieldService);

            // Create a statement to select custom fields.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("entityType = :entityType")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("entityType", CustomFieldEntityType.LINE_ITEM.ToString());

            // Retrieve a small amount of custom fields at a time, paging through
            // until all custom fields have been retrieved.
            CustomFieldPage page = new CustomFieldPage();

            try {
                do
                {
                    page = customFieldService.getCustomFieldsByStatement(statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        // Print out some information for each custom field.
                        int i = page.startIndex;
                        foreach (CustomField customField in page.results)
                        {
                            Console.WriteLine("{0}) Custom field with ID \"{1}\" and name \"{2}\" was found.",
                                              i++,
                                              customField.id,
                                              customField.name);
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get custom fields. Exception says \"{0}\"",
                                  e.Message);
            }
        }
示例#13
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser dfpUser)
        {
            CustomFieldService customFieldService =
                (CustomFieldService)dfpUser.GetService(DfpService.v201608.CustomFieldService);

            // Create a statement to select custom fields.
            int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("entityType = :entityType")
                                                .OrderBy("id ASC")
                                                .Limit(pageSize)
                                                .AddValue("entityType", CustomFieldEntityType.LINE_ITEM.ToString());

            // Retrieve a small amount of custom fields at a time, paging through until all
            // custom fields have been retrieved.
            int totalResultSetSize = 0;

            do
            {
                CustomFieldPage page = customFieldService.getCustomFieldsByStatement(
                    statementBuilder.ToStatement());

                // Print out some information for each custom field.
                if (page.results != null)
                {
                    totalResultSetSize = page.totalResultSetSize;
                    int i = page.startIndex;
                    foreach (CustomField customField in page.results)
                    {
                        Console.WriteLine(
                            "{0}) Custom field with ID {1} and name \"{2}\" was found.",
                            i++,
                            customField.id,
                            customField.name
                            );
                    }
                }

                statementBuilder.IncreaseOffsetBy(pageSize);
            } while (statementBuilder.GetOffset() < totalResultSetSize);

            Console.WriteLine("Number of results found: {0}", totalResultSetSize);
        }
        /// <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 CustomFieldService.
            CustomFieldService customFieldService = (CustomFieldService)user.GetService(
                DfpService.v201311.CustomFieldService);

            // Create statement to select only custom fields that apply to line items.
            String    statementText   = "WHERE entityType = :entityType LIMIT 500";
            Statement filterStatement = new StatementBuilder(statementText)
                                        .AddValue("entityType", CustomFieldEntityType.LINE_ITEM.ToString())
                                        .ToStatement();

            // Set defaults for page and offset.
            CustomFieldPage page   = new CustomFieldPage();
            int             offset = 0;
            int             i      = 0;

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

                    // Get custom fields by statement.
                    page = customFieldService.getCustomFieldsByStatement(filterStatement);

                    if (page.results != null)
                    {
                        foreach (CustomField customField in page.results)
                        {
                            Console.WriteLine("{0}) Custom field with ID \"{1}\" and name \"{2}\" was found.", i,
                                              customField.id, customField.name);
                            i++;
                        }
                    }
                    offset += 500;
                } while (offset < page.totalResultSetSize);
                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get all line item custom fields. 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 CustomFieldService.
            CustomFieldService customFieldService = (CustomFieldService)user.GetService(
                DfpService.v201602.CustomFieldService);

            // Create statement to select only custom fields that apply to line items.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("entityType = :entityType")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("entityType", CustomFieldEntityType.LINE_ITEM.ToString());

            // Set default for page.
            CustomFieldPage page = new CustomFieldPage();
            int             i    = 0;

            try {
                do
                {
                    // Get custom fields by statement.
                    page = customFieldService.getCustomFieldsByStatement(statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        foreach (CustomField customField in page.results)
                        {
                            Console.WriteLine("{0}) Custom field with ID \"{1}\" and name \"{2}\" was found.", i,
                                              customField.id, customField.name);
                            i++;
                        }
                    }
                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < page.totalResultSetSize);
                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get all line item custom fields. Exception says \"{0}\"",
                                  e.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 CustomFieldService.
            CustomFieldService customFieldService = (CustomFieldService)user.GetService(
                DfpService.v201311.CustomFieldService);

            // Create statement to select only active custom fields that apply to
            // line items.
            String    statementText   = "WHERE entityType = :entityType and isActive = :isActive LIMIT 500";
            Statement filterStatement = new StatementBuilder(statementText)
                                        .AddValue("entityType", CustomFieldEntityType.LINE_ITEM.ToString())
                                        .AddValue("isActive", true)
                                        .ToStatement();

            // Set defaults for page and offset.
            CustomFieldPage page           = new CustomFieldPage();
            int             offset         = 0;
            int             i              = 0;
            List <string>   customFieldIds = new List <string>();

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

                    // Get custom fields by statement.
                    page = customFieldService.getCustomFieldsByStatement(filterStatement);

                    if (page.results != null)
                    {
                        foreach (CustomField customField in page.results)
                        {
                            Console.WriteLine("{0}) Custom field with ID \"{1}\" and name \"{2}\" will be " +
                                              "deactivated.", i, customField.id, customField.name);
                            customFieldIds.Add(customField.id.ToString());
                            i++;
                        }
                    }
                    offset += 500;
                } while (offset < page.totalResultSetSize);

                Console.WriteLine("Number of custom fields to be deactivated: " + customFieldIds.Count);

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

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

                    // Perform action.
                    UpdateResult result = customFieldService.performCustomFieldAction(
                        action, filterStatement);

                    // Display results.
                    if (result != null && result.numChanges > 0)
                    {
                        Console.WriteLine("Number of custom fields deactivated: " + result.numChanges);
                    }
                    else
                    {
                        Console.WriteLine("No custom fields were deactivated.");
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to deactivate custom fields. Exception says \"{0}\"", ex.Message);
            }
        }
 public ModuleBaseController(
     ILogger <ModuleBaseController> logger,
     CustomFieldService customFieldsService) : base(logger)
 {
     _customFieldService = customFieldsService;
 }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (CustomFieldService customFieldService = (CustomFieldService)user.GetService(
                       DfpService.v201705.CustomFieldService)) {
                // Set the ID of the custom field to update.
                int customFieldId = int.Parse(_T("INSERT_CUSTOM_FIELD_ID_HERE"));

                // Create statement to select only active custom fields that apply to
                // line items.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("id", customFieldId);

                // Set default for page.
                CustomFieldPage page           = new CustomFieldPage();
                int             i              = 0;
                List <string>   customFieldIds = new List <string>();

                try {
                    do
                    {
                        // Get custom fields by statement.
                        page = customFieldService.getCustomFieldsByStatement(statementBuilder.ToStatement());

                        if (page.results != null)
                        {
                            foreach (CustomField customField in page.results)
                            {
                                Console.WriteLine("{0}) Custom field with ID \"{1}\" and name \"{2}\" will be " +
                                                  "deactivated.", i, customField.id, customField.name);
                                customFieldIds.Add(customField.id.ToString());
                                i++;
                            }
                        }
                        statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                    } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                    Console.WriteLine("Number of custom fields to be deactivated: " + customFieldIds.Count);

                    if (customFieldIds.Count > 0)
                    {
                        // Remove limit and offset from statement.
                        statementBuilder.RemoveLimitAndOffset();

                        // Create action.
                        Google.Api.Ads.Dfp.v201705.DeactivateCustomFields action =
                            new Google.Api.Ads.Dfp.v201705.DeactivateCustomFields();

                        // Perform action.
                        UpdateResult result = customFieldService.performCustomFieldAction(action,
                                                                                          statementBuilder.ToStatement());

                        // Display results.
                        if (result != null && result.numChanges > 0)
                        {
                            Console.WriteLine("Number of custom fields deactivated: " + result.numChanges);
                        }
                        else
                        {
                            Console.WriteLine("No custom fields were deactivated.");
                        }
                    }
                } catch (Exception e) {
                    Console.WriteLine("Failed to deactivate custom fields. Exception says \"{0}\"",
                                      e.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 CustomFieldService.
            CustomFieldService customFieldService = (CustomFieldService)user.GetService(
                DfpService.v201502.CustomFieldService);

            // Get the LineItemService.
            LineItemService lineItemService = (LineItemService)user.GetService(
                DfpService.v201502.LineItemService);

            // Set the IDs of the custom fields, custom field option, and line item.
            long customFieldId       = long.Parse(_T("INSERT_STRING_CUSTOM_FIELD_ID_HERE"));
            long customFieldOptionId = long.Parse(_T("INSERT_CUSTOM_FIELD_OPTION_ID_HERE"));
            long lineItemId          = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE"));

            try {
                // Get the drop-down custom field id.
                long dropDownCustomFieldId =
                    customFieldService.getCustomFieldOption(customFieldOptionId).customFieldId;

                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("id", lineItemId);

                // Get the line item.
                LineItemPage lineItemPage = lineItemService.getLineItemsByStatement(
                    statementBuilder.ToStatement());
                LineItem lineItem = lineItemPage.results[0];

                // Create custom field values.
                List <BaseCustomFieldValue> customFieldValues = new List <BaseCustomFieldValue>();
                TextValue textValue = new TextValue();
                textValue.value = "Custom field value";

                CustomFieldValue customFieldValue = new CustomFieldValue();
                customFieldValue.customFieldId = customFieldId;
                customFieldValue.value         = textValue;
                customFieldValues.Add(customFieldValue);

                DropDownCustomFieldValue dropDownCustomFieldValue = new DropDownCustomFieldValue();
                dropDownCustomFieldValue.customFieldId       = dropDownCustomFieldId;
                dropDownCustomFieldValue.customFieldOptionId = customFieldOptionId;
                customFieldValues.Add(dropDownCustomFieldValue);

                // Only add existing custom field values for different custom fields than
                // the ones you are setting.
                if (lineItem.customFieldValues != null)
                {
                    foreach (BaseCustomFieldValue oldCustomFieldValue in lineItem.customFieldValues)
                    {
                        if (!(oldCustomFieldValue.customFieldId == customFieldId) &&
                            !(oldCustomFieldValue.customFieldId == dropDownCustomFieldId))
                        {
                            customFieldValues.Add(oldCustomFieldValue);
                        }
                    }
                }

                lineItem.customFieldValues = customFieldValues.ToArray();

                // Update the line item on the server.
                LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[] { lineItem });

                if (lineItems != null)
                {
                    foreach (LineItem updatedLineItem in lineItems)
                    {
                        List <String> customFieldValueStrings = new List <String>();
                        foreach (BaseCustomFieldValue baseCustomFieldValue in lineItem.customFieldValues)
                        {
                            if (baseCustomFieldValue is CustomFieldValue &&
                                ((CustomFieldValue)baseCustomFieldValue).value is TextValue)
                            {
                                customFieldValueStrings.Add("{ID: '" + baseCustomFieldValue.customFieldId
                                                            + "', value: '"
                                                            + ((TextValue)((CustomFieldValue)baseCustomFieldValue).value).value
                                                            + "'}");
                            }
                            else if (baseCustomFieldValue is DropDownCustomFieldValue)
                            {
                                customFieldValueStrings.Add("{ID: '" + baseCustomFieldValue.customFieldId
                                                            + "', custom field option ID: '"
                                                            + ((DropDownCustomFieldValue)baseCustomFieldValue).customFieldOptionId
                                                            + "'}");
                            }
                        }
                        Console.WriteLine("A line item with ID \"{0}\" set with custom field values \"{1}\".",
                                          updatedLineItem.id, string.Join(", ", customFieldValueStrings.ToArray()));
                    }
                }
                else
                {
                    Console.WriteLine("No line items were updated.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to update line items. Exception says \"{0}\"", ex.Message);
            }
        }