-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathContextBase.cs
More file actions
71 lines (57 loc) · 1.67 KB
/
ContextBase.cs
File metadata and controls
71 lines (57 loc) · 1.67 KB
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
using System;
using System.Threading;
using ServiceStack.Logging;
using ServiceStack.Service;
using ServiceStack.ServiceModel.Version100;
namespace SilverlightStack.Client
{
public class ContextBase<TAppContext>
{
protected ILog log;
protected IServiceClient serviceClient;
protected TAppContext appContext;
public ContextBase(IServiceClient serviceClient, TAppContext appContext)
{
this.serviceClient = serviceClient;
this.appContext = appContext;
this.log = LogManager.GetLogger(GetType());
}
public event EventHandler<DataEventArgs> DataLoaded;
protected void OnDataLoaded(DataEventArgs e)
{
var loaded = DataLoaded;
if (loaded != null) loaded(this, e);
}
protected TResponse Send<TResponse>(object request, Func<ResponseStatus> chechResponseStatus)
{
var response = serviceClient.Send<TResponse>(request);
AssertSuccessResponse(chechResponseStatus());
return response;
}
private static void AssertSuccessResponse(ResponseStatus responseStatus)
{
if (!responseStatus.IsSuccess)
{
throw new SilverlightStackException(responseStatus.ErrorCode);
}
}
protected void InvokeAsync(Action action)
{
ThreadPool.QueueUserWorkItem(delegate {
action();
});
//asyncAction.BeginInvoke is not supported in Silverlight
//var asyncAction = (Action)delegate {
// try
// {
// action();
// }
// catch (Exception ex)
// {
// log.Error(string.Format("Error executing async command '{0}': {1}", action.Method.Name, ex.Message), ex);
// }
//};
//asyncAction.BeginInvoke(null, null);
}
}
}