コード例 #1
0
        public void Leave(Peer peer)
        {
            registration.Stop();
            SuperPeerServiceClient ssc = new SuperPeerServiceClient();

            ssc.RemovePeer(peer);
        }
コード例 #2
0
        /// <summary>
        /// Creates a PeerName and registers it along with the metadata specified as command line arguments
        /// </summary>
        private static void CreateAndPublishPeerName()
        {
            try{
                // Creates a the PeerName to register using the classifier and type provided on the command line
                PeerName peerName = new PeerName(peerNameClassifier, peerNameType);

                // Create a registration object which represents the registration of the PeerName in a Cloud
                PeerNameRegistration peerNameRegistration = new PeerNameRegistration();
                peerNameRegistration.PeerName = peerName;
                peerNameRegistration.Port     = portNumber;
                peerNameRegistration.Comment  = comment;
                peerNameRegistration.Cloud    = cloudName;
                // Since the peerNameRegistration.EndPointCollection is not specified, all (IPv4&IPv6)
                // addresses assigned to the local host will automatically be assocaited with the
                // peerNameRegistration instance.  This behavior can be control via peerNameRegistration.UseAutoEndPointSelection

                //Note: Additional information may be specified on the PeerNameRegistration object, which is not shown in this example.

                //Starting the registration means the name is published for other peers to resolve
                peerNameRegistration.Start();
                Console.WriteLine("Registration of Peer Name: {0} complete.", peerName.ToString(), cloudName);
                Console.WriteLine();

                Console.WriteLine("Press any key to stop the registration and close the program");
                Console.ReadKey();

                // Stopping the registration means the name is no longer published
                peerNameRegistration.Stop();
            } catch (Exception e) {
                Console.WriteLine("Error creating and registering the PeerName: {0} \n", e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
コード例 #3
0
        private static void Main(string[] args)
        {
            // Creates a secure (not spoofable) PeerName
            var peerName = new PeerName("MikesWebServer", PeerNameType.Secured);
            var pnReg    = new PeerNameRegistration {
                PeerName = peerName,
                Port     = 80,
                //OPTIONAL
                //The properties set below are optional.  You can register a PeerName without setting these properties
                Comment = "up to 39 unicode char comment",
                Data    = Encoding.UTF8.GetBytes("A data blob associated with the name")
            };

            /*
             * OPTIONAL
             * The properties below are also optional, but will not be set (ie. are commented out) for this example
             * pnReg.IPEndPointCollection = // a list of all {IPv4/v6 address, port} pairs to associate with the peername
             * pnReg.Cloud = //the scope in which the name should be registered (local subnet, internet, etc)
             */

            //Starting the registration means the name is published for others to resolve
            pnReg.Start();
            Console.WriteLine("Registration of Peer Name: {0} complete.", peerName);
            Console.WriteLine();
            Console.WriteLine("Press any key to stop the registration and close the program");
            Console.ReadKey();

            pnReg.Stop();
        }
コード例 #4
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // Остановка регистрации
            peerNameRegistration.Stop();

            // Остановка WCF-сервиса
            host.Close();
        }
コード例 #5
0
 public void StopPeerRegistration()
 {
     if (_peerNameRegistration != null)
     {
         _peerNameRegistration?.Stop();
         _peerNameRegistration = null;
     }
 }
コード例 #6
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // stop registration
            _peerNameRegistration.Stop();

            // stop wcf service
            _host.Close();
        }
コード例 #7
0
 public void Dispose()
 {
     if (peerNameRegistration != null)
     {
         peerNameRegistration.Stop();
         peerNameRegistration = null;
     }
 }
コード例 #8
0
 public void Stop()
 {
     if (_peerNameRegistration != null)
     {
         _peerNameRegistration.Stop();
     }
     _peerNameRegistration = null;
 }
コード例 #9
0
        static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
        {
            if (registration != null)
            {
                registration.Stop();
            }

            if (host != null)
            {
                host.Close();
            }
        }
コード例 #10
0
        private void Window_Closed(object sender, EventArgs e)
        {
            _logger.Debug("Closing window...");

            _registration.Stop();
            foreach (var peer in AvailablePeers)
            {
                peer.PeerEntry.ServiceProxy.ExcludeFromList(_user.DisplayedName);
            }

            _host.Close();
            _refreshPeerTimer = null;
        }
コード例 #11
0
        protected override void OnClosing(CancelEventArgs e)
        {
            // Остановить регистрацию
            _peerNameRegistration.Stop();
            _peerNameRegistration.Dispose();

            // Остановить WCF-сервис
            if (_host.State == CommunicationState.Opened)
            {
                _host.Close();
            }

            base.OnClosing(e);
        }
コード例 #12
0
        protected override void OnClosing(CancelEventArgs e)
        {
            // Stop registration
            peerNameRegistration.Stop();
            peerNameRegistration.Dispose();

            // Stop WCF service
            if (host.State == CommunicationState.Opened)
            {
                host.Close();
            }

            base.OnClosing(e);
        }
コード例 #13
0
        internal void Closing()
        {
            try
            {
                // Остановка регистрации
                peerNameRegistration?.Stop();

                // Остановка сервиса
                host?.Close();
            }
            catch (InvalidOperationException)
            {
                // ...
            }
        }
コード例 #14
0
        private void Stop()
        {
            if (!Started)
            {
                return;
            }
            Started = false;

            #region Взято отюда: https://professorweb.ru/my/csharp/web/level8/8_3.php

            // Остановка регистрации
            peerNameRegistration.Stop();

            // Остановка WCF-сервиса
            host.Close();

            #endregion
        }
コード例 #15
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                }

                // Остановка регистрации
                peerNameRegistration.Stop();

                // Остановка WCF-сервиса
                host.Close();

                disposedValue = true;
            }
        }
