mirror of https://github.com/icedream/npsharp.git
Make RPC stream accessible from high-level API since it's incomplete as fuck.
parent
817007c135
commit
b380f926ca
|
@ -20,7 +20,8 @@ namespace NPSharp.NP
|
|||
private readonly ushort _port;
|
||||
private CancellationToken _cancellationToken;
|
||||
private CancellationTokenSource _cancellationTokenSource;
|
||||
private RPCClientStream _rpc;
|
||||
|
||||
public RPCClientStream RPC { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the NP client with a specified host and port.
|
||||
|
@ -58,7 +59,7 @@ namespace NPSharp.NP
|
|||
|
||||
try
|
||||
{
|
||||
_rpc = RPCClientStream.Open(_host, _port);
|
||||
RPC = RPCClientStream.Open(_host, _port);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
|
@ -77,7 +78,7 @@ namespace NPSharp.NP
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
if (_rpc.Read() == null)
|
||||
if (RPC.Read() == null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +105,7 @@ namespace NPSharp.NP
|
|||
_cancellationTokenSource.Cancel(true);
|
||||
// TODO: Find a cleaner way to cancel _processingTask (focus: _rpc.Read)
|
||||
//_procTask.Wait(_cancellationToken);
|
||||
_rpc.Close();
|
||||
RPC.Close();
|
||||
|
||||
LoginId = 0;
|
||||
|
||||
|
@ -122,7 +123,7 @@ namespace NPSharp.NP
|
|||
{
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
_rpc.AttachHandlerForNextMessage(packet =>
|
||||
RPC.AttachHandlerForNextMessage(packet =>
|
||||
{
|
||||
var result = packet as AuthenticateResultMessage;
|
||||
if (result == null)
|
||||
|
@ -134,7 +135,7 @@ namespace NPSharp.NP
|
|||
SessionToken = result.SessionToken;
|
||||
tcs.SetResult(true);
|
||||
});
|
||||
_rpc.Send(new AuthenticateWithTokenMessage {Token = token});
|
||||
RPC.Send(new AuthenticateWithTokenMessage {Token = token});
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
|
@ -150,14 +151,14 @@ namespace NPSharp.NP
|
|||
{
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
_rpc.AttachHandlerForNextMessage(packet =>
|
||||
RPC.AttachHandlerForNextMessage(packet =>
|
||||
{
|
||||
var result = (StorageWriteUserFileResultMessage) packet;
|
||||
if (result.Result != 0)
|
||||
tcs.SetResult(false);
|
||||
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;
|
||||
}
|
||||
|
@ -171,7 +172,7 @@ namespace NPSharp.NP
|
|||
{
|
||||
var tcs = new TaskCompletionSource<byte[]>();
|
||||
|
||||
_rpc.AttachHandlerForNextMessage(packet =>
|
||||
RPC.AttachHandlerForNextMessage(packet =>
|
||||
{
|
||||
var result = (StorageUserFileMessage) packet;
|
||||
if (result.Result != 0)
|
||||
|
@ -181,7 +182,7 @@ namespace NPSharp.NP
|
|||
}
|
||||
tcs.SetResult(result.FileData);
|
||||
});
|
||||
_rpc.Send(new StorageGetUserFileMessage {FileName = filename, NPID = LoginId});
|
||||
RPC.Send(new StorageGetUserFileMessage {FileName = filename, NPID = LoginId});
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
|
@ -209,7 +210,7 @@ namespace NPSharp.NP
|
|||
{
|
||||
var tcs = new TaskCompletionSource<byte[]>();
|
||||
|
||||
_rpc.AttachHandlerForNextMessage(packet =>
|
||||
RPC.AttachHandlerForNextMessage(packet =>
|
||||
{
|
||||
var result = (StoragePublisherFileMessage) packet;
|
||||
if (result.Result != 0)
|
||||
|
@ -219,7 +220,7 @@ namespace NPSharp.NP
|
|||
}
|
||||
tcs.SetResult(result.FileData);
|
||||
});
|
||||
_rpc.Send(new StorageGetPublisherFileMessage {FileName = filename});
|
||||
RPC.Send(new StorageGetPublisherFileMessage {FileName = filename});
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
|
@ -238,7 +239,7 @@ namespace NPSharp.NP
|
|||
|
||||
public void SendRandomString(string data)
|
||||
{
|
||||
_rpc.Send(new StorageSendRandomStringMessage {RandomString = data});
|
||||
RPC.Send(new StorageSendRandomStringMessage {RandomString = data});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using log4net;
|
||||
using NPSharp.RPC.Messages;
|
||||
|
||||
namespace NPSharp.RPC
|
||||
|
@ -32,11 +31,6 @@ namespace NPSharp.RPC
|
|||
protected readonly List<KeyValuePair<uint, Action<TRecv>>> TypeCallbacks =
|
||||
new List<KeyValuePair<uint, Action<TRecv>>>();
|
||||
|
||||
/// <summary>
|
||||
/// Logger instance.
|
||||
/// </summary>
|
||||
private readonly ILog _log;
|
||||
|
||||
/// <summary>
|
||||
/// ID of the next message.
|
||||
/// </summary>
|
||||
|
@ -53,7 +47,6 @@ namespace NPSharp.RPC
|
|||
/// <param name="sock">Client's network stream</param>
|
||||
protected RPCStream(Socket sock)
|
||||
{
|
||||
_log = LogManager.GetLogger("RPC");
|
||||
_sock = sock;
|
||||
}
|
||||
|
||||
|
@ -138,7 +131,7 @@ namespace NPSharp.RPC
|
|||
|
||||
_sock.Send(buffer);
|
||||
|
||||
if (typeof (TSend) == typeof (RPCClientMessage))
|
||||
if (typeof(TSend) == typeof(RPCClientMessage))
|
||||
IterateMessageID();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue