Merge remote-tracking branch 'github/master'

Conflicts:
	src/client/NP/NPClient.cs
feature-npv2
Icedream 2014-05-31 00:41:22 +02:00
commit 27fbe3e7e3
2 changed files with 15 additions and 21 deletions

View File

@ -20,7 +20,8 @@ namespace NPSharp.NP
private readonly ushort _port; private readonly ushort _port;
private CancellationToken _cancellationToken; private CancellationToken _cancellationToken;
private CancellationTokenSource _cancellationTokenSource; private CancellationTokenSource _cancellationTokenSource;
private RPCClientStream _rpc;
public RPCClientStream RPC { get; private set; }
/// <summary> /// <summary>
/// Initializes the NP client with a specified host and port. /// Initializes the NP client with a specified host and port.
@ -63,7 +64,7 @@ namespace NPSharp.NP
try try
{ {
_rpc = RPCClientStream.Open(_host, _port); RPC = RPCClientStream.Open(_host, _port);
} }
catch (Exception err) catch (Exception err)
{ {
@ -82,7 +83,7 @@ namespace NPSharp.NP
{ {
while (true) while (true)
{ {
if (_rpc.Read() == null) if (RPC.Read() == null)
break; break;
} }
} }
@ -109,7 +110,7 @@ namespace NPSharp.NP
_cancellationTokenSource.Cancel(true); _cancellationTokenSource.Cancel(true);
// TODO: Find a cleaner way to cancel _processingTask (focus: _rpc.Read) // TODO: Find a cleaner way to cancel _processingTask (focus: _rpc.Read)
//_procTask.Wait(_cancellationToken); //_procTask.Wait(_cancellationToken);
_rpc.Close(); RPC.Close();
LoginId = 0; LoginId = 0;
@ -127,7 +128,7 @@ namespace NPSharp.NP
{ {
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<bool>();
_rpc.AttachHandlerForNextMessage(packet => RPC.AttachHandlerForNextMessage(packet =>
{ {
var result = packet as AuthenticateResultMessage; var result = packet as AuthenticateResultMessage;
if (result == null) if (result == null)
@ -139,7 +140,7 @@ namespace NPSharp.NP
SessionToken = result.SessionToken; SessionToken = result.SessionToken;
tcs.SetResult(true); tcs.SetResult(true);
}); });
_rpc.Send(new AuthenticateWithTokenMessage {Token = token}); RPC.Send(new AuthenticateWithTokenMessage {Token = token});
return await tcs.Task; return await tcs.Task;
} }
@ -211,14 +212,14 @@ namespace NPSharp.NP
{ {
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<bool>();
_rpc.AttachHandlerForNextMessage(packet => RPC.AttachHandlerForNextMessage(packet =>
{ {
var result = (StorageWriteUserFileResultMessage) packet; var result = (StorageWriteUserFileResultMessage) packet;
if (result.Result != 0) if (result.Result != 0)
tcs.SetResult(false); tcs.SetResult(false);
tcs.SetResult(true); tcs.SetResult(true);
}); });
_rpc.Send(new StorageWriteUserFileMessage {FileData = contents, FileName = filename, NPID = LoginId}); RPC.Send(new StorageWriteUserFileMessage {FileData = contents, FileName = filename, NPID = LoginId});
return await tcs.Task; return await tcs.Task;
} }
@ -232,7 +233,7 @@ namespace NPSharp.NP
{ {
var tcs = new TaskCompletionSource<byte[]>(); var tcs = new TaskCompletionSource<byte[]>();
_rpc.AttachHandlerForNextMessage(packet => RPC.AttachHandlerForNextMessage(packet =>
{ {
var result = (StorageUserFileMessage) packet; var result = (StorageUserFileMessage) packet;
if (result.Result != 0) if (result.Result != 0)
@ -242,7 +243,7 @@ namespace NPSharp.NP
} }
tcs.SetResult(result.FileData); tcs.SetResult(result.FileData);
}); });
_rpc.Send(new StorageGetUserFileMessage {FileName = filename, NPID = LoginId}); RPC.Send(new StorageGetUserFileMessage {FileName = filename, NPID = LoginId});
return await tcs.Task; return await tcs.Task;
} }
@ -270,7 +271,7 @@ namespace NPSharp.NP
{ {
var tcs = new TaskCompletionSource<byte[]>(); var tcs = new TaskCompletionSource<byte[]>();
_rpc.AttachHandlerForNextMessage(packet => RPC.AttachHandlerForNextMessage(packet =>
{ {
var result = (StoragePublisherFileMessage) packet; var result = (StoragePublisherFileMessage) packet;
if (result.Result != 0) if (result.Result != 0)
@ -280,7 +281,7 @@ namespace NPSharp.NP
} }
tcs.SetResult(result.FileData); tcs.SetResult(result.FileData);
}); });
_rpc.Send(new StorageGetPublisherFileMessage {FileName = filename}); RPC.Send(new StorageGetPublisherFileMessage {FileName = filename});
return await tcs.Task; return await tcs.Task;
} }
@ -299,7 +300,7 @@ namespace NPSharp.NP
public void SendRandomString(string data) public void SendRandomString(string data)
{ {
_rpc.Send(new StorageSendRandomStringMessage {RandomString = data}); RPC.Send(new StorageSendRandomStringMessage {RandomString = data});
} }
} }
} }

View File

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Sockets; using System.Net.Sockets;
using log4net;
using NPSharp.RPC.Messages; using NPSharp.RPC.Messages;
namespace NPSharp.RPC namespace NPSharp.RPC
@ -32,11 +31,6 @@ namespace NPSharp.RPC
protected readonly List<KeyValuePair<uint, Action<TRecv>>> TypeCallbacks = protected readonly List<KeyValuePair<uint, Action<TRecv>>> TypeCallbacks =
new List<KeyValuePair<uint, Action<TRecv>>>(); new List<KeyValuePair<uint, Action<TRecv>>>();
/// <summary>
/// Logger instance.
/// </summary>
private readonly ILog _log;
/// <summary> /// <summary>
/// ID of the next message. /// ID of the next message.
/// </summary> /// </summary>
@ -53,7 +47,6 @@ namespace NPSharp.RPC
/// <param name="sock">Client's network stream</param> /// <param name="sock">Client's network stream</param>
protected RPCStream(Socket sock) protected RPCStream(Socket sock)
{ {
_log = LogManager.GetLogger("RPC");
_sock = sock; _sock = sock;
} }