diff --git a/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj b/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj
index 979d441..55baa8f 100644
--- a/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj
+++ b/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj
@@ -11,7 +11,7 @@
http://www.esiur.com
https://github.com/esiur/esiur-dotnet/
True
- 1.2.3
+ 1.2.5
diff --git a/Esiur.Stores.MongoDB/MongoDBStore.cs b/Esiur.Stores.MongoDB/MongoDBStore.cs
index 451871e..aab580f 100644
--- a/Esiur.Stores.MongoDB/MongoDBStore.cs
+++ b/Esiur.Stores.MongoDB/MongoDBStore.cs
@@ -1,6 +1,6 @@
using Esiur.Resource;
using System;
-using Esiur.Engine;
+using Esiur.Core;
using MongoDB.Driver.Core;
using MongoDB.Driver;
using MongoDB.Bson;
@@ -530,12 +530,14 @@ namespace Esiur.Stores.MongoDB
var attrsDoc = ComposeStructure(attrs);
+ var type = ResourceProxy.GetBaseType(resource);
+
var document = new BsonDocument
{
{ "parents", parents },
{ "children", children },
{"attributes", attrsDoc },
- { "classname", resource.GetType().FullName + "," + resource.GetType().GetTypeInfo().Assembly.GetName().Name },
+ { "classname", type.FullName + "," + type.GetTypeInfo().Assembly.GetName().Name },
{ "name", resource.Instance.Name },
{ "_id", new BsonObjectId(new ObjectId(resource.Instance.Attributes["objectId"].ToString())) },
{"values", values }
diff --git a/Esiur/Engine/AsyncAwaiter.cs b/Esiur/Core/AsyncAwaiter.cs
similarity index 67%
rename from Esiur/Engine/AsyncAwaiter.cs
rename to Esiur/Core/AsyncAwaiter.cs
index 2c1af2e..cead3c4 100644
--- a/Esiur/Engine/AsyncAwaiter.cs
+++ b/Esiur/Core/AsyncAwaiter.cs
@@ -3,21 +3,21 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
-namespace Esiur.Engine
+namespace Esiur.Core
{
public class AsyncAwaiter : INotifyCompletion
{
- Action callback = null;
- T result;
+ public Action callback = null;
+ public T result;
private bool completed;
public AsyncAwaiter(AsyncReply reply)
{
reply.Then(x =>
{
- completed = true;
- result = x;
- callback?.Invoke();
+ this.completed = true;
+ this.result = x;
+ this.callback?.Invoke();
});
}
@@ -28,10 +28,10 @@ namespace Esiur.Engine
public bool IsCompleted => completed;
- //From INotifyCompletion
public void OnCompleted(Action continuation)
{
- Console.WriteLine("Continue....");
+ // Continue....
+ callback = continuation;
}
diff --git a/Esiur/Engine/AsyncBag.cs b/Esiur/Core/AsyncBag.cs
similarity index 99%
rename from Esiur/Engine/AsyncBag.cs
rename to Esiur/Core/AsyncBag.cs
index e277df5..7109eda 100644
--- a/Esiur/Engine/AsyncBag.cs
+++ b/Esiur/Core/AsyncBag.cs
@@ -28,7 +28,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Esiur.Engine
+namespace Esiur.Core
{
public class AsyncBag: AsyncReply
{
diff --git a/Esiur/Engine/AsyncException.cs b/Esiur/Core/AsyncException.cs
similarity index 68%
rename from Esiur/Engine/AsyncException.cs
rename to Esiur/Core/AsyncException.cs
index fea9a4b..eb52267 100644
--- a/Esiur/Engine/AsyncException.cs
+++ b/Esiur/Core/AsyncException.cs
@@ -26,39 +26,8 @@ using System;
using System.Collections.Generic;
using System.Text;
-namespace Esiur.Engine
+namespace Esiur.Core
{
- public enum ExceptionCode : ushort
- {
- HostNotReachable,
- AccessDenied,
- ResourceNotFound,
- AttachDenied,
- InvalidMethod,
- InvokeDenied,
- CreateDenied,
- AddParentDenied,
- AddChildDenied,
- ViewAttributeDenied,
- UpdateAttributeDenied,
- StoreNotFound,
- ParentNotFound,
- ChildNotFound,
- ResourceIsNotStore,
- DeleteDenied,
- DeleteFailed,
- UpdateAttributeFailed,
- GetAttributesFailed,
- ClearAttributesFailed,
- TemplateNotFound,
- RenameDenied,
- ClassNotFound,
- MethodNotFound,
- PropertyNotFound,
- SetPropertyDenied,
- ReadOnlyProperty
- }
-
public class AsyncException: Exception
{
diff --git a/Esiur/Engine/AsyncQueue.cs b/Esiur/Core/AsyncQueue.cs
similarity index 99%
rename from Esiur/Engine/AsyncQueue.cs
rename to Esiur/Core/AsyncQueue.cs
index 4ad2c0e..227df86 100644
--- a/Esiur/Engine/AsyncQueue.cs
+++ b/Esiur/Core/AsyncQueue.cs
@@ -28,7 +28,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Esiur.Engine
+namespace Esiur.Core
{
public class AsyncQueue : AsyncReply
{
diff --git a/Esiur/Engine/AsyncReplyGeneric.cs b/Esiur/Core/AsyncReply.cs
similarity index 90%
rename from Esiur/Engine/AsyncReplyGeneric.cs
rename to Esiur/Core/AsyncReply.cs
index c32c0b2..54f35c3 100644
--- a/Esiur/Engine/AsyncReplyGeneric.cs
+++ b/Esiur/Core/AsyncReply.cs
@@ -32,7 +32,7 @@ using System.Reflection;
using System.Threading;
using System.Runtime.CompilerServices;
-namespace Esiur.Engine
+namespace Esiur.Core
{
public class AsyncReply: IAsyncReply
{
@@ -53,8 +53,6 @@ namespace Esiur.Engine
protected bool resultReady = false;
AsyncException exception;
- TaskCompletionSource
-
+
diff --git a/Esiur/Misc/Global.cs b/Esiur/Misc/Global.cs
index da593e8..20c7848 100644
--- a/Esiur/Misc/Global.cs
+++ b/Esiur/Misc/Global.cs
@@ -35,7 +35,7 @@ using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Net.NetworkInformation;
using System.Linq;
-using Esiur.Engine;
+using Esiur.Core;
using System.Diagnostics;
using System.Runtime.InteropServices;
diff --git a/Esiur/Net/DataLink/PacketFilter.cs b/Esiur/Net/DataLink/PacketFilter.cs
index 9acb2b2..3c6da41 100644
--- a/Esiur/Net/DataLink/PacketFilter.cs
+++ b/Esiur/Net/DataLink/PacketFilter.cs
@@ -26,7 +26,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Data;
using Esiur.Net.Packets;
using Esiur.Resource;
diff --git a/Esiur/Net/DataLink/PacketServer.cs b/Esiur/Net/DataLink/PacketServer.cs
index 072bff5..8eac7da 100644
--- a/Esiur/Net/DataLink/PacketServer.cs
+++ b/Esiur/Net/DataLink/PacketServer.cs
@@ -26,7 +26,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Data;
using System.Runtime.InteropServices;
using Esiur.Net.Packets;
diff --git a/Esiur/Net/DataLink/PacketSource.cs b/Esiur/Net/DataLink/PacketSource.cs
index 30c3bd3..b2568a5 100644
--- a/Esiur/Net/DataLink/PacketSource.cs
+++ b/Esiur/Net/DataLink/PacketSource.cs
@@ -27,7 +27,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Resource;
namespace Esiur.Net.DataLink
diff --git a/Esiur/Net/HTTP/HTTPFilter.cs b/Esiur/Net/HTTP/HTTPFilter.cs
index 64d6fa9..2c8df44 100644
--- a/Esiur/Net/HTTP/HTTPFilter.cs
+++ b/Esiur/Net/HTTP/HTTPFilter.cs
@@ -32,7 +32,7 @@ using System.Net;
using System.Collections;
using System.Collections.Generic;
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Resource;
namespace Esiur.Net.HTTP
diff --git a/Esiur/Net/HTTP/HTTPServer.cs b/Esiur/Net/HTTP/HTTPServer.cs
index 53d3e4e..5b43499 100644
--- a/Esiur/Net/HTTP/HTTPServer.cs
+++ b/Esiur/Net/HTTP/HTTPServer.cs
@@ -34,7 +34,7 @@ using System.Collections.Generic;
using Esiur.Net.Sockets;
using Esiur.Data;
using Esiur.Misc;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Net.Packets;
using System.Security.Cryptography.X509Certificates;
using Esiur.Resource;
diff --git a/Esiur/Net/HTTP/HTTPSession.cs b/Esiur/Net/HTTP/HTTPSession.cs
index 3b56eb8..c2ea05a 100644
--- a/Esiur/Net/HTTP/HTTPSession.cs
+++ b/Esiur/Net/HTTP/HTTPSession.cs
@@ -33,7 +33,7 @@ using System.Collections;
using System.Collections.Generic;
using Esiur.Data;
using Esiur.Misc;
-using Esiur.Engine;
+using Esiur.Core;
namespace Esiur.Net.HTTP
{
diff --git a/Esiur/Net/HTTP/IIPoWS.cs b/Esiur/Net/HTTP/IIPoWS.cs
index 1957e7c..f9cd2cd 100644
--- a/Esiur/Net/HTTP/IIPoWS.cs
+++ b/Esiur/Net/HTTP/IIPoWS.cs
@@ -30,7 +30,7 @@ using System.Threading.Tasks;
using Esiur.Resource;
using Esiur.Net.IIP;
using Esiur.Net.Sockets;
-using Esiur.Engine;
+using Esiur.Core;
namespace Esiur.Net.HTTP
{
diff --git a/Esiur/Net/IIP/DistributedConnection.cs b/Esiur/Net/IIP/DistributedConnection.cs
index 027d743..cd5a3dd 100644
--- a/Esiur/Net/IIP/DistributedConnection.cs
+++ b/Esiur/Net/IIP/DistributedConnection.cs
@@ -31,7 +31,7 @@ using System.Security.Cryptography;
using Esiur.Net.Sockets;
using Esiur.Data;
using Esiur.Misc;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Net.Packets;
using Esiur.Resource;
using Esiur.Security.Authority;
@@ -62,6 +62,8 @@ namespace Esiur.Net.IIP
Session session;
+ AsyncReply openReply;
+
byte[] localPassword;
byte[] localNonce, remoteNonce;
@@ -109,8 +111,11 @@ namespace Esiur.Net.IIP
/// Send data to the other end as parameters
///
/// Values will be converted to bytes then sent.
- internal void SendParams(params object[] values)
+ internal SendList SendParams(IAsyncReply reply = null)//params object[] values)
{
+ return new SendList(this, reply);
+
+ /*
var data = BinaryList.ToBytes(values);
if (ready)
@@ -149,6 +154,7 @@ namespace Esiur.Net.IIP
// Get calling method name
//Console.WriteLine("TX " + hostType + " " + ar.Length + " " + stackTrace.GetFrame(1).GetMethod().ToString());
+ */
}
///
@@ -199,13 +205,28 @@ namespace Esiur.Net.IIP
if (socket.State == SocketState.Established)
{
- SendParams((byte)0x60, (byte)dmn.Length, dmn, localNonce, (byte)un.Length, un);
+ SendParams()
+ .AddUInt8(0x60)
+ .AddUInt8((byte)dmn.Length)
+ .AddUInt8Array(dmn)
+ .AddUInt8Array(localNonce)
+ .AddUInt8((byte)un.Length)
+ .AddUInt8Array(un)
+ .Done();//, dmn, localNonce, (byte)un.Length, un);
}
else
{
socket.OnConnect += () =>
{ // declare (Credentials -> No Auth, No Enctypt)
- SendParams((byte)0x60, (byte)dmn.Length, dmn, localNonce, (byte)un.Length, un);
+ //SendParams((byte)0x60, (byte)dmn.Length, dmn, localNonce, (byte)un.Length, un);
+ SendParams()
+ .AddUInt8(0x60)
+ .AddUInt8((byte)dmn.Length)
+ .AddUInt8Array(dmn)
+ .AddUInt8Array(localNonce)
+ .AddUInt8((byte)un.Length)
+ .AddUInt8Array(un)
+ .Done();
};
}
}
@@ -569,12 +590,17 @@ namespace Esiur.Net.IIP
session.RemoteAuthentication.Username = authPacket.RemoteUsername;
remoteNonce = authPacket.RemoteNonce;
session.RemoteAuthentication.Domain = authPacket.Domain;
- SendParams((byte)0xa0, localNonce);
+ SendParams()
+ .AddUInt8(0xa0)
+ .AddUInt8Array(localNonce)
+ .Done();
+ //SendParams((byte)0xa0, localNonce);
}
else
{
//Console.WriteLine("User not found");
- SendParams((byte)0xc0, (byte)1, (ushort)14, DC.ToBytes("User not found"));
+ //SendParams((byte)0xc0, (byte)1, (ushort)14, DC.ToBytes("User not found"));
+ SendParams().AddUInt8(0xc0).AddUInt8(1).AddUInt16(14).AddString("User not found").Done();
}
});
@@ -592,21 +618,29 @@ namespace Esiur.Net.IIP
if (pw != null)
{
var hashFunc = SHA256.Create();
- var hash = hashFunc.ComputeHash(BinaryList.ToBytes(pw, remoteNonce, localNonce));
+ //var hash = hashFunc.ComputeHash(BinaryList.ToBytes(pw, remoteNonce, localNonce));
+ var hash = hashFunc.ComputeHash((new BinaryList())
+ .AddUInt8Array(pw)
+ .AddUInt8Array( remoteNonce)
+ .AddUInt8Array(localNonce)
+ .ToArray());
if (hash.SequenceEqual(remoteHash))
{
- // send our hash
- var localHash = hashFunc.ComputeHash(BinaryList.ToBytes(localNonce, remoteNonce, pw));
+ // send our hash
+ //var localHash = hashFunc.ComputeHash(BinaryList.ToBytes(localNonce, remoteNonce, pw));
+ //SendParams((byte)0, localHash);
- SendParams((byte)0, localHash);
+ var localHash = hashFunc.ComputeHash((new BinaryList()).AddUInt8Array(localNonce).AddUInt8Array(remoteNonce).AddUInt8Array(pw).ToArray());
+ SendParams().AddUInt8(0).AddUInt8Array(localHash).Done();
readyToEstablish = true;
}
else
{
- Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:DENIED");
+ //Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:DENIED");
//Console.WriteLine("Incorrect password");
- SendParams((byte)0xc0, (byte)1, (ushort)5, DC.ToBytes("Error"));
+ //SendParams((byte)0xc0, (byte)1, (ushort)5, DC.ToBytes("Error"));
+ SendParams().AddUInt8(0xc0).AddUInt8(1).AddUInt16(5).AddString("Error").Done();
}
}
});
@@ -618,12 +652,18 @@ namespace Esiur.Net.IIP
var r = new Random();
session.Id = new byte[32];
r.NextBytes(session.Id);
- SendParams((byte)0x28, session.Id);
+ //SendParams((byte)0x28, session.Id);
+ SendParams()
+ .AddUInt8(0x28)
+ .AddUInt8Array(session.Id)
+ .Done();
+
ready = true;
+ openReply?.Trigger(true);
OnReady?.Invoke(this);
Server.Membership.Login(session);
- Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:AUTH");
+ //Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:AUTH");
}
}
@@ -637,9 +677,19 @@ namespace Esiur.Net.IIP
// send our hash
var hashFunc = SHA256.Create();
- var localHash = hashFunc.ComputeHash(BinaryList.ToBytes(localPassword, localNonce, remoteNonce));
+ //var localHash = hashFunc.ComputeHash(BinaryList.ToBytes(localPassword, localNonce, remoteNonce));
+ var localHash = hashFunc.ComputeHash(new BinaryList()
+ .AddUInt8Array(localPassword)
+ .AddUInt8Array(localNonce)
+ .AddUInt8Array(remoteNonce)
+ .ToArray());
- SendParams((byte)0, localHash);
+ SendParams()
+ .AddUInt8(0)
+ .AddUInt8Array(localHash)
+ .Done();
+
+ //SendParams((byte)0, localHash);
}
else if (authPacket.Command == IIPAuthPacket.IIPAuthPacketCommand.Action)
{
@@ -647,16 +697,33 @@ namespace Esiur.Net.IIP
{
// check if the server knows my password
var hashFunc = SHA256.Create();
- var remoteHash = hashFunc.ComputeHash(BinaryList.ToBytes(remoteNonce, localNonce, localPassword));
+ //var remoteHash = hashFunc.ComputeHash(BinaryList.ToBytes(remoteNonce, localNonce, localPassword));
+ var remoteHash = hashFunc.ComputeHash(new BinaryList()
+ .AddUInt8Array(remoteNonce)
+ .AddUInt8Array(localNonce)
+ .AddUInt8Array(localPassword)
+ .ToArray());
+
if (remoteHash.SequenceEqual(authPacket.Hash))
{
// send establish request
- SendParams((byte)0x20, (ushort)0);
+ //SendParams((byte)0x20, (ushort)0);
+ SendParams()
+ .AddUInt8(0x20)
+ .AddUInt16(0)
+ .Done();
}
else
{
- SendParams((byte)0xc0, 1, (ushort)5, DC.ToBytes("Error"));
+ SendParams()
+ .AddUInt8(0xc0)
+ .AddUInt8(1)
+ .AddUInt16(5)
+ .AddString("Error")
+ .Done();
+
+ //SendParams((byte)0xc0, 1, (ushort)5, DC.ToBytes("Error"));
}
}
else if (authPacket.Action == IIPAuthPacket.IIPAuthPacketAction.ConnectionEstablished)
@@ -664,12 +731,14 @@ namespace Esiur.Net.IIP
session.Id = authPacket.SessionId;
ready = true;
+ openReply?.Trigger(true);
OnReady?.Invoke(this);
}
}
else if (authPacket.Command == IIPAuthPacket.IIPAuthPacketCommand.Error)
{
+ openReply?.TriggerError(new AsyncException(ErrorType.Management, authPacket.ErrorCode, authPacket.ErrorMessage));
OnError?.Invoke(this, authPacket.ErrorCode, authPacket.ErrorMessage);
Close();
}
@@ -710,6 +779,40 @@ namespace Esiur.Net.IIP
///
public AsyncReply Trigger(ResourceTrigger trigger)
{
+ if (trigger == ResourceTrigger.Open)
+ {
+ if (Instance.Attributes.ContainsKey("username")
+ && Instance.Attributes.ContainsKey("password"))
+ {
+ var hostname = String.Join("://", Instance.Name.Split(new string[] { "://" }, StringSplitOptions.None).Skip(1)).Split('/')[0];
+ // assign domain from hostname if not provided
+
+ var address = hostname.Split(':')[0];
+ var port = ushort.Parse(hostname.Split(':')[1]);
+ var username = Instance.Attributes["username"].ToString();
+
+ var domain = Instance.Attributes.ContainsKey("domain") ? Instance.Attributes["domain"].ToString() : address;
+
+ session = new Session(new ClientAuthentication()
+ , new HostAuthentication());
+
+ session.LocalAuthentication.Domain = domain;
+ session.LocalAuthentication.Username = username;
+ localPassword = DC.ToBytes(Instance.Attributes["password"].ToString());
+
+ openReply = new AsyncReply();
+ var sock = new TCPSocket();
+
+
+ sock.Connect(domain, port).Then((x)=> {
+ Assign(sock);
+ //rt.trigger(true);
+ }).Error((x) => openReply.TriggerError(x));
+
+ return openReply;
+ }
+ }
+
return new AsyncReply();
}
@@ -720,7 +823,9 @@ namespace Esiur.Net.IIP
///
public bool Put(IResource resource)
{
- resources.Add(Convert.ToUInt32(resource.Instance.Name), (DistributedResource)resource);
+ if (Codec.IsLocalResource(resource, this))
+ resources.Add((resource as DistributedResource).Id, (DistributedResource)resource);
+ // else ... send it to the peer
return true;
}
diff --git a/Esiur/Net/IIP/DistributedConnectionProtocol.cs b/Esiur/Net/IIP/DistributedConnectionProtocol.cs
index 43861c5..a58401c 100644
--- a/Esiur/Net/IIP/DistributedConnectionProtocol.cs
+++ b/Esiur/Net/IIP/DistributedConnectionProtocol.cs
@@ -23,7 +23,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Net.Packets;
using Esiur.Resource;
using Esiur.Resource.Template;
@@ -52,7 +52,7 @@ namespace Esiur.Net.IIP
KeyList> requests = new KeyList>();
- uint callbackCounter = 0;
+ volatile uint callbackCounter = 0;
AsyncQueue queue = new AsyncQueue();
@@ -62,6 +62,16 @@ namespace Esiur.Net.IIP
/// Packet action.
/// Arguments to send.
///
+ internal SendList SendRequest(IIPPacket.IIPPacketAction action)
+ {
+ var reply = new AsyncReply();
+ var c = callbackCounter++; // avoid thread racing
+ requests.Add(c, reply);
+
+ return (SendList)SendParams(reply).AddUInt8((byte)(0x40 | (byte)action)).AddUInt32(c);
+ }
+
+ /*
internal IAsyncReply SendRequest(IIPPacket.IIPPacketAction action, params object[] args)
{
var reply = new AsyncReply();
@@ -72,11 +82,13 @@ namespace Esiur.Net.IIP
requests.Add(callbackCounter, reply);
return reply;
}
+ */
- uint maxcallerid = 0;
+ //uint maxcallerid = 0;
- internal void SendReply(IIPPacket.IIPPacketAction action, uint callbackId, params object[] args)
+ internal SendList SendReply(IIPPacket.IIPPacketAction action, uint callbackId)
{
+ /*
if (callbackId > maxcallerid)
{
maxcallerid = callbackId;
@@ -86,18 +98,18 @@ namespace Esiur.Net.IIP
Console.Beep();
}
+ */
- var bl = new BinaryList((byte)(0x80 | (byte)action), callbackId);
- bl.AddRange(args);
- Send(bl.ToArray());
- //Console.WriteLine("SendReply " + action.ToString() + " " + callbackId);
+ return (SendList)SendParams().AddUInt8((byte)(0x80 | (byte)action)).AddUInt32(callbackId);
}
- internal void SendEvent(IIPPacket.IIPPacketEvent evt, params object[] args)
+ internal SendList SendEvent(IIPPacket.IIPPacketEvent evt)
{
- var bl = new BinaryList((byte)(evt));
- bl.AddRange(args);
- Send(bl.ToArray());
+ //var bl = new BinaryList((byte)(evt));
+ //bl.AddRange(args);
+ //Send(bl.ToArray());
+
+ return (SendList)SendParams().AddUInt8((byte)(evt));
}
internal AsyncReply SendInvokeByArrayArguments(uint instanceId, byte index, object[] parameters)
@@ -105,11 +117,19 @@ namespace Esiur.Net.IIP
var pb = Codec.ComposeVarArray(parameters, this, true);
var reply = new AsyncReply();
- callbackCounter++;
- var bl = new BinaryList((byte)(0x40 | (byte)Packets.IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments),
- callbackCounter, instanceId, index, pb);
- Send(bl.ToArray());
- requests.Add(callbackCounter, reply);
+ var c = callbackCounter++;
+ requests.Add(c, reply);
+
+ SendParams().AddUInt8((byte)(0x40 | (byte)Packets.IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments))
+ .AddUInt32(c)
+ .AddUInt32(instanceId)
+ .AddUInt8(index)
+ .AddUInt8Array(pb)
+ .Done();
+
+ //var bl = new BinaryList((byte)(0x40 | (byte)Packets.IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments),
+ // callbackCounter, instanceId, index, pb);
+ //Send(bl.ToArray());
return reply;
}
@@ -118,6 +138,7 @@ namespace Esiur.Net.IIP
{
var pb = Codec.ComposeStructure(parameters, this, true, true, true);
+ /*
var reply = new AsyncReply();
callbackCounter++;
var bl = new BinaryList((byte)(0x40 | (byte)Packets.IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments),
@@ -126,6 +147,19 @@ namespace Esiur.Net.IIP
requests.Add(callbackCounter, reply);
return reply;
+ */
+
+ var reply = new AsyncReply();
+ var c = callbackCounter++;
+ requests.Add(c, reply);
+
+ SendParams().AddUInt8((byte)(0x40 | (byte)Packets.IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments))
+ .AddUInt32(c)
+ .AddUInt32(instanceId)
+ .AddUInt8(index)
+ .AddUInt8Array(pb)
+ .Done();
+ return reply;
}
@@ -133,20 +167,40 @@ namespace Esiur.Net.IIP
{
var msg = DC.ToBytes(errorMessage);
if (type == ErrorType.Management)
- SendParams((byte)(0xC0 | (byte)IIPPacket.IIPPacketReport.ManagementError), callbackId, errorCode);
+ SendParams()
+ .AddUInt8((byte)(0xC0 | (byte)IIPPacket.IIPPacketReport.ManagementError))
+ .AddUInt32(callbackId)
+ .AddUInt16(errorCode)
+ .Done();
else if (type == ErrorType.Exception)
- SendParams((byte)(0xC0 | (byte)IIPPacket.IIPPacketReport.ExecutionError), callbackId, errorCode, (ushort)msg.Length, msg);
+ SendParams()
+ .AddUInt8((byte)(0xC0 | (byte)IIPPacket.IIPPacketReport.ExecutionError))
+ .AddUInt32(callbackId)
+ .AddUInt16(errorCode)
+ .AddUInt16((ushort)msg.Length)
+ .AddUInt8Array(msg)
+ .Done();
}
void SendProgress(uint callbackId, int value, int max)
{
- SendParams((byte)(0xC0 | (byte)IIPPacket.IIPPacketReport.ProgressReport), callbackId, value, max);
+ SendParams()
+ .AddUInt8((byte)(0xC0 | (byte)IIPPacket.IIPPacketReport.ProgressReport))
+ .AddUInt32(callbackId)
+ .AddInt32(value)
+ .AddInt32(max)
+ .Done();
+ //SendParams(, callbackId, value, max);
}
void SendChunk(uint callbackId, object chunk)
{
var c = Codec.Compose(chunk, this, true);
- SendParams((byte)(0xC0 | (byte)IIPPacket.IIPPacketReport.ChunkStream), callbackId, c);
+ SendParams()
+ .AddUInt8((byte)(0xC0 | (byte)IIPPacket.IIPPacketReport.ChunkStream))
+ .AddUInt32(callbackId)
+ .AddUInt8Array(c)
+ .Done();
}
void IIPReply(uint callbackId, params object[] results)
@@ -214,7 +268,7 @@ namespace Esiur.Net.IIP
Codec.Parse(content, 0, this).Then((arguments) =>
{
- var pt = r.Instance.Template.GetPropertyTemplate(index);
+ var pt = r.Instance.Template.GetPropertyTemplateByIndex(index);
if (pt != null)
{
item.Trigger(new DistributedResourceQueueItem((DistributedResource)r,
@@ -277,7 +331,7 @@ namespace Esiur.Net.IIP
Codec.ParseVarArray(content, this).Then((arguments) =>
{
- var et = r.Instance.Template.GetEventTemplate(index);
+ var et = r.Instance.Template.GetEventTemplateByIndex(index);
if (et != null)
{
item.Trigger(new DistributedResourceQueueItem((DistributedResource)r,
@@ -384,10 +438,19 @@ namespace Esiur.Net.IIP
}
var r = res as IResource;
+
+ // unsubscribe
+ r.Instance.ResourceEventOccurred -= Instance_EventOccurred;
+ r.Instance.ResourceModified -= Instance_PropertyModified;
+ r.Instance.ResourceDestroyed -= Instance_ResourceDestroyed;
+ r.Instance.Children.OnAdd -= Children_OnAdd;
+ r.Instance.Children.OnRemoved -= Children_OnRemoved;
+ r.Instance.Attributes.OnModified -= Attributes_OnModified;
+
+ // subscribe
r.Instance.ResourceEventOccurred += Instance_EventOccurred;
r.Instance.ResourceModified += Instance_PropertyModified;
r.Instance.ResourceDestroyed += Instance_ResourceDestroyed;
-
r.Instance.Children.OnAdd += Children_OnAdd;
r.Instance.Children.OnRemoved += Children_OnRemoved;
r.Instance.Attributes.OnModified += Attributes_OnModified;
@@ -397,18 +460,24 @@ namespace Esiur.Net.IIP
if (r is DistributedResource)
{
// reply ok
- SendReply(IIPPacket.IIPPacketAction.AttachResource,
- callback, r.Instance.Template.ClassId,
- r.Instance.Age, (ushort)link.Length, link,
- Codec.ComposePropertyValueArray((r as DistributedResource)._Serialize(), this, true));
+ SendReply(IIPPacket.IIPPacketAction.AttachResource, callback)
+ .AddGuid(r.Instance.Template.ClassId)
+ .AddUInt64(r.Instance.Age)
+ .AddUInt16((ushort)link.Length)
+ .AddUInt8Array(link)
+ .AddUInt8Array(Codec.ComposePropertyValueArray((r as DistributedResource)._Serialize(), this, true))
+ .Done();
}
else
{
// reply ok
- SendReply(IIPPacket.IIPPacketAction.AttachResource,
- callback, r.Instance.Template.ClassId,
- r.Instance.Age, (ushort)link.Length, link,
- Codec.ComposePropertyValueArray(r.Instance.Serialize(), this, true));
+ SendReply(IIPPacket.IIPPacketAction.AttachResource, callback)
+ .AddGuid(r.Instance.Template.ClassId)
+ .AddUInt64(r.Instance.Age)
+ .AddUInt16((ushort)link.Length)
+ .AddUInt8Array(link)
+ .AddUInt8Array(Codec.ComposePropertyValueArray(r.Instance.Serialize(), this, true))
+ .Done();
}
}
else
@@ -426,19 +495,29 @@ namespace Esiur.Net.IIP
{
var instance = (sender.Owner as Instance);
var name = DC.ToBytes(newValue.ToString());
- SendEvent(IIPPacket.IIPPacketEvent.ChildRemoved, instance.Id, (ushort)name.Length, name);
+ SendEvent(IIPPacket.IIPPacketEvent.ChildRemoved)
+ .AddUInt32(instance.Id)
+ .AddUInt16((ushort)name.Length)
+ .AddUInt8Array(name)
+ .Done();
}
}
private void Children_OnRemoved(Instance sender, IResource value)
{
- SendEvent(IIPPacket.IIPPacketEvent.ChildRemoved, sender.Id, value.Instance.Id);
+ SendEvent(IIPPacket.IIPPacketEvent.ChildRemoved)
+ .AddUInt32(sender.Id)
+ .AddUInt32(value.Instance.Id)
+ .Done();
}
private void Children_OnAdd(Instance sender, IResource value)
{
//if (sender.Applicable(sender.Resource, this.session, ActionType.))
- SendEvent(IIPPacket.IIPPacketEvent.ChildAdded, sender.Id, value.Instance.Id);
+ SendEvent(IIPPacket.IIPPacketEvent.ChildAdded)
+ .AddUInt32(sender.Id)
+ .AddUInt32(value.Instance.Id)
+ .Done();
}
void IIPRequestReattachResource(uint callback, uint resourceId, ulong resourceAge)
@@ -448,13 +527,27 @@ namespace Esiur.Net.IIP
if (res != null)
{
var r = res as IResource;
+ // unsubscribe
+ r.Instance.ResourceEventOccurred -= Instance_EventOccurred;
+ r.Instance.ResourceModified -= Instance_PropertyModified;
+ r.Instance.ResourceDestroyed -= Instance_ResourceDestroyed;
+ r.Instance.Children.OnAdd -= Children_OnAdd;
+ r.Instance.Children.OnRemoved -= Children_OnRemoved;
+ r.Instance.Attributes.OnModified -= Attributes_OnModified;
+
+ // subscribe
r.Instance.ResourceEventOccurred += Instance_EventOccurred;
r.Instance.ResourceModified += Instance_PropertyModified;
r.Instance.ResourceDestroyed += Instance_ResourceDestroyed;
+ r.Instance.Children.OnAdd += Children_OnAdd;
+ r.Instance.Children.OnRemoved += Children_OnRemoved;
+ r.Instance.Attributes.OnModified += Attributes_OnModified;
+
// reply ok
- SendReply(IIPPacket.IIPPacketAction.ReattachResource,
- callback, r.Instance.Age,
- Codec.ComposePropertyValueArray(r.Instance.Serialize(), this, true));
+ SendReply(IIPPacket.IIPPacketAction.ReattachResource, callback)
+ .AddUInt64(r.Instance.Age)
+ .AddUInt8Array(Codec.ComposePropertyValueArray(r.Instance.Serialize(), this, true))
+ .Done();
}
else
{
@@ -475,7 +568,7 @@ namespace Esiur.Net.IIP
r.Instance.ResourceModified -= Instance_PropertyModified;
r.Instance.ResourceDestroyed -= Instance_ResourceDestroyed;
// reply ok
- SendReply(IIPPacket.IIPPacketAction.DetachResource, callback);
+ SendReply(IIPPacket.IIPPacketAction.DetachResource, callback).Done();
}
else
{
@@ -599,7 +692,9 @@ namespace Esiur.Net.IIP
Warehouse.Put(resource, name, store as IStore, parent);
- SendReply(IIPPacket.IIPPacketAction.CreateResource, callback, resource.Instance.Id);
+ SendReply(IIPPacket.IIPPacketAction.CreateResource, callback)
+ .AddUInt32(resource.Instance.Id)
+ .Done();
});
});
@@ -625,7 +720,7 @@ namespace Esiur.Net.IIP
}
if (Warehouse.Remove(r))
- SendReply(IIPPacket.IIPPacketAction.DeleteResource, callback);
+ SendReply(IIPPacket.IIPPacketAction.DeleteResource, callback).Done();
//SendParams((byte)0x84, callback);
else
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.DeleteFailed);
@@ -657,8 +752,9 @@ namespace Esiur.Net.IIP
var st = r.Instance.GetAttributes(attrs);
if (st != null)
- SendReply(all ? IIPPacket.IIPPacketAction.GetAllAttributes : IIPPacket.IIPPacketAction.GetAttributes, callback,
- Codec.ComposeStructure(st, this, true, true, true));
+ SendReply(all ? IIPPacket.IIPPacketAction.GetAllAttributes : IIPPacket.IIPPacketAction.GetAttributes, callback)
+ .AddUInt8Array(Codec.ComposeStructure(st, this, true, true, true))
+ .Done();
else
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.GetAttributesFailed);
@@ -697,7 +793,7 @@ namespace Esiur.Net.IIP
parent.Instance.Children.Add(child);
- SendReply(IIPPacket.IIPPacketAction.AddChild, callback);
+ SendReply(IIPPacket.IIPPacketAction.AddChild, callback).Done();
//child.Instance.Parents
});
@@ -736,7 +832,7 @@ namespace Esiur.Net.IIP
parent.Instance.Children.Remove(child);
- SendReply(IIPPacket.IIPPacketAction.RemoveChild, callback);
+ SendReply(IIPPacket.IIPPacketAction.RemoveChild, callback).Done();
//child.Instance.Parents
});
@@ -761,7 +857,7 @@ namespace Esiur.Net.IIP
resource.Instance.Name = name.GetString(0, (uint)name.Length);
- SendReply(IIPPacket.IIPPacketAction.RenameResource, callback);
+ SendReply(IIPPacket.IIPPacketAction.RenameResource, callback).Done();
});
}
@@ -775,10 +871,9 @@ namespace Esiur.Net.IIP
return;
}
- SendReply(IIPPacket.IIPPacketAction.ResourceChildren, callback,
-
- Codec.ComposeResourceArray(resource.Instance.Children.ToArray(), this, true)
- );
+ SendReply(IIPPacket.IIPPacketAction.ResourceChildren, callback)
+ .AddUInt8Array(Codec.ComposeResourceArray(resource.Instance.Children.ToArray(), this, true))
+ .Done();
});
}
@@ -793,11 +888,9 @@ namespace Esiur.Net.IIP
return;
}
- SendReply(IIPPacket.IIPPacketAction.ResourceParents, callback,
-
- Codec.ComposeResourceArray(resource.Instance.Parents.ToArray(), this, true)
- );
-
+ SendReply(IIPPacket.IIPPacketAction.ResourceParents, callback)
+ .AddUInt8Array(Codec.ComposeResourceArray(resource.Instance.Parents.ToArray(), this, true))
+ .Done();
});
}
@@ -823,7 +916,7 @@ namespace Esiur.Net.IIP
attrs = attributes.GetStringArray(0, (uint)attributes.Length);
if (r.Instance.RemoveAttributes(attrs))
- SendReply(all ? IIPPacket.IIPPacketAction.ClearAllAttributes : IIPPacket.IIPPacketAction.ClearAttributes, callback);
+ SendReply(all ? IIPPacket.IIPPacketAction.ClearAllAttributes : IIPPacket.IIPPacketAction.ClearAttributes, callback).Done();
else
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.UpdateAttributeFailed);
@@ -850,7 +943,7 @@ namespace Esiur.Net.IIP
{
if (r.Instance.SetAttributes(attrs, clearAttributes))
SendReply(clearAttributes ? IIPPacket.IIPPacketAction.ClearAllAttributes : IIPPacket.IIPPacketAction.ClearAttributes,
- callback);
+ callback).Done();
else
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.UpdateAttributeFailed);
});
@@ -864,7 +957,10 @@ namespace Esiur.Net.IIP
Warehouse.GetTemplate(className).Then((t) =>
{
if (t != null)
- SendReply(IIPPacket.IIPPacketAction.TemplateFromClassName, callback, (uint)t.Content.Length, t.Content);
+ SendReply(IIPPacket.IIPPacketAction.TemplateFromClassName, callback)
+ .AddInt32(t.Content.Length)
+ .AddUInt8Array(t.Content)
+ .Done();
else
{
// reply failed
@@ -878,7 +974,10 @@ namespace Esiur.Net.IIP
Warehouse.GetTemplate(classId).Then((t) =>
{
if (t != null)
- SendReply(IIPPacket.IIPPacketAction.TemplateFromClassId, callback, (uint)t.Content.Length, t.Content);
+ SendReply(IIPPacket.IIPPacketAction.TemplateFromClassId, callback)
+ .AddInt32(t.Content.Length)
+ .AddUInt8Array(t.Content)
+ .Done();
else
{
// reply failed
@@ -894,8 +993,10 @@ namespace Esiur.Net.IIP
Warehouse.Get(resourceId).Then((r) =>
{
if (r != null)
- SendReply(IIPPacket.IIPPacketAction.TemplateFromResourceId, callback,
- (uint)r.Instance.Template.Content.Length, r.Instance.Template.Content);
+ SendReply(IIPPacket.IIPPacketAction.TemplateFromResourceId, callback)
+ .AddInt32(r.Instance.Template.Content.Length)
+ .AddUInt8Array(r.Instance.Template.Content)
+ .Done();
else
{
// reply failed
@@ -918,7 +1019,9 @@ namespace Esiur.Net.IIP
if (list.Length == 0)
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.ResourceNotFound);
else
- SendReply(IIPPacket.IIPPacketAction.QueryLink, callback, Codec.ComposeResourceArray(list, this, true));
+ SendReply(IIPPacket.IIPPacketAction.QueryLink, callback)
+ .AddUInt8Array(Codec.ComposeResourceArray(list, this, true))
+ .Done();
//}
//else
//{
@@ -942,7 +1045,7 @@ namespace Esiur.Net.IIP
{
Codec.ParseVarArray(content, this).Then((arguments) =>
{
- var ft = r.Instance.Template.GetFunctionTemplate(index);
+ var ft = r.Instance.Template.GetFunctionTemplateByIndex(index);
if (ft != null)
{
if (r is DistributedResource)
@@ -952,7 +1055,9 @@ namespace Esiur.Net.IIP
{
rt.Then(res =>
{
- SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback, Codec.Compose(res, this));
+ SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback)
+ .AddUInt8Array(Codec.Compose(res, this))
+ .Done();
});
}
else
@@ -1007,7 +1112,7 @@ namespace Esiur.Net.IIP
{
rt = fi.Invoke(r, args);
}
- catch(Exception ex)
+ catch (Exception ex)
{
SendError(ErrorType.Exception, callback, 0, ex.ToString());
return;
@@ -1020,7 +1125,9 @@ namespace Esiur.Net.IIP
foreach (var v in enu)
SendChunk(callback, v);
- SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback, (byte)DataType.Void);
+ SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback)
+ .AddUInt8((byte)DataType.Void)
+ .Done();
}
else if (rt is Task)
@@ -1032,18 +1139,22 @@ namespace Esiur.Net.IIP
#else
var res = t.GetType().GetProperty("Result").GetValue(t);
#endif
- SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback, Codec.Compose(res, this));
+ SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback)
+ .AddUInt8Array(Codec.Compose(res, this))
+ .Done();
});
//await t;
//SendParams((byte)0x90, callback, Codec.Compose(res, this));
}
- else if (rt.GetType().GetTypeInfo().IsGenericType
- && rt.GetType().GetGenericTypeDefinition() == typeof(IAsyncReply<>))
+ else if (rt is IAsyncReply)// Codec.ImplementsInterface(rt.GetType(), typeof(IAsyncReply<>)))// rt.GetType().GetTypeInfo().IsGenericType
+ //&& rt.GetType().GetGenericTypeDefinition() == typeof(IAsyncReply<>))
{
(rt as IAsyncReply).Then(res =>
{
- SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback, Codec.Compose(res, this));
+ SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback)
+ .AddUInt8Array(Codec.Compose(res, this))
+ .Done();
}).Error(ex =>
{
SendError(ErrorType.Exception, callback, (ushort)ex.Code, ex.Message);
@@ -1057,7 +1168,9 @@ namespace Esiur.Net.IIP
}
else
{
- SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback, Codec.Compose(rt, this));
+ SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback)
+ .AddUInt8Array(Codec.Compose(rt, this))
+ .Done();
}
}
else
@@ -1087,29 +1200,31 @@ namespace Esiur.Net.IIP
{
if (r != null)
{
- Codec.ParseStructure(content, 0, (uint)content.Length, this).Then((namedArgs) =>
- {
- var ft = r.Instance.Template.GetFunctionTemplate(index);
- if (ft != null)
- {
- if (r is DistributedResource)
- {
- var rt = (r as DistributedResource)._InvokeByNamedArguments(index, namedArgs);
- if (rt != null)
- {
- rt.Then(res =>
- {
- SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback, Codec.Compose(res, this));
- });
- }
- else
- {
+ Codec.ParseStructure(content, 0, (uint)content.Length, this).Then((namedArgs) =>
+ {
+ var ft = r.Instance.Template.GetFunctionTemplateByIndex(index);
+ if (ft != null)
+ {
+ if (r is DistributedResource)
+ {
+ var rt = (r as DistributedResource)._InvokeByNamedArguments(index, namedArgs);
+ if (rt != null)
+ {
+ rt.Then(res =>
+ {
+ SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
+ .AddUInt8Array(Codec.Compose(res, this))
+ .Done();
+ });
+ }
+ else
+ {
// function not found on a distributed object
}
- }
- else
- {
+ }
+ else
+ {
#if NETSTANDARD1_5
var fi = r.GetType().GetTypeInfo().GetMethod(ft.Name);
#else
@@ -1117,101 +1232,107 @@ namespace Esiur.Net.IIP
#endif
if (fi != null)
- {
- if (r.Instance.Applicable(session, ActionType.Execute, ft) == Ruling.Denied)
- {
- SendError(ErrorType.Management, callback,
- (ushort)ExceptionCode.InvokeDenied);
- return;
- }
+ {
+ if (r.Instance.Applicable(session, ActionType.Execute, ft) == Ruling.Denied)
+ {
+ SendError(ErrorType.Management, callback,
+ (ushort)ExceptionCode.InvokeDenied);
+ return;
+ }
// cast arguments
ParameterInfo[] pi = fi.GetParameters();
- object[] args = new object[pi.Length];
+ object[] args = new object[pi.Length];
- for (var i = 0; i < pi.Length; i++)
- {
- if (pi[i].ParameterType == typeof(DistributedConnection))
- {
- args[i] = this;
- }
- else if (namedArgs.ContainsKey(pi[i].Name))
- {
- args[i] = DC.CastConvert(namedArgs[pi[i].Name], pi[i].ParameterType);
- }
- }
+ for (var i = 0; i < pi.Length; i++)
+ {
+ if (pi[i].ParameterType == typeof(DistributedConnection))
+ {
+ args[i] = this;
+ }
+ else if (namedArgs.ContainsKey(pi[i].Name))
+ {
+ args[i] = DC.CastConvert(namedArgs[pi[i].Name], pi[i].ParameterType);
+ }
+ }
-
- object rt;
- try
- {
- rt = fi.Invoke(r, args);
- }
- catch (Exception ex)
- {
- SendError(ErrorType.Exception, callback, 0, ex.ToString());
- return;
- }
+ object rt;
- if (rt is System.Collections.IEnumerable && !(rt is Array))
- {
- var enu = rt as System.Collections.IEnumerable;
+ try
+ {
+ rt = fi.Invoke(r, args);
+ }
+ catch (Exception ex)
+ {
+ SendError(ErrorType.Exception, callback, 0, ex.ToString());
+ return;
+ }
- foreach (var v in enu)
- SendChunk(callback, v);
+ if (rt is System.Collections.IEnumerable && !(rt is Array))
+ {
+ var enu = rt as System.Collections.IEnumerable;
- SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback, (byte)DataType.Void);
+ foreach (var v in enu)
+ SendChunk(callback, v);
- }
- else if (rt is Task)
- {
- (rt as Task).ContinueWith(t =>
- {
+ SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
+ .AddUInt8((byte)DataType.Void)
+ .Done();
+ }
+ else if (rt is Task)
+ {
+ (rt as Task).ContinueWith(t =>
+ {
#if NETSTANDARD1_5
var res = t.GetType().GetTypeInfo().GetProperty("Result").GetValue(t);
#else
var res = t.GetType().GetProperty("Result").GetValue(t);
#endif
- SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback, Codec.Compose(res, this));
- });
+ SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
+ .AddUInt8Array(Codec.Compose(res, this))
+ .Done();
+ });
- }
-// else if (rt is AsyncReply)
- else if (rt.GetType().GetTypeInfo().IsGenericType
- && rt.GetType().GetGenericTypeDefinition() == typeof(IAsyncReply<>))
- {
- (rt as IAsyncReply).Then(res =>
- {
- SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback, Codec.Compose(res, this));
- }).Error(ex =>
- {
- SendError(ErrorType.Exception, callback, (ushort)ex.Code, ex.Message);
- }).Progress((pt, pv, pm) =>
- {
- SendProgress(callback, pv, pm);
- }).Chunk(v =>
- {
- SendChunk(callback, v);
- });
- }
- else
- {
- SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback, Codec.Compose(rt, this));
- }
- }
- else
+ }
+ else if (rt is IAsyncReply)
+ {
+ (rt as IAsyncReply).Then(res =>
{
+ SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
+ .AddUInt8Array(Codec.Compose(res, this))
+ .Done();
+
+ }).Error(ex =>
+ {
+ SendError(ErrorType.Exception, callback, (ushort)ex.Code, ex.Message);
+ }).Progress((pt, pv, pm) =>
+ {
+ SendProgress(callback, pv, pm);
+ }).Chunk(v =>
+ {
+ SendChunk(callback, v);
+ });
+ }
+ else
+ {
+ SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
+ .AddUInt8Array(Codec.Compose(rt, this))
+ .Done();
+ }
+ }
+ else
+ {
// ft found, fi not found, this should never happen
}
- }
- }
- else
- {
+ }
+ }
+ else
+ {
// no function at this index
}
- });
+ });
}
else
{
@@ -1226,13 +1347,14 @@ namespace Esiur.Net.IIP
{
if (r != null)
{
- var pt = r.Instance.Template.GetFunctionTemplate(index);
+ var pt = r.Instance.Template.GetFunctionTemplateByIndex(index);
if (pt != null)
{
if (r is DistributedResource)
{
- SendReply(IIPPacket.IIPPacketAction.GetProperty, callback,
- Codec.Compose((r as DistributedResource)._Get(pt.Index), this));
+ SendReply(IIPPacket.IIPPacketAction.GetProperty, callback)
+ .AddUInt8Array(Codec.Compose((r as DistributedResource)._Get(pt.Index), this))
+ .Done();
}
else
{
@@ -1244,8 +1366,9 @@ namespace Esiur.Net.IIP
if (pi != null)
{
- SendReply(IIPPacket.IIPPacketAction.GetProperty,
- callback, Codec.Compose(pi.GetValue(r), this));
+ SendReply(IIPPacket.IIPPacketAction.GetProperty, callback)
+ .AddUInt8Array(Codec.Compose(pi.GetValue(r), this))
+ .Done();
}
else
{
@@ -1292,7 +1415,9 @@ namespace Esiur.Net.IIP
}*/
- SendReply(IIPPacket.IIPPacketAction.ResourceHistory, callback, history);
+ SendReply(IIPPacket.IIPPacketAction.ResourceHistory, callback)
+ .AddUInt8Array(history)
+ .Done();
});
}
@@ -1305,7 +1430,7 @@ namespace Esiur.Net.IIP
{
if (r != null)
{
- var pt = r.Instance.Template.GetFunctionTemplate(index);
+ var pt = r.Instance.Template.GetFunctionTemplateByIndex(index);
if (pt != null)
{
if (r.Instance.GetAge(index) > age)
@@ -1317,8 +1442,9 @@ namespace Esiur.Net.IIP
#endif
if (pi != null)
{
- SendReply(IIPPacket.IIPPacketAction.GetPropertyIfModified, callback,
- Codec.Compose(pi.GetValue(r), this));
+ SendReply(IIPPacket.IIPPacketAction.GetPropertyIfModified, callback)
+ .AddUInt8Array(Codec.Compose(pi.GetValue(r), this))
+ .Done();
}
else
{
@@ -1327,8 +1453,9 @@ namespace Esiur.Net.IIP
}
else
{
- SendReply(IIPPacket.IIPPacketAction.GetPropertyIfModified, callback,
- (byte)DataType.NotModified);
+ SendReply(IIPPacket.IIPPacketAction.GetPropertyIfModified, callback)
+ .AddUInt8((byte)DataType.NotModified)
+ .Done();
}
}
else
@@ -1351,7 +1478,7 @@ namespace Esiur.Net.IIP
{
- var pt = r.Instance.Template.GetPropertyTemplate(index);
+ var pt = r.Instance.Template.GetPropertyTemplateByIndex(index);
if (pt != null)
{
Codec.Parse(content, 0, this).Then((value) =>
@@ -1361,7 +1488,7 @@ namespace Esiur.Net.IIP
// propagation
(r as DistributedResource)._Set(index, value).Then((x) =>
{
- SendReply(IIPPacket.IIPPacketAction.SetProperty, callback);
+ SendReply(IIPPacket.IIPPacketAction.SetProperty, callback).Done();
}).Error(x =>
{
SendError(x.Type, callback, (ushort)x.Code, x.Message);
@@ -1378,7 +1505,7 @@ namespace Esiur.Net.IIP
#endif*/
var pi = pt.Info;
-
+
if (pi != null)
{
@@ -1405,17 +1532,17 @@ namespace Esiur.Net.IIP
value = DC.CastConvert(value, pi.PropertyType);
}
-
+
try
{
pi.SetValue(r, value);
- SendReply(IIPPacket.IIPPacketAction.SetProperty, callback);
+ SendReply(IIPPacket.IIPPacketAction.SetProperty, callback).Done();
}
- catch(Exception ex)
+ catch (Exception ex)
{
SendError(ErrorType.Exception, callback, 0, ex.Message);
}
-
+
}
else
{
@@ -1591,16 +1718,19 @@ namespace Esiur.Net.IIP
var reply = new AsyncReply();
templateRequests.Add(classId, reply);
- SendRequest(IIPPacket.IIPPacketAction.TemplateFromClassId, classId).Then((rt) =>
- {
- templateRequests.Remove(classId);
- templates.Add(((ResourceTemplate)rt[0]).ClassId, (ResourceTemplate)rt[0]);
- Warehouse.PutTemplate(rt[0] as ResourceTemplate);
- reply.Trigger(rt[0]);
- }).Error((ex) =>
- {
- reply.TriggerError(ex);
- });
+ SendRequest(IIPPacket.IIPPacketAction.TemplateFromClassId)
+ .AddGuid(classId)
+ .Done()
+ .Then((rt) =>
+ {
+ templateRequests.Remove(classId);
+ templates.Add(((ResourceTemplate)rt[0]).ClassId, (ResourceTemplate)rt[0]);
+ Warehouse.PutTemplate(rt[0] as ResourceTemplate);
+ reply.Trigger(rt[0]);
+ }).Error((ex) =>
+ {
+ reply.TriggerError(ex);
+ });
return reply;
}
@@ -1692,29 +1822,32 @@ namespace Esiur.Net.IIP
var reply = new AsyncReply();
resourceRequests.Add(id, reply);
- SendRequest(IIPPacket.IIPPacketAction.AttachResource, id).Then((rt) =>
- {
- var dr = new DistributedResource(this, id, (ulong)rt[1], (string)rt[2]);
+ SendRequest(IIPPacket.IIPPacketAction.AttachResource)
+ .AddUInt32(id)
+ .Done()
+ .Then((rt) =>
+ {
+ var dr = new DistributedResource(this, id, (ulong)rt[1], (string)rt[2]);
- GetTemplate((Guid)rt[0]).Then((tmp) =>
- {
- // ClassId, ResourceAge, ResourceLink, Content
- Warehouse.Put(dr, id.ToString(), this, null, tmp);
+ GetTemplate((Guid)rt[0]).Then((tmp) =>
+ {
+ // ClassId, ResourceAge, ResourceLink, Content
+ Warehouse.Put(dr, id.ToString(), this, null, tmp);
- Codec.ParsePropertyValueArray((byte[])rt[3], this).Then((ar) =>
- {
- dr._Attached(ar);
- resourceRequests.Remove(id);
- reply.Trigger(dr);
- });
- }).Error((ex) =>
- {
- reply.TriggerError(ex);
- });
- }).Error((ex) =>
- {
- reply.TriggerError(ex);
- });
+ Codec.ParsePropertyValueArray((byte[])rt[3], this).Then((ar) =>
+ {
+ dr._Attached(ar);
+ resourceRequests.Remove(id);
+ reply.Trigger(dr);
+ });
+ }).Error((ex) =>
+ {
+ reply.TriggerError(ex);
+ });
+ }).Error((ex) =>
+ {
+ reply.TriggerError(ex);
+ });
return reply;
}
@@ -1724,14 +1857,17 @@ namespace Esiur.Net.IIP
{
var rt = new AsyncReply();
- SendRequest(IIPPacket.IIPPacketAction.ResourceChildren, resource.Instance.Id).Then(ar =>
- {
- var d = (byte[])ar[0];
- Codec.ParseResourceArray(d, 0, (uint)d.Length, this).Then(resources =>
- {
- rt.Trigger(resources);
- }).Error(ex => rt.TriggerError(ex));
- });
+ SendRequest(IIPPacket.IIPPacketAction.ResourceChildren)
+ .AddUInt32(resource.Instance.Id)
+ .Done()
+ .Then(ar =>
+ {
+ var d = (byte[])ar[0];
+ Codec.ParseResourceArray(d, 0, (uint)d.Length, this).Then(resources =>
+ {
+ rt.Trigger(resources);
+ }).Error(ex => rt.TriggerError(ex));
+ });
return rt;
}
@@ -1740,14 +1876,17 @@ namespace Esiur.Net.IIP
{
var rt = new AsyncReply();
- SendRequest(IIPPacket.IIPPacketAction.ResourceParents, resource.Instance.Id).Then(ar =>
- {
- var d = (byte[])ar[0];
- Codec.ParseResourceArray(d, 0, (uint)d.Length, this).Then(resources =>
+ SendRequest(IIPPacket.IIPPacketAction.ResourceParents)
+ .AddUInt32(resource.Instance.Id)
+ .Done()
+ .Then(ar =>
{
- rt.Trigger(resources);
- }).Error(ex => rt.TriggerError(ex));
- });
+ var d = (byte[])ar[0];
+ Codec.ParseResourceArray(d, 0, (uint)d.Length, this).Then(resources =>
+ {
+ rt.Trigger(resources);
+ }).Error(ex => rt.TriggerError(ex));
+ });
return rt;
}
@@ -1757,17 +1896,21 @@ namespace Esiur.Net.IIP
var rt = new AsyncReply();
if (attributes == null)
- SendRequest(IIPPacket.IIPPacketAction.ClearAllAttributes, resource.Instance.Id).Then(ar =>
- {
- rt.Trigger(true);
- }).Error(ex => rt.TriggerError(ex));
+ SendRequest(IIPPacket.IIPPacketAction.ClearAllAttributes)
+ .AddUInt32(resource.Instance.Id)
+ .Done()
+ .Then(ar => rt.Trigger(true))
+ .Error(ex => rt.TriggerError(ex));
else
{
var attrs = DC.ToBytes(attributes);
- SendRequest(IIPPacket.IIPPacketAction.ClearAttributes, resource.Instance.Id, (uint)attrs.Length, attrs).Then(ar =>
- {
- rt.Trigger(true);
- }).Error(ex => rt.TriggerChunk(ex));
+ SendRequest(IIPPacket.IIPPacketAction.ClearAttributes)
+ .AddUInt32(resource.Instance.Id)
+ .AddInt32(attrs.Length)
+ .AddUInt8Array(attrs)
+ .Done()
+ .Then(ar => rt.Trigger(true))
+ .Error(ex => rt.TriggerError(ex));
}
return rt;
@@ -1777,12 +1920,12 @@ namespace Esiur.Net.IIP
{
var rt = new AsyncReply();
- SendRequest(clearAttributes ? IIPPacket.IIPPacketAction.UpdateAllAttributes : IIPPacket.IIPPacketAction.UpdateAttributes
- , resource.Instance.Id,
- Codec.ComposeStructure(attributes, this, true, true, true)).Then(ar =>
- {
- rt.Trigger(true);
- }).Error(ex => rt.TriggerError(ex));
+ SendRequest(clearAttributes ? IIPPacket.IIPPacketAction.UpdateAllAttributes : IIPPacket.IIPPacketAction.UpdateAttributes)
+ .AddUInt32(resource.Instance.Id)
+ .AddUInt8Array(Codec.ComposeStructure(attributes, this, true, true, true))
+ .Done()
+ .Then(ar => rt.Trigger(true))
+ .Error(ex => rt.TriggerError(ex));
return rt;
}
@@ -1793,32 +1936,40 @@ namespace Esiur.Net.IIP
if (attributes == null)
{
- SendRequest(IIPPacket.IIPPacketAction.GetAllAttributes, resource.Instance.Id).Then(ar =>
- {
- var d = ar[0] as byte[];
- Codec.ParseStructure(d, 0, (uint)d.Length, this).Then(st =>
+ SendRequest(IIPPacket.IIPPacketAction.GetAllAttributes)
+ .AddUInt32(resource.Instance.Id)
+ .Done()
+ .Then(ar =>
{
+ var d = ar[0] as byte[];
+ Codec.ParseStructure(d, 0, (uint)d.Length, this).Then(st =>
+ {
- resource.Instance.SetAttributes(st);
+ resource.Instance.SetAttributes(st);
- rt.Trigger(st);
- }).Error(ex => rt.TriggerError(ex));
- });
+ rt.Trigger(st);
+ }).Error(ex => rt.TriggerError(ex));
+ });
}
else
{
var attrs = DC.ToBytes(attributes);
- SendRequest(IIPPacket.IIPPacketAction.GetAttributes, resource.Instance.Id, (uint)attrs.Length, attrs).Then(ar =>
- {
- var d = ar[0] as byte[];
- Codec.ParseStructure(d, 0, (uint)d.Length, this).Then(st =>
+ SendRequest(IIPPacket.IIPPacketAction.GetAttributes)
+ .AddUInt32(resource.Instance.Id)
+ .AddInt32(attrs.Length)
+ .AddUInt8Array(attrs)
+ .Done()
+ .Then(ar =>
{
+ var d = ar[0] as byte[];
+ Codec.ParseStructure(d, 0, (uint)d.Length, this).Then(st =>
+ {
- resource.Instance.SetAttributes(st);
+ resource.Instance.SetAttributes(st);
- rt.Trigger(st);
- }).Error(ex => rt.TriggerError(ex));
- });
+ rt.Trigger(st);
+ }).Error(ex => rt.TriggerError(ex));
+ });
}
return rt;
@@ -1842,18 +1993,19 @@ namespace Esiur.Net.IIP
var reply = new AsyncReply>();
- SendRequest(IIPPacket.IIPPacketAction.ResourceHistory, dr.Id, fromDate, toDate).Then(rt =>
- {
- var content = (byte[])rt[0];
-
- Codec.ParseHistory(content, 0, (uint)content.Length, resource, this).Then((history) =>
+ SendRequest(IIPPacket.IIPPacketAction.ResourceHistory)
+ .AddUInt32(dr.Id)
+ .AddDateTime(fromDate)
+ .AddDateTime(toDate)
+ .Done()
+ .Then(rt =>
{
- reply.Trigger(history);
- });
- }).Error((ex) =>
- {
- reply.TriggerError(ex);
- }); ;
+ var content = (byte[])rt[0];
+
+ Codec.ParseHistory(content, 0, (uint)content.Length, resource, this)
+ .Then((history) => reply.Trigger(history));
+
+ }).Error((ex) => reply.TriggerError(ex));
return reply;
}
@@ -1871,15 +2023,18 @@ namespace Esiur.Net.IIP
var str = DC.ToBytes(path);
var reply = new AsyncReply();
- SendRequest(IIPPacket.IIPPacketAction.QueryLink, (ushort)str.Length, str).Then(args =>
- {
- var content = args[0] as byte[];
+ SendRequest(IIPPacket.IIPPacketAction.QueryLink)
+ .AddUInt16((ushort)str.Length)
+ .AddUInt8Array(str)
+ .Done()
+ .Then(args =>
+ {
+ var content = args[0] as byte[];
- Codec.ParseResourceArray(content, 0, (uint)content.Length, this).Then(resources =>
- {
- reply.Trigger(resources);
- });
- });
+ Codec.ParseResourceArray(content, 0, (uint)content.Length, this)
+ .Then(resources => reply.Trigger(resources));
+
+ }).Error(ex=>reply.TriggerError(ex));
return reply;
}
@@ -1897,25 +2052,30 @@ namespace Esiur.Net.IIP
public AsyncReply Create(IStore store, IResource parent, string className, object[] parameters, Structure attributes, Structure values)
{
var reply = new AsyncReply();
- var pkt = new BinaryList(store.Instance.Id,
- parent.Instance.Id,
- className.Length, Encoding.ASCII.GetBytes(className),
- Codec.ComposeVarArray(parameters, this, true),
- Codec.ComposeStructure(attributes, this, true, true, true),
- Codec.ComposeStructure(values, this));
+ var pkt = new BinaryList()
+ .AddUInt32(store.Instance.Id)
+ .AddUInt32(parent.Instance.Id)
+ .AddUInt8((byte)className.Length)
+ .AddString(className)
+ .AddUInt8Array(Codec.ComposeVarArray(parameters, this, true))
+ .AddUInt8Array(Codec.ComposeStructure(attributes, this, true, true, true))
+ .AddUInt8Array(Codec.ComposeStructure(values, this));
- pkt.Insert(8, pkt.Length);
+ pkt.InsertInt32(8, pkt.Length);
- SendRequest(IIPPacket.IIPPacketAction.CreateResource, pkt.ToArray()).Then(args =>
- {
- var rid = (uint)args[0];
-
- Fetch(rid).Then((r) =>
+ SendRequest(IIPPacket.IIPPacketAction.CreateResource)
+ .AddUInt8Array(pkt.ToArray())
+ .Done()
+ .Then(args =>
{
- reply.Trigger(r);
- });
+ var rid = (uint)args[0];
- });
+ Fetch(rid).Then((r) =>
+ {
+ reply.Trigger(r);
+ });
+
+ });
return reply;
}
@@ -1923,17 +2083,23 @@ namespace Esiur.Net.IIP
private void Instance_ResourceDestroyed(IResource resource)
{
// compose the packet
- SendEvent(IIPPacket.IIPPacketEvent.ResourceDestroyed, resource.Instance.Id);
+ SendEvent(IIPPacket.IIPPacketEvent.ResourceDestroyed)
+ .AddUInt32(resource.Instance.Id)
+ .Done();
}
private void Instance_PropertyModified(IResource resource, string name, object newValue)
{
- var pt = resource.Instance.Template.GetPropertyTemplate(name);
+ var pt = resource.Instance.Template.GetPropertyTemplateByName(name);
if (pt == null)
return;
- SendEvent(IIPPacket.IIPPacketEvent.PropertyUpdated, resource.Instance.Id, pt.Index, Codec.Compose(newValue, this));
+ SendEvent(IIPPacket.IIPPacketEvent.PropertyUpdated)
+ .AddUInt32(resource.Instance.Id)
+ .AddUInt8(pt.Index)
+ .AddUInt8Array(Codec.Compose(newValue, this))
+ .Done();
}
@@ -1941,7 +2107,7 @@ namespace Esiur.Net.IIP
private void Instance_EventOccurred(IResource resource, object issuer, Session[] receivers, string name, object[] args)
{
- var et = resource.Instance.Template.GetEventTemplate(name);
+ var et = resource.Instance.Template.GetEventTemplateByName(name);
if (et == null)
return;
@@ -1964,8 +2130,11 @@ namespace Esiur.Net.IIP
return;
// compose the packet
- SendEvent(IIPPacket.IIPPacketEvent.EventOccurred,
- resource.Instance.Id, (byte)et.Index, Codec.ComposeVarArray(args, this, true));
+ SendEvent(IIPPacket.IIPPacketEvent.EventOccurred)
+ .AddUInt32(resource.Instance.Id)
+ .AddUInt8((byte)et.Index)
+ .AddUInt8Array(Codec.ComposeVarArray(args, this, true))
+ .Done();
}
}
}
diff --git a/Esiur/Net/IIP/DistributedResource.cs b/Esiur/Net/IIP/DistributedResource.cs
index 140ae9f..dbd6519 100644
--- a/Esiur/Net/IIP/DistributedResource.cs
+++ b/Esiur/Net/IIP/DistributedResource.cs
@@ -33,7 +33,7 @@ using Esiur.Misc;
using Esiur.Data;
using System.Dynamic;
using System.Security.Cryptography;
-using Esiur.Engine;
+using Esiur.Core;
using System.Runtime.CompilerServices;
using System.Reflection.Emit;
using System.Linq;
@@ -229,7 +229,7 @@ namespace Esiur.Net.IIP
internal void _EmitEventByIndex(byte index, object[] args)
{
- var et = Instance.Template.GetEventTemplate(index);
+ var et = Instance.Template.GetEventTemplateByIndex(index);
events[index]?.Invoke(this, args);
Instance.EmitResourceEvent(null, null, et.Name, args);
}
@@ -261,7 +261,7 @@ namespace Esiur.Net.IIP
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
- var ft = Instance.Template.GetFunctionTemplate(binder.Name);
+ var ft = Instance.Template.GetFunctionTemplateByName(binder.Name);
var reply = new AsyncReply();
@@ -325,7 +325,7 @@ namespace Esiur.Net.IIP
if (!isAttached)
return false;
- var pt = Instance.Template.GetPropertyTemplate(binder.Name);
+ var pt = Instance.Template.GetPropertyTemplateByName(binder.Name);
if (pt != null)
{
@@ -334,7 +334,7 @@ namespace Esiur.Net.IIP
}
else
{
- var et = Instance.Template.GetEventTemplate(binder.Name);
+ var et = Instance.Template.GetEventTemplateByName(binder.Name);
if (et == null)
return false;
@@ -347,7 +347,7 @@ namespace Esiur.Net.IIP
internal void _UpdatePropertyByIndex(byte index, object value)
{
- var pt = Instance.Template.GetPropertyTemplate(index);
+ var pt = Instance.Template.GetPropertyTemplateByIndex(index);
properties[index] = value;
Instance.EmitModification(pt, value);
}
@@ -366,12 +366,18 @@ namespace Esiur.Net.IIP
var reply = new AsyncReply();
var parameters = Codec.Compose(value, connection);
- connection.SendRequest(Packets.IIPPacket.IIPPacketAction.SetProperty, instanceId, index, parameters).Then((res) =>
- {
- // not really needed, server will always send property modified, this only happens if the programmer forgot to emit in property setter
- properties[index] = value;
- reply.Trigger(null);
- });
+ connection.SendRequest(Packets.IIPPacket.IIPPacketAction.SetProperty)
+ .AddUInt32(instanceId)
+ .AddUInt8(index)
+ .AddUInt8Array(parameters)
+ .Done()
+ .Then((res) =>
+ {
+ // not really needed, server will always send property modified,
+ // this only happens if the programmer forgot to emit in property setter
+ properties[index] = value;
+ reply.Trigger(null);
+ });
return reply;
}
@@ -384,7 +390,7 @@ namespace Esiur.Net.IIP
if (!isAttached)
return false;
- var pt = Instance.Template.GetPropertyTemplate(binder.Name);
+ var pt = Instance.Template.GetPropertyTemplateByName(binder.Name);
if (pt != null)
{
@@ -393,7 +399,7 @@ namespace Esiur.Net.IIP
}
else
{
- var et = Instance.Template.GetEventTemplate(binder.Name);
+ var et = Instance.Template.GetEventTemplateByName(binder.Name);
if (et == null)
return false;
diff --git a/Esiur/Net/IIP/DistributedServer.cs b/Esiur/Net/IIP/DistributedServer.cs
index 0cec3fe..b3611c9 100644
--- a/Esiur/Net/IIP/DistributedServer.cs
+++ b/Esiur/Net/IIP/DistributedServer.cs
@@ -30,7 +30,7 @@ using Esiur.Net.Sockets;
using Esiur.Misc;
using System.Threading;
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using System.Net;
using Esiur.Resource;
using Esiur.Security.Membership;
@@ -128,7 +128,7 @@ namespace Esiur.Net.IIP
protected override void ClientConnected(DistributedConnection sender)
{
- //Console.WriteLine("DistributedConnection Client Connected");
+ Console.WriteLine("DistributedConnection Client Connected");
}
diff --git a/Esiur/Net/NetworkConnection.cs b/Esiur/Net/NetworkConnection.cs
index 1802cef..bf81c23 100644
--- a/Esiur/Net/NetworkConnection.cs
+++ b/Esiur/Net/NetworkConnection.cs
@@ -31,7 +31,7 @@ using System.Net;
using System.Collections;
using System.Collections.Generic;
using Esiur.Misc;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Data;
using Esiur.Net.Sockets;
using Esiur.Resource;
diff --git a/Esiur/Net/NetworkServer.cs b/Esiur/Net/NetworkServer.cs
index ac62098..b5c118b 100644
--- a/Esiur/Net/NetworkServer.cs
+++ b/Esiur/Net/NetworkServer.cs
@@ -27,7 +27,7 @@ using System.Threading;
using System.Collections.Generic;
using Esiur.Data;
using Esiur.Misc;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Net.Sockets;
using Esiur.Resource;
using System.Threading.Tasks;
diff --git a/Esiur/Net/NetworkSession.cs b/Esiur/Net/NetworkSession.cs
index 2626734..ea974c8 100644
--- a/Esiur/Net/NetworkSession.cs
+++ b/Esiur/Net/NetworkSession.cs
@@ -33,7 +33,7 @@ using System.Collections;
using System.Collections.Generic;
using Esiur.Data;
using Esiur.Misc;
-using Esiur.Engine;
+using Esiur.Core;
namespace Esiur.Net
{
diff --git a/Esiur/Net/Packets/IIPPacket.cs b/Esiur/Net/Packets/IIPPacket.cs
index 714c913..5cfb1aa 100644
--- a/Esiur/Net/Packets/IIPPacket.cs
+++ b/Esiur/Net/Packets/IIPPacket.cs
@@ -23,7 +23,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Misc;
using Esiur.Net.Packets;
using System;
diff --git a/Esiur/Net/SendList.cs b/Esiur/Net/SendList.cs
new file mode 100644
index 0000000..2513d87
--- /dev/null
+++ b/Esiur/Net/SendList.cs
@@ -0,0 +1,26 @@
+using Esiur.Core;
+using Esiur.Data;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Esiur.Net
+{
+ public class SendList : BinaryList
+ {
+ NetworkConnection connection;
+ IAsyncReply reply;
+
+ public SendList(NetworkConnection connection, IAsyncReply reply)
+ {
+ this.reply = reply;
+ this.connection = connection;
+ }
+
+ public override IAsyncReply Done()
+ {
+ connection.Send(this.ToArray());
+ return reply;
+ }
+ }
+}
diff --git a/Esiur/Net/Sockets/ISocket.cs b/Esiur/Net/Sockets/ISocket.cs
index 26e9274..25c20cf 100644
--- a/Esiur/Net/Sockets/ISocket.cs
+++ b/Esiur/Net/Sockets/ISocket.cs
@@ -34,7 +34,7 @@ using Esiur.Data;
using Esiur.Misc;
using System.Collections.Concurrent;
using Esiur.Resource;
-using Esiur.Engine;
+using Esiur.Core;
namespace Esiur.Net.Sockets
{
@@ -53,7 +53,7 @@ namespace Esiur.Net.Sockets
void Send(byte[] message);
void Send(byte[] message, int offset, int size);
void Close();
- bool Connect(string hostname, ushort port);
+ AsyncReply Connect(string hostname, ushort port);
bool Begin();
//ISocket Accept();
AsyncReply Accept();
diff --git a/Esiur/Net/Sockets/SSLSocket.cs b/Esiur/Net/Sockets/SSLSocket.cs
index 58eb7e1..c98836b 100644
--- a/Esiur/Net/Sockets/SSLSocket.cs
+++ b/Esiur/Net/Sockets/SSLSocket.cs
@@ -29,7 +29,7 @@ using System.Text;
using System.Net.Sockets;
using System.Net;
using Esiur.Misc;
-using Esiur.Engine;
+using Esiur.Core;
using System.Threading;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
@@ -77,20 +77,29 @@ namespace Esiur.Net.Sockets
}
}
- public bool Connect(string hostname, ushort port)
+ public AsyncReply Connect(string hostname, ushort port)
{
+ var rt = new AsyncReply();
+
try
{
- this.hostname = hostname;
- server = false;
state = SocketState.Connecting;
- sock.ConnectAsync(hostname, port).ContinueWith(Connected);
- return true;
+ sock.ConnectAsync(hostname, port).ContinueWith((x) =>
+ {
+ if (x.IsFaulted)
+ rt.TriggerError(x.Exception);
+ else
+ rt.Trigger(true);
+
+ Connected(x);
+ });
}
- catch
+ catch (Exception ex)
{
- return false;
+ rt.TriggerError(ex);
}
+
+ return rt;
}
private void DataSent(Task task)
diff --git a/Esiur/Net/Sockets/TCPSocket.cs b/Esiur/Net/Sockets/TCPSocket.cs
index 62b6345..9cb77fd 100644
--- a/Esiur/Net/Sockets/TCPSocket.cs
+++ b/Esiur/Net/Sockets/TCPSocket.cs
@@ -29,7 +29,7 @@ using System.Text;
using System.Net.Sockets;
using System.Net;
using Esiur.Misc;
-using Esiur.Engine;
+using Esiur.Core;
using System.Threading;
using Esiur.Resource;
using System.Threading.Tasks;
@@ -62,13 +62,6 @@ namespace Esiur.Net.Sockets
SocketAsyncEventArgs socketArgs = new SocketAsyncEventArgs();
- private void Connected(Task t)
- {
- state = SocketState.Established;
- OnConnect?.Invoke();
- Begin();
- }
-
public bool Begin()
{
if (began)
@@ -86,18 +79,34 @@ namespace Esiur.Net.Sockets
return true;
}
- public bool Connect(string hostname, ushort port)
+ public AsyncReply Connect(string hostname, ushort port)
{
+ var rt = new AsyncReply();
+
try
{
state = SocketState.Connecting;
- sock.ConnectAsync(hostname, port).ContinueWith(Connected);
- return true;
+ sock.ConnectAsync(hostname, port).ContinueWith((x) =>
+ {
+
+ if (x.IsFaulted)
+ rt.TriggerError(x.Exception);
+ else
+ {
+
+ state = SocketState.Established;
+ OnConnect?.Invoke();
+ Begin();
+ rt.Trigger(true);
+ }
+ });
}
- catch
+ catch (Exception ex)
{
- return false;
+ rt.TriggerError(ex);
}
+
+ return rt;
}
@@ -117,7 +126,7 @@ namespace Esiur.Net.Sockets
}
//if (receiveNetworkBuffer.Protected)
- // Console.WriteLine();
+ // Console.WriteLine();
//lock (receiveNetworkBuffer.SyncLock)
receiveNetworkBuffer.Write(receiveBuffer, 0, (uint)task.Result);
@@ -128,7 +137,7 @@ namespace Esiur.Net.Sockets
if (state == SocketState.Established)
{
sock.ReceiveAsync(receiveBufferSegment, SocketFlags.None).ContinueWith(DataReceived);
-
+
}
}
@@ -149,7 +158,7 @@ namespace Esiur.Net.Sockets
try
{
// SocketError err;
-
+
if (state == SocketState.Closed || state == SocketState.Terminated)
return;
@@ -162,7 +171,7 @@ namespace Esiur.Net.Sockets
//if (receiveNetworkBuffer.Protected)
// Console.WriteLine();
-
+
//lock (receiveNetworkBuffer.SyncLock)
receiveNetworkBuffer.Write(receiveBuffer, 0, (uint)e.BytesTransferred);
diff --git a/Esiur/Net/Sockets/WSSocket.cs b/Esiur/Net/Sockets/WSSocket.cs
index b913aa5..b462a7c 100644
--- a/Esiur/Net/Sockets/WSSocket.cs
+++ b/Esiur/Net/Sockets/WSSocket.cs
@@ -31,7 +31,7 @@ using System.Net;
using Esiur.Net.Packets;
using Esiur.Misc;
using System.IO;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Resource;
using Esiur.Data;
@@ -236,7 +236,7 @@ namespace Esiur.Net.Sockets
sock.Close();
}
- public bool Connect(string hostname, ushort port)
+ public AsyncReply Connect(string hostname, ushort port)
{
throw new NotImplementedException();
}
diff --git a/Esiur/Net/TCP/TCPFilter.cs b/Esiur/Net/TCP/TCPFilter.cs
index df86ebb..c39ad7f 100644
--- a/Esiur/Net/TCP/TCPFilter.cs
+++ b/Esiur/Net/TCP/TCPFilter.cs
@@ -29,7 +29,7 @@ using System.Text;
using System.Collections;
using Esiur.Data;
using Esiur.Net.Sockets;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Resource;
namespace Esiur.Net.TCP
diff --git a/Esiur/Net/TCP/TCPServer.cs b/Esiur/Net/TCP/TCPServer.cs
index b5b739b..3c2ccd5 100644
--- a/Esiur/Net/TCP/TCPServer.cs
+++ b/Esiur/Net/TCP/TCPServer.cs
@@ -30,7 +30,7 @@ using Esiur.Net.Sockets;
using Esiur.Misc;
using System.Threading;
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using System.Net;
using Esiur.Resource;
diff --git a/Esiur/Net/UDP/UDPFilter.cs b/Esiur/Net/UDP/UDPFilter.cs
index 01633f9..2ae4298 100644
--- a/Esiur/Net/UDP/UDPFilter.cs
+++ b/Esiur/Net/UDP/UDPFilter.cs
@@ -29,7 +29,7 @@ using System.Text;
using System.Collections;
using System.Net;
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Resource;
namespace Esiur.Net.UDP
diff --git a/Esiur/Resource/IResource.cs b/Esiur/Resource/IResource.cs
index 95a6230..3b640e6 100644
--- a/Esiur/Resource/IResource.cs
+++ b/Esiur/Resource/IResource.cs
@@ -27,7 +27,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
namespace Esiur.Resource
{
diff --git a/Esiur/Resource/IStore.cs b/Esiur/Resource/IStore.cs
index 96df8af..577a252 100644
--- a/Esiur/Resource/IStore.cs
+++ b/Esiur/Resource/IStore.cs
@@ -23,7 +23,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Resource.Template;
using System;
using System.Collections.Generic;
diff --git a/Esiur/Resource/Instance.cs b/Esiur/Resource/Instance.cs
index 473e7fe..1524b92 100644
--- a/Esiur/Resource/Instance.cs
+++ b/Esiur/Resource/Instance.cs
@@ -11,6 +11,7 @@ using Esiur.Misc;
using Esiur.Security.Permissions;
using Esiur.Resource.Template;
using Esiur.Security.Authority;
+using Esiur.Proxy;
namespace Esiur.Resource
{
@@ -265,7 +266,7 @@ namespace Esiur.Resource
///
public bool LoadProperty(string name, ulong age, DateTime modificationDate, object value)
{
- var pt = template.GetPropertyTemplate(name);
+ var pt = template.GetPropertyTemplateByName(name);
if (pt == null)
return false;
@@ -336,7 +337,7 @@ namespace Esiur.Resource
{
for (byte i = 0; i < properties.Length; i++)
{
- var pt = this.template.GetPropertyTemplate(i);
+ var pt = this.template.GetPropertyTemplateByIndex(i);
if (pt != null)
{
var pv = properties[i];
@@ -486,7 +487,7 @@ namespace Esiur.Resource
object value;
if (GetPropertyValue(propertyName, out value))
{
- var pt = template.GetPropertyTemplate(propertyName);
+ var pt = template.GetPropertyTemplateByName(propertyName);
EmitModification(pt, value);
}
}
@@ -515,7 +516,7 @@ namespace Esiur.Resource
#endif
*/
- var pt = template.GetPropertyTemplate(name);
+ var pt = template.GetPropertyTemplateByName(name);
if (pt != null && pt.Info != null)
{
@@ -712,7 +713,7 @@ namespace Esiur.Resource
}
// connect events
- Type t = resource.GetType();
+ Type t = ResourceProxy.GetBaseType(resource);
#if NETSTANDARD1_5
var events = t.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
diff --git a/Esiur/Resource/Resource.cs b/Esiur/Resource/Resource.cs
index 5b5474e..0b31c8f 100644
--- a/Esiur/Resource/Resource.cs
+++ b/Esiur/Resource/Resource.cs
@@ -24,7 +24,7 @@ SOFTWARE.
using System;
using System.Collections.Generic;
using System.Text;
-using Esiur.Engine;
+using Esiur.Core;
namespace Esiur.Resource
{
diff --git a/Esiur/Resource/ResourceEventHandler.cs b/Esiur/Resource/ResourceEventHandler.cs
index 18954e1..662d013 100644
--- a/Esiur/Resource/ResourceEventHandler.cs
+++ b/Esiur/Resource/ResourceEventHandler.cs
@@ -22,7 +22,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Net.IIP;
using Esiur.Security.Authority;
using System;
diff --git a/Esiur/Resource/ResourceProperty.cs b/Esiur/Resource/ResourceProperty.cs
index aef6567..82fb3f4 100644
--- a/Esiur/Resource/ResourceProperty.cs
+++ b/Esiur/Resource/ResourceProperty.cs
@@ -63,7 +63,7 @@ namespace Esiur.Resource
}
}
- public ResourceProperty(StorageMode storage = StorageMode.Volatile, string readExpansion = null, string writeExpansion = null)
+ public ResourceProperty(StorageMode storage = StorageMode.NonVolatile, string readExpansion = null, string writeExpansion = null)
{
this.readExpansion = readExpansion;
this.writeExpansion = writeExpansion;
diff --git a/Esiur/Resource/ResourceTrigger.cs b/Esiur/Resource/ResourceTrigger.cs
index 837d75e..237392f 100644
--- a/Esiur/Resource/ResourceTrigger.cs
+++ b/Esiur/Resource/ResourceTrigger.cs
@@ -32,7 +32,7 @@ namespace Esiur.Resource
{
public enum ResourceTrigger : int
{
- Loaded = 0,
+ Open = 0,
Initialize,
Terminate,
Configure,
diff --git a/Esiur/Resource/Storable.cs b/Esiur/Resource/Storable.cs
index 76184cc..8701c4f 100644
--- a/Esiur/Resource/Storable.cs
+++ b/Esiur/Resource/Storable.cs
@@ -23,7 +23,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using System;
using System.Collections.Generic;
using System.Linq;
diff --git a/Esiur/Resource/StorageMode.cs b/Esiur/Resource/StorageMode.cs
index 5513838..5f557f5 100644
--- a/Esiur/Resource/StorageMode.cs
+++ b/Esiur/Resource/StorageMode.cs
@@ -6,8 +6,8 @@ namespace Esiur.Resource
{
public enum StorageMode : byte
{
- Volatile = 0,
NonVolatile,
+ Volatile,
Recordable
}
}
diff --git a/Esiur/Resource/Template/EventTemplate.cs b/Esiur/Resource/Template/EventTemplate.cs
index e132e97..dd95868 100644
--- a/Esiur/Resource/Template/EventTemplate.cs
+++ b/Esiur/Resource/Template/EventTemplate.cs
@@ -22,10 +22,20 @@ namespace Esiur.Resource.Template
if (Expansion != null)
{
var exp = DC.ToBytes(Expansion);
- return BinaryList.ToBytes((byte)0x50, exp.Length, exp, (byte)name.Length, name);
+ return new BinaryList()
+ .AddUInt8(0x50)
+ .AddInt32(exp.Length)
+ .AddUInt8Array(exp)
+ .AddUInt8((byte)name.Length)
+ .AddUInt8Array(name)
+ .ToArray();
}
else
- return BinaryList.ToBytes((byte)0x40, (byte)name.Length, name);
+ return new BinaryList()
+ .AddUInt8(0x40)
+ .AddUInt8((byte)name.Length)
+ .AddUInt8Array(name)
+ .ToArray();
}
diff --git a/Esiur/Resource/Template/FunctionTemplate.cs b/Esiur/Resource/Template/FunctionTemplate.cs
index 694df5a..0ecae96 100644
--- a/Esiur/Resource/Template/FunctionTemplate.cs
+++ b/Esiur/Resource/Template/FunctionTemplate.cs
@@ -30,10 +30,18 @@ namespace Esiur.Resource.Template
if (Expansion != null)
{
var exp = DC.ToBytes(Expansion);
- return BinaryList.ToBytes((byte)(0x10 | (IsVoid ? 0x8 : 0x0)), (byte)name.Length, name, exp.Length, exp);
+ return new BinaryList().AddUInt8((byte)(0x10 | (IsVoid ? 0x8 : 0x0)))
+ .AddUInt8((byte)name.Length)
+ .AddUInt8Array(name)
+ .AddInt32(exp.Length)
+ .AddUInt8Array(exp)
+ .ToArray();
}
else
- return BinaryList.ToBytes((byte)(IsVoid ? 0x8 : 0x0), (byte)name.Length, name);
+ return new BinaryList().AddUInt8((byte)(IsVoid ? 0x8 : 0x0))
+ .AddUInt8((byte)name.Length)
+ .AddUInt8Array(name)
+ .ToArray();
}
diff --git a/Esiur/Resource/Template/PropertyTemplate.cs b/Esiur/Resource/Template/PropertyTemplate.cs
index ed77f92..99876c4 100644
--- a/Esiur/Resource/Template/PropertyTemplate.cs
+++ b/Esiur/Resource/Template/PropertyTemplate.cs
@@ -73,20 +73,44 @@ namespace Esiur.Resource.Template
{
var rexp = DC.ToBytes(ReadExpansion);
var wexp = DC.ToBytes(WriteExpansion);
- return BinaryList.ToBytes((byte)(0x38 | pv), (byte)name.Length, name, wexp.Length, wexp, rexp.Length, rexp);
+ return new BinaryList()
+ .AddUInt8((byte)(0x38 | pv))
+ .AddUInt8((byte)name.Length)
+ .AddUInt8Array(name)
+ .AddInt32(wexp.Length)
+ .AddUInt8Array(wexp)
+ .AddInt32(rexp.Length)
+ .AddUInt8Array(rexp)
+ .ToArray();
}
else if (WriteExpansion != null)
{
var wexp = DC.ToBytes(WriteExpansion);
- return BinaryList.ToBytes((byte)(0x30 | pv), (byte)name.Length, name, wexp.Length, wexp);
+ return new BinaryList()
+ .AddUInt8((byte)(0x30 | pv))
+ .AddUInt8((byte)name.Length)
+ .AddUInt8Array(name)
+ .AddInt32(wexp.Length)
+ .AddUInt8Array(wexp)
+ .ToArray();
}
else if (ReadExpansion != null)
{
var rexp = DC.ToBytes(ReadExpansion);
- return BinaryList.ToBytes((byte)(0x28 | pv), (byte)name.Length, name, rexp.Length, rexp);
+ return new BinaryList()
+ .AddUInt8((byte)(0x28 | pv))
+ .AddUInt8((byte)name.Length)
+ .AddUInt8Array(name)
+ .AddInt32(rexp.Length)
+ .AddUInt8Array(rexp)
+ .ToArray();
}
else
- return BinaryList.ToBytes((byte)(0x20 | pv), (byte)name.Length, name);
+ return new BinaryList()
+ .AddUInt8((byte)(0x20 | pv))
+ .AddUInt8((byte)name.Length)
+ .AddUInt8Array(name)
+ .ToArray();
}
public PropertyTemplate(ResourceTemplate template, byte index, string name, string read, string write, StorageMode storage)
diff --git a/Esiur/Resource/Template/ResourceTemplate.cs b/Esiur/Resource/Template/ResourceTemplate.cs
index dceb89d..6e05d58 100644
--- a/Esiur/Resource/Template/ResourceTemplate.cs
+++ b/Esiur/Resource/Template/ResourceTemplate.cs
@@ -5,7 +5,7 @@ using System.Text;
using System.Reflection;
using Esiur.Misc;
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using System.Security.Cryptography;
using Esiur.Proxy;
@@ -32,16 +32,16 @@ namespace Esiur.Resource.Template
public MemberTemplate GetMemberTemplate(MemberInfo member)
{
if (member is MethodInfo)
- return GetFunctionTemplate(member.Name);
+ return GetFunctionTemplateByName(member.Name);
else if (member is EventInfo)
- return GetEventTemplate(member.Name);
+ return GetEventTemplateByName(member.Name);
else if (member is PropertyInfo)
- return GetPropertyTemplate(member.Name);
+ return GetPropertyTemplateByName(member.Name);
else
return null;
}
- public EventTemplate GetEventTemplate(string eventName)
+ public EventTemplate GetEventTemplateByName(string eventName)
{
foreach (var i in events)
if (i.Name == eventName)
@@ -49,7 +49,7 @@ namespace Esiur.Resource.Template
return null;
}
- public EventTemplate GetEventTemplate(byte index)
+ public EventTemplate GetEventTemplateByIndex(byte index)
{
foreach (var i in events)
if (i.Index == index)
@@ -57,14 +57,14 @@ namespace Esiur.Resource.Template
return null;
}
- public FunctionTemplate GetFunctionTemplate(string functionName)
+ public FunctionTemplate GetFunctionTemplateByName(string functionName)
{
foreach (var i in functions)
if (i.Name == functionName)
return i;
return null;
}
- public FunctionTemplate GetFunctionTemplate(byte index)
+ public FunctionTemplate GetFunctionTemplateByIndex(byte index)
{
foreach (var i in functions)
if (i.Index == index)
@@ -72,7 +72,7 @@ namespace Esiur.Resource.Template
return null;
}
- public PropertyTemplate GetPropertyTemplate(byte index)
+ public PropertyTemplate GetPropertyTemplateByIndex(byte index)
{
foreach (var i in properties)
if (i.Index == index)
@@ -80,7 +80,7 @@ namespace Esiur.Resource.Template
return null;
}
- public PropertyTemplate GetPropertyTemplate(string propertyName)
+ public PropertyTemplate GetPropertyTemplateByName(string propertyName)
{
foreach (var i in properties)
if (i.Name == propertyName)
@@ -200,16 +200,20 @@ namespace Esiur.Resource.Template
// bake it binarily
var b = new BinaryList();
- b.Append(classId);
- b.Append((byte)className.Length, className);
- b.Append(version);
- b.Append((ushort)members.Count);
+ b.AddGuid(classId)
+ .AddUInt8((byte)className.Length)
+ .AddString(className)
+ .AddInt32(version)
+ .AddUInt16((ushort)members.Count);
+
+
foreach (var ft in functions)
- b.Append(ft.Compose());
+ b.AddUInt8Array(ft.Compose());
foreach (var pt in properties)
- b.Append(pt.Compose());
+ b.AddUInt8Array(pt.Compose());
foreach (var et in events)
- b.Append(et.Compose());
+ b.AddUInt8Array(et.Compose());
+
content = b.ToArray();
}
diff --git a/Esiur/Resource/Warehouse.cs b/Esiur/Resource/Warehouse.cs
index eb0b931..45ea9e6 100644
--- a/Esiur/Resource/Warehouse.cs
+++ b/Esiur/Resource/Warehouse.cs
@@ -23,7 +23,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Proxy;
using Esiur.Resource.Template;
using Esiur.Security.Permissions;
@@ -54,7 +54,7 @@ namespace Esiur.Resource
public static event StoreConnectedEvent StoreConnected;
public static event StoreDisconnectedEvent StoreDisconnected;
- static KeyList protocols = new KeyList();
+ public static KeyList> Protocols { get; } = new KeyList>();
///
/// Get a store by its name.
@@ -277,15 +277,15 @@ namespace Esiur.Resource
var rt = new AsyncReply();
- if (protocols.ContainsKey(url[0]))
+ if (Protocols.ContainsKey(url[0]))
{
- var handler = protocols[url[0]];
+ var handler = Protocols[url[0]];
- var store = Activator.CreateInstance(handler.GetType()) as IStore;
+ var store = handler();// Activator.CreateInstance(handler.GetType()) as IStore;
Put(store, url[0] + "://" + hostname, null, parent, null, 0, manager, attributes);
- store.Trigger(ResourceTrigger.Initialize).Then(x => {
+ store.Trigger(ResourceTrigger.Open).Then(x => {
if (pathname.Length > 0 && pathname != "")
store.Get(pathname).Then(r => {
rt.Trigger(r);
@@ -345,7 +345,7 @@ namespace Esiur.Resource
resources.Add(resource.Instance.Id, resource);
- if (!storeIsOpen)
+ if (storeIsOpen)
resource.Trigger(ResourceTrigger.Initialize);
}
diff --git a/Esiur/Security/Authority/CACertificate.cs b/Esiur/Security/Authority/CACertificate.cs
index 28dcfb3..3dac45c 100644
--- a/Esiur/Security/Authority/CACertificate.cs
+++ b/Esiur/Security/Authority/CACertificate.cs
@@ -23,7 +23,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Misc;
using Esiur.Security.Cryptography;
using Esiur.Security.Integrity;
@@ -131,16 +131,20 @@ namespace Esiur.Security.Authority
BinaryList cr = new BinaryList();
// make header
-
- cr.Append(id, issueDate, expireDate);
+
+ cr.AddUInt64(id)
+ .AddDateTime(issueDate)
+ .AddDateTime(expireDate);
+
// hash function
- cr.Append((byte)((byte)hashFunction << 4));
+ cr.AddUInt8((byte)((byte)hashFunction << 4));
this.hashFunction = hashFunction;
// CA Name
this.name = authorityName;
- cr.Append((byte)(authorityName.Length), Encoding.ASCII.GetBytes(authorityName));
+ cr.AddUInt8((byte)(authorityName.Length))
+ .AddUInt8Array(Encoding.ASCII.GetBytes(authorityName));
// public key
rsa = RSA.Create();// new RSACryptoServiceProvider(2048);
@@ -148,14 +152,16 @@ namespace Esiur.Security.Authority
RSAParameters dRSAKey = rsa.ExportParameters(true);
- cr.Append((byte)dRSAKey.Exponent.Length, dRSAKey.Exponent, (ushort)dRSAKey.Modulus.Length, dRSAKey.Modulus);
+ cr.AddUInt8((byte)dRSAKey.Exponent.Length)
+ .AddUInt8Array(dRSAKey.Exponent)
+ .AddUInt16((ushort)dRSAKey.Modulus.Length)
+ .AddUInt8Array(dRSAKey.Modulus);
publicRawData = cr.ToArray();
privateRawData = DC.Merge(dRSAKey.D, dRSAKey.DP, dRSAKey.DQ, dRSAKey.InverseQ, dRSAKey.P, dRSAKey.Q);
-
}
public override bool Save(string filename, bool includePrivate = false)
@@ -163,9 +169,15 @@ namespace Esiur.Security.Authority
try
{
if (includePrivate)
- File.WriteAllBytes(filename, BinaryList.ToBytes((byte)CertificateType.CAPrivate, publicRawData, privateRawData));
+ File.WriteAllBytes(filename, new BinaryList()
+ .AddUInt8((byte)CertificateType.CAPrivate)
+ .AddUInt8Array(publicRawData)
+ .AddUInt8Array(privateRawData)
+ .ToArray());
else
- File.WriteAllBytes(filename, BinaryList.ToBytes((byte)CertificateType.CAPublic, publicRawData));
+ File.WriteAllBytes(filename, new BinaryList()
+ .AddUInt8((byte)CertificateType.CAPublic)
+ .AddUInt8Array(publicRawData).ToArray());
return true;
}
@@ -178,7 +190,10 @@ namespace Esiur.Security.Authority
public override byte[] Serialize(bool includePrivate = false)
{
if (includePrivate)
- return BinaryList.ToBytes(publicRawData, privateRawData);
+ return new BinaryList()
+ .AddUInt8Array(publicRawData)
+ .AddUInt8Array(privateRawData)
+ .ToArray();
else
return publicRawData;
}
diff --git a/Esiur/Security/Authority/Certificate.cs b/Esiur/Security/Authority/Certificate.cs
index cc91da8..f23ed87 100644
--- a/Esiur/Security/Authority/Certificate.cs
+++ b/Esiur/Security/Authority/Certificate.cs
@@ -23,7 +23,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Misc;
using Esiur.Security.Cryptography;
using Esiur.Security.Integrity;
diff --git a/Esiur/Security/Authority/DomainCertificate.cs b/Esiur/Security/Authority/DomainCertificate.cs
index 5f294fa..ca034d2 100644
--- a/Esiur/Security/Authority/DomainCertificate.cs
+++ b/Esiur/Security/Authority/DomainCertificate.cs
@@ -166,44 +166,50 @@ namespace Esiur.Security.Authority
var cr = new BinaryList();
// id
- cr.Append(id);
+ cr.AddUInt64(id);
// ip
this.ip = ip;
this.ip6 = ip6;
- cr.Append(ip);
+ cr.AddUInt32(ip);
if (ip6?.Length == 16)
- cr.Append(ip6);
+ cr.AddUInt8Array(ip6);
else
- cr.Append(new byte[16]);
+ cr.AddUInt8Array(new byte[16]);
- cr.Append(issueDate, expireDate);
+ cr.AddDateTime(issueDate)
+ .AddDateTime(expireDate);
// domain
this.domain = domain;
- cr.Append((byte)(domain.Length), Encoding.ASCII.GetBytes(domain));
+ cr.AddUInt8((byte)(domain.Length))
+ .AddUInt8Array(Encoding.ASCII.GetBytes(domain));
// CA
this.caName = authority.Name;
- cr.Append((byte)(authority.Name.Length), Encoding.ASCII.GetBytes(authority.Name));
+ cr.AddUInt8((byte)(authority.Name.Length))
+ .AddUInt8Array(Encoding.ASCII.GetBytes(authority.Name));
this.authorityName = authority.Name;
// CA Index
//co.KeyIndex = authority.KeyIndex;
this.caId = authority.Id;
- cr.Append(caId);
+ cr.AddUInt64(caId);
// public key
rsa = RSA.Create();// new RSACryptoServiceProvider(2048);
rsa.KeySize = 2048;
RSAParameters dRSAKey = rsa.ExportParameters(true);
- cr.Append((byte)dRSAKey.Exponent.Length, dRSAKey.Exponent, (ushort)dRSAKey.Modulus.Length, dRSAKey.Modulus, AsymetricEncryptionAlgorithmType.RSA);
+ cr.AddUInt8((byte)dRSAKey.Exponent.Length)
+ .AddUInt8Array(dRSAKey.Exponent)
+ .AddUInt16((ushort)dRSAKey.Modulus.Length)
+ .AddUInt8Array(dRSAKey.Modulus);
publicRawData = cr.ToArray();
@@ -220,9 +226,9 @@ namespace Esiur.Security.Authority
try
{
if (includePrivate)
- File.WriteAllBytes(filename, BinaryList.ToBytes((byte)CertificateType.DomainPrivate, publicRawData, signature, privateRawData));
+ File.WriteAllBytes(filename, DC.Merge(new byte[] { (byte)CertificateType.DomainPrivate }, publicRawData, signature, privateRawData));
else
- File.WriteAllBytes(filename, BinaryList.ToBytes((byte)CertificateType.DomainPublic, publicRawData, signature));
+ File.WriteAllBytes(filename, DC.Merge(new byte[] { (byte)CertificateType.DomainPublic }, publicRawData, signature));
return true;
}
@@ -235,9 +241,9 @@ namespace Esiur.Security.Authority
public override byte[] Serialize(bool includePrivate = false)
{
if (includePrivate)
- return BinaryList.ToBytes(publicRawData, signature, privateRawData);
+ return DC.Merge(publicRawData, signature, privateRawData);
else
- return BinaryList.ToBytes(publicRawData, signature);
+ return DC.Merge(publicRawData, signature);
}
}
diff --git a/Esiur/Security/Authority/Session.cs b/Esiur/Security/Authority/Session.cs
index 29e8608..c502aeb 100644
--- a/Esiur/Security/Authority/Session.cs
+++ b/Esiur/Security/Authority/Session.cs
@@ -22,7 +22,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Net;
using Esiur.Resource;
using System;
diff --git a/Esiur/Security/Authority/UserCertificate.cs b/Esiur/Security/Authority/UserCertificate.cs
index d538bcb..6e62678 100644
--- a/Esiur/Security/Authority/UserCertificate.cs
+++ b/Esiur/Security/Authority/UserCertificate.cs
@@ -170,42 +170,45 @@ namespace Esiur.Security.Authority
var cr = new BinaryList();
//id
- cr.Append(id);
+ cr.AddUInt64(id);
// ip
this.ip = ip;
this.ip6 = ip6;
- cr.Append(ip);
+ cr.AddUInt32(ip);
if (ip6?.Length == 16)
- cr.Append(ip6);
+ cr.AddUInt8Array(ip6);
else
- cr.Append(new byte[16]);
+ cr.AddUInt8Array(new byte[16]);
// dates
this.issueDate = DateTime.UtcNow;
this.expireDate = expireDate;
- cr.Append(issueDate, expireDate);
+ cr.AddDateTime(issueDate)
+ .AddDateTime(expireDate);
// domain
this.domainId = domainCertificate.Id;
- cr.Append(domainCertificate.Id);
+ cr.AddUInt64(domainCertificate.Id);
this.domain = domainCertificate.Domain;
- cr.Append((byte)domainCertificate.Domain.Length, Encoding.ASCII.GetBytes(domainCertificate.Domain));
+ cr.AddUInt8((byte)domainCertificate.Domain.Length)
+ .AddUInt8Array(Encoding.ASCII.GetBytes(domainCertificate.Domain));
// username
this.username = username;
- cr.Append((byte)(username.Length), Encoding.ASCII.GetBytes(username));
+ cr.AddUInt8((byte)(username.Length))
+ .AddUInt8Array(Encoding.ASCII.GetBytes(username));
// hash function (SHA1)
- cr.Append((byte)((byte)hashFunction << 4));// (byte)0x10);
+ cr.AddUInt8((byte)((byte)hashFunction << 4));// (byte)0x10);
// public key
@@ -214,7 +217,10 @@ namespace Esiur.Security.Authority
// write public certificate file
var key = rsa.ExportParameters(true);
- publicRawData = BinaryList.ToBytes((byte)key.Exponent.Length, key.Exponent, (ushort)key.Modulus.Length, key.Modulus);
+ publicRawData = new BinaryList().AddUInt8((byte)key.Exponent.Length)
+ .AddUInt8Array(key.Exponent)
+ .AddUInt16((ushort)key.Modulus.Length)
+ .AddUInt8Array(key.Modulus).ToArray();
// sign it
@@ -231,9 +237,9 @@ namespace Esiur.Security.Authority
try
{
if (includePrivate)
- File.WriteAllBytes(filename, BinaryList.ToBytes((byte)CertificateType.DomainPrivate, publicRawData, signature, privateRawData));
+ File.WriteAllBytes(filename, DC.Merge(new byte[] { (byte)CertificateType.DomainPrivate }, publicRawData, signature, privateRawData));
else
- File.WriteAllBytes(filename, BinaryList.ToBytes((byte)CertificateType.DomainPublic, publicRawData, signature));
+ File.WriteAllBytes(filename, DC.Merge(new byte[] { (byte)CertificateType.DomainPublic }, publicRawData, signature));
return true;
}
@@ -246,9 +252,9 @@ namespace Esiur.Security.Authority
public override byte[] Serialize(bool includePrivate = false)
{
if (includePrivate)
- return BinaryList.ToBytes(publicRawData, signature, privateRawData);
+ return DC.Merge(publicRawData, signature, privateRawData);
else
- return BinaryList.ToBytes(publicRawData, signature);
+ return DC.Merge(publicRawData, signature);
}
}
}
diff --git a/Esiur/Security/Integrity/SHA256.cs b/Esiur/Security/Integrity/SHA256.cs
new file mode 100644
index 0000000..3e2541e
--- /dev/null
+++ b/Esiur/Security/Integrity/SHA256.cs
@@ -0,0 +1,157 @@
+using Esiur.Data;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Esiur.Security.Integrity
+{
+ public static class SHA256
+ {
+
+ static uint RROT(uint n, int d)
+ {
+ return (n >> d) | (n << (32 - d));
+ }
+
+ public static byte[] Compute(byte[] msg)
+ {
+ /*
+ Note 1: All variables are 32 bit unsigned integers and addition is calculated modulo 2^32
+ Note 2: For each round, there is one round constant k[i] and one entry in the message schedule array w[i], 0 ≤ i ≤ 63
+ Note 3: The compression function uses 8 working variables, a through h
+ Note 4: Big-endian convention is used when expressing the constants in this pseudocode,
+ and when parsing message block data from bytes to words, for example,
+ the first word of the input message "abc" after padding is 0x61626380
+ */
+
+ // Initialize hash values:
+ // (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
+
+ var hash = new uint[] { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
+
+ // Initialize array of round constants:
+ // (first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311):
+ var k = new uint[] {
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 };
+
+
+
+ // Pre-processing:
+ // begin with the original message of length L bits
+ ulong L = (ulong)msg.Length * 8;
+
+ // append a single '1' bit
+ // append K '0' bits, where K is the minimum number >= 0 such that L + 1 + K + 64 is a multiple of 512
+
+ var K = 512 - ((L + 1 + 64) % 512);
+
+ if (K == 512)
+ K = 0;
+
+ var paddingLength = (K + 1) / 8;
+ var paddingBytes = new byte[paddingLength];
+ paddingBytes[0] = 0x80;
+
+ var data = new BinaryList().AddUInt8Array(msg).AddUInt8Array(paddingBytes).AddUInt64(L).ToArray();
+
+
+
+ // append L as a 64-bit big-endian integer, making the total post-processed length a multiple of 512 bits
+
+ // Process the message in successive 512-bit chunks:
+ // break message into 512-bit chunks
+ // for each chunk
+
+ for (var chunk = 0; chunk < data.Length; chunk += 64)
+ {
+ // create a 64-entry message schedule array w[0..63] of 32-bit words
+ // (The initial values in w[0..63] don't matter, so many implementations zero them here)
+ // copy chunk into first 16 words w[0..15] of the message schedule array
+
+ var w = new uint[64];
+ for (var i = 0; i < 16; i++)
+ w[i] = data.GetUInt32((uint)(chunk + (i * 4)));
+
+ //for(var i = 16; i < 64; i++)
+ // w[i] = 0;
+
+ // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array:
+ // for i from 16 to 63
+ // s0 := (w[i-15] rightrotate 7) xor (w[i-15] rightrotate 18) xor (w[i-15] rightshift 3)
+ // s1 := (w[i-2] rightrotate 17) xor (w[i-2] rightrotate 19) xor (w[i-2] rightshift 10)
+ // w[i] := w[i-16] + s0 + w[i-7] + s1
+
+ for (var i = 16; i < 64; i++)
+ {
+ var s0 = SHA256.RROT(w[i - 15], 7) ^ SHA256.RROT(w[i - 15], 18) ^ (w[i - 15] >> 3);
+ var s1 = SHA256.RROT(w[i - 2], 17) ^ SHA256.RROT(w[i - 2], 19) ^ (w[i - 2] >> 10);
+ w[i] = w[i - 16] + s0 + w[i - 7] + s1;
+ }
+
+ // Initialize working variables to current hash value:
+ var a = hash[0];
+ var b = hash[1];
+ var c = hash[2];
+ var d = hash[3];
+ var e = hash[4];
+ var f = hash[5];
+ var g = hash[6];
+ var h = hash[7];
+
+
+ // Compression function main loop:
+ for (var i = 0; i < 64; i++)
+ {
+ var S1 = SHA256.RROT(e, 6) ^ SHA256.RROT(e, 11) ^ SHA256.RROT(e, 25);
+ var ch = (e & f) ^ ((~e) & g);
+ var temp1 = h + S1 + ch + k[i] + w[i];
+ var S0 = SHA256.RROT(a, 2) ^ SHA256.RROT(a, 13) ^ SHA256.RROT(a, 22);
+ var maj = (a & b) ^ (a & c) ^ (b & c);
+ uint temp2 = S0 + maj;
+
+ h = g;
+ g = f;
+ f = e;
+ e = (d + temp1) >> 0;
+ d = c;
+ c = b;
+ b = a;
+ a = (temp1 + temp2) >> 0;
+ }
+
+ // Add the compressed chunk to the current hash value:
+
+ hash[0] = (hash[0] + a) >> 0;
+ hash[1] = (hash[1] + b) >> 0;
+ hash[2] = (hash[2] + c) >> 0;
+ hash[3] = (hash[3] + d) >> 0;
+ hash[4] = (hash[4] + e) >> 0;
+ hash[5] = (hash[5] + f) >> 0;
+ hash[6] = (hash[6] + g) >> 0;
+ hash[7] = (hash[7] + h) >> 0;
+
+
+ }
+
+
+
+
+ // Produce the final hash value (big-endian):
+ //digest := hash := h0 append h1 append h2 append h3 append h4 append h5 append h6 append h7
+
+ var results = new BinaryList();
+ for (var i = 0; i < 8; i++)
+ results.AddUInt32(hash[i]);
+
+
+ return results.ToArray();
+ }
+ }
+}
diff --git a/Esiur/Security/Membership/IMembership.cs b/Esiur/Security/Membership/IMembership.cs
index cf2988c..c6d4799 100644
--- a/Esiur/Security/Membership/IMembership.cs
+++ b/Esiur/Security/Membership/IMembership.cs
@@ -29,7 +29,7 @@ using System.Text;
using System.Threading.Tasks;
using Esiur.Data;
using Esiur.Net.IIP;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Security.Authority;
using Esiur.Resource;
diff --git a/Esiur/Security/Membership/IUser.cs b/Esiur/Security/Membership/IUser.cs
index 11f7cd2..e354baf 100644
--- a/Esiur/Security/Membership/IUser.cs
+++ b/Esiur/Security/Membership/IUser.cs
@@ -22,7 +22,7 @@ SOFTWARE.
*/
-using Esiur.Engine;
+using Esiur.Core;
using System;
using System.Collections.Generic;
using System.Linq;
diff --git a/Esiur/Security/Permissions/IPermissionsManager.cs b/Esiur/Security/Permissions/IPermissionsManager.cs
index 9e94fea..fca2d65 100644
--- a/Esiur/Security/Permissions/IPermissionsManager.cs
+++ b/Esiur/Security/Permissions/IPermissionsManager.cs
@@ -23,7 +23,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Net;
using Esiur.Resource;
using Esiur.Resource.Template;
diff --git a/Esiur/Security/Permissions/ParentalPermissionsManager.cs b/Esiur/Security/Permissions/ParentalPermissionsManager.cs
index dff3bde..fb878d6 100644
--- a/Esiur/Security/Permissions/ParentalPermissionsManager.cs
+++ b/Esiur/Security/Permissions/ParentalPermissionsManager.cs
@@ -26,7 +26,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Resource;
using Esiur.Resource.Template;
using Esiur.Security.Authority;
diff --git a/Esiur/Security/Permissions/UserPermissionsManager.cs b/Esiur/Security/Permissions/UserPermissionsManager.cs
index c2f58d5..e318bb0 100644
--- a/Esiur/Security/Permissions/UserPermissionsManager.cs
+++ b/Esiur/Security/Permissions/UserPermissionsManager.cs
@@ -26,7 +26,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Resource;
using Esiur.Resource.Template;
using Esiur.Security.Authority;
diff --git a/Esiur/Stores/MemoryStore.cs b/Esiur/Stores/MemoryStore.cs
index 30a2ea7..f80d048 100644
--- a/Esiur/Stores/MemoryStore.cs
+++ b/Esiur/Stores/MemoryStore.cs
@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Data;
using Esiur.Resource.Template;
diff --git a/Test/MyMembership.cs b/Test/MyMembership.cs
index 0a72bd5..2c78096 100644
--- a/Test/MyMembership.cs
+++ b/Test/MyMembership.cs
@@ -1,5 +1,5 @@
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Resource;
using Esiur.Security.Authority;
using Esiur.Security.Membership;
diff --git a/Test/MyObject.cs b/Test/MyObject.cs
index 1317bb7..9e6f44d 100644
--- a/Test/MyObject.cs
+++ b/Test/MyObject.cs
@@ -1,5 +1,5 @@
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Net.IIP;
using Esiur.Resource;
using System;
@@ -29,9 +29,9 @@ namespace Test
[ResourceFunction]
- public int Add(int value)
+ public int Add(int? value)
{
- Level += value;
+ Level += (int)value;
LevelUp?.Invoke(null, "going up", value);
return Level;
}
diff --git a/Test/Program.cs b/Test/Program.cs
index b5d70c7..2b53bf6 100644
--- a/Test/Program.cs
+++ b/Test/Program.cs
@@ -23,7 +23,7 @@ SOFTWARE.
*/
using Esiur.Data;
-using Esiur.Engine;
+using Esiur.Core;
using Esiur.Net.HTTP;
using Esiur.Net.IIP;
using Esiur.Net.Sockets;
@@ -35,61 +35,29 @@ using System;
using System.Threading;
using System.Threading.Tasks;
+using Esiur.Security.Integrity;
+using System.Linq;
+
namespace Test
{
class Program
{
- static MyObject myObject;
- static DistributedResource remoteObject;
-
+ static MyObject localObject;
+ static IResource remoteObject;
+
static async Task Main(string[] args)
{
-
- //AsyncContext.Run(() => ());
+
+ Warehouse.Protocols.Add("iip", () => new DistributedConnection());
// Create stores to keep objects.
var system = Warehouse.New("system");
var remote = Warehouse.New("remote");
var mongo = Warehouse.New("db");
- /*
- var system = await Warehouse.Get("mem://system").Task;
- var remote = await Warehouse.Get("mem://remote").Task;
- var mongo = await Warehouse.Get("mongo://db").Task;
- var iip = await Warehouse.Get("iip://:5000").Task;
- var iws = await Warehouse.Get("iipows://:5001", new Structure() { ["iip"] = iip }).Task;
- */
-
- var ok = await Warehouse.Open();
-
-
- // Open the warehouse
-
-
- // Create new object if the store is empty
- if (mongo.Count == 0)
- myObject = Warehouse.New("my", mongo, null,
- new UserPermissionsManager(new Structure()
- {
- ["demo@localhost"] = new Structure()
- {
- ["Subtract"] = new Structure { ["Execute"] = "yes" },
- ["Stream"] = new Structure { ["Execute"] = "yes" },
- ["_attach"] = "yes",
- ["_get_attributes"] = "yes",
- ["_set_attributes"] = "yes",
- }
- }));
- else
- myObject =(MyObject) (await Warehouse.Get("db/my"));//.Then((o) => { myObject = (MyObject)o; });
-
-
- //var obj = ProxyObject.();
- //Warehouse.Put(obj, "dd", system);
- //obj.Level2= 33;
// Create new distributed server object
var iip = Warehouse.New("iip", system);
@@ -108,6 +76,44 @@ namespace Test
wsOverHttp.DistributedServer = iip;
+
+ /*
+ var system = await Warehouse.Get("mem://system").Task;
+ var remote = await Warehouse.Get("mem://remote").Task;
+ var mongo = await Warehouse.Get("mongo://db").Task;
+ var iip = await Warehouse.Get("iip://:5000").Task;
+ var iws = await Warehouse.Get("iipows://:5001", new Structure() { ["iip"] = iip }).Task;
+ */
+
+ var ok = await Warehouse.Open();
+
+
+ // Open the warehouse
+
+
+ // Create new object if the store is empty
+ if (mongo.Count == 0)
+ localObject = Warehouse.New("my", mongo, null,
+ new UserPermissionsManager(new Structure()
+ {
+ ["demo@localhost"] = new Structure()
+ {
+ ["Subtract"] = new Structure { ["Execute"] = "yes" },
+ ["Stream"] = new Structure { ["Execute"] = "yes" },
+ ["_attach"] = "yes",
+ ["_get_attributes"] = "yes",
+ ["_set_attributes"] = "yes",
+ }
+ }));
+ else
+ localObject = (MyObject)(await Warehouse.Get("db/my"));//.Then((o) => { myObject = (MyObject)o; });
+
+
+ //var obj = ProxyObject.();
+ //Warehouse.Put(obj, "dd", system);
+ //obj.Level2= 33;
+
+
Warehouse.StoreConnected += (store, name) =>
{
if (store.Instance.Parents.Contains(iip))
@@ -124,7 +130,7 @@ namespace Test
};
// Start testing
- // TestClient();
+ TestClient();
var running = true;
@@ -143,83 +149,63 @@ namespace Test
});
else
{
- myObject.Level = 88;
- Console.WriteLine(myObject.Name + " " + myObject.Level );
+ localObject.Level = 88;
+ Console.WriteLine(localObject.Name + " " + localObject.Level);
}
}
}
- private static void TestClient()
+ private static async void TestClient()
{
- //return;
- // Create a new client
- var client = new DistributedConnection(new TCPSocket("localhost", 5000), "localhost", "demo", "1234");
- // Put the client in our memory store
- var remote = Warehouse.GetStore("remote");
- Warehouse.Put(client, "Endpoint", remote);
+ remoteObject = await Warehouse.Get("iip://localhost:5000/db/my", new Structure() { ["username"] = "demo", ["password"] = "1234" });
+ dynamic x = remoteObject;
- client.OnReady += async (c) =>
+
+ Console.WriteLine("My Name is: " + x.Name);
+ x.Name = "Hamoo";
+ x.LevelUp += new DistributedResourceEvent((sender, parameters) =>
{
- // Get remote object from the server.
- //remoteObject = await client.Get("db/my").Task as DistributedResource;
+ Console.WriteLine("LevelUp " + parameters[0] + " " + parameters[1]);
+ });
- dynamic x = remoteObject;
+ x.LevelDown += new DistributedResourceEvent((sender, parameters) =>
+ {
+ Console.WriteLine("LevelUp " + parameters[0] + " " + parameters[1]);
+ });
- Console.WriteLine("My Name is: " + x.Name);
- x.Name = "Hamoo";
- x.LevelUp += new DistributedResourceEvent((sender, parameters) =>
- {
- Console.WriteLine("LevelUp " + parameters[0] + " " + parameters[1]);
- });
+
+ (x.Stream(10) as AsyncReply).Then(r =>
+ {
+ Console.WriteLine("Stream ended: " + r);
+ }).Chunk(r =>
+ {
+ Console.WriteLine("Chunk..." + r);
+ }).Progress((t, v, m) => Console.WriteLine("Processing {0}/{1}", v, m));
- x.LevelDown += new DistributedResourceEvent((sender, parameters) =>
- {
- Console.WriteLine("LevelUp " + parameters[0] + " " + parameters[1]);
- });
+ var rt = await x.Subtract(10);
- (x.Stream(10) as AsyncReply).Then(r =>
- {
- Console.WriteLine("Stream ended: " + r);
- }).Chunk(r =>
- {
- Console.WriteLine("Chunk..." + r);
- }).Progress((t, v, m) => Console.WriteLine("Processing {0}/{1}", v, m));
- var rt = await x.Subtract(10).Task;
+ Console.WriteLine(rt);
+ // Getting object record
+ (remoteObject.Instance.Store as DistributedConnection).GetRecord(remoteObject, DateTime.Now - TimeSpan.FromDays(1), DateTime.Now).Then(record =>
+ {
+ Console.WriteLine("Records received: " + record.Count);
+ });
- //var rt2 = await x.Add(10).Task;
+ //var timer = new Timer(T_Elapsed, null, 5000, 5000);
+
- Console.WriteLine(rt);
- /*
- (x.Subtract(10) as AsyncReply).Then((r) =>
- {
- Console.WriteLine("Subtracted: " + r + " " + x.Level);
- }).Error((ex) =>
- {
- Console.WriteLine("Exception " + ex.Code + " " + ex.Message);
- });
-
- // Getting object record
- client.GetRecord(remoteObject, DateTime.Now - TimeSpan.FromDays(1), DateTime.Now).Then(record =>
- {
- Console.WriteLine("Records received: " + record.Count);
- });
-
- var t = new Timer(T_Elapsed, null, 5000, 5000);
- */
- };
}
private static void T_Elapsed(object state)
{
- myObject.Level++;
+ localObject.Level++;
dynamic o = remoteObject;
- Console.WriteLine(myObject.Level + " " + o.Level + o.Me.Me.Level);
- Console.WriteLine(o.Info.ToString());
+ Console.WriteLine(localObject.Level + " " + o.Level + o.Me.Me.Level);
}
}
}