Révision be694ed4 TestXamConnections/TestXamConnections.Android/Connection/InternConnectionService.cs
TestXamConnections/TestXamConnections.Android/Connection/InternConnectionService.cs | ||
---|---|---|
23 | 23 |
public class InternConnectionService : IConnectionService |
24 | 24 |
{ |
25 | 25 |
public EventHandler<byte[]> DataReceivedEvent { get; set; } |
26 |
public EventHandler<string> ConnectionFailedEvent { get; set; } |
|
27 | 26 |
|
28 | 27 |
private readonly IntentReceiver intentReceiver; |
29 | 28 |
private readonly Context appContext; |
... | ... | |
31 | 30 |
/* La fonction connect dans le cas du connexion en interne |
32 | 31 |
* Est en fait, la configuration de l'IntentReceiver |
33 | 32 |
*/ |
34 |
public async Task Connect(Dictionary<string, string> param)
|
|
33 |
public Task<bool> Connect(Dictionary<string, string> param)
|
|
35 | 34 |
{ |
36 | 35 |
if (param.ContainsKey(ConnectionConstants.RECEIVABLE_INTENTS_KEY)) |
37 | 36 |
{ |
... | ... | |
42 | 41 |
IntentFilter intentFilter = new IntentFilter(); |
43 | 42 |
intents.ForEach(intent => intentFilter.AddAction(intent)); |
44 | 43 |
|
45 |
await Task.Run( () => appContext.RegisterReceiver(intentReceiver, intentFilter) );
|
|
44 |
appContext.RegisterReceiver(intentReceiver, intentFilter);
|
|
46 | 45 |
} |
47 | 46 |
else |
48 | 47 |
{ |
49 |
ConnectionFailedEvent.Invoke(this, null);
|
|
48 |
return Task.FromResult(false);
|
|
50 | 49 |
} |
51 |
return; |
|
50 |
return Task.FromResult(true);
|
|
52 | 51 |
} |
53 | 52 |
|
54 | 53 |
public Task<bool> SendCommand(string command) |
... | ... | |
80 | 79 |
break; |
81 | 80 |
|
82 | 81 |
case AgridentConstants.ACTION_AGRIDENT_ERROR: |
83 |
DataReceivedEvent.Invoke(this, Encoding.ASCII.GetBytes("ERROR")); |
|
82 |
DataReceivedEvent.Invoke(this, Encoding.ASCII.GetBytes(AgridentConstants.ACTION_AGRIDENT_ERROR)); |
|
83 |
break; |
|
84 |
|
|
85 |
case AgridentConstants.ACTION_AGRIDENT_SERVICE_START: |
|
86 |
DataReceivedEvent.Invoke(this, Encoding.ASCII.GetBytes(AgridentConstants.ACTION_AGRIDENT_SERVICE_START)); |
|
87 |
break; |
|
88 |
|
|
89 |
case AgridentConstants.ACTION_AGRIDENT_SERVICE_STOP: |
|
90 |
DataReceivedEvent.Invoke(this, Encoding.ASCII.GetBytes(AgridentConstants.ACTION_AGRIDENT_SERVICE_STOP)); |
|
84 | 91 |
break; |
85 | 92 |
|
86 | 93 |
default: |
Formats disponibles : Unified diff