private void HandleHandoverResponse(Session session, HandoverResponseMessage handoverResponse) { BubbleLink bubbleLink = bubble.GetBubbleLink(session); foreach (Handover handover in handovers) { if (handoverResponse.RequestMessageId == handover.HandoverRequestMessageId) { LogUtil.Info("Received handover response (" + handoverResponse.FailureCode + ") from " + bubbleLink.RemoteBubbleName + " to " + bubble.BubbleName + " for object " + handover.ObjectId + ")."); // If failure then rollback if (handoverResponse.FailureCode != MxpResponseCodes.SUCCESS) { bubble.CloudCache.PutObject(handover.CloudObject, true); } else { ParticipantLink participant = bubble.GetParticipant(handover.ParticipantId); Session participantSession = bubble.GetParticipantSession(participant); HandoverEventMessage handoverEvent = new HandoverEventMessage(); handoverEvent.SourceBubbleId = bubble.BubbleId; handoverEvent.TargetBubbleId = handover.RemoteBubbleId; handover.CloudObject.ToObjectFragment(handoverEvent.ObjectFragment); participantSession.Send(handoverEvent); } } } }
private void RequestIdentify(BubbleLink bubbleLink, CloudObject cloudObject) { Session session = bubble.GetBubbleLinkSession(bubbleLink); Guid participantId = cloudObject.OwnerId; ParticipantLink participantLink = bubble.GetParticipant(cloudObject.OwnerId); // Delegate to access participant identity string participantIdentity = CloudParticipantIdentify(participantId); IdentifyRequestMessage identifyRequest = (IdentifyRequestMessage)MessageFactory.Current.ReserveMessage(typeof(IdentifyRequestMessage)); identifyRequest.ParticipantId = participantId; identifyRequest.ParticipantIdentityType = IdentifyRequestMessage.OPEN_ID_IDENTITY; identifyRequest.ParticipantIdentity = participantIdentity; Handover handover = new Handover(); handover.Started = DateTime.Now; handover.RemoteBubbleId = bubbleLink.RemoteBubbleId; handover.ParticipantId = cloudObject.OwnerId; handover.ObjectId = cloudObject.ObjectId; handover.IdentityRequestMessageId = identifyRequest.MessageId; handovers.Add(handover); LogUtil.Info("Sent identify request from " + bubble.BubbleName + " to " + bubbleLink.RemoteBubbleName + " for " + identifyRequest.ParticipantIdentity + " (" + identifyRequest.ParticipantIdentityType + ") to be able to handover object " + cloudObject.ObjectId + "."); session.Send(identifyRequest); }
private void HandleIdentifyResponse(Session session, IdentifyResponseMessage identifyResponse) { foreach (Handover handover in handovers) { if (identifyResponse.RequestMessageId == handover.IdentityRequestMessageId) { CloudObject cloudObject = bubble.CloudCache.GetObject(handover.ObjectId); if (cloudObject == null) { return; } if (cloudObject.BubbleId != bubble.BubbleId) { throw new Exception("Remote objects can not need to be handed over."); } ParticipantLink participantLink = bubble.GetParticipant(cloudObject.OwnerId); BubbleLink bubbleLink = bubble.GetBubbleLink(handover.RemoteBubbleId); LogUtil.Info("Received identify response (" + identifyResponse.FailureCode + ") from " + bubble.BubbleName + " to " + bubbleLink.RemoteBubbleName + " to be able to handover object " + handover.ObjectId + "."); if (identifyResponse.FailureCode != MxpResponseCodes.SUCCESS) { return; } HandoverRequestMessage handoverRequest = (HandoverRequestMessage)MessageFactory.Current.ReserveMessage(typeof(HandoverRequestMessage)); handoverRequest.SourceBubbleId = bubble.BubbleId; handoverRequest.TargetBubbleId = handover.RemoteBubbleId; cloudObject.ToObjectFragment(handoverRequest.ObjectFragment); handoverRequest.ObjectFragment.Location.X = cloudObject.Location.X - bubbleLink.RemoteBubbleCenter.X; handoverRequest.ObjectFragment.Location.Y = cloudObject.Location.Y - bubbleLink.RemoteBubbleCenter.Y; handoverRequest.ObjectFragment.Location.Z = cloudObject.Location.Z - bubbleLink.RemoteBubbleCenter.Z; handover.HandoverRequestMessageId = handoverRequest.MessageId; session.Send(handoverRequest); // Storing cloud object in case of rollback handover.CloudObject = cloudObject; // Removing cloud object from bubble. bubble.CloudCache.RemoveObject(cloudObject.ObjectId); return; } } }