Ejemplo n.º 1
0
        public NetPeerServer(string MyBaseAddress)
        {
            cprs = new CustomPeerResolverService();
            cprs.ControlShape = true;

            host = new ServiceHost(cprs, new Uri[] { new Uri(MyBaseAddress) });
        }
Ejemplo n.º 2
0
 public static void Stop()
 {
     crs.Close();
     customResolver.Close();
     crs = null;
     customResolver = null;
 }
Ejemplo n.º 3
0
 public static void Start()
 {
     if (crs == null && customResolver == null)
     {
         crs = new CustomPeerResolverService();
         crs.ControlShape = false;
         customResolver = new ServiceHost(crs);
         crs.Open();
         customResolver.BeginOpen((AsyncCallback)((t) =>
         {
             App.Log.Info("Служба разрешения имен запущена успешно!");
             App.ViewModel.AddLogMessage("Служба разрешения имен запущена успешно!");
         }), null);//.Open();
     }
 }
Ejemplo n.º 4
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     try
     {
         cprs = new CustomPeerResolverService();
         cprs.RefreshInterval = TimeSpan.FromSeconds(5);
         host = new ServiceHost(cprs);
         cprs.ControlShape = true;
         cprs.Open();
         host.Open(TimeSpan.FromDays(1000000));
         lblMessage.Text = "Serwer zosta³ uruchomiony.";
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         btnStartServer.Enabled = false;
         btnStopServer.Enabled = true;
     }
 }
Ejemplo n.º 5
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     try
     {
         Binding bind = new NetPeerTcpBinding();
         cprs = new CustomPeerResolverService();
         cprs.RefreshInterval = TimeSpan.FromSeconds(5);
         host = new ServiceHost(cprs, new Uri[] { new Uri("net.tcp://127.0.0.1/ChatServer") });
         cprs.ControlShape = true;
         cprs.Open();
         host.Open(TimeSpan.FromDays(1000000));
         lblMessage.Text = "Server started successfully.";
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         btnStart.Enabled = false;
         btnStop.Enabled = true;
     }
 }
Ejemplo n.º 6
0
		protected void SetUp ()
		{
			cprs = new CustomPeerResolverService ();
		}
 public static void Release(CustomPeerResolverService.LiteLock liteLock)
 {
     if (liteLock != null)
     {
         if (liteLock.forWrite)
         {
             liteLock.locker.ReleaseWriterLock();
         }
         else
         {
             liteLock.locker.ReleaseReaderLock();
         }
     }
 }
 public static void Acquire(out CustomPeerResolverService.LiteLock liteLock, ReaderWriterLock locker, bool forWrite)
 {
     CustomPeerResolverService.LiteLock @lock = new CustomPeerResolverService.LiteLock(locker, forWrite);
     try
     {
     }
     finally
     {
         if (forWrite)
         {
             locker.AcquireWriterLock(@lock.timeout);
         }
         else
         {
             locker.AcquireReaderLock(@lock.timeout);
         }
         liteLock = @lock;
     }
 }
 public static void Acquire(out CustomPeerResolverService.LiteLock liteLock, ReaderWriterLock locker)
 {
     Acquire(out liteLock, locker, false);
 }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
           
         
         

            List<ServiceHost> hosts = new List<ServiceHost>();
            ServiceHost host1 = new ServiceHost(typeof(RegisterService));

            ServiceHost host2 = new ServiceHost(typeof(ChatterService));
          
           
            cprs = new CustomPeerResolverService();
            cprs.RefreshInterval = TimeSpan.FromSeconds(5);

            cprs.ControlShape = true;
            cprs.Open();
          
            ServiceHost host3 = new ServiceHost(cprs);
            hosts.Add(host1);
            hosts.Add(host2);
            hosts.Add(host3);

            Console.WriteLine("***************输入\"exit\" 关闭程序***************");
            Console.WriteLine();
            foreach (ServiceHost host in hosts)
            {
                host.Opened += delegate
                {
                    ;
                    MyLogger.Logger.Info(host.Description.Name + "已经启动");
                };
                host.Closed += delegate
                {

                    MyLogger.Logger.Info(host.Description.Name + "已经关闭");
                };
                host.Open();

            }
          

            
            string s = String.Empty;
            while (true)
            {

                s = Console.ReadLine();

                if (s.Trim().ToLower() == "exit")
                {
                    break;
                }
                else if (s.Trim().ToLower() == "clear")
                {
                    Console.Clear();
                }

            }

           ChatterService.isAlive = false;
            foreach (ServiceHost host in hosts)
            {
                host.Close();
            }
        }