コード例 #16
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (textBox_talk.Text == "")
            {
                return;
            }
            resourceNameReg.Stop();
            register();
            resourceNameReg.Start();

            ListViewItem item = new ListViewItem();

            item.SubItems.Add(resourceNameReg.Comment);
            item.SubItems.Add(textBox_Name.Text);
            item.SubItems.Add(textBox_talk.Text);
            listView1.Items.Add(item);

            textBox_talk.Text = "";
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: Br3nda/sfdocsamples
        static void Main(string[] args)
        {
            foreach (Cloud c in Cloud.GetAvailableClouds())
            {
                Console.WriteLine("Cloud: {0}", c.Name);
            }

            Console.WriteLine();
            Console.Write("Enter Peer Name Classifier: ");
            string classifier = Console.ReadLine();

            PeerName peerName = new PeerName(classifier, PeerNameType.Unsecured);

            using (PeerNameRegistration registration = new PeerNameRegistration(peerName, 8080))
            {
                string timestamp = string.Format("Peer Created at: {0}", DateTime.Now.ToShortTimeString());
                registration.Comment = timestamp;

                UnicodeEncoding encoding = new UnicodeEncoding();
                byte[]          data     = encoding.GetBytes(timestamp);
                registration.Data = data;

                try
                {
                    registration.Start();

                    Console.WriteLine("Peer Registration Successful.");
                    Console.WriteLine("Peer Host Name: {0}", registration.PeerName.PeerHostName);

                    Console.WriteLine("Press Enter to Exit...");
                    Console.ReadLine();

                    registration.Stop();
                }
                catch (PeerToPeerException ex)
                {
                    Console.WriteLine("PeerToPeer Exception: {0}", ex.Message);
                }
            }
        }
コード例 #18
0
        public void StartService()
        {
            Peer = new PeerName(App.ClientIdentifier, PeerNameType.Unsecured);
            PeerNameRegistration registeration = new PeerNameRegistration(Peer, 3030);

            registeration.Cloud   = Cloud.Available;
            registeration.Comment = App.AppId.ToString();
            Console.WriteLine(string.Join(Environment.NewLine, Cloud.GetAvailableClouds().Select(s => "name: " + s.Name + " scope: " + s.Scope)));
            registeration.Start();

            host = new ServiceHost(this);
            host.CloseTimeout = TimeSpan.FromMilliseconds(1);
            host.Open(TimeSpan.FromDays(100));


            channelFactory = new ChannelFactory <ISurveyExchangeService>("SurveyExchangeServiceEndpoint");
            Channel        = channelFactory.CreateChannel();

            //żaden event na host ani channel nie zwraca od kiedy service działa
            Thread.Sleep(2000);
            Channel.Ping(App.AppId);
            host.Closing += (sender, e) => registeration.Stop();
        }
