2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00

Blazor support

This commit is contained in:
2022-08-30 22:28:19 +03:00
parent 4cc0657869
commit 216b891bf8
12 changed files with 282 additions and 187 deletions

View File

@ -42,6 +42,7 @@ using static Esiur.Net.Packets.IIPPacket;
using Esiur.Net.HTTP;
using System.Timers;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace Esiur.Net.IIP;
public partial class DistributedConnection : NetworkConnection, IStore
@ -1005,7 +1006,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
var r = new Random();
session.Id = new byte[32];
r.NextBytes(session.Id);
SendParams().AddUInt8(0x28)
.AddUInt8Array(session.Id)
.Done();
@ -1227,6 +1228,12 @@ public partial class DistributedConnection : NetworkConnection, IStore
[Attribute]
public string Username { get; set; }
[Attribute]
public bool UseWebSocket { get; set; }
[Attribute]
public bool SecureWebSocket { get; set; }
[Attribute]
public string Password { get; set; }
@ -1308,7 +1315,13 @@ public partial class DistributedConnection : NetworkConnection, IStore
throw new AsyncException(ErrorType.Exception, 0, "Session not initialized");
if (socket == null)
socket = new TCPSocket();
{
var os = RuntimeInformation.FrameworkDescription;
if (UseWebSocket || RuntimeInformation.OSDescription == "Browser")
socket = new ClientWSocket();
else
socket = new TCPSocket();
}
if (port > 0)
this._port = port;
@ -1378,16 +1391,22 @@ public partial class DistributedConnection : NetworkConnection, IStore
if (dataType.Identifier == TransmissionTypeIdentifier.ResourceList)
{
// remove from suspended.
suspendedResources.Remove(r.DistributedResourceInstanceId);
// parse them as int
var id = data.GetUInt32(8, Endian.Little);
// id changed ?
if (id != r.DistributedResourceInstanceId)
r.DistributedResourceInstanceId = id;
neededResources[id] = r;
suspendedResources.Remove(id);
await Fetch(id, null);
Console.WriteLine("Restored " + id);
}
}
catch (AsyncException ex)
@ -1398,6 +1417,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
}
else
{
Global.Log(ex);
break;
}
}

View File

@ -1798,6 +1798,10 @@ partial class DistributedConnection
void IIPRequestSetProperty(uint callback, uint resourceId, byte index, TransmissionType transmissionType, byte[] content)
{
// un hold the socket to send data immediately
this.Socket.Unhold();
Warehouse.GetById(resourceId).Then((r) =>
{
if (r != null)
@ -1863,6 +1867,7 @@ partial class DistributedConnection
try
{
pi.SetValue(r, value);
SendReply(IIPPacket.IIPPacketAction.SetProperty, callback).Done();
}

View File

@ -412,6 +412,8 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
/// <returns>Indicator when the property is set.</returns>
protected object _SetSync(byte index, object value)
{
Console.WriteLine("Setting..." + index + " " + value);
if (destroyed)
throw new Exception("Trying to access a destroyed object.");
@ -428,7 +430,10 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
if (properties[index] == value)
return value;
return _Set(index, value).Wait();
var rt = _Set(index, value).Wait();
Console.WriteLine("Done Setting");
return rt;
}
/// <summary>