mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-06-27 14:53:11 +00:00
1.4.0
This commit is contained in:
@ -2,198 +2,165 @@ import '../Core/IDestructible.dart';
|
||||
import 'Codec.dart';
|
||||
import 'dart:collection';
|
||||
|
||||
class AutoList<T, ST> extends IDestructible with IterableMixin
|
||||
{
|
||||
class AutoList<T, ST> extends IDestructible with IterableMixin {
|
||||
List<T> _list = <T>[];
|
||||
|
||||
List<T> _list = new List<T>();
|
||||
ST _state;
|
||||
bool _removableList;
|
||||
|
||||
sort(Function comparer) {
|
||||
_list.sort(comparer);
|
||||
}
|
||||
|
||||
ST _state;
|
||||
bool _removableList;
|
||||
Iterator<T> get iterator => _list.iterator;
|
||||
|
||||
sort(Function comparer)
|
||||
{
|
||||
_list.sort(comparer);
|
||||
}
|
||||
/// <summary>
|
||||
/// Convert AutoList to array
|
||||
/// </summary>
|
||||
/// <returns>Array</returns>
|
||||
//List<T> toList()
|
||||
//{
|
||||
// list.OrderBy()
|
||||
// return _list;
|
||||
//}
|
||||
|
||||
Iterator<T> get iterator => _list.iterator;
|
||||
/// Create a new instance of AutoList
|
||||
/// <param name="state">State object to be included when an event is raised.</param>
|
||||
AutoList([ST state, List<T> values]) {
|
||||
this._state = state;
|
||||
this._removableList = Codec.implementsInterface<T, IDestructible>();
|
||||
|
||||
if (values != null) addRange(values);
|
||||
|
||||
/// <summary>
|
||||
/// Convert AutoList to array
|
||||
/// </summary>
|
||||
/// <returns>Array</returns>
|
||||
//List<T> toList()
|
||||
//{
|
||||
// list.OrderBy()
|
||||
// return _list;
|
||||
//}
|
||||
register("modified");
|
||||
register("added");
|
||||
register("removed");
|
||||
register("cleared");
|
||||
}
|
||||
|
||||
|
||||
/// Create a new instance of AutoList
|
||||
/// <param name="state">State object to be included when an event is raised.</param>
|
||||
AutoList([ST state, List<T> values])
|
||||
{
|
||||
this._state = state;
|
||||
this._removableList = Codec.implementsInterface<T, IDestructible>();
|
||||
/// <summary>
|
||||
/// Synchronization lock of the list
|
||||
/// </summary>
|
||||
//public object SyncRoot
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return syncRoot;
|
||||
// }
|
||||
//}
|
||||
|
||||
if (values != null)
|
||||
addRange(values);
|
||||
/// <summary>
|
||||
/// First item in the list
|
||||
/// </summary>
|
||||
//T first()
|
||||
//{
|
||||
// return _list.first;
|
||||
//}
|
||||
|
||||
register("modified");
|
||||
register("added");
|
||||
register("removed");
|
||||
register("cleared");
|
||||
}
|
||||
operator [](index) {
|
||||
return _list[index];
|
||||
}
|
||||
|
||||
|
||||
operator []=(index, value) {
|
||||
var oldValue = _list[index];
|
||||
|
||||
/// <summary>
|
||||
/// Synchronization lock of the list
|
||||
/// </summary>
|
||||
//public object SyncRoot
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return syncRoot;
|
||||
// }
|
||||
//}
|
||||
if (_removableList) {
|
||||
if (oldValue != null)
|
||||
(oldValue as IDestructible).off("destroy", _itemDestroyed);
|
||||
if (value != null) value.on("destroy", _itemDestroyed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// First item in the list
|
||||
/// </summary>
|
||||
//T first()
|
||||
//{
|
||||
// return _list.first;
|
||||
//}
|
||||
//lock (syncRoot)
|
||||
_list[index] = value;
|
||||
|
||||
operator [](index)
|
||||
{
|
||||
return _list[index];
|
||||
}
|
||||
emitArgs("modified", [_state, index, oldValue, value]);
|
||||
}
|
||||
|
||||
operator []=(index, value)
|
||||
{
|
||||
var oldValue = _list[index];
|
||||
/// <summary>
|
||||
/// Add item to the list
|
||||
/// </summary>
|
||||
add(T value) {
|
||||
if (_removableList) if (value != null)
|
||||
(value as IDestructible).on("destroy", _itemDestroyed);
|
||||
|
||||
if (_removableList)
|
||||
{
|
||||
if (oldValue != null)
|
||||
(oldValue as IDestructible).off("destroy", _itemDestroyed);
|
||||
if (value != null)
|
||||
value.on("destroy", _itemDestroyed);
|
||||
}
|
||||
// lock (syncRoot)
|
||||
_list.add(value);
|
||||
|
||||
//lock (syncRoot)
|
||||
_list[index] = value;
|
||||
emitArgs("add", [_state, value]);
|
||||
}
|
||||
|
||||
emitArgs("modified", [_state, index, oldValue, value]);
|
||||
}
|
||||
/// <summary>
|
||||
/// Add an array of items to the list
|
||||
/// </summary>
|
||||
addRange(List<T> values) {
|
||||
values.forEach((x) => add(x));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add item to the list
|
||||
/// </summary>
|
||||
add(T value)
|
||||
{
|
||||
if (_removableList)
|
||||
if (value != null)
|
||||
(value as IDestructible).on("destroy", _itemDestroyed);
|
||||
_itemDestroyed(T sender) {
|
||||
remove(sender);
|
||||
}
|
||||
|
||||
// lock (syncRoot)
|
||||
_list.add(value);
|
||||
/// <summary>
|
||||
/// Clear the list
|
||||
/// </summary>
|
||||
clear() {
|
||||
if (_removableList)
|
||||
_list
|
||||
.forEach((x) => (x as IDestructible)?.off("destroy", _itemDestroyed));
|
||||
|
||||
emitArgs("add",[_state, value]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an array of items to the list
|
||||
/// </summary>
|
||||
addRange(List<T> values)
|
||||
{
|
||||
values.forEach((x)=>add(x));
|
||||
}
|
||||
|
||||
_itemDestroyed(T sender)
|
||||
{
|
||||
remove(sender);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear the list
|
||||
/// </summary>
|
||||
clear()
|
||||
{
|
||||
if (_removableList)
|
||||
_list.forEach((x)=>(x as IDestructible)?.off("destroy", _itemDestroyed));
|
||||
|
||||
|
||||
// lock (syncRoot)
|
||||
_list.clear();
|
||||
_list.clear();
|
||||
|
||||
emitArgs("cleared", [_state]);
|
||||
emitArgs("cleared", [_state]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove an item from the list
|
||||
/// <param name="value">Item to remove</param>
|
||||
/// </summary>
|
||||
remove(T value) {
|
||||
if (!_list.contains(value)) return;
|
||||
|
||||
if (_removableList) if (value != null)
|
||||
(value as IDestructible).off("destroy", _itemDestroyed);
|
||||
|
||||
//lock (syncRoot)
|
||||
_list.remove(value);
|
||||
|
||||
emitArgs("removed", [_state, value]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of items in the list
|
||||
/// </summary>
|
||||
get count => _list.length;
|
||||
get length => _list.length;
|
||||
|
||||
/// <summary>
|
||||
/// Check if an item exists in the list
|
||||
/// </summary>
|
||||
/// <param name="value">Item to check if exists</param>
|
||||
//contains(T value) => _list.contains(value);
|
||||
|
||||
/// <summary>
|
||||
/// Check if any item of the given array is in the list
|
||||
/// </summary>
|
||||
/// <param name="values">Array of items</param>
|
||||
containsAny(values) {
|
||||
if (values is List<T>) {
|
||||
for (var v in values) {
|
||||
if (_list.contains(v)) return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove an item from the list
|
||||
/// <param name="value">Item to remove</param>
|
||||
/// </summary>
|
||||
remove(T value)
|
||||
{
|
||||
if (!_list.contains(value))
|
||||
return;
|
||||
|
||||
if (_removableList)
|
||||
if (value != null)
|
||||
(value as IDestructible).off("destroy", _itemDestroyed);
|
||||
|
||||
//lock (syncRoot)
|
||||
_list.remove(value);
|
||||
|
||||
emitArgs("removed", [_state, value]);
|
||||
} else if (values is AutoList<T, ST>) {
|
||||
for (var v in values._list) {
|
||||
if (_list.contains(v)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of items in the list
|
||||
/// </summary>
|
||||
get count => _list.length;
|
||||
get length => _list.length;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if an item exists in the list
|
||||
/// </summary>
|
||||
/// <param name="value">Item to check if exists</param>
|
||||
//contains(T value) => _list.contains(value);
|
||||
|
||||
/// <summary>
|
||||
/// Check if any item of the given array is in the list
|
||||
/// </summary>
|
||||
/// <param name="values">Array of items</param>
|
||||
containsAny(values)
|
||||
{
|
||||
|
||||
if (values is List<T>)
|
||||
{
|
||||
for(var v in values)
|
||||
{
|
||||
if (_list.contains(v))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (values is AutoList<T, ST>)
|
||||
{
|
||||
|
||||
for(var v in values._list)
|
||||
{
|
||||
if (_list.contains(v))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
@override
|
||||
void destroy() {
|
||||
clear();
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
import 'package:esiur/src/Resource/Template/TemplateType.dart';
|
||||
import '../Resource/Template/TemplateType.dart';
|
||||
|
||||
import 'DataType.dart';
|
||||
import 'Guid.dart';
|
||||
@ -78,10 +78,11 @@ class Codec {
|
||||
static List<int> getStructureDateTypes(
|
||||
Structure structure, DistributedConnection connection) {
|
||||
var keys = structure.getKeys();
|
||||
var types = new List<int>(keys.length);
|
||||
var types = new List<int>.generate(
|
||||
keys.length, (i) => Codec.getDataType(structure[keys[i]], connection));
|
||||
|
||||
for (var i = 0; i < keys.length; i++)
|
||||
types[i] = Codec.getDataType(structure[keys[i]], connection);
|
||||
// for (var i = 0; i < keys.length; i++)
|
||||
// types[i] = Codec.getDataType(structure[keys[i]], connection);
|
||||
return types;
|
||||
}
|
||||
|
||||
@ -325,7 +326,7 @@ class Codec {
|
||||
|
||||
record.deserialize(value);
|
||||
|
||||
reply.trigger(null);
|
||||
reply.trigger(record);
|
||||
} else {
|
||||
var record = new Record();
|
||||
|
||||
@ -336,8 +337,8 @@ class Codec {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
connection.getTemplate(classId).then((tmp) {
|
||||
parseVarArray(data, offset, length, connection).then((ar) {
|
||||
connection.getTemplate(classId).then<dynamic>((tmp) {
|
||||
parseVarArray(data, offset, length, connection).then<dynamic>((ar) {
|
||||
var record = new Record();
|
||||
|
||||
for (var i = 0; i < tmp.properties.length; i++)
|
||||
@ -619,8 +620,8 @@ class Codec {
|
||||
{
|
||||
var reply = new AsyncReply<Structure>();
|
||||
var bag = new AsyncBag<dynamic>();
|
||||
var keylist = new List<String>();
|
||||
var typelist = new List<int>();
|
||||
var keylist = <String>[];
|
||||
var typelist = <int>[];
|
||||
var sizeObject = new SizeObject();
|
||||
|
||||
if (keys == null) {
|
||||
@ -888,10 +889,9 @@ class Codec {
|
||||
/// <returns>True, if the resource owner is the given connection, otherwise False.</returns>
|
||||
static bool isLocalResource(
|
||||
IResource resource, DistributedConnection connection) {
|
||||
if (resource is DistributedResource) if ((resource as DistributedResource)
|
||||
.connection ==
|
||||
connection) return true;
|
||||
|
||||
if (resource is DistributedResource) {
|
||||
if (resource.connection == connection) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1010,7 +1010,26 @@ class Codec {
|
||||
var end = offset + length;
|
||||
|
||||
//
|
||||
var result = data[offset++];
|
||||
|
||||
// Is typed array ?
|
||||
var type = (data[offset] & 0xF0);
|
||||
|
||||
var result = data[offset++] & 0xF;
|
||||
|
||||
if (type == ResourceArrayType.Wrapper) {
|
||||
var classId = data.getGuid(offset);
|
||||
offset += 16;
|
||||
var tmp = Warehouse.getTemplateByClassId(classId, TemplateType.Resource);
|
||||
// not mine, look if the type is elsewhere
|
||||
if (tmp == null)
|
||||
Warehouse.getTemplateByClassId(classId, TemplateType.Wrapper);
|
||||
reply.arrayType = tmp?.definedType;
|
||||
} else if (type == ResourceArrayType.Static) {
|
||||
var classId = data.getGuid(offset);
|
||||
offset += 16;
|
||||
var tmp = Warehouse.getTemplateByClassId(classId, TemplateType.Wrapper);
|
||||
reply.arrayType = tmp?.definedType;
|
||||
}
|
||||
|
||||
AsyncReply<IResource> previous = null;
|
||||
|
||||
@ -1036,7 +1055,7 @@ class Codec {
|
||||
} else if (result == ResourceComparisonResult.Same) {
|
||||
current = previous;
|
||||
} else if (result == ResourceComparisonResult.Local) {
|
||||
current = Warehouse.get(data.getUint32(offset));
|
||||
current = Warehouse.getById(data.getUint32(offset));
|
||||
offset += 4;
|
||||
} else if (result == ResourceComparisonResult.Distributed) {
|
||||
current = connection.fetch(data.getUint32(offset));
|
||||
|
@ -9,7 +9,7 @@ class Guid {
|
||||
|
||||
DC get value => _data;
|
||||
|
||||
bool operator ==(Object other) {
|
||||
bool operator ==(other) {
|
||||
if (other is Guid)
|
||||
return _data.sequenceEqual(other._data);
|
||||
else
|
||||
@ -20,4 +20,7 @@ class Guid {
|
||||
String toString() {
|
||||
return _data.getString(0, _data.length);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => _data.toString().hashCode;
|
||||
}
|
||||
|
@ -27,130 +27,96 @@ import '../Core/IDestructible.dart';
|
||||
import 'dart:collection';
|
||||
import 'Codec.dart';
|
||||
|
||||
class KeyList<KT, T> extends IEventHandler with MapMixin<KT, T>
|
||||
{
|
||||
class KeyList<KT, T> extends IEventHandler with MapMixin<KT, T> {
|
||||
dynamic owner;
|
||||
|
||||
dynamic owner;
|
||||
|
||||
Map<KT, T> _map = new Map<KT, T>();
|
||||
|
||||
Iterator<KT> get iterator => _map.keys.iterator;
|
||||
Map<KT, T> _map = new Map<KT, T>();
|
||||
|
||||
Iterable<KT> get keys => _map.keys;
|
||||
Iterable<T> get values => _map.values;
|
||||
|
||||
Iterator<KT> get iterator => _map.keys.iterator;
|
||||
|
||||
operator[](index) => _map[index];
|
||||
Iterable<KT> get keys => _map.keys;
|
||||
Iterable<T> get values => _map.values;
|
||||
|
||||
operator []= (index, value) => add(index, value);
|
||||
|
||||
operator [](index) => _map[index];
|
||||
|
||||
at(int index) => _map.values.elementAt(index);
|
||||
operator []=(index, value) => add(index, value);
|
||||
|
||||
|
||||
bool _removableList;
|
||||
at(int index) => _map.values.elementAt(index);
|
||||
|
||||
bool _removableList;
|
||||
|
||||
T take(KT key)
|
||||
{
|
||||
if (_map.containsKey(key))
|
||||
{
|
||||
var v = _map[key];
|
||||
remove(key);
|
||||
return v;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
T take(KT key) {
|
||||
if (_map.containsKey(key)) {
|
||||
var v = _map[key];
|
||||
remove(key);
|
||||
return v;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
List<T> toArray() => _map.values.toList();
|
||||
|
||||
void add(KT key, T value) {
|
||||
if (_removableList) if (value != null)
|
||||
(value as IDestructible).on("destroy", _itemDestroyed);
|
||||
|
||||
if (_map.containsKey(key)) {
|
||||
var oldValue = _map[key];
|
||||
if (_removableList) if (oldValue != null)
|
||||
(oldValue as IDestructible).off("destroy", _itemDestroyed);
|
||||
|
||||
_map[key] = value;
|
||||
|
||||
emitArgs("modified", [key, oldValue, value, this]);
|
||||
} else {
|
||||
_map[key] = value;
|
||||
|
||||
emitArgs("add", [value, this]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<T> toArray() => _map.values.toList();
|
||||
_itemDestroyed(T sender) {
|
||||
removeValue(sender);
|
||||
}
|
||||
|
||||
void add(KT key, T value)
|
||||
{
|
||||
if (_removableList)
|
||||
if (value != null)
|
||||
(value as IDestructible).on("destroy", _itemDestroyed);
|
||||
removeValue(T value) {
|
||||
var toRemove = <KT>[];
|
||||
for (var k in _map.keys) if (_map[k] == value) toRemove.add(k);
|
||||
|
||||
if (_map.containsKey(key))
|
||||
{
|
||||
var oldValue = _map[key];
|
||||
if (_removableList)
|
||||
if (oldValue != null)
|
||||
(oldValue as IDestructible).off("destroy", _itemDestroyed);
|
||||
for (var k in toRemove) remove(k);
|
||||
}
|
||||
|
||||
_map[key] = value;
|
||||
clear() {
|
||||
if (_removableList)
|
||||
for (var v in _map.values)
|
||||
(v as IDestructible)?.off("destroy", _itemDestroyed);
|
||||
|
||||
emitArgs("modified", [key, oldValue, value, this]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_map[key] = value;
|
||||
_map.clear();
|
||||
|
||||
emitArgs("add", [value, this]);
|
||||
emitArgs("cleared", [this]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
T remove(key) {
|
||||
if (!_map.containsKey(key)) return null;
|
||||
|
||||
_itemDestroyed(T sender)
|
||||
{
|
||||
removeValue(sender);
|
||||
}
|
||||
var value = _map[key];
|
||||
|
||||
removeValue(T value)
|
||||
{
|
||||
var toRemove = new List<KT>();
|
||||
for (var k in _map.keys)
|
||||
if (_map[k] == value)
|
||||
toRemove.add(k);
|
||||
if (_removableList)
|
||||
(value as IDestructible)?.off("destroy", _itemDestroyed);
|
||||
|
||||
for (var k in toRemove)
|
||||
remove(k);
|
||||
}
|
||||
_map.remove(key);
|
||||
|
||||
clear()
|
||||
{
|
||||
if (_removableList)
|
||||
for (var v in _map.values)
|
||||
(v as IDestructible)?.off("destroy", _itemDestroyed);
|
||||
|
||||
_map.clear();
|
||||
emitArgs("removed", [key, value, this]);
|
||||
|
||||
emitArgs("cleared", [this]);
|
||||
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int get count => _map.length;
|
||||
|
||||
bool contains(KT key) => _map.containsKey(key);
|
||||
|
||||
T remove(key)
|
||||
{
|
||||
if (!_map.containsKey(key))
|
||||
return null;
|
||||
|
||||
var value = _map[key];
|
||||
|
||||
if (_removableList)
|
||||
(value as IDestructible)?.off("destroy", _itemDestroyed);
|
||||
|
||||
|
||||
_map.remove(key);
|
||||
|
||||
emitArgs("removed", [key, value, this]);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int get count => _map.length;
|
||||
|
||||
bool contains(KT key) => _map.containsKey(key);
|
||||
|
||||
|
||||
KeyList([owner = null])
|
||||
{
|
||||
_removableList = Codec.implementsInterface<T, IDestructible>();
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
KeyList([owner = null]) {
|
||||
_removableList = Codec.implementsInterface<T, IDestructible>();
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import 'package:esiur/src/Resource/Template/TemplateDescriber.dart';
|
||||
import '../Resource/Template/TemplateDescriber.dart';
|
||||
|
||||
import 'IRecord.dart';
|
||||
import 'KeyList.dart';
|
||||
|
Reference in New Issue
Block a user