/// <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()); }
/// <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); } }