Exemplo n.º 1
0
        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."
                });
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        private void buttonLoad_Click(object sender, EventArgs e)
        {
            PeerNearMeCollection peerNearMeCollection = PeerCollaboration.GetPeersNearMe();

            foreach (PeerNearMe peerNearMe in peerNearMeCollection)
            {
                peerNearMe.RefreshDataAsync("Load");
            }
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        //------------------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------------------
        // <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);
        }
Exemplo n.º 6
0
        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");
                }
            }
        }
Exemplo n.º 7
0
        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);
        }