-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApiService.cs
executable file
·64 lines (55 loc) · 2.14 KB
/
ApiService.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
using System;
using System.Xml.Linq;
namespace AmxMobile.Phone7.SixBookmarks
{
public class ApiService : RestServiceProxy
{
public ApiService()
: base("apirest.aspx")
{
}
public void Logon(string password, Action<LogonResponse> result, Failed failed)
{
// create the request...
RestRequestArgs args = new RestRequestArgs("logon");
args["password"] = password;
// send the request...
this.SendRequest(args, (Action<XElement>)delegate(XElement element)
{
// walk...
LogonResponse response = LogonResponse.FromXmlElement(element);
if (response == null)
throw new InvalidOperationException("'response' is null.");
// call...
result(response);
}, failed);
}
internal override bool IsAuthenticated
{
get
{
// make this return true, otherwise we'll get a
// stack overflow...
return true;
}
}
internal static void Authenticate(Action callback, Failed failed)
{
ApiService service = new ApiService();
service.Logon(ApiPassword, (Action<LogonResponse>)delegate(LogonResponse result)
{
// we have a result from *our* call to ApiService, if that works, call back to the next
// item in the chain...
if (result.Result == LogonResult.LogonOk)
{
// store the token in static memory...
Token = result.Token;
// call the caller...
callback();
}
else
throw new InvalidOperationException(string.Format("A response of '{0}' was returned when authenticating the API. Check that the the values of ApiUsername and ApiPassword correspond to your unique API account.", result.Result));
}, failed);
}
}
}