/// <summary>
        /// Gets the ad types.
        /// </summary>
        /// <returns></returns>
        internal AdType[] GetAdTypes()
        {
            // Create AdRemoteService instance.
            AdRemoteService service = (AdRemoteService)user.GetService(
                DfaService.v1_20.AdRemoteService);

            // Get ad types.
            return(service.getAdTypes());
        }
Example #2
0
        /// <summary>
        /// Handles the Click event of the btnAdTypes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="eventArgs">The <see cref="System.EventArgs"/> instance containing
        /// the event data.</param>
        protected void OnGetAdTypesButtonClick(object sender, EventArgs eventArgs)
        {
            ConfigureUserForOAuth();

            try {
                // Set the username. This is required for the LoginService to work
                // correctly when authenticating using OAuth2.
                (user.Config as DfaAppConfig).DfaUserName = txtUserName.Text;

                // Create AdRemoteService instance.
                AdRemoteService service = (AdRemoteService)user.GetService(
                    DfaService.v1_20.AdRemoteService);

                // Get ad types.
                AdType[] adTypes = service.getAdTypes();

                // Display ad type and its id.
                foreach (AdType result in adTypes)
                {
                    Console.WriteLine("Ad type with name \"{0}\" and id \"{1}\" was found.", result.name,
                                      result.id);
                }

                // Display ad types.
                if (adTypes != null && adTypes.Length > 0)
                {
                    DataTable dataTable = new DataTable();
                    dataTable.Columns.AddRange(new DataColumn[] {
                        new DataColumn("Serial No.", typeof(int)),
                        new DataColumn("Id", typeof(long)),
                        new DataColumn("Ad Type", typeof(string)),
                    });
                    for (int i = 0; i < adTypes.Length; i++)
                    {
                        AdType  result  = adTypes[i];
                        DataRow dataRow = dataTable.NewRow();
                        dataRow.ItemArray = new object[] { i + 1, result.id, result.name };
                        dataTable.Rows.Add(dataRow);
                    }

                    AdTypeGrid.DataSource = dataTable;
                    AdTypeGrid.DataBind();
                }
                else
                {
                    Response.Write("No ad types were found.");
                }
            } catch (Exception e) {
                Response.Write(string.Format("Failed to get ad types. Exception says \"{0}\"",
                                             e.Message));
            }
        }
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        static void Main(string[] args)
        {
            DfaUser      user   = new DfaUser();
            DfaAppConfig config = (user.Config as DfaAppConfig);

            if (config.AuthorizationMethod == DfaAuthorizationMethod.OAuth2)
            {
                if (config.OAuth2Mode == OAuth2Flow.APPLICATION &&
                    string.IsNullOrEmpty(config.OAuth2RefreshToken))
                {
                    DoAuth2Authorization(user);
                }
            }
            else
            {
                throw new Exception("Authorization mode is not OAuth.");
            }

            // Set the username. This is required for the LoginService to work
            // correctly when authenticating using OAuth2.
            Console.Write("Enter the user name: ");
            string userName = Console.ReadLine();

            (user.Config as DfaAppConfig).DfaUserName = userName;

            // Create AdRemoteService instance.
            AdRemoteService service = (AdRemoteService)user.GetService(
                DfaService.v1_20.AdRemoteService);

            try {
                // Get ad types.
                AdType[] adTypes = service.getAdTypes();

                // Display ad type and its id.
                foreach (AdType result in adTypes)
                {
                    Console.WriteLine("Ad type with name \"{0}\" and id \"{1}\" was found.", result.name,
                                      result.id);
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to retrieve ad types. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Create AdRemoteService instance.
            AdRemoteService service = (AdRemoteService)user.GetService(
                DfaService.v1_19.AdRemoteService);

            try {
                // Get ad types.
                AdType[] adTypes = service.getAdTypes();

                // Display ad type and its id.
                foreach (AdType result in adTypes)
                {
                    Console.WriteLine("Ad type with name \"{0}\" and id \"{1}\" was found.", result.name,
                                      result.id);
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to retrieve ad types. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();

            string userName        = _T("INSERT_USERNAME_HERE");
            string password        = _T("INSERT_PASSWORD_HERE");
            string applicationName = _T("INSERT_APPLICATION_NAME_HERE");

            headers.Add("userName", userName);
            headers.Add("password", password);
            headers.Add("applicationName", applicationName);

            // If you have already used LoginRemoteService to obtain your token, then
            // you can set the authToken header instead of the password header like:
            //     string authToken = _T("INSERT_AUTH_TOKEN_HERE");
            //     headers.Add("authToken", authToken);

            // Since we are creating a custom DfaUser, we don't use the user passed
            // as a method argument.
            DfaUser user1 = new DfaUser(headers);

            // Create AdRemoteService instance.
            AdRemoteService service = (AdRemoteService)user1.GetService(
                DfaService.v1_20.AdRemoteService);

            try {
                // Get ad types.
                AdType[] adTypes = service.getAdTypes();

                // Display ad type and its id.
                foreach (AdType result in adTypes)
                {
                    Console.WriteLine("Ad type with name \"{0} and id \"{1}\" was found.", result.name,
                                      result.id);
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to retrieve ad types. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
Example #6
0
 public void Init()
 {
     user            = new DfaUser();
     adRemoteService = (AdRemoteService)user.GetService(DfaService.v1_20.AdRemoteService);
 }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Create AdRemoteService instance.
            AdRemoteService service = (AdRemoteService)user.GetService(
                DfaService.v1_20.AdRemoteService);

            long   campaignId  = long.Parse(_T("INSERT_CAMPAIGN_ID_HERE"));
            long   sizeId      = long.Parse(_T("INSERT_SIZE_ID_HERE"));
            long   creativeId  = long.Parse(_T("INSERT_CREATIVE_ID_HERE"));
            long   placementId = long.Parse(_T("INSERT_PLACEMENT_ID_HERE"));
            String adName      = _T("INSERT_AD_NAME_HERE");
            long   typeId      = long.Parse(_T("INSERT_AD_TYPEID_HERE"));

            // Create rotation group structure.
            RotationGroup rotationGroup = new RotationGroup();

            rotationGroup.id         = 0;
            rotationGroup.name       = adName;
            rotationGroup.active     = true;
            rotationGroup.archived   = false;
            rotationGroup.campaignId = campaignId;
            rotationGroup.sizeId     = sizeId;
            rotationGroup.typeId     = typeId;
            rotationGroup.priority   = 12;
            rotationGroup.ratio      = 1;

            // Set ad start and end dates.
            rotationGroup.startTime = DateTime.Today.AddDays(1);
            rotationGroup.endTime   = DateTime.Today.AddMonths(1);

            // Add creatives to the ad.
            CreativeAssignment creativeAssignment = new CreativeAssignment();

            creativeAssignment.active     = true;
            creativeAssignment.creativeId = creativeId;

            // Create click through url.
            ClickThroughUrl clickThroughUrl = new ClickThroughUrl();

            clickThroughUrl.defaultLandingPageUsed = true;
            clickThroughUrl.landingPageId          = 0;
            creativeAssignment.clickThroughUrl     = clickThroughUrl;

            // Create creative assigments.
            rotationGroup.creativeAssignments = new CreativeAssignment[] { creativeAssignment };
            rotationGroup.rotationType        = 1;

            // Assign ad to placement.
            PlacementAssignment placementAssignment = new PlacementAssignment();

            placementAssignment.active         = true;
            placementAssignment.placementId    = placementId;
            rotationGroup.placementAssignments = new PlacementAssignment[] { placementAssignment };

            try {
                // Create rotation group.
                AdSaveResult result = service.saveAd(rotationGroup);

                // Display new ad id.
                Console.WriteLine("Ad with id \"{0}\" was created.", result.id);
            } catch (Exception ex) {
                Console.WriteLine("Failed to create rotation group. Exception says \"{0}\"", ex.Message);
            }
        }