forked from BingAds/BingAds-dotNet-SDK
/
ExampleBase.cs
70 lines (63 loc) · 2.34 KB
/
ExampleBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.BingAds;
using Microsoft.BingAds.CampaignManagement;
namespace BingAdsExamples
{
/// <summary>
/// Provides a base class for extending and experimenting with Bing Ads examples.
/// </summary>
public abstract class ExampleBase
{
public delegate void SendMessageDelegate(String msg);
public SendMessageDelegate OutputStatusMessage;
/// <summary>
/// The description of the example.
/// </summary>
public abstract String Description { get; }
/// <summary>
/// The name of the example
/// </summary>
public String ExampleName
{
get
{
var s = GetType();
return s.Name;
}
}
/// <summary>
/// Initializes a new instance of the ExampleBase class, and sets the default output status message.
/// </summary>
protected ExampleBase()
{
OutputStatusMessage = OutputStatusMessageDefault;
}
/// <summary>
/// Write to the console by default, if the example does not implement its own OutputStatusMessage method.
/// </summary>
/// <param name="msg">The message sent to console output.</param>
private void OutputStatusMessageDefault(String msg)
{
Console.WriteLine(msg);
}
/// <summary>
/// Each example must implement either Run or RunAsync as the main entry point.
/// </summary>
/// <param name="authorizationData">Represents a user who intends to access the corresponding customer and account. </param>
public virtual void Run(AuthorizationData authorizationData)
{
throw new NotImplementedException("You must implement either Run or RunAsync");
}
/// <summary>
/// Each example must implement either Run or RunAsync as the main entry point.
/// </summary>
/// <param name="authorizationData">Represents a user who intends to access the corresponding customer and account.</param>
/// <returns></returns>
public virtual async Task RunAsync(AuthorizationData authorizationData)
{
await Task.Factory.StartNew(() => Run(authorizationData));
}
}
}