Example #1
0
 private void StopDeviceThreads()
 {
     if (srv != null)
     {
         srv.StopServer();
     }
     srv = null;
 }
Example #2
0
        private void MainThread()
        {



            InfoReport("Load config from :" +GetMyDir() + "\\ASSVServiceCFG.xml");
            int RequestInterval = 60000;
            XmlDocument xml=null;
            XmlElement node = null;
            xml = new XmlDocument();
            try
            {
                xml.Load(GetMyDir() + "\\ASSVServiceCFG.xml");
                
                node = (XmlElement)xml.LastChild;
            }
            catch (Exception)
            {
                
                
            }
           
            String sAddr;
            short  nPort;

            try{
                sAddr = node.Attributes.GetNamedItem("serveraddress").Value;
            }catch(System.Exception ex){
                sAddr = "192.168.9.146";
            }

            try{
                nPort = Convert.ToInt16 ( node.Attributes.GetNamedItem("serverport").Value);
            }catch(System.Exception ex){
                nPort = 2060;
            }
            
            eventLog1.BeginInit();

            ASSVCallBack.Caller caller = null;

            bool bLogged = false;
            do
            {
                bLogged = false;
                do
                {
                    // случилось команда на выход из сервиса
                    if (pStopServiceEvent.WaitOne(1, false))
                    {
                        try
                        {

                            InfoReport("Exiting working thread");
                            pStopApprovedEvent.Set();
                            return;
                        }
                        catch (Exception Ex)
                        {
                            ErrorReport("Exiting working thread error: " + Ex.Message);
                            return;
                        }
                    }



                    // запускаем TCP  сервер слушать порт
                    try
                    {
                        if (srv == null)
                        {
                            InfoReport("Start ASSV Server");
                            srv = new ASSVServerLib.TCPServer(sAddr, nPort);
                            srv.StartServer();
                        }
                        else
                        {
                            if (!srv.IsLive())
                            {
                                try
                                {
                                    InfoReport("Stop ASSV Server");
                                    srv.StopServer();
                                    srv = null;
                                }
                                catch (Exception Ex)
                                {
                                    ErrorReport("Error while stopping TCP Listenner... " + Ex.Message);

                                }
                            }
                        }
                    }
                    catch (Exception Ex)
                    {
                        ErrorReport("Error while start TCP Listenner... " + Ex.Message);
                        
                    }

                    System.Threading.Thread.Sleep(1000);

                    if (caller != null)
                    {
                        if (caller.isOK())
                        {
                            try
                            {

                                caller.ScanASSV();
                            }
                            catch (Exception Ex)
                            {
                                ErrorReport("Error as ASSVCallback ... " + Ex.Message);
                                caller = null;
                            }
                        }
                        else
                        {
                            caller = null;
                        }
                    }
                    else
                    {
                        try
                        {
                            InfoReport("Create caller object");
                            caller = new ASSVCallBack.Caller();
                        }
                        catch (System.Exception ex)
                        {
                        }
                    }
                    


                } while (!pStopServiceEvent.WaitOne(1000, false) && !bLogged);
             

               

               
            } while (!pStopServiceEvent.WaitOne(RequestInterval, false));

            try
            {
                InfoReport("Closing ASSVService...");
                StopDeviceThreads();
                base.OnStop();
                eventLog1.Dispose();
                return;
            }
            catch (Exception Ex)
            {
                ErrorReport("Closing ASSVService error:" + Ex.Message);
            }
            
            
        }
Example #3
0
 private void StopDeviceThreads()
 {
     if (srv!=null) srv.StopServer();
     srv = null;
 }
Example #4
0
        private void MainThread()
        {
            InfoReport("Load config from :" + GetMyDir() + "\\ASSVServiceCFG.xml");
            int         RequestInterval = 60000;
            XmlDocument xml             = null;
            XmlElement  node            = null;

            xml = new XmlDocument();
            try
            {
                xml.Load(GetMyDir() + "\\ASSVServiceCFG.xml");

                node = (XmlElement)xml.LastChild;
            }
            catch (Exception)
            {
            }

            String sAddr;
            short  nPort;

            try{
                sAddr = node.Attributes.GetNamedItem("serveraddress").Value;
            }catch (System.Exception ex) {
                sAddr = "192.168.9.146";
            }

            try{
                nPort = Convert.ToInt16(node.Attributes.GetNamedItem("serverport").Value);
            }catch (System.Exception ex) {
                nPort = 2060;
            }

            eventLog1.BeginInit();

            ASSVCallBack.Caller caller = null;

            bool bLogged = false;

            do
            {
                bLogged = false;
                do
                {
                    // случилось команда на выход из сервиса
                    if (pStopServiceEvent.WaitOne(1, false))
                    {
                        try
                        {
                            InfoReport("Exiting working thread");
                            pStopApprovedEvent.Set();
                            return;
                        }
                        catch (Exception Ex)
                        {
                            ErrorReport("Exiting working thread error: " + Ex.Message);
                            return;
                        }
                    }



                    // запускаем TCP  сервер слушать порт
                    try
                    {
                        if (srv == null)
                        {
                            InfoReport("Start ASSV Server");
                            srv = new ASSVServerLib.TCPServer(sAddr, nPort);
                            srv.StartServer();
                        }
                        else
                        {
                            if (!srv.IsLive())
                            {
                                try
                                {
                                    InfoReport("Stop ASSV Server");
                                    srv.StopServer();
                                    srv = null;
                                }
                                catch (Exception Ex)
                                {
                                    ErrorReport("Error while stopping TCP Listenner... " + Ex.Message);
                                }
                            }
                        }
                    }
                    catch (Exception Ex)
                    {
                        ErrorReport("Error while start TCP Listenner... " + Ex.Message);
                    }

                    System.Threading.Thread.Sleep(1000);

                    if (caller != null)
                    {
                        if (caller.isOK())
                        {
                            try
                            {
                                caller.ScanASSV();
                            }
                            catch (Exception Ex)
                            {
                                ErrorReport("Error as ASSVCallback ... " + Ex.Message);
                                caller = null;
                            }
                        }
                        else
                        {
                            caller = null;
                        }
                    }
                    else
                    {
                        try
                        {
                            InfoReport("Create caller object");
                            caller = new ASSVCallBack.Caller();
                        }
                        catch (System.Exception ex)
                        {
                        }
                    }
                } while (!pStopServiceEvent.WaitOne(1000, false) && !bLogged);
            } while (!pStopServiceEvent.WaitOne(RequestInterval, false));

            try
            {
                InfoReport("Closing ASSVService...");
                StopDeviceThreads();
                base.OnStop();
                eventLog1.Dispose();
                return;
            }
            catch (Exception Ex)
            {
                ErrorReport("Closing ASSVService error:" + Ex.Message);
            }
        }