diff --git a/CHANGELOG.md b/CHANGELOG.md index f44c7fc..a687720 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [1.2.3] - Release +Improved property updating + +## [1.2.2] - Hotfix +Bugfix + ## [1.2.1] - Release. Reconnect error handling diff --git a/lib/src/Data/KeyValuePair.dart b/lib/src/Data/KeyValuePair.dart new file mode 100644 index 0000000..3f11c37 --- /dev/null +++ b/lib/src/Data/KeyValuePair.dart @@ -0,0 +1,7 @@ +class KeyValuePair +{ + K key; + V value; + + KeyValuePair(this.key, this.value); +} \ No newline at end of file diff --git a/lib/src/Net/IIP/DistributedConnection.dart b/lib/src/Net/IIP/DistributedConnection.dart index f6dc61c..0f42a5a 100644 --- a/lib/src/Net/IIP/DistributedConnection.dart +++ b/lib/src/Net/IIP/DistributedConnection.dart @@ -1257,12 +1257,6 @@ class DistributedConnection extends NetworkConnection with IStore } var r = res as IResource; - r.instance.on("resourceEventOccurred", _instance_EventOccurred); - r.instance.on("resourceModified", _instance_PropertyModified); - r.instance.on("resourceDestroyed", _instance_ResourceDestroyed); - r.instance.children.on("add", _children_OnAdd); - r.instance.children.on("removed", _children_OnRemoved); - r.instance.attributes.on("modified", _attributes_OnModified); var link = DC.stringToBytes(r.instance.link); @@ -1288,6 +1282,14 @@ class DistributedConnection extends NetworkConnection with IStore .addDC(Codec.composePropertyValueArray(r.instance.serialize(), this, true)) .done(); } + + r.instance.on("resourceEventOccurred", _instance_EventOccurred); + r.instance.on("resourceModified", _instance_PropertyModified); + r.instance.on("resourceDestroyed", _instance_ResourceDestroyed); + r.instance.children.on("add", _children_OnAdd); + r.instance.children.on("removed", _children_OnRemoved); + r.instance.attributes.on("modified", _attributes_OnModified); + } else { diff --git a/lib/src/Net/IIP/DistributedResource.dart b/lib/src/Net/IIP/DistributedResource.dart index b270057..7f5ac34 100644 --- a/lib/src/Net/IIP/DistributedResource.dart +++ b/lib/src/Net/IIP/DistributedResource.dart @@ -23,6 +23,7 @@ SOFTWARE. */ import 'package:esyur/esyur.dart'; +import 'package:esyur/src/Data/KeyValuePair.dart'; import '../../Resource/IResource.dart'; import '../../Core/AsyncReply.dart'; @@ -43,10 +44,11 @@ class DistributedResource extends IResource String _link; List _properties; - - bool _destroyed = false; + + List> _queued_updates =List>(); + /// /// Connection responsible for the distributed resource. /// @@ -162,12 +164,22 @@ class DistributedResource extends IResource _attached = true; + if (_queued_updates.length > 0) + { + _queued_updates.forEach((kv)=>updatePropertyByIndex(kv.key, kv.value)); + _queued_updates.clear(); + } + } return true; } void emitEventByIndex(int index, List args) { + // neglect events when the object is not yet attached + if (!_attached) + return; + var et = instance.template.getEventTemplateByIndex(index); //events[index]?.Invoke(this, args); emitArgs(et.name, args); @@ -296,9 +308,16 @@ class DistributedResource extends IResource void updatePropertyByIndex(int index, dynamic value) { - var pt = instance.template.getPropertyTemplateByIndex(index); - _properties[index] = value; - instance.emitModification(pt, value); + if (!_attached) + { + _queued_updates.add(KeyValuePair(index, value)); + } + else + { + var pt = instance.template.getPropertyTemplateByIndex(index); + _properties[index] = value; + instance.emitModification(pt, value); + } } /// diff --git a/pubspec.yaml b/pubspec.yaml index 936af19..ff67879 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: esyur description: Distributed Object Framework. -version: 1.2.1 +version: 1.2.3 # author: Ahmed Zamil homepage: https://github.com/esyur/esyur-dart diff --git a/test/main.dart b/test/main.dart index 844b814..1947c34 100644 --- a/test/main.dart +++ b/test/main.dart @@ -5,20 +5,29 @@ import 'dart:io'; main() async { //test("Connect to server", () async { - - // connect to the server - var x = await Warehouse.get("iip://localhost:5000/sys/su", {"username": "admin", "password": "1234" - , "domain": "example.com"}); - var now = DateTime.now(); + // // // connect to the server + // var x = await Warehouse.get("iip://localhost:5000/sys/su", {"username": "admin", "password": "1234" + // , "domain": "example.com"}); + var x = await Warehouse.get("iip://gps.dijlh.com:2628/app", {"username": "delta", "password": "interactivereflection2020" + , "domain": "gps.dijlh.com"}); + // desc(x); - + var date = DateTime.now(); + + var from =DateTime(date.year, date.month, date.day); + var to =DateTime(date.year, date.month, date.day + 1); + List trackers = await x.getMyTrackers(); + + + var rt = await x.getObjectTracks(trackers[0], from, to, 0, 0, 0); + print("Time ${DateTime.now().difference(now).inSeconds}"); print(x.suspended);