public AlarmHandler(UDPSocket udpSocket, List <APParser> alarmList, DB_AlarmHandler database, VideoFilesManager videoFilesManager)
        {
            this.udpSocket         = udpSocket;
            this.alarmList         = alarmList;
            this.database          = database;
            this.videoFilesManager = videoFilesManager;
            time_last      = new DateTime(1, 1, 1, 0, 0, 0);
            apEncapsulator = new APEncapsulator();

            AlarmHandlerThread = new Thread(new ThreadStart(AlarmHandleFunc));
        }
 public VideoHandler(int pk_id, DateTime time, DB_AlarmHandler database, VideoFilesManager videoFilesManager, int index1, int index2, int index3)
 {
     index[0]               = index1;
     index[1]               = index2;
     index[2]               = index3;
     this.pk_id             = pk_id;
     this.time              = time;
     this.database          = database;
     this.videoFilesManager = videoFilesManager;
     VideoHandlerThread     = new Thread(new ThreadStart(VideoHandleFunc));
     this.Start();
 }
Beispiel #3
0
        public bool Init()
        {
            //List创建
            try
            {
                Log.write("Launching service");
                apOrderList  = new List <APParser>();
                dbResultList = new List <APParser>();
                dbOrderList  = new List <APParser>();
                alarmList    = new List <APParser>();
                apLotList    = new List <APParser>();

                apMsgHandlerList    = new List <APMsgHandler>();
                DB_ApMsgHandlerList = new List <DB_APMsgHandler>();

                apEncapsulator = new APEncapsulator();
                Log.write("Initilizing Scheduler");
                scheduler = new Scheduler(apMsgHandlerList, apOrderList);

                //本地數據
                Log.write("Get Local data", 1);
                configManager = new ConfigManager();
                string server_address  = configManager.dbConfig.db.address;     // "192.168.0.200,2433";
                string server_name     = configManager.dbConfig.users.userName; //"sa";
                string server_password = configManager.dbConfig.users.password; // "witop_402507";
                string table           = configManager.dbConfig.db.table;       //"FilesDB";
                int    cmd_enable      = Convert.ToInt32(configManager.serviceConfig.record.cmd_enable);
                count_Handler = Convert.ToInt32(configManager.serviceConfig.APthread.count);
                int bufferSize = Convert.ToInt32(configManager.serviceConfig.record.Buffer);
                Log.level = Convert.ToInt32(configManager.serviceConfig.log.level);
                string APPath = configManager.serviceConfig.AP.path;

                //Launch AP
                //RunBat(APPath);


                /*DateTime time = new DateTime(2017, 04, 19, 19,30, 00);
                 * string resultFile = "";
                 * if (videoFilesManager.PathExist(time, 1))
                 * {
                 *  videoFilesManager.GetFile(time, 1, ref resultFile);
                 * }//get the files*/
                //对象创建

                Log.write("Initialize HikVision", 1);
                hikvision = new HIKVISION();
                if (hikvision.Init())
                {
                    Log.write("HikVision Initialize succeed", 1);
                    if (hikvision.login_IP("192.168.0.92", 8000, "admin", "admin123"))
                    {
                        Log.write("HikVision login succeed!", 1);
                    }
                    else
                    {
                        Log.write("HikVision login failed!", 1);
                    }
                }
                else
                {
                    Log.write("HikVision Initialize failed!", 1);
                }


                Log.write("Initialize UDP Socket", 1);
                udpsocket = new UDPSocket(apOrderList, dbResultList, alarmList, apLotList, bufferSize);

                string strLog = "Connect to database-server_address:" + server_address + "  server_name:" + server_name + "  table:" + table;
                Log.write(strLog, 2);
                //AP多线程处理
                for (int i = 0; i < count_Handler; i++)
                {
                    Log.write("Initialize DB_APMsgHandler" + i.ToString(), 1);
                    DB_APMsgHandler db_APMsgHandler = new DB_APMsgHandler(cmd_enable, i);

                    Log.write("Initialize APMsgHandler" + i.ToString(), 1);
                    APMsgHandler apMsgHandler = new APMsgHandler(udpsocket, db_APMsgHandler, apOrderList, i);

                    if (!db_APMsgHandler.Open(server_address, server_name, server_password, table))
                    {
                        Log.write("Open database " + i.ToString() + " failed!", 1);
                        bRunningNormal = false;
                    }
                    DB_ApMsgHandlerList.Add(db_APMsgHandler);
                    apMsgHandlerList.Add(apMsgHandler);
                }

                //数据库DB_Base
                Log.write("Initialize DB_Base", 1);
                db_Base = new DB_Core(cmd_enable);
                if (!db_Base.Open(server_address, server_name, server_password, table))
                {
                    Log.write("Open database failed!", 1);
                    bRunningNormal = false;
                }
                //数据库db_DBMsgHandler
                Log.write("Initialize db_DBMsgHandler", 1);
                db_DBMsgHandler = new DB_DBMsgHandler(cmd_enable);
                if (!db_DBMsgHandler.Open(server_address, server_name, server_password, table))
                {
                    Log.write("Open database failed!", 1);
                    bRunningNormal = false;
                }

                //数据库db_DBMsgHandler
                Log.write("Initialize db_AlarmHandler", 1);
                db_AlarmHandler = new DB_AlarmHandler(cmd_enable, 1);
                if (!db_AlarmHandler.Open(server_address, server_name, server_password, table))
                {
                    Log.write("Open database failed!", 1);
                    bRunningNormal = false;
                }

                //数据库dbOrderMonitor
                Log.write("Initialize dbOrderMonitor", 1);
                dbOrderMonitor = new DBOrderMonitor(dbOrderList);
                if (!dbOrderMonitor.Open(server_address, server_name, server_password, table))
                {
                    Log.write("Open database failed!", 1);
                    bRunningNormal = false;
                }

                //数据库DB_APLotHandler
                Log.write("Initialize db_DB_APLotHandler", 1);
                db_APLotHandler = new DB_APLotHandler(cmd_enable, 1);
                if (!db_APLotHandler.Open(server_address, server_name, server_password, table))
                {
                    Log.write("Open database failed!", 1);
                    bRunningNormal = false;
                }

                // Log.write("Initialize APMsgHandler", 1);
                //apMsgHandler = new APMsgHandler(udpsocket, database, apOrderList);
                //处理线程----------------

                //Video operator
                videoFilesManager = new VideoFilesManager(db_Base, configManager.serviceConfig.Path.path_video,
                                                          configManager.serviceConfig.Path.path_dest,
                                                          configManager.serviceConfig.Path.IP,
                                                          Convert.ToInt32(configManager.serviceConfig.Path.Port));


                Log.write("Initialize DBMsgHandler", 1);
                dbMsgHandler = new DBMsgHandler(udpsocket, db_DBMsgHandler, dbOrderList, dbResultList);

                Log.write("Initialize alarmHandler", 1);
                alarmHandler = new AlarmHandler(udpsocket, alarmList, db_AlarmHandler, videoFilesManager);
                Log.write("Initialize alarmHandler", 1);
                apLotHandler = new APLotHandler(udpsocket, db_APLotHandler, apLotList, 1);



                return(true);
            }
            catch (Exception ex)
            {
                Log.write("Init:ERROR-" + ex.Message, 0);
                bRunningNormal = false;
                return(false);
            }
            finally
            {
                int    listenPort = Convert.ToInt32(configManager.apConfig.local.localPort);   //6668;
                string RemoteIP   = configManager.apConfig.remote.remoteIP;                    // "192.168.0.27";
                int    RemotePort = Convert.ToInt32(configManager.apConfig.remote.remotePort); // 5555;
                string strLog     = "Open UDP Port-Listen Port:" + listenPort.ToString() + "  Remote IP:" + RemoteIP + "  Remote Port:" + RemotePort;
                Log.write(strLog, 2);
                udpsocket.Init(listenPort, RemoteIP, RemotePort);

                udpsocket.Event_ResumeAPMsgHandler   += scheduler.onWorking; //事件通知关联
                udpsocket.Event_Timeout              += this.Job_Timeout;    //事件通知关联
                udpsocket.Event_ResumeAPLotHandler   += apLotHandler.Resume; //事件通知关联
                udpsocket.Event_ResumeAlarmHandler   += alarmHandler.Resume;
                dbOrderMonitor.Event_ResumeDBHandler += dbMsgHandler.Resume; //事件通知关联

                Log.write("Starting thread", 1);

                udpsocket.Start();

                for (int i = 0; i < apMsgHandlerList.Count; i++)
                {
                    APMsgHandler apMsgHandler = apMsgHandlerList[i];
                    apMsgHandler.Start();
                }
                //apMsgHandler.Start();
                dbMsgHandler.Start();
                dbOrderMonitor.Start();
                alarmHandler.Start();
                apLotHandler.Start();
                videoFilesManager.Start();

                if (bRunningNormal)
                {
                    UpdateAllStatus();
                    Log.write("Update manager server status", 1);
                    if (!db_Base.ManagerServer_Status(true))
                    {
                        bRunningNormal = false;
                    }
                }
                bInit = true;
            }
        }