Ejemplo n.º 1
0
        public virtual void OnStop()
        {
            OnStopDelegate del = (OnStopDelegate)Lua.GetFunction(typeof(OnStopDelegate), "OnStop");

            if (del != null)
            {
                del();
            }
        }
Ejemplo n.º 2
0
        public UDPSocket(IPEndPoint localEndPoint, int packetSize, bool dontFragment, short ttl, OnReceiveDelegate onReceive, OnStopDelegate onStop)
        {
            m_PacketSize = packetSize;
            m_Disposed   = false;
            m_OnReceive  = onReceive;
            m_OnStop     = onStop;

            m_SendFifo = new Queue <PacketBuffer>();

            m_ReceiveFifo = new AutoPumpQueue <PacketBuffer>(
                (sender, data) =>
            {
                bool isDisposed = false;

                lock (m_Sync)
                {
                    isDisposed = m_Disposed;
                }

                if (!isDisposed)
                {
                    m_OnReceive(this, (IPEndPoint)data.EndPoint, data.Data);
                }
            }
                );

            m_SendPending    = false;
            m_ReceivePending = 0;

            m_IPv6   = (localEndPoint.AddressFamily == AddressFamily.InterNetworkV6);
            m_Socket = new Socket(localEndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
            m_Socket.EnableBroadcast = true;
            m_Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
            m_Socket.SendBufferSize    = 65536;
            m_Socket.ReceiveBufferSize = 65536;
            if (!m_IPv6)
            {
                m_Socket.DontFragment = dontFragment;
            }
            if (ttl >= 0)
            {
                m_Socket.Ttl = ttl;
            }
            m_Socket.Bind(localEndPoint);
            m_LocalEndPoint = m_Socket.LocalEndPoint;

            m_Socket.IOControl((IOControlCode)SIO_UDP_CONNRESET, new byte[] { 0, 0, 0, 0 }, null);

            BeginReceive();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Stop this service.
        /// </summary>
        public void OnStop()
        {
            ServiceEngineEvents.StoppingServices.Source = this.GetType().Name;
            Messenger.Default.Send <LogEventMessage>(ServiceEngineEvents.StoppingServices);
            foreach (object o in instanceArray)
            {
                try {
                    IService service = (IService)o;
                    if (service != null)
                    {
                        //invoke the delegate asynchronous to stop each started service.
                        OnStopDelegate osd = new OnStopDelegate(service.Stop);
                        osd.BeginInvoke(null, null);
                    }
                }
                catch (Exception ex) {
                    ServiceEngineEvents.OnServiceEngineError.Source     = this.GetType().Name;
                    ServiceEngineEvents.OnServiceEngineError.FormatArgs = new object[] { ex.Source, "OnStop", ex.ToString() };
                    Messenger.Default.Send <LogEventMessage>(ServiceEngineEvents.OnServiceEngineError);
                }
            }

            //give sometime for the each instance to shut down gracefully
            Thread.Sleep(5000);
            foreach (object o in threadArray)
            {
                try {
                    Thread t = (Thread)o;
                    if (t != null)
                    {
                        //if the thread is still live at this point, shut it down forcefully.
                        if (t.IsAlive == true)
                        {
                            t.Abort();
                        }
                    }
                }
                catch (Exception ex) {
                    ServiceEngineEvents.OnServiceEngineError.Source     = this.GetType().Name;
                    ServiceEngineEvents.OnServiceEngineError.FormatArgs = new object[] { ex.Source, "OnStop", ex.ToString() };
                    Messenger.Default.Send <LogEventMessage>(ServiceEngineEvents.OnServiceEngineError);
                }
            }
            ServiceEngineEvents.ServicesStopped.Source = this.GetType().Name;
            Messenger.Default.Send <LogEventMessage>(ServiceEngineEvents.ServicesStopped);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Stop this service.
        /// </summary>
        protected override void OnStop()
        {
            foreach (object o in instanceArray)
            {
                try
                {
                    IService service = (IService)o;
                    if (service != null)
                    {
                        //invoke the delegate asynchronous to stop each started service.
                        OnStopDelegate osd = new OnStopDelegate(service.Stop);
                        osd.BeginInvoke(null, null);
                    }
                }
                catch (Exception ex)
                {
                    //write to the event log
                }
            }

            //give sometime for the each instance to shut down gracefully
            Thread.Sleep(5000);
            foreach (object o in threadArray)
            {
                try
                {
                    Thread t = (Thread)o;
                    if (t != null)
                    {
                        //if the thread is still live at this point, shut it down forcefully.
                        if (t.IsAlive == true)
                        {
                            t.Abort();
                        }
                    }
                }
                catch (Exception ex)
                {
                    //write to the event log
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// This replaces all older delegates rather than adding a new one to the list.
 /// See docs for ()
 /// </summary>
 /// <param name="del">An OnStopDelegate</param>
 public void SetOnStopDelegate(OnStopDelegate del)
 {
     this.onStopDelegates = del;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Removes a OnDetectedDelegate
 /// See docs for ()
 /// </summary>
 /// <param name="del">An OnStopDelegate</param>
 public void RemoveOnStopDelegate(OnStopDelegate del)
 {
     this.onStopDelegates -= del;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Add a new delegate to be triggered when the firing system is stopped. 
 /// This is caused by destroying the object which has this component or if
 /// the object or component are disabled (The system will restart when  
 /// enabled again)
 /// The delegate signature is:  delegate()
 /// </summary>
 /// <param name="del">An OnStopDelegate</param>
 public void AddOnStopDelegate(OnStopDelegate del)
 {
     this.onStopDelegates += del;
 }
 /// <summary>
 /// Removes a OnDetectedDelegate
 /// See docs for ()
 /// </summary>
 /// <param name="del">An OnStopDelegate</param>
 public void RemoveOnStopDelegate(OnStopDelegate del)
 {
     this.onStopDelegates -= del;
 }
 /// <summary>
 /// This replaces all older delegates rather than adding a new one to the list.
 /// See docs for ()
 /// </summary>
 /// <param name="del">An OnStopDelegate</param>
 public void SetOnStopDelegate(OnStopDelegate del)
 {
     this.onStopDelegates = del;
 }
 /// <summary>
 /// Add a new delegate to be triggered when the firing system is stopped.
 /// This is caused by destroying the object which has this component or if
 /// the object or component are disabled (The system will restart when
 /// enabled again)
 /// The delegate signature is:  delegate()
 /// </summary>
 /// <param name="del">An OnStopDelegate</param>
 public void AddOnStopDelegate(OnStopDelegate del)
 {
     this.onStopDelegates += del;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Add a new delegate to be triggered when the firing system is stopped.
 /// This is caused by destroying the object which has this component or if
 /// the object or component are disabled (The system will restart when
 /// enabled again)
 /// The delegate signature is:  delegate()
 /// **This will only allow a delegate to be added once.**
 /// </summary>
 /// <param name="del">An OnStopDelegate</param>
 public void AddOnStopDelegate(OnStopDelegate del)
 {
     this.onStopDelegates -= del;  // Cheap way to ensure unique (add only once)
     this.onStopDelegates += del;
 }
Ejemplo n.º 12
0
 public void AddOnStopDelegate(OnStopDelegate del)
 {
     mOnStopDelegates.Add(del);
 }
 /// <summary>
 /// Add a new delegate to be triggered when the firing system is stopped. 
 /// This is caused by destroying the object which has this component or if
 /// the object or component are disabled (The system will restart when  
 /// enabled again)
 /// The delegate signature is:  delegate()
 /// **This will only allow a delegate to be added once.**
 /// </summary>
 /// <param name="del">An OnStopDelegate</param>
 public void AddOnStopDelegate(OnStopDelegate del)
 {
     this.onStopDelegates -= del;  // Cheap way to ensure unique (add only once)
     this.onStopDelegates += del;
 }