diff --git a/Esyur.Stores.MongoDB/MongoDBStore.cs b/Esyur.Stores.MongoDB/MongoDBStore.cs index 2f72f1f..8aa940a 100644 --- a/Esyur.Stores.MongoDB/MongoDBStore.cs +++ b/Esyur.Stores.MongoDB/MongoDBStore.cs @@ -25,7 +25,6 @@ namespace Esyur.Stores.MongoDB IMongoCollection resourcesCollection; - Dictionary resources = new Dictionary(); @@ -35,12 +34,16 @@ namespace Esyur.Stores.MongoDB [ResourceEvent] public event ResourceEventHanlder ResourceRemoved; + int count = 0; + [ResourceProperty] public virtual int Count { get { - return (int)resourcesCollection.CountDocuments(x => true); + return count; + + //return (int)resourcesCollection.Count(x => true); } } @@ -85,8 +88,11 @@ namespace Esyur.Stores.MongoDB this.database.DropCollection("record_" + objectId); resourcesCollection.DeleteOne(filter); + count--; + ResourceRemoved?.Invoke(resource); + Instance.Modified("Count"); return true; @@ -317,6 +323,8 @@ namespace Esyur.Stores.MongoDB ResourceAdded?.Invoke(resource); + count++; + Instance.Modified("Count"); return true; @@ -543,6 +551,10 @@ namespace Esyur.Stores.MongoDB resourcesCollection = this.database.GetCollection(collectionName); + + count = (int)resourcesCollection.CountDocuments(x => true); + + // return new AsyncReply(true); diff --git a/Esyur/Data/DataConverter.cs b/Esyur/Data/DataConverter.cs index 3803e63..6a4b23f 100644 --- a/Esyur/Data/DataConverter.cs +++ b/Esyur/Data/DataConverter.cs @@ -640,7 +640,7 @@ namespace Esyur.Data public static sbyte[] GetInt8Array(this byte[] data, uint offset, uint length) { var rt = new sbyte[length]; - Buffer.BlockCopy(rt, (int)offset, rt, 0, (int)length); + Buffer.BlockCopy(data, (int)offset, rt, 0, (int)length); return rt; } @@ -652,7 +652,7 @@ namespace Esyur.Data public static byte[] GetUInt8Array(this byte[] data, uint offset, uint length) { var rt = new byte[length]; - Buffer.BlockCopy(rt, (int)offset, rt, 0, (int)length); + Buffer.BlockCopy(data, (int)offset, rt, 0, (int)length); return rt; } diff --git a/Esyur/Data/DataType.cs b/Esyur/Data/DataType.cs index e79739e..9be1abf 100644 --- a/Esyur/Data/DataType.cs +++ b/Esyur/Data/DataType.cs @@ -57,8 +57,8 @@ namespace Esyur.Data //Array = 0x80, VarArray = 0x80, BoolArray, - UInt8Array, Int8Array, + UInt8Array, CharArray, Int16Array, UInt16Array, diff --git a/Esyur/Data/KeyList.cs b/Esyur/Data/KeyList.cs index 655bdcd..2229927 100644 --- a/Esyur/Data/KeyList.cs +++ b/Esyur/Data/KeyList.cs @@ -36,7 +36,7 @@ using Esyur.Core; namespace Esyur.Data { - public class KeyList : IEnumerable + public class KeyList : IEnumerable> { private readonly object syncRoot = new object(); private Dictionary dic; @@ -144,11 +144,18 @@ namespace Esyur.Data } } - public IEnumerator GetEnumerator() + + public IEnumerator> GetEnumerator() { return dic.GetEnumerator(); } + IEnumerator IEnumerable.GetEnumerator() + { + return dic.GetEnumerator(); + } + + public void Clear() { if (removableList) diff --git a/Esyur/Esyur.csproj b/Esyur/Esyur.csproj index b9b0552..6afb314 100644 --- a/Esyur/Esyur.csproj +++ b/Esyur/Esyur.csproj @@ -34,6 +34,7 @@ + diff --git a/Esyur/Net/IIP/DistributedConnectionProtocol.cs b/Esyur/Net/IIP/DistributedConnectionProtocol.cs index 42486f7..a543178 100644 --- a/Esyur/Net/IIP/DistributedConnectionProtocol.cs +++ b/Esyur/Net/IIP/DistributedConnectionProtocol.cs @@ -1167,7 +1167,7 @@ namespace Esyur.Net.IIP return; } - if (rt is System.Collections.IEnumerable && !(rt is Array)) + if (rt is System.Collections.IEnumerable && !(rt is Array || rt is Structure)) { var enu = rt as System.Collections.IEnumerable; diff --git a/Esyur/Resource/Warehouse.cs b/Esyur/Resource/Warehouse.cs index a921331..aa0e11e 100644 --- a/Esyur/Resource/Warehouse.cs +++ b/Esyur/Resource/Warehouse.cs @@ -34,6 +34,7 @@ using System.Text; using System.Threading.Tasks; using Esyur.Net.IIP; using System.Text.RegularExpressions; +using Esyur.Misc; namespace Esyur.Resource { @@ -82,6 +83,8 @@ namespace Esyur.Resource return null; } + public static WeakReference[] Resources => resources.Values.ToArray(); + /// /// Get a resource by instance Id. /// @@ -475,6 +478,9 @@ namespace Esyur.Resource } + var t = resource.GetType(); + Global.Counters["T-" + t.Namespace + "." + t.Name]++; + resources.Add(resource.Instance.Id, new WeakReference(resource)); if (warehouseIsOpen) @@ -531,7 +537,9 @@ namespace Esyur.Resource } } - Put(res, name, store, parent, null, 0, manager, attributes); + if (store != null || parent != null || res is IStore) + Put(res, name, store, parent, null, 0, manager, attributes); + return (T)res; } diff --git a/Esyur/Stores/MemoryStore.cs b/Esyur/Stores/MemoryStore.cs index 9b1df7d..a7287cc 100644 --- a/Esyur/Stores/MemoryStore.cs +++ b/Esyur/Stores/MemoryStore.cs @@ -16,7 +16,7 @@ namespace Esyur.Stores public event DestroyedEvent OnDestroy; - Dictionary resources = new Dictionary(); + KeyList resources = new KeyList(); public void Destroy() { @@ -37,11 +37,13 @@ namespace Esyur.Stores if (r.Value.Instance.Name == path) return new AsyncReply(r.Value); + return new AsyncReply(null); } public bool Put(IResource resource) { + resources.Add(resource.Instance.Id, resource);// new WeakReference(resource)); resource.Instance.Attributes["children"] = new AutoList(resource.Instance); resource.Instance.Attributes["parents"] = new AutoList(resource.Instance);