mirror of
				https://github.com/esiur/esiur-dotnet.git
				synced 2025-10-31 16:01:34 +00:00 
			
		
		
		
	async put
This commit is contained in:
		| @@ -48,7 +48,7 @@ namespace Esiur.Stores.MongoDB | |||||||
|         IMongoDatabase database; |         IMongoDatabase database; | ||||||
|         IMongoCollection<BsonDocument> resourcesCollection; |         IMongoCollection<BsonDocument> resourcesCollection; | ||||||
|  |  | ||||||
|         Dictionary<string, WeakReference> resources = new Dictionary<string, WeakReference>(); |         KeyList<string, WeakReference> resources = new KeyList<string, WeakReference>(); | ||||||
|  |  | ||||||
|  |  | ||||||
|         [Public] |         [Public] | ||||||
| @@ -158,7 +158,8 @@ namespace Esiur.Stores.MongoDB | |||||||
|             else |             else | ||||||
|                 resources.Add(id, new WeakReference(resource)); |                 resources.Add(id, new WeakReference(resource)); | ||||||
|  |  | ||||||
|             Warehouse.Put(resource, document["name"].AsString, this); |             //@TODO this causes store.put to be invoked, need fix  | ||||||
|  |             await Warehouse.Put(resource, document["name"].AsString, this); | ||||||
|  |  | ||||||
|  |  | ||||||
|             var parents = document["parents"].AsBsonArray; |             var parents = document["parents"].AsBsonArray; | ||||||
|   | |||||||
| @@ -36,9 +36,9 @@ namespace Esiur.Stores.MongoDB | |||||||
|     public class MongoDBStore<T> : MongoDBStore where T:IResource |     public class MongoDBStore<T> : MongoDBStore where T:IResource | ||||||
|     { |     { | ||||||
|         [Public] |         [Public] | ||||||
|         public T New(string name = null, object properties = null) |         public async AsyncReply<T> New(string name = null, object properties = null) | ||||||
|         { |         { | ||||||
|             var resource = Warehouse.New<T>(name, this, null, null, null, properties); |             var resource = await Warehouse.New<T>(name, this, null, null, null, properties); | ||||||
|             resource.Instance.Managers.AddRange(this.Instance.Managers.ToArray()); |             resource.Instance.Managers.AddRange(this.Instance.Managers.ToArray()); | ||||||
|             return resource; |             return resource; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -36,5 +36,6 @@ namespace Esiur.Core | |||||||
|         SetPropertyDenied, |         SetPropertyDenied, | ||||||
|         ReadOnlyProperty, |         ReadOnlyProperty, | ||||||
|         GeneralFailure, |         GeneralFailure, | ||||||
|  |         AddToStoreFailed | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -759,12 +759,18 @@ namespace Esiur.Net.IIP | |||||||
|                                         .Done(); |                                         .Done(); | ||||||
|  |  | ||||||
|                                     ready = true; |                                     ready = true; | ||||||
|                                     Warehouse.Put(this, this.LocalUsername, null, Server); |                                     Warehouse.Put(this, this.LocalUsername, null, Server).Then(x => | ||||||
|  |                                     { | ||||||
|  |                                         openReply?.Trigger(true); | ||||||
|  |                                         OnReady?.Invoke(this); | ||||||
|  |  | ||||||
|                                     openReply?.Trigger(true); |                                         Server?.Membership.Login(session); | ||||||
|                                     OnReady?.Invoke(this); |  | ||||||
|  |                                     }).Error(x=> | ||||||
|  |                                     { | ||||||
|  |                                         openReply?.TriggerError(x); | ||||||
|  |                                     }); | ||||||
|  |  | ||||||
|                                     Server?.Membership.Login(session); |  | ||||||
|  |  | ||||||
|                                     //Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:AUTH"); |                                     //Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:AUTH"); | ||||||
|  |  | ||||||
| @@ -835,10 +841,12 @@ namespace Esiur.Net.IIP | |||||||
|  |  | ||||||
|                                 ready = true; |                                 ready = true; | ||||||
|                                 // put it in the warehouse |                                 // put it in the warehouse | ||||||
|                                 Warehouse.Put(this, this.LocalUsername, null, Server); |                                 Warehouse.Put(this, this.LocalUsername, null, Server).Then(x => | ||||||
|  |                                 { | ||||||
|  |                                     openReply?.Trigger(true); | ||||||
|  |                                     OnReady?.Invoke(this); | ||||||
|  |  | ||||||
|                                 openReply?.Trigger(true); |                                 }).Error(x=> openReply?.TriggerError(x)); | ||||||
|                                 OnReady?.Invoke(this); |  | ||||||
|  |  | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
| @@ -945,7 +953,7 @@ namespace Esiur.Net.IIP | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return new AsyncReply<bool>(); |             return new AsyncReply<bool>(true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -770,11 +770,16 @@ namespace Esiur.Net.IIP | |||||||
|                                 // create the resource |                                 // create the resource | ||||||
|                                 var resource = Activator.CreateInstance(type, args) as IResource; |                                 var resource = Activator.CreateInstance(type, args) as IResource; | ||||||
|  |  | ||||||
|                                 Warehouse.Put(resource, name, store as IStore, parent); |                                 Warehouse.Put(resource, name, store as IStore, parent).Then(ok => | ||||||
|  |                                 { | ||||||
|  |                                     SendReply(IIPPacket.IIPPacketAction.CreateResource, callback) | ||||||
|  |                                    .AddUInt32(resource.Instance.Id) | ||||||
|  |                                    .Done(); | ||||||
|  |  | ||||||
|                                 SendReply(IIPPacket.IIPPacketAction.CreateResource, callback) |                                 }).Error(x => | ||||||
|                                            .AddUInt32(resource.Instance.Id) |                                 { | ||||||
|                                            .Done(); |                                     SendError(ErrorType.Exception, callback, (ushort)ExceptionCode.AddToStoreFailed); | ||||||
|  |                                 }); | ||||||
|  |  | ||||||
|                             }); |                             }); | ||||||
|                         }); |                         }); | ||||||
| @@ -1959,14 +1964,27 @@ namespace Esiur.Net.IIP | |||||||
|                             { |                             { | ||||||
|                                 // ClassId, ResourceAge, ResourceLink, Content |                                 // ClassId, ResourceAge, ResourceLink, Content | ||||||
|                                 if (resource == null) |                                 if (resource == null) | ||||||
|                                     Warehouse.Put(dr, id.ToString(), this, null, tmp); |  | ||||||
|  |  | ||||||
|                                 Codec.ParsePropertyValueArray((byte[])rt[3], this).Then((ar) => |  | ||||||
|                                 { |                                 { | ||||||
|                                     dr._Attach(ar); |                                     Warehouse.Put(dr, id.ToString(), this, null, tmp).Then((ok) => | ||||||
|                                     resourceRequests.Remove(id); |                                     { | ||||||
|                                     reply.Trigger(dr); |                                         Codec.ParsePropertyValueArray((byte[])rt[3], this).Then((ar) => | ||||||
|                                 }); |                                         { | ||||||
|  |                                             dr._Attach(ar); | ||||||
|  |                                             resourceRequests.Remove(id); | ||||||
|  |                                             reply.Trigger(dr); | ||||||
|  |                                         }); | ||||||
|  |                                     }).Error(ex=>reply.TriggerError(ex)); | ||||||
|  |                                 } | ||||||
|  |                                 else | ||||||
|  |                                 { | ||||||
|  |                                     Codec.ParsePropertyValueArray((byte[])rt[3], this).Then((ar) => | ||||||
|  |                                     { | ||||||
|  |                                         dr._Attach(ar); | ||||||
|  |                                         resourceRequests.Remove(id); | ||||||
|  |                                         reply.Trigger(dr); | ||||||
|  |                                     }).Error(ex=>reply.TriggerError(ex)); | ||||||
|  |                                 } | ||||||
|  |  | ||||||
|                             }).Error((ex) => |                             }).Error((ex) => | ||||||
|                             { |                             { | ||||||
|                                 reply.TriggerError(ex); |                                 reply.TriggerError(ex); | ||||||
|   | |||||||
| @@ -535,25 +535,11 @@ namespace Esiur.Resource | |||||||
|                 parent = null; |                 parent = null; | ||||||
|  |  | ||||||
|  |  | ||||||
|             /* |              | ||||||
|             if (parent == null) |  | ||||||
|             { |  | ||||||
|                 if (!(resource is IStore)) |  | ||||||
|                     store.Instance.Children.Add(resource); |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|                 parent.Instance.Children.Add(resource); |  | ||||||
|                */ |  | ||||||
|  |  | ||||||
|  |  | ||||||
|             if (resource is IStore) |             if (resource is IStore) | ||||||
|             { |  | ||||||
|  |  | ||||||
|                 stores.TryAdd(resource as IStore, new List<WeakReference<IResource>>()); |                 stores.TryAdd(resource as IStore, new List<WeakReference<IResource>>()); | ||||||
|                 StoreConnected?.Invoke(resource as IStore, name); |              | ||||||
|             } |  | ||||||
|             //else |  | ||||||
|  |  | ||||||
|  |  | ||||||
|             if (!await store.Put(resource)) |             if (!await store.Put(resource)) | ||||||
|                 return false; |                 return false; | ||||||
| @@ -563,16 +549,12 @@ namespace Esiur.Resource | |||||||
|             { |             { | ||||||
|                 await parent.Instance.Store.AddChild(parent, resource); |                 await parent.Instance.Store.AddChild(parent, resource); | ||||||
|                 await store.AddParent(resource, parent); |                 await store.AddParent(resource, parent); | ||||||
|                 //store.AddChild(parent, resource); |  | ||||||
|  |  | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             var t = resource.GetType(); |             var t = resource.GetType(); | ||||||
|             Global.Counters["T-" + t.Namespace + "." + t.Name]++; |             Global.Counters["T-" + t.Namespace + "." + t.Name]++; | ||||||
|  |  | ||||||
|             //var wr = new WeakReference<IResource>(resource); |  | ||||||
|  |  | ||||||
|             //lock (resourcesLock) |  | ||||||
|             resources.TryAdd(resource.Instance.Id, resourceReference); |             resources.TryAdd(resource.Instance.Id, resourceReference); | ||||||
|  |  | ||||||
|             if (warehouseIsOpen) |             if (warehouseIsOpen) | ||||||
| @@ -580,11 +562,12 @@ namespace Esiur.Resource | |||||||
|                 await resource.Trigger(ResourceTrigger.Initialize); |                 await resource.Trigger(ResourceTrigger.Initialize); | ||||||
|                 if (resource is IStore) |                 if (resource is IStore) | ||||||
|                     await resource.Trigger(ResourceTrigger.Open); |                     await resource.Trigger(ResourceTrigger.Open); | ||||||
|  |  | ||||||
|                 return true; |  | ||||||
|             } |             } | ||||||
|             else |              | ||||||
|                 return true; |             if (resource is IStore) | ||||||
|  |                 StoreConnected?.Invoke(resource as IStore, name); | ||||||
|  |  | ||||||
|  |             return true; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user