public override PeerInvitationResponse Invite(PeerApplication applicationToInvite, string message, byte[] invitationData) { if (m_Disposed) { throw new ObjectDisposedException(this.GetType().FullName); } PeerCollaborationPermission.UnrestrictedPeerCollaborationPermission.Demand(); if (applicationToInvite == null) { throw new ArgumentNullException("applicationToInvite"); } if (applicationToInvite.Id == Guid.Empty) { throw new PeerToPeerException(SR.GetString(SR.Collab_EmptyGuidError)); } // // We need at least one endpoint to send invitation to // PeerEndPointCollection peerEndPoints = PeerEndPoints; if ((peerEndPoints == null) || (peerEndPoints.Count == 0)) { throw new PeerToPeerException(SR.GetString(SR.Collab_NoEndpointFound)); } PeerEndPoint peerEndPoint = PeerEndPoints[0]; PeerInvitationResponse response = InternalInviteEndPoint(applicationToInvite.Id, message, invitationData, peerEndPoint, null); // throw an exception if the response type is ERROR CollaborationHelperFunctions.ThrowIfInvitationResponseInvalid(response); return(response); }
public override void InviteAsync(PeerApplication applicationToInvite, string message, byte[] invitationData, Object userToken) { if (m_Disposed) { throw new ObjectDisposedException(this.GetType().FullName); } PeerCollaborationPermission.UnrestrictedPeerCollaborationPermission.Demand(); if (applicationToInvite == null) { throw new ArgumentNullException("applicationToInvite"); } if (applicationToInvite.Id == Guid.Empty) { throw new PeerToPeerException(SR.GetString(SR.Collab_EmptyGuidError)); } if (userToken == null) { throw new ArgumentException(SR.GetString(SR.NullUserToken)); } // // We need at least one endpoint to send invitation to // PeerEndPointCollection peerEndPoints = PeerEndPoints; if ((peerEndPoints == null) || (peerEndPoints.Count == 0)) { throw new PeerToPeerException(SR.GetString(SR.Collab_NoEndpointFound)); } InternalInviteAsync(applicationToInvite.Id, message, invitationData, peerEndPoints, null, userToken); }
internal override void ApplicationChangedCallback(object state, bool timedOut) { SafeCollabData eventData = null; int errorCode = 0; Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "ApplicationChangedCallback() called."); if (m_Disposed) { return; } while (true) { ApplicationChangedEventArgs appChangedArgs = null; // // Get the event data for the fired event // try{ lock (LockAppChangedEvent){ if (m_safeAppChangedEvent.IsInvalid) { return; } errorCode = UnsafeCollabNativeMethods.PeerCollabGetEventData(m_safeAppChangedEvent, out eventData); } if (errorCode == UnsafeCollabReturnCodes.PEER_S_NO_EVENT_DATA) { break; } else if (errorCode != 0) { Logging.P2PTraceSource.TraceEvent(TraceEventType.Error, 0, "PeerCollabGetEventData returned with errorcode {0}", errorCode); throw PeerToPeerException.CreateFromHr(SR.GetString(SR.Collab_GetApplicationChangedDataFailed), errorCode); } PEER_COLLAB_EVENT_DATA ped = (PEER_COLLAB_EVENT_DATA)Marshal.PtrToStructure(eventData.DangerousGetHandle(), typeof(PEER_COLLAB_EVENT_DATA)); if (ped.eventType == PeerCollabEventType.MyApplicationChanged) { PEER_EVENT_APPLICATION_CHANGED_DATA appData = ped.applicationChangedData; PEER_APPLICATION pa = (PEER_APPLICATION)Marshal.PtrToStructure(appData.pApplication, typeof(PEER_APPLICATION)); PeerApplication peerApplication = CollaborationHelperFunctions.ConvertPEER_APPLICATIONToPeerApplication(pa);; PeerEndPoint peerEndPoint = null; if (appData.pEndPoint != IntPtr.Zero) { PEER_ENDPOINT pe = (PEER_ENDPOINT)Marshal.PtrToStructure(appData.pEndPoint, typeof(PEER_ENDPOINT)); peerEndPoint = CollaborationHelperFunctions.ConvertPEER_ENDPOINTToPeerEndPoint(pe); } appChangedArgs = new ApplicationChangedEventArgs(peerEndPoint, null, appData.changeType, peerApplication); } } finally{ if (eventData != null) { eventData.Dispose(); } } // // Fire the callback with the marshalled event args data // if (appChangedArgs != null) { OnApplicationChanged(appChangedArgs); } } Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "Leaving ApplicationChangedCallback()."); }