mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
MAUI Support
This commit is contained in:
@ -321,7 +321,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
{
|
||||
var r = resource as DistributedResource;
|
||||
if (r.Instance.Store == this)
|
||||
return this.Instance.Name + "/" + r.Id;
|
||||
return this.Instance.Name + "/" + r.DistributedResourceInstanceId;
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -1362,9 +1362,9 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
foreach (var r in toBeRestored)
|
||||
{
|
||||
|
||||
var link = DC.ToBytes(r.Link);
|
||||
var link = DC.ToBytes(r.DistributedResourceLink);
|
||||
|
||||
Console.WriteLine("Restoreing " + r.Link);
|
||||
Console.WriteLine("Restoreing " + r.DistributedResourceLink);
|
||||
|
||||
try
|
||||
{
|
||||
@ -1380,8 +1380,8 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
{
|
||||
// parse them as int
|
||||
var id = data.GetUInt32(8, Endian.Little);
|
||||
if (id != r.Id)
|
||||
r.Id = id;
|
||||
if (id != r.DistributedResourceInstanceId)
|
||||
r.DistributedResourceInstanceId = id;
|
||||
|
||||
neededResources[id] = r;
|
||||
suspendedResources.Remove(id);
|
||||
@ -1426,7 +1426,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
public AsyncReply<bool> Put(IResource resource)
|
||||
{
|
||||
if (Codec.IsLocalResource(resource, this))
|
||||
neededResources.Add((resource as DistributedResource).Id, (DistributedResource)resource);
|
||||
neededResources.Add((resource as DistributedResource).DistributedResourceInstanceId, (DistributedResource)resource);
|
||||
// else ... send it to the peer
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
@ -1550,7 +1550,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
if (x.TryGetTarget(out r))
|
||||
{
|
||||
r.Suspend();
|
||||
suspendedResources[r.Id] = x;
|
||||
suspendedResources[r.DistributedResourceInstanceId] = x;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -638,8 +638,8 @@ partial class DistributedConnection
|
||||
public bool RemoveChild(IResource parent, IResource child)
|
||||
{
|
||||
SendEvent(IIPPacket.IIPPacketEvent.ChildRemoved)
|
||||
.AddUInt32((parent as DistributedResource).Id)
|
||||
.AddUInt32((child as DistributedResource).Id)
|
||||
.AddUInt32((parent as DistributedResource).DistributedResourceInstanceId)
|
||||
.AddUInt32((child as DistributedResource).DistributedResourceInstanceId)
|
||||
.Done();
|
||||
|
||||
return true;
|
||||
@ -648,8 +648,8 @@ partial class DistributedConnection
|
||||
public bool AddChild(IResource parent, IResource child)
|
||||
{
|
||||
SendEvent(IIPPacket.IIPPacketEvent.ChildAdded)
|
||||
.AddUInt32((parent as DistributedResource).Id)
|
||||
.AddUInt32((child as DistributedResource).Id)
|
||||
.AddUInt32((parent as DistributedResource).DistributedResourceInstanceId)
|
||||
.AddUInt32((child as DistributedResource).DistributedResourceInstanceId)
|
||||
.Done();
|
||||
|
||||
return true;
|
||||
@ -2228,7 +2228,7 @@ partial class DistributedConnection
|
||||
else
|
||||
return request;
|
||||
}
|
||||
else if (resource != null && !resource.Suspended)
|
||||
else if (resource != null && !resource.DistributedResourceSuspended)
|
||||
{
|
||||
// @REVIEW: this should never happen
|
||||
Global.Log("DCON", LogType.Error, "Resource not moved to attached.");
|
||||
@ -2496,13 +2496,13 @@ partial class DistributedConnection
|
||||
{
|
||||
var dr = resource as DistributedResource;
|
||||
|
||||
if (dr.Connection != this)
|
||||
if (dr.DistributedResourceConnection != this)
|
||||
return new AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>>(null);
|
||||
|
||||
var reply = new AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>>();
|
||||
|
||||
SendRequest(IIPPacket.IIPPacketAction.ResourceHistory)
|
||||
.AddUInt32(dr.Id)
|
||||
.AddUInt32(dr.DistributedResourceInstanceId)
|
||||
.AddDateTime(fromDate)
|
||||
.AddDateTime(toDate)
|
||||
.Done()
|
||||
|
@ -45,14 +45,15 @@ using Esiur.Resource.Template;
|
||||
namespace Esiur.Net.IIP;
|
||||
|
||||
//[System.Runtime.InteropServices.ComVisible(true)]
|
||||
public class DistributedResource : DynamicObject, IResource
|
||||
public class DistributedResource : DynamicObject, IResource, INotifyPropertyChanged
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Raised when the distributed resource is destroyed.
|
||||
/// </summary>
|
||||
public event DestroyedEvent OnDestroy;
|
||||
public event PropertyModifiedEvent PropertyModified;
|
||||
//public event PropertyModifiedEvent PropertyModified;
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
uint instanceId;
|
||||
DistributedConnection connection;
|
||||
@ -84,12 +85,12 @@ public class DistributedResource : DynamicObject, IResource
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Connection responsible for the distributed resource.
|
||||
/// </summary>
|
||||
public DistributedConnection Connection
|
||||
public DistributedConnection DistributedResourceConnection
|
||||
{
|
||||
get { return connection; }
|
||||
}
|
||||
@ -97,7 +98,7 @@ public class DistributedResource : DynamicObject, IResource
|
||||
/// <summary>
|
||||
/// Resource link
|
||||
/// </summary>
|
||||
public string Link
|
||||
public string DistributedResourceLink
|
||||
{
|
||||
get { return link; }
|
||||
}
|
||||
@ -105,7 +106,7 @@ public class DistributedResource : DynamicObject, IResource
|
||||
/// <summary>
|
||||
/// Instance Id given by the other end.
|
||||
/// </summary>
|
||||
public uint Id
|
||||
public uint DistributedResourceInstanceId
|
||||
{
|
||||
get { return instanceId; }
|
||||
internal set { instanceId = value; }
|
||||
@ -136,9 +137,9 @@ public class DistributedResource : DynamicObject, IResource
|
||||
/// <summary>
|
||||
/// Resource is attached when all its properties are received.
|
||||
/// </summary>
|
||||
internal bool Attached => attached;
|
||||
public bool DistributedResourceAttached => attached;
|
||||
|
||||
internal bool Suspended => suspended;
|
||||
public bool DistributedResourceSuspended => suspended;
|
||||
|
||||
|
||||
// public DistributedResourceStack Stack
|
||||
@ -292,7 +293,7 @@ public class DistributedResource : DynamicObject, IResource
|
||||
var ft = Instance.Template.GetFunctionTemplateByName(binder.Name);
|
||||
|
||||
var reply = new AsyncReply<object>();
|
||||
|
||||
|
||||
if (attached && ft != null)
|
||||
{
|
||||
var indexedArgs = new Map<byte, object>();
|
||||
@ -315,7 +316,7 @@ public class DistributedResource : DynamicObject, IResource
|
||||
indexedArgs.Add(i, pi.GetValue(args[0]));
|
||||
}
|
||||
|
||||
result =_Invoke(ft.Index, indexedArgs);
|
||||
result = _Invoke(ft.Index, indexedArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -403,6 +404,33 @@ public class DistributedResource : DynamicObject, IResource
|
||||
Instance.EmitModification(pt, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set property value.
|
||||
/// </summary>
|
||||
/// <param name="index">Zero-based property index.</param>
|
||||
/// <param name="value">Value</param>
|
||||
/// <returns>Indicator when the property is set.</returns>
|
||||
protected object _SetSync(byte index, object value)
|
||||
{
|
||||
if (destroyed)
|
||||
throw new Exception("Trying to access a destroyed object.");
|
||||
|
||||
if (suspended)
|
||||
throw new Exception("Trying to access a suspended object.");
|
||||
|
||||
if (!attached)
|
||||
return null;
|
||||
|
||||
if (index >= properties.Length)
|
||||
return null;
|
||||
|
||||
// Don't set the same current value
|
||||
if (properties[index] == value)
|
||||
return value;
|
||||
|
||||
return _Set(index, value).Wait();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set property value.
|
||||
/// </summary>
|
||||
@ -411,6 +439,15 @@ public class DistributedResource : DynamicObject, IResource
|
||||
/// <returns>Indicator when the property is set.</returns>
|
||||
protected internal AsyncReply<object> _Set(byte index, object value)
|
||||
{
|
||||
if (destroyed)
|
||||
throw new Exception("Trying to access a destroyed object.");
|
||||
|
||||
if (suspended)
|
||||
throw new Exception("Trying to access a suspended object.");
|
||||
|
||||
if (!attached)
|
||||
return null;
|
||||
|
||||
if (index >= properties.Length)
|
||||
return null;
|
||||
|
||||
@ -424,16 +461,15 @@ public class DistributedResource : DynamicObject, IResource
|
||||
.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;
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
public override bool TrySetMember(SetMemberBinder binder, object value)
|
||||
{
|
||||
if (destroyed)
|
||||
@ -521,12 +557,19 @@ public class DistributedResource : DynamicObject, IResource
|
||||
{
|
||||
|
||||
if (trigger == ResourceTrigger.Initialize)
|
||||
this.Instance.PropertyModified += this.PropertyModified;
|
||||
|
||||
{
|
||||
this.Instance.PropertyModified += (x) =>
|
||||
this.PropertyChanged?.Invoke(this, new ResourcePropertyChangedEventArgs(x.Name));
|
||||
}
|
||||
// do nothing.
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
|
||||
protected virtual void EmitPropertyChanged(string name)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
||||
}
|
||||
|
||||
~DistributedResource()
|
||||
{
|
||||
Destroy();
|
||||
|
23
Esiur/Net/IIP/ResourcePropertyChangedEventArgs.cs
Normal file
23
Esiur/Net/IIP/ResourcePropertyChangedEventArgs.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Esiur.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.IIP
|
||||
{
|
||||
public class ResourcePropertyChangedEventArgs : PropertyChangedEventArgs
|
||||
{
|
||||
public ResourcePropertyChangedEventArgs(string propertyName) : base(propertyName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ResourcePropertyChangedEventArgs(PropertyModificationInfo info) : base(info.Name)
|
||||
{
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public readonly PropertyModificationInfo Info;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user