コード例 #1
0
        private void StartStopDisposeLifecycleComps(IStartable start, IStartable stop, IDisposable disp, One one)
        {
            start.Start();

            // post instantiation startup
            Assert.AreEqual(4, one.getStarting().Count);
            Assert.AreEqual("One", one.getStarting()[0]);
            Assert.AreEqual("Two", one.getStarting()[1]);
            Assert.AreEqual("Three", one.getStarting()[2]);
            Assert.AreEqual("Four", one.getStarting()[3]);

            stop.Stop();

            // post instantiation shutdown - REVERSE order.
            Assert.AreEqual(4, one.getStopping().Count);
            Assert.AreEqual("Four", one.getStopping()[0]);
            Assert.AreEqual("Three", one.getStopping()[1]);
            Assert.AreEqual("Two", one.getStopping()[2]);
            Assert.AreEqual("One", one.getStopping()[3]);

            disp.Dispose();

            // post instantiation shutdown - REVERSE order.
            Assert.AreEqual(4, one.getDisposing().Count);
            Assert.AreEqual("Four", one.getDisposing()[0]);
            Assert.AreEqual("Three", one.getDisposing()[1]);
            Assert.AreEqual("Two", one.getDisposing()[2]);
            Assert.AreEqual("One", one.getDisposing()[3]);
        }
コード例 #2
0
        /// <summary>
        /// stop the transport on the specifies port.
        /// </summary>
        /// <param name="transport">
        /// an IStartable object that specifies the transport.
        /// </param>
        /// <param name="listenedLocalEndPoints">
        /// an ICollection&lt;IPEndPoint&gt; that contains the listened local endpoint.<para/>
        /// if null, stop the EndPoint(specifiedAddress, portToStop), it's used by UdpClient.
        /// </param>
        /// <param name="specifiedAddress">
        /// when listenedLocalEndPoints is null, using this address instead.<para/>
        /// if null, using IPAddress.Any.
        /// </param>
        /// <param name="localEndPoint">
        /// an object that specifies the port to stop.
        /// </param>
        public static void StopTransportByPort(IStartable transport,
                                               ICollection <IPEndPoint> listenedLocalEndPoints, IPAddress specifiedAddress, object localEndPoint)
        {
            int port;

            try
            {
                port = Convert.ToInt32(localEndPoint, CultureInfo.InvariantCulture);
            }
            catch (Exception)
            {
                throw new ArgumentException("localEndPoint is not an IPEndPoint/port.", "localEndPoint");
            }

            if (listenedLocalEndPoints == null)
            {
                if (specifiedAddress == null)
                {
                    specifiedAddress = IPAddress.Any;
                }

                transport.Stop(new IPEndPoint(specifiedAddress, port));

                return;
            }

            // get all endpoint to stop.
            IPEndPoint[] endpoints = new IPEndPoint[listenedLocalEndPoints.Count];

            listenedLocalEndPoints.CopyTo(endpoints, 0);

            // stop the specified endpoint.
            foreach (IPEndPoint ep in endpoints)
            {
                if (ep.Port == port)
                {
                    transport.Stop(ep);
                }
            }
        }
コード例 #3
0
        private void Run(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("No startup assembly given.");
                Environment.Exit(-1);
            }

            var assbly = args[0];
            var param  = args.Skip(1);

            try
            {
                AssemblyCatalog      cat  = new AssemblyCatalog(Assembly.LoadFrom(assbly));
                CompositionContainer cont = new CompositionContainer(cat);
                cont.ComposeParts(this);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while loading assembly.");
                Console.WriteLine(ex);
                Environment.Exit(-1);
            }

            if (_node == null)
            {
                Console.WriteLine("Assembly loaded, but no IStartable found.");
                Environment.Exit(-1);
            }

            ManualResetEvent ev = new ManualResetEvent(false);

            try
            {
                _node.Start(param).Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while starting ...");
                Console.WriteLine(ex);
            }

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                _node.Stop();
                ev.Set();
            };

            ev.WaitOne();
        }
コード例 #4
0
        internal static void SafeStop(this IStartable startable, Tracer tracer)
        {
            Contract.Requires <ArgumentNullException>(tracer != null);

            if (startable == null)
            {
                return;
            }

            if (startable.IsStarted)
            {
                try
                {
                    tracer.Verbose("Stopping {0} ...", startable);
                    startable.Stop();
                    tracer.Info("Successfully stopped {0}.", startable);
                }
                catch (Exception excp)
                {
                    tracer.Severe(excp, "Exception Stop()ing {0}", startable);
                }
            }
        }
コード例 #5
0
        private void StartStopDisposeLifecycleComps(IStartable start, IStartable stop, IDisposable disp, One one)
        {
            start.Start();

            // post instantiation startup
            Assert.AreEqual(4, one.getStarting().Count);
            Assert.AreEqual("One", one.getStarting()[0]);
            Assert.AreEqual("Two", one.getStarting()[1]);
            Assert.AreEqual("Three", one.getStarting()[2]);
            Assert.AreEqual("Four", one.getStarting()[3]);

            stop.Stop();

            // post instantiation shutdown - REVERSE order.
            Assert.AreEqual(4, one.getStopping().Count);
            Assert.AreEqual("Four", one.getStopping()[0]);
            Assert.AreEqual("Three", one.getStopping()[1]);
            Assert.AreEqual("Two", one.getStopping()[2]);
            Assert.AreEqual("One", one.getStopping()[3]);

            disp.Dispose();

            // post instantiation shutdown - REVERSE order.
            Assert.AreEqual(4, one.getDisposing().Count);
            Assert.AreEqual("Four", one.getDisposing()[0]);
            Assert.AreEqual("Three", one.getDisposing()[1]);
            Assert.AreEqual("Two", one.getDisposing()[2]);
            Assert.AreEqual("One", one.getDisposing()[3]);
        }