private void RefreshButton_Click(object sender, RoutedEventArgs e) { // Get local peers PeerNearMeCollection peersNearMe = PeerCollaboration.GetPeersNearMe(); // Prepare for new peers PeerList.Items.Clear(); // Examine peers foreach (PeerNearMe peerNearMe in peersNearMe) { PeerList.Items.Add( new PeerEntry { PeerNearMe = peerNearMe, PresenceStatus = peerNearMe.GetPresenceInfo(peerNearMe.PeerEndPoints[0]).PresenceStatus, DisplayString = peerNearMe.Nickname }); } // Add failure message if necessary if (PeerList.Items.Count == 0) { PeerList.Items.Add( new PeerEntry { DisplayString = "No peers found." }); } }
// </Snippet4> //------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------ // <Snippet5> // Enumerating all local registered applications. private static void EnumLocalRegisteredApplications() { PeerApplicationCollection pac = null; Console.WriteLine("Attempting to enumerate all local registered collaboration applications..."); try { pac = PeerCollaboration.GetLocalRegisteredApplications(PeerApplicationRegistrationType.AllUsers); foreach (PeerApplication pa in pac) { Console.WriteLine("Registered application:\n ID: {0}\n Description: {1}\n", pa.Id, pa.Description); } } catch (PeerToPeerException p2pEx) { Console.WriteLine("The Peer Collaboration Infrastructure could not return an enumeration of the registered applications: {0}", p2pEx.Message); } catch (Exception ex) { Console.WriteLine("Unexpected exception caught when trying to enumerate the registered collaboration applications: {0}.", ex.Message); } finally { foreach (PeerApplication pa in pac) { pa.Dispose(); } } return; }
private void btnGet_Click(object sender, RoutedEventArgs e) { // 取得目前所有登入的Peer端點 PeerNearMeCollection pnmc = PeerCollaboration.GetPeersNearMe(); String str = ""; foreach (PeerNearMe pnm in pnmc) { // 取得Peer端點的暱稱 str = pnm.Nickname; // 取得Peer端點的位置 PeerEndPointCollection pepc = pnm.PeerEndPoints; foreach (PeerEndPoint pep in pepc) { // 回傳System.Net.IPEndPoint物件 IPEndPoint ipEndPoint = pep.EndPoint; // 取得Peer端點的IP位址 str = str + ", " + ipEndPoint.Address.ToString() + ":"; // 取得Peer端點的通訊埠 str = str + ipEndPoint.Port.ToString(); } lstPeer.Items.Add(str); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { // Sign in to PNM PeerCollaboration.SignIn(PeerScope.NearMe); // Get local peer name to display this.Title = string.Format("PNMSample - {0}", ContactManager.LocalContact.Nickname); }
private void buttonLoad_Click(object sender, EventArgs e) { PeerNearMeCollection peerNearMeCollection = PeerCollaboration.GetPeersNearMe(); foreach (PeerNearMe peerNearMe in peerNearMeCollection) { peerNearMe.RefreshDataAsync("Load"); } }
private void btnSignIn_Click(object sender, RoutedEventArgs e) { // 登入至Internet之範圍 PeerCollaboration.SignIn(PeerScope.NearMe); // 宣告當Peer端點登入或登出時所觸發之事件 // 並定義所呼叫的方法為PeerNearMeChangedCallback PeerNearMe.PeerNearMeChanged += new EventHandler <PeerNearMeChangedEventArgs>(PeerNearMeChangedCallback); }
private void ClosePeer() { if (!PeerOpened) { return; } PeerNearMe.PeerNearMeChanged -= PeerNearMe_PeerNearMeChanged; PeerCollaboration.SignOut(PeerScope); peerObject.Dispose(); peerObject = null; }
private void SetSendData() { peerObject.Data = Data; try { PeerCollaboration.SetObject(peerObject); AddLog(ContactManager.LocalContact.Nickname, Data, LogType.Send); } catch (Exception ex) { AddLog("SetSendData:" + ex.Message, LogType.System); } }
//------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------ // <Snippet1> //This function signs the users into the Collaboration Infrastructure. public static bool PeerCollabSignin() { bool result = false; try { PeerCollaboration.SignIn(PeerScope.All); result = true; } catch (Exception ex) { Console.WriteLine("Error signing in: {0}", ex.Message); } return(result); }
// </Snippet3> //------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------ // <Snippet4> // Registering Notepad.exe as a collab application with a fixed GUID. // Note: If you're using the application to send invitations, // the same application with the same GUID must be registered on the remote peer machine. private static PeerApplication RegisterCollabApp() { PeerApplication application = null; string pathToApp = "%SystemRoot%\\notepad.exe"; Guid appGuid = new Guid(0xAAAAAAAA, 0xFADE, 0xDEAF, 0xBE, 0xEF, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAE); application = new PeerApplication(); application.Id = appGuid; application.Path = pathToApp; application.Description = "Peer Collaboration Sample -- notepad.exe"; application.PeerScope = PeerScope.All; application.CommandLineArgs = "n"; application.Data = ASCIIEncoding.ASCII.GetBytes("Test"); Console.WriteLine("Attempting to register the application \"notepad.exe\"..."); try { PeerApplicationCollection pac = PeerCollaboration.GetLocalRegisteredApplications(PeerApplicationRegistrationType.AllUsers); if (pac.Contains(application)) { Console.WriteLine("The application is already registered on the peer."); } else { PeerCollaboration.RegisterApplication(application, PeerApplicationRegistrationType.AllUsers); Console.WriteLine("Application registration succeeded!"); } } catch (ArgumentException argEx) { Console.WriteLine("The application was previously registered with the Peer Collaboration Infrastructure: {0}.", argEx.Message); } catch (PeerToPeerException p2pEx) { Console.WriteLine("The application failed to register with the Peer Collaboration Infrastructure: {0}", p2pEx.Message); } catch (Exception ex) { Console.WriteLine("An unexpected exception occurred when trying to register the application: {0}.", ex.Message); } return(application); }
static void Main(string[] args) { /* PeerName pn = new PeerName("Peer classifier", PeerNameType.Unsecured); * PeerNameRegistration pnr = new PeerNameRegistration(pn, 8080); * pnr.Comment = "Комментарий"; * pnr.Cloud = Cloud.Available; * pnr.Start();*/ //PeerCollaboration.SignIn(PeerScope.Internet); var peers = PeerCollaboration.GetPeersNearMe(); peers[0].AddToContactManager("displayName", "nickName", null); Console.ReadKey(); // PeerName pn = new PeerName("0.Peer classifier"); //PeerNameResolver pnres = new PeerNameResolver(); //PeerNameRecordCollection pnrc = pnres.Resolve(pn, Cloud.AllLinkLocal, 5); //Console.ReadKey(); }
//------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------ // <Snippet2> //This function retrieves the peers near me as a PeerNearMeCollection. public static PeerNearMeCollection GetPeersNearMe() { PeerNearMeCollection peers = null; try { peers = PeerCollaboration.GetPeersNearMe(); if (peers == null || peers.Count == 0) { Console.WriteLine("There are no peers near me."); } foreach (PeerNearMe pnm in peers) { Console.WriteLine("Getting the peers near me: {0}, nickname {1}, isOnline {2}", pnm.ToString(), pnm.Nickname, pnm.IsOnline); } } catch (PeerToPeerException p2pEx) { Console.WriteLine("Could not obtain an enumeration of the peers near me: {0}", p2pEx.Message); } catch (InvalidOperationException ioEx) { Console.WriteLine("The application is no longer signed into the Peer Collaboration Infrastructure: {0}", ioEx.Message); } catch (Exception ex) { Console.WriteLine("Unexpected exception caught when trying to enumerate the peers near me: {0}", ex.Message); } return(peers); }
private void buttonStartOrUpdate_Click(object sender, EventArgs e) { if (PeerOpened) { AddLog("UpdateSend", LogType.System); SetSendData(); } else { try { PeerCollaboration.SignIn(PeerScope); } catch (PeerToPeerException ex) { AddLog("SignIn:" + ex.Message, LogType.System); return; } SetupPeer(); UpdateUI(); PeerNearMe.PeerNearMeChanged += PeerNearMe_PeerNearMeChanged; AddLog("StartPeer", LogType.System); SetSendData(); //buttonLoad.PerformClick(); PeerNearMeCollection peerNearMeCollection = PeerCollaboration.GetPeersNearMe(); foreach (PeerNearMe peerNearMe in peerNearMeCollection) { peerNearMe.RefreshDataCompleted += peerNearMe_RefreshDataCompleted; peerNearMe.RefreshDataAsync("Setup"); } } }
public static PeerNearMe CreateFromPeerEndPoint(PeerEndPoint peerEndPoint) { Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "Entering CreateFromPeerEndPoint."); CollaborationHelperFunctions.Initialize(); if (peerEndPoint == null) { throw new ArgumentNullException("peerEndPoint"); } if (peerEndPoint.EndPoint == null) { throw new PeerToPeerException(SR.GetString(SR.Collab_NoEndPointInPeerEndPoint)); } PeerNearMeCollection peers = PeerCollaboration.GetPeersNearMe(); PeerNearMe peer = null; foreach (PeerNearMe peerNearMe in peers) { PeerEndPointCollection peerEndPoints = peerNearMe.PeerEndPoints; if ((peerEndPoints != null) && (peerEndPoints.Count != 0) && (peerEndPoints[0].Equals(peerEndPoint))) { peer = peerNearMe; } } if (peer == null) { // // No peer found, throw // throw new PeerToPeerException(SR.GetString(SR.Collab_EndPointNotAPeerNearMe)); } Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "Leaving CreateFromPeerEndPoint."); return(peer); }
private void btnSignIn_Click(object sender, RoutedEventArgs e) { // 登入至Internet之範圍 PeerCollaboration.SignIn(PeerScope.NearMe); }
private void btnSignOut_Click(object sender, RoutedEventArgs e) { // 登出近端分享 PeerCollaboration.SignOut(PeerScope.NearMe); }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { // Sign out of PNM PeerCollaboration.SignOut(PeerScope.NearMe); }