コード例 #19
0
 public void removeRegistration()
 {
     _stopFlag.Set();
     mRegistration.Stop();
 }
コード例 #20
0
 public void Stop()
 {
     Console.WriteLine("Stop registration and host");
     peerNameRegistration.Stop(); //stop registration
     host.Close();                //stop wcf
 }
コード例 #21
0
ファイル: Program.cs プロジェクト: RyuumaKishita/DemoP2P.Net
        static void Main(string[] args)
        {
            try
            {
                if (args.Length != 4)
                {
#if DEBUG
                    Console.WriteLine("invalid arguments");
                    Console.ReadLine();
#endif
                    return;
                }

                string pipeName         = args[0];
                string connectionTarget = args[1];
                string portNoStr        = args[2];
                string param3           = args[3];
#if DEBUG
                Console.WriteLine($"{nameof(pipeName)}={pipeName},{nameof(connectionTarget)}={connectionTarget},{nameof(portNoStr)}={portNoStr},{nameof(param3)}={param3}");
#endif

                int      portNo   = int.Parse(portNoStr);
                PeerName peerName = null;
                Cloud    cloud    = null;

                switch (connectionTarget.ToLower())
                {
                case "global":
                    cloud    = Cloud.Global;
                    peerName = PeerName.CreateFromPeerHostName(param3);
                    break;

                case "local":
                    cloud    = Cloud.AllLinkLocal;
                    peerName = new PeerName(param3, PeerNameType.Secured);
                    break;

                default:
                    throw new ArgumentException("invalid argument", "param 1");
                }

                using (var namedPipeRead = new NamedPipeClientStream(".", pipeName, PipeDirection.In, PipeOptions.Asynchronous))
                {
                    namedPipeRead.Connect();
#if DEBUG
                    Console.WriteLine("connect named pipe");
#endif
                    var peerNameRegistration = new PeerNameRegistration(peerName, portNo, cloud);
                    try
                    {
                        while (namedPipeRead.IsConnected)
                        {
                            var readBuffer = new byte[4096];
                            int length     = namedPipeRead.Read(readBuffer, 0, readBuffer.Length);
#if DEBUG
                            //Console.WriteLine($"read {nameof(buffer)}[{length}]={BitConverter.ToString(buffer, 0, length).Replace("-", string.Empty)}");
                            Console.WriteLine("read");
#endif
                            if (0 == length)
                            {
                                ;
                            }
                            else
                            {
#if DEBUG
                                Console.WriteLine("regist start");
#endif
                                var registBuffer = new byte[length];
                                Buffer.BlockCopy(readBuffer, 0, registBuffer, 0, length);
                                peerNameRegistration.Data = registBuffer;
                                if (peerNameRegistration.IsRegistered())
                                {
                                    peerNameRegistration.Update();
                                }
                                else
                                {
                                    peerNameRegistration.Start();
                                }
#if DEBUG
                                Console.WriteLine("regist end");
#endif
                            }
                        }
                    }
                    finally
                    {
                        peerNameRegistration.Stop();
                    }
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.WriteLine(ex);
                Console.ReadLine();
#endif
            }
#if DEBUG
            Console.WriteLine("end");
#endif
        }
コード例 #22
0
 public void Stop()
 {
     _peerRegist.Stop();
 }
コード例 #23
0
 public static void DeregisterNodeInPNRP()
 {
     _peerNameRegistration.Stop();
 }
コード例 #24
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     _pnr.Stop();
     _host.Close();
 }
コード例 #25
0
 public void Dispose()
 {
     _nameRegistrator.Stop();
 }
コード例 #26
0
 internal void Stop()
 {
     //Stop the publish for others to resolve
     Logger.Log.Info("Stop P2P.");
     pnReg.Stop();
 }