diff --git a/Esiur/Core/ExceptionCode.cs b/Esiur/Core/ExceptionCode.cs
index a54e75a..05314c1 100644
--- a/Esiur/Core/ExceptionCode.cs
+++ b/Esiur/Core/ExceptionCode.cs
@@ -6,6 +6,7 @@ namespace Esiur.Core;
public enum ExceptionCode : ushort
{
+ RuntimeException,
HostNotReachable,
AccessDenied,
UserOrTokenNotFound,
diff --git a/Esiur/Data/Codec.cs b/Esiur/Data/Codec.cs
index 3f8f9d5..7033bba 100644
--- a/Esiur/Data/Codec.cs
+++ b/Esiur/Data/Codec.cs
@@ -154,7 +154,7 @@ public static class Codec
public static bool IsLocalResource(IResource resource, DistributedConnection connection)
{
if (resource is DistributedResource)
- if ((resource as DistributedResource).Connection == connection)
+ if ((resource as DistributedResource).DistributedResourceConnection == connection)
return true;
return false;
diff --git a/Esiur/Data/DataSerializer.cs b/Esiur/Data/DataSerializer.cs
index 31ef2eb..754c6ce 100644
--- a/Esiur/Data/DataSerializer.cs
+++ b/Esiur/Data/DataSerializer.cs
@@ -321,7 +321,7 @@ public static class DataSerializer
{
fixed (byte* ptr = rt)
- *((uint*)ptr) = (resource as DistributedResource).Id;
+ *((uint*)ptr) = (resource as DistributedResource).DistributedResourceInstanceId;
return (TransmissionTypeIdentifier.ResourceLocal, rt);
}
diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj
index ea10c02..c6ceb7b 100644
--- a/Esiur/Esiur.csproj
+++ b/Esiur/Esiur.csproj
@@ -6,7 +6,7 @@
Ahmed Kh. Zamil
http://www.esiur.com
true
- 2.3.1
+ 2.3.4
https://github.com/esiur/esiur-dotnet
Ahmed Kh. Zamil
diff --git a/Esiur/Misc/Global.cs b/Esiur/Misc/Global.cs
index f3c35f3..05053ae 100644
--- a/Esiur/Misc/Global.cs
+++ b/Esiur/Misc/Global.cs
@@ -46,12 +46,10 @@ namespace Esiur.Misc;
public static class Global
{
private static KeyList variables = new KeyList();
- // private static Hashtable m_Cached = new Hashtable();
- //internal static bool SystemIsWorking = false;
- private static Random rand = new Random(System.Environment.TickCount);
+ private static Random rand = new Random();// System.Environment.TickCount);
+
- //public static Encoding DefaultEncoding = Encoding.GetEncoding(1252);// .GetEncoding("windows-1252");
public static KeyList Counters = new KeyList();
@@ -68,7 +66,7 @@ public static class Global
}
catch (Exception ex)
{
- Console.WriteLine(ex.ToString());
+ Log(ex);
return "{}";
}
}
@@ -86,18 +84,8 @@ public static class Global
- public static string Version { get; } = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
+ public static string Version { get; } = typeof(Global).Assembly.GetName().Version.ToString(); //FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
- //FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
- // string version = fvi.FileVersion;
-
-
- /*
- public static char GetDirectorySeparator()
- {
- return System.IO.Path.DirectorySeparatorChar;
- }
- */
public static void Log(Exception ex, params object[] arguments)
{
@@ -147,12 +135,7 @@ public static class Global
SystemLog?.Invoke(service, type, message);
}
- /*
- public static string GetTempPath()
- {
- return System.IO.Path.GetTempPath();
- }
- */
+
public static string RemoveControlCharacters(string inString)
{
@@ -184,49 +167,9 @@ public static class Global
Console.WriteLine(k + ":" + Counters[k]);
}
}
- // Encoding ANSI = Encoding.GetEncoding(1252);
+
- /*
-public static Hashtable Cached
-{
- get
- {
- return m_Cached;
- }
-}*/
-
- /*
- public static string ByteArrayToMAC(byte[] array)
- {
- string rt="";
-
- if (array == null)
- return "00:00:00:00:00:00";
- else
- {
- //for (int i = 0; i < array.Length - 1; i++)
- // rt += Convert.ToString(array[i], 16) + ":";
-
- //rt += Convert.ToString(array[array.Length - 1], 16);
-
- rt = BitConverter.ToString(array);
- rt = rt.Replace('-', ':');
- return rt;
- }
-
- }
- */
-
-
-
- /*
- public static string IPAddressFromInt32(UInt32 IP)
- {
- //var dIP = DC.ToBytes(IP);
-
- return (IP >> 24) + "." + ((IP >> 16) & 0xFF) + "." + ((IP >> 8) & 0xFF) + "." + (IP & 0xFF);
- }
- */
+
public static KeyList Variables
{
@@ -356,66 +299,9 @@ public static Hashtable Cached
}
}
- public static string GetUserPart(string strAddress)
- {
- return strAddress.Substring(0, strAddress.IndexOf("@", 0));
- }
-
- public static byte[][] GetBytesFromChunk(byte[] Data, int ChunkSize)
- {
- if (ChunkSize == 1)
- {
- byte[][] ar = new byte[0][];
- int ptr = 0;
- while (ptr < Data.Length)
- {
- Array.Resize(ref ar, ar.Length + 1);
- ar[ar.Length - 1] = new byte[Data[ptr]];
- Buffer.BlockCopy(Data, ++ptr, ar[ar.Length - 1], 0, Data[ptr]);
- ptr += Data[ptr] + 1;
- }
- return ar;
- }
- return null;
- }
-
-
-
-
-
- public static string GetFileTitle(string Filename)
- {
- string[] s = Filename.Split(Path.DirectorySeparatorChar);
- return s[s.Length - 1];
- }
-
- public static string GetNewFileName(string FileDir)
- {
- string tempGetNewFileName = null;
- short i = 0;
- string NewFile = null;
- NewFile = FileDir;
- Begin:
- FileInfo FF = new FileInfo(NewFile);
- if (FF.Exists)
- {
- //If FSO.FileExists(NewFile) Then
- i++; //= i + 1;
- NewFile = FileDir.Substring(0, FileDir.Length - 4) + "_" + i + "." + FileDir.Substring(FileDir.Length - 3);
- goto Begin;
- }
- else
- {
- tempGetNewFileName = NewFile;
- }
- return tempGetNewFileName;
- }
+
/////////////////////////////////////
- public static string TrimEx(string strIn)
- {
- return strIn.Replace("\r", "").Replace("\n", "");
- }
/*
public static bool IsUnix()
@@ -442,48 +328,18 @@ public static Hashtable Cached
public static string GenerateCode(int length)
{
- return GenerateCode(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");// ~!@#$%^&*()_-+=\\?/");
+ return GenerateCode(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
}
public static string GenerateCode(int length, string chars)
- //public static string GenerateCode(int Length)
{
- //var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_-+=\\?/";
var result = new string(
Enumerable.Repeat(chars, length)
.Select(s => s[rand.Next(s.Length)])
.ToArray());
- //if (result.Length < length)
- // Console.WriteLine();
- return result;
- /*
- int len = 0;
- string code = "";
-
- while(len < Length)
- {
- var c = Convert.ToChar((byte)(rand.NextDouble() * 255));
- if (Char.IsLetterOrDigit(c))
- {
- code += c;
- len++;
- }
- }
-
- return code;
- */
- }
-
- public static string ReplaceOnce(string Expression, string Find, string Replacement)
- {
- int pos = Expression.IndexOf(Find);
- if (pos != -1)
- return Expression.Substring(0, pos) + Replacement + Expression.Substring(pos + Find.Length);
- else
- return Expression;
- }
-
-
+ return result;
+ }
+
public static Regex GetRouteRegex(string url)
{
@@ -511,9 +367,5 @@ public static Hashtable Cached
return new Regex("^" + Regex.Escape(url) + "$");
}
}
-
- //public void Replace(string Expression, string Find, string Replacement, int Start, int Count)
- //{
- // Expression.IndexOf(
- //}
+
}
diff --git a/Esiur/Net/IIP/DistributedConnection.cs b/Esiur/Net/IIP/DistributedConnection.cs
index b2ca850..ac15763 100644
--- a/Esiur/Net/IIP/DistributedConnection.cs
+++ b/Esiur/Net/IIP/DistributedConnection.cs
@@ -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 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(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;
}
}
diff --git a/Esiur/Net/IIP/DistributedConnectionProtocol.cs b/Esiur/Net/IIP/DistributedConnectionProtocol.cs
index 7421151..8ea6f27 100644
--- a/Esiur/Net/IIP/DistributedConnectionProtocol.cs
+++ b/Esiur/Net/IIP/DistributedConnectionProtocol.cs
@@ -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>(null);
var reply = new AsyncReply>();
SendRequest(IIPPacket.IIPPacketAction.ResourceHistory)
- .AddUInt32(dr.Id)
+ .AddUInt32(dr.DistributedResourceInstanceId)
.AddDateTime(fromDate)
.AddDateTime(toDate)
.Done()
diff --git a/Esiur/Net/IIP/DistributedResource.cs b/Esiur/Net/IIP/DistributedResource.cs
index 32adb86..5263201 100644
--- a/Esiur/Net/IIP/DistributedResource.cs
+++ b/Esiur/Net/IIP/DistributedResource.cs
@@ -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
{
///
/// Raised when the distributed resource is destroyed.
///
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
//}
-
+
///
/// Connection responsible for the distributed resource.
///
- public DistributedConnection Connection
+ public DistributedConnection DistributedResourceConnection
{
get { return connection; }
}
@@ -97,7 +98,7 @@ public class DistributedResource : DynamicObject, IResource
///
/// Resource link
///
- public string Link
+ public string DistributedResourceLink
{
get { return link; }
}
@@ -105,7 +106,7 @@ public class DistributedResource : DynamicObject, IResource
///
/// Instance Id given by the other end.
///
- public uint Id
+ public uint DistributedResourceInstanceId
{
get { return instanceId; }
internal set { instanceId = value; }
@@ -136,9 +137,9 @@ public class DistributedResource : DynamicObject, IResource
///
/// Resource is attached when all its properties are received.
///
- 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