-
Notifications
You must be signed in to change notification settings - Fork 9
/
ProgramSync.cs
92 lines (76 loc) · 3.59 KB
/
ProgramSync.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
namespace SampleApp
{
using System;
using System.Collections.Generic;
using System.Threading;
using Adobe.Target.Client;
using Adobe.Target.Client.Model;
using Adobe.Target.Delivery.Model;
using Microsoft.Extensions.Logging;
internal class ProgramSync
{
private static TargetClient targetClient;
private static ILogger<ProgramSync> logger;
public static void Main(string[] args)
{
Console.WriteLine("Sync app");
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddSimpleConsole(options => options.TimestampFormat = "hh:mm:ss ");
builder.SetMinimumLevel(LogLevel.Debug);
});
logger = loggerFactory.CreateLogger<ProgramSync>();
// Initialize the SDK
var targetClientConfig = new TargetClientConfig.Builder("adobetargetmobile", "B8A054D958807F770A495DD6@AdobeOrg")
.SetLogger(logger)
.SetDecisioningMethod(DecisioningMethod.OnDevice)
.SetOnDeviceDecisioningReady(DecisioningReady)
.SetArtifactDownloadSucceeded(artifact => Console.WriteLine("ArtifactDownloadSucceeded: " + artifact))
.SetArtifactDownloadFailed(exception => Console.WriteLine("ArtifactDownloadFailed " + exception.Message))
.Build();
targetClient = TargetClient.Create(targetClientConfig);
// sample server-side GetOffers call
var deliveryRequest = new TargetDeliveryRequest.Builder()
.SetDecisioningMethod(DecisioningMethod.ServerSide)
.SetThirdPartyId("testThirdPartyId")
.SetContext(new Context(ChannelType.Web))
.SetExecute(new ExecuteRequest(null, new List<MboxRequest>
{
new (index: 0, name: "a1-serverside-ab")
}))
.Build();
var response = targetClient.GetOffers(deliveryRequest);
App.PrintCookies(logger, response);
// sample SendNotifications call
var notificationRequest = new TargetDeliveryRequest.Builder()
.SetDecisioningMethod(DecisioningMethod.ServerSide)
.SetSessionId(response.Request.SessionId)
.SetTntId(response.Response?.Id?.TntId)
.SetThirdPartyId("testThirdPartyId")
.SetContext(new Context(ChannelType.Web))
.SetNotifications(new List<Notification>()
{
new (id:"notificationId1", type: MetricType.Display, timestamp: DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
tokens: new List<string>())
})
.Build();
var notificationResponse = targetClient.SendNotifications(notificationRequest);
App.PrintCookies(logger, notificationResponse);
Thread.Sleep(3000);
}
private static void DecisioningReady()
{
Console.WriteLine("OnDeviceDecisioningReady");
// sample on-device GetOffers call
var deliveryRequest = new TargetDeliveryRequest.Builder()
.SetContext(new Context(ChannelType.Web, geo: new Geo("193.105.140.131")))
.SetExecute(new ExecuteRequest(new RequestDetails(), new List<MboxRequest>
{
new (index: 1, name: "a1-mobile-tstsree")
}))
.Build();
var response = targetClient.GetOffers(deliveryRequest);
App.PrintCookies(logger, response);
}
}
}