Beispiel #1
0
        static void Main(string[] args)
        {
            XmlDocument xml;

            xml = new XmlDocument();
            xml.Load(GetMyDir() + "\\ASSVServiceCFG.xml");
            XmlElement node;

            node = (XmlElement)xml.LastChild;
            String sAddr;
            short  nPort;

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

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


            Console.WriteLine("Start server on " + sAddr + ":" + nPort.ToString());
            ASSVServerLib.TCPServer srv = new ASSVServerLib.TCPServer(sAddr, nPort);
            srv.StartServer();

            ASSVCallBack.Caller caller = null;
            try
            {
                caller = new ASSVCallBack.Caller();
            }
            catch (System.Exception ex)
            {
            }
            while (true)
            {
                if (!srv.IsLive())
                {
                    srv.StopServer();
                    System.Threading.Thread.Sleep(2000);
                    srv = new ASSVServerLib.TCPServer(sAddr, nPort);
                    srv.StartServer();
                }

                if (caller != null)
                {
                    try
                    {
                        caller.ScanASSV();
                    }
                    catch (Exception Ex)
                    {
                        Console.WriteLine("Error as ASSVCallback ... " + Ex.Message);
                    }
                }
                System.Threading.Thread.Sleep(30000);
            }
        }
Beispiel #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);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {

            XmlDocument xml;
            xml = new XmlDocument();
            xml.Load(GetMyDir() + "\\ASSVServiceCFG.xml");
            XmlElement node;
            node = (XmlElement)xml.LastChild;
            String sAddr;
            short nPort;

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

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


            Console.WriteLine("Start server on " + sAddr + ":" + nPort.ToString() );
            ASSVServerLib.TCPServer srv = new ASSVServerLib.TCPServer(sAddr, nPort);
            srv.StartServer();

            ASSVCallBack.Caller caller = null;
            try
            {
                caller = new ASSVCallBack.Caller();
            }
            catch (System.Exception ex)
            {
            }
            while (true)
            {


                if (!srv.IsLive())
                {
                    srv.StopServer();
                    System.Threading.Thread.Sleep(2000); 
                    srv = new ASSVServerLib.TCPServer(sAddr, nPort);
                    srv.StartServer();
                }

                if (caller != null)
                {
                    try
                    {
                        caller.ScanASSV();
                    }
                    catch (Exception Ex)
                    {
                        Console.WriteLine("Error as ASSVCallback ... " + Ex.Message);

                    }
                }
                System.Threading.Thread.Sleep(30000);
                
            }

        }