private OperationResponse ItemOperationAttachInterestArea( Item item, AttachInterestArea operation, InterestArea interestArea, SendParameters sendParameters) { if (item.Disposed) { return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound"); } lock (interestArea.SyncRoot) { interestArea.Detach(); interestArea.AttachToItem(item); interestArea.UpdateInterestManagement(); } // use item channel to ensure that this event arrives before any move or subscribe events OperationResponse response = operation.GetOperationResponse(MethodReturnValue.Ok); sendParameters.ChannelId = Settings.ItemEventChannel; this.Peer.SendOperationResponse(response, sendParameters); operation.OnComplete(); return null; }
/// <summary> /// Handles operation AttachInterestArea: Attaches an existing InterestArea to an existing Item. /// </summary> public OperationResponse OperationAttachInterestArea(PeerBase peer, OperationRequest request, SendParameters sendParameters) { var operation = new AttachInterestArea(peer.Protocol, request); if (!operation.IsValid) { return new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() }; } operation.OnStart(); InterestArea interestArea; if (this.TryGetInterestArea(operation.InterestAreaId, out interestArea) == false) { return operation.GetOperationResponse((int)ReturnCode.InterestAreaNotFound, "InterestAreaNotFound"); } Item item; bool actorItem; if (string.IsNullOrEmpty(operation.ItemId)) { item = this.Avatar; actorItem = true; // set return vaues operation.ItemId = item.Id; } else { actorItem = this.TryGetItem(operation.ItemId, out item); } if (actorItem) { // we are already in the item thread, invoke directly return this.ItemOperationAttachInterestArea(item, operation, interestArea, sendParameters); } else { // search world cache just to see if item exists at all if (this.World.ItemCache.TryGetItem(operation.ItemId, out item) == false) { return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound"); } else { // second parameter (peer) allows us to send an error event to the client (in case of an error) item.Fiber.Enqueue(() => this.ExecItemOperation(() => this.ItemOperationAttachInterestArea(item, operation, interestArea, sendParameters), sendParameters)); // response is sent later return null; } } }