mirror of
				https://github.com/esiur/esiur-dart.git
				synced 2025-11-04 09:11:35 +00:00 
			
		
		
		
	Dart 2.7
This commit is contained in:
		@@ -26,7 +26,7 @@ class AsyncBag<T> extends AsyncReply<List<T>>
 | 
			
		||||
            var k = _replies[i];
 | 
			
		||||
            var index = i;
 | 
			
		||||
 | 
			
		||||
            k.then((r)
 | 
			
		||||
            k.then<dynamic>((r)
 | 
			
		||||
            {
 | 
			
		||||
                _results[index] = r;
 | 
			
		||||
                _count++;
 | 
			
		||||
 
 | 
			
		||||
@@ -60,6 +60,13 @@ class AsyncReply<T> implements Future<T>
 | 
			
		||||
      _resultReady = val;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
  AsyncReply<T> next(Function(T) callback)
 | 
			
		||||
  {
 | 
			
		||||
    then(callback);
 | 
			
		||||
    return this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  AsyncReply<R> then<R>(FutureOr<R> onValue(T value), {Function onError}) 
 | 
			
		||||
  {
 | 
			
		||||
      _callbacks.add(onValue);
 | 
			
		||||
@@ -83,8 +90,10 @@ class AsyncReply<T> implements Future<T>
 | 
			
		||||
      if (_resultReady)
 | 
			
		||||
          onValue(result);
 | 
			
		||||
 | 
			
		||||
      return this as AsyncReply<R>;
 | 
			
		||||
      
 | 
			
		||||
      if (R == Null)
 | 
			
		||||
        return null;
 | 
			
		||||
      else
 | 
			
		||||
        return this as AsyncReply<R>;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  AsyncReply<T> whenComplete(FutureOr action())
 | 
			
		||||
 
 | 
			
		||||
@@ -175,11 +175,13 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
        if (instance.attributes.containsKey("username")
 | 
			
		||||
          && instance.attributes.containsKey("password"))
 | 
			
		||||
        {
 | 
			
		||||
            var hostname = instance.name.split ("://").skip(1).join("://").split("/")[0];
 | 
			
		||||
 | 
			
		||||
          
 | 
			
		||||
            var host = instance.name.split(":");// ("://").skip(1).join("://").split("/")[0];
 | 
			
		||||
            // assign domain from hostname if not provided
 | 
			
		||||
 | 
			
		||||
            var address = hostname.split(":")[0];
 | 
			
		||||
            var port = int.parse(hostname.split(":")[1]);
 | 
			
		||||
            var address = host[0];
 | 
			
		||||
            var port = int.parse(host[1]);
 | 
			
		||||
            var username = instance.attributes["username"].toString();
 | 
			
		||||
 | 
			
		||||
            var domain = instance.attributes.containsKey("domain") ? instance.attributes["domain"] : address;
 | 
			
		||||
@@ -195,7 +197,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
            var sock = new TCPSocket();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            sock.connect(domain, port).then((x){
 | 
			
		||||
            sock.connect(domain, port).then<dynamic>((x){
 | 
			
		||||
              assign(sock);
 | 
			
		||||
              //rt.trigger(true);
 | 
			
		||||
            }).error((x)=>_openReply.triggerError(x));
 | 
			
		||||
@@ -1987,7 +1989,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
                          if (r is DistributedResource)
 | 
			
		||||
                          {
 | 
			
		||||
                              // propagation
 | 
			
		||||
                              (r as DistributedResource).set(index, value).then((x)
 | 
			
		||||
                              (r as DistributedResource).set(index, value).then<dynamic>((x)
 | 
			
		||||
                              {
 | 
			
		||||
                                  sendReply(IIPPacketAction.SetProperty, callback).done();
 | 
			
		||||
                              }).error((x)
 | 
			
		||||
@@ -2087,7 +2089,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
          sendRequest(IIPPacketAction.TemplateFromClassId)
 | 
			
		||||
                      .addGuid(classId)
 | 
			
		||||
                      .done()
 | 
			
		||||
                      .then((rt)
 | 
			
		||||
                      .then<dynamic>((rt)
 | 
			
		||||
                      {
 | 
			
		||||
                          _templateRequests.remove(classId);
 | 
			
		||||
                          _templates[(rt[0] as ResourceTemplate).classId] = rt[0] as ResourceTemplate;
 | 
			
		||||
@@ -2112,7 +2114,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
 | 
			
		||||
          var rt = new AsyncReply<IResource>();
 | 
			
		||||
 | 
			
		||||
          query(path).then((ar)
 | 
			
		||||
          query(path).then<dynamic>((ar)
 | 
			
		||||
          {
 | 
			
		||||
              if (ar?.length > 0)
 | 
			
		||||
                  rt.trigger(ar[0]);
 | 
			
		||||
@@ -2167,7 +2169,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
          sendRequest(IIPPacketAction.AttachResource)
 | 
			
		||||
                      .addUint32(id)
 | 
			
		||||
                      .done()
 | 
			
		||||
                      .then((rt)
 | 
			
		||||
                      .then<dynamic>((rt)
 | 
			
		||||
                      {
 | 
			
		||||
 | 
			
		||||
                        //print("fetched ${id}");
 | 
			
		||||
@@ -2175,7 +2177,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
                          var dr = new DistributedResource(this, id, rt[1], rt[2]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                          getTemplate(rt[0] as Guid).then((tmp)
 | 
			
		||||
                          getTemplate(rt[0] as Guid).then<dynamic>((tmp)
 | 
			
		||||
                          {
 | 
			
		||||
                              //print("New template ");
 | 
			
		||||
 | 
			
		||||
@@ -2211,7 +2213,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
          sendRequest(IIPPacketAction.ResourceChildren)
 | 
			
		||||
                      .addUint32(resource.instance.id)
 | 
			
		||||
                      .done()
 | 
			
		||||
                      .then((ar)
 | 
			
		||||
                      .then<dynamic>((ar)
 | 
			
		||||
                      {
 | 
			
		||||
                          var d = ar[0] as DC;
 | 
			
		||||
                          Codec.parseResourceArray(d, 0, d.length, this).then((resources)
 | 
			
		||||
@@ -2230,10 +2232,10 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
          sendRequest(IIPPacketAction.ResourceParents)
 | 
			
		||||
              .addUint32(resource.instance.id)
 | 
			
		||||
              .done()
 | 
			
		||||
              .then((ar)
 | 
			
		||||
              .then<dynamic>((ar)
 | 
			
		||||
              {
 | 
			
		||||
                  var d = ar[0] as DC;
 | 
			
		||||
                  Codec.parseResourceArray(d, 0, d.length, this).then((resources)
 | 
			
		||||
                  Codec.parseResourceArray(d, 0, d.length, this).then<dynamic>((resources)
 | 
			
		||||
                  {
 | 
			
		||||
                      rt.trigger(resources);
 | 
			
		||||
                  }).error((ex) => rt.triggerError(ex));
 | 
			
		||||
@@ -2250,7 +2252,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
              sendRequest(IIPPacketAction.ClearAllAttributes)
 | 
			
		||||
                  .addUint32(resource.instance.id)
 | 
			
		||||
                  .done()
 | 
			
		||||
                  .then((ar) => rt.trigger(true))
 | 
			
		||||
                  .then<dynamic>((ar) => rt.trigger(true))
 | 
			
		||||
                  .error((ex) => rt.triggerError(ex));
 | 
			
		||||
          else
 | 
			
		||||
          {
 | 
			
		||||
@@ -2260,7 +2262,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
                  .addInt32(attrs.length)
 | 
			
		||||
                  .addDC(attrs)
 | 
			
		||||
                  .done()
 | 
			
		||||
                  .then((ar) => rt.trigger(true))
 | 
			
		||||
                  .then<dynamic>((ar) => rt.trigger(true))
 | 
			
		||||
                  .error((ex) => rt.triggerError(ex));
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
@@ -2275,7 +2277,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
              .addUint32(resource.instance.id)
 | 
			
		||||
              .addDC(Codec.composeStructure(attributes, this, true, true, true))
 | 
			
		||||
              .done()
 | 
			
		||||
              .then((ar) => rt.trigger(true))
 | 
			
		||||
              .then<dynamic>((ar) => rt.trigger(true))
 | 
			
		||||
              .error((ex) => rt.triggerError(ex));
 | 
			
		||||
 | 
			
		||||
          return rt;
 | 
			
		||||
@@ -2293,7 +2295,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
                  .then((ar)
 | 
			
		||||
                  {
 | 
			
		||||
                      var d = ar[0] as DC;
 | 
			
		||||
                      Codec.parseStructure(d, 0, d.length, this).then((st)
 | 
			
		||||
                      Codec.parseStructure(d, 0, d.length, this).then<dynamic>((st)
 | 
			
		||||
                      {
 | 
			
		||||
                          resource.instance.setAttributes(st);
 | 
			
		||||
                          rt.trigger(st);
 | 
			
		||||
@@ -2311,7 +2313,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
                  .then((ar)
 | 
			
		||||
                  {
 | 
			
		||||
                      var d = ar[0] as DC;
 | 
			
		||||
                      Codec.parseStructure(d, 0, d.length, this).then((st)
 | 
			
		||||
                      Codec.parseStructure(d, 0, d.length, this).then<dynamic>((st)
 | 
			
		||||
                      {
 | 
			
		||||
 | 
			
		||||
                          resource.instance.setAttributes(st);
 | 
			
		||||
@@ -2347,7 +2349,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
                  .addDateTime(fromDate)
 | 
			
		||||
                  .addDateTime(toDate)
 | 
			
		||||
                  .done()
 | 
			
		||||
                  .then((rt)
 | 
			
		||||
                  .then<dynamic>((rt)
 | 
			
		||||
                  {
 | 
			
		||||
                      var content = rt[0] as DC;
 | 
			
		||||
 | 
			
		||||
@@ -2376,7 +2378,7 @@ class DistributedConnection extends NetworkConnection with IStore
 | 
			
		||||
                      .addUint16(str.length)
 | 
			
		||||
                      .addDC(str)
 | 
			
		||||
                      .done()
 | 
			
		||||
                      .then((args)
 | 
			
		||||
                      .then<dynamic>((args)
 | 
			
		||||
                      {
 | 
			
		||||
                          var content = args[0] as DC;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -156,6 +156,7 @@ class NetworkConnection extends IDestructible
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            if (_sock != null)
 | 
			
		||||
                _sock.close();
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -102,6 +102,7 @@ class TCPSocket extends ISocket
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void doneHandler(){
 | 
			
		||||
      close();
 | 
			
		||||
      sock.destroy();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,8 @@ SOFTWARE.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 | 
			
		||||
import 'dart:io';
 | 
			
		||||
import 'ISocket.dart';
 | 
			
		||||
import '../../Data/DC.dart';
 | 
			
		||||
@@ -187,3 +189,4 @@ class WSSocket extends ISocket
 | 
			
		||||
        return reply;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
*/
 | 
			
		||||
@@ -46,7 +46,6 @@ class Warehouse
 | 
			
		||||
 | 
			
		||||
    static KeyList<Guid, ResourceTemplate> _templates = new KeyList<Guid, ResourceTemplate>();
 | 
			
		||||
 | 
			
		||||
    static bool storeIsOpen = false;
 | 
			
		||||
 | 
			
		||||
    //public delegate void StoreConnectedEvent(IStore store, string name);
 | 
			
		||||
    //public delegate void StoreDisconnectedEvent(IStore store);
 | 
			
		||||
@@ -54,8 +53,12 @@ class Warehouse
 | 
			
		||||
    //public static event StoreConnectedEvent StoreConnected;
 | 
			
		||||
    ///public static event StoreDisconnectedEvent StoreDisconnected;
 | 
			
		||||
 | 
			
		||||
    static bool _warehouseIsOpen = false;
 | 
			
		||||
 | 
			
		||||
    static KeyList<String, IStore Function()> protocols = _getSupportedProtocols();
 | 
			
		||||
 | 
			
		||||
    static final _urlRegex = RegExp(r'^(?:([^\s|:]*):\/\/([^\/]*)\/?(.*))');
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Get a store by its name.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
@@ -125,7 +128,7 @@ class Warehouse
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                rt.trigger(true);
 | 
			
		||||
                storeIsOpen = true;
 | 
			
		||||
                _warehouseIsOpen = true;
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
@@ -240,7 +243,65 @@ class Warehouse
 | 
			
		||||
    /// <returns>Resource instance.</returns>
 | 
			
		||||
    static AsyncReply<dynamic> get(String path, [attributes = null, IResource parent = null, IPermissionsManager manager = null])
 | 
			
		||||
    {
 | 
			
		||||
            var rt = new AsyncReply<IResource>();
 | 
			
		||||
 | 
			
		||||
            // Should we create a new store ?
 | 
			
		||||
 | 
			
		||||
            if (_urlRegex.hasMatch(path))
 | 
			
		||||
            //if (path.contains("://"))
 | 
			
		||||
            {
 | 
			
		||||
                var url = _urlRegex.allMatches(path).first;
 | 
			
		||||
 | 
			
		||||
                //var url = path.split(_urlRegex);
 | 
			
		||||
 | 
			
		||||
                //var url = path.split(new string[] { "://" }, 2, StringSplitOptions.None);
 | 
			
		||||
                //var hostname = url[1].Split(new char[] { '/' }, 2)[0];
 | 
			
		||||
                //var pathname = string.Join("/", url[1].Split(new char[] { '/' }).Skip(1));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                if (protocols.containsKey(url[1]))
 | 
			
		||||
                {
 | 
			
		||||
                    var handler = protocols[url[1]];
 | 
			
		||||
 | 
			
		||||
                    var store = handler();
 | 
			
		||||
                    put(store, url[2], null, parent, null, 0, manager, attributes);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                    store.trigger(ResourceTrigger.Open).then<dynamic>((x)
 | 
			
		||||
                    {
 | 
			
		||||
 | 
			
		||||
                        _warehouseIsOpen = true;
 | 
			
		||||
 | 
			
		||||
                        if (url[3].length > 0 && url[3] != "")
 | 
			
		||||
                            store.get(url[3]).then<dynamic>((r)
 | 
			
		||||
                            {
 | 
			
		||||
                                rt.trigger(r);
 | 
			
		||||
                            }).error((e) => rt.triggerError(e));
 | 
			
		||||
                        else
 | 
			
		||||
                            rt.trigger(store);
 | 
			
		||||
                    }).error((e)
 | 
			
		||||
                    {
 | 
			
		||||
                        rt.triggerError(e);
 | 
			
		||||
                        Warehouse.remove(store);
 | 
			
		||||
                    });
 | 
			
		||||
 | 
			
		||||
                    return rt;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            query(path).then((rs)
 | 
			
		||||
            {
 | 
			
		||||
                if (rs != null && rs.length > 0)
 | 
			
		||||
                    rt.trigger(rs[0]);
 | 
			
		||||
                else
 | 
			
		||||
                    rt.trigger(null);
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            return rt;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
        var p = path.split('/');
 | 
			
		||||
        IResource res;
 | 
			
		||||
 | 
			
		||||
@@ -286,9 +347,9 @@ class Warehouse
 | 
			
		||||
                put(store, url[0] + "://" + hostname, null, parent, null, 0, manager, attributes);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                store.trigger(ResourceTrigger.Open).then((x){
 | 
			
		||||
                store.trigger(ResourceTrigger.Open).then<dynamic>((x){
 | 
			
		||||
                    if (pathname.length > 0 && pathname != "")
 | 
			
		||||
                        store.get(pathname).then((r) => rt.trigger(r)
 | 
			
		||||
                        store.get(pathname).then<dynamic>((r) => rt.trigger(r)
 | 
			
		||||
                            ).error((e) => 
 | 
			
		||||
                            
 | 
			
		||||
                            rt.triggerError(e)
 | 
			
		||||
@@ -307,6 +368,7 @@ class Warehouse
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        return new AsyncReply<IResource>.ready(null);
 | 
			
		||||
        */
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
@@ -348,8 +410,8 @@ class Warehouse
 | 
			
		||||
 | 
			
		||||
        _resources[resource.instance.id] = resource;
 | 
			
		||||
 | 
			
		||||
        //if (!storeIsOpen)
 | 
			
		||||
        //      resource.trigger(ResourceTrigger.Initialize);
 | 
			
		||||
        if (_warehouseIsOpen)
 | 
			
		||||
              resource.trigger(ResourceTrigger.Initialize);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
name: esyur
 | 
			
		||||
description: Distributed Object Framework.
 | 
			
		||||
version: 1.0.5
 | 
			
		||||
version: 1.1.2
 | 
			
		||||
author: Ahmed Zamil <ahmed@dijlh.com>
 | 
			
		||||
homepage: https://github.com/esyur/esyur-dart
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,12 +6,22 @@ main()
 | 
			
		||||
{
 | 
			
		||||
    test("Connect to server", () async {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // connect to the server
 | 
			
		||||
    var x = await Warehouse.get("iip://localhost:5000/db/my", {"username": "demo", "password": "1234"});
 | 
			
		||||
    var x = await Warehouse.get("iip://192.168.88.220:5000/sys/su", {"username": "admin", "password": "1234"
 | 
			
		||||
    , "domain": "khalid.com"});
 | 
			
		||||
 
 | 
			
		||||
 //   x.instance.store.on("close", ()=>print("Closed"));
 | 
			
		||||
    x.instance.store.on("close", (x){
 | 
			
		||||
        print("Closed");
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
  x.on("modified", (peoperty, value){
 | 
			
		||||
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
   // var users = await x.Users.Slice(0, 10);
 | 
			
		||||
 | 
			
		||||
   // print(users);
 | 
			
		||||
 //   await sleep(Duration(seconds: 10));
 | 
			
		||||
 | 
			
		||||
    // get property
 | 
			
		||||
    print(x.Level);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user