private void CreateRecData()
        {
            RecorderSetup RecSetup = new RecorderSetup();

            RecSetup.recorderURL        = "";
            RecSetup.recorderURLPort    = 8085;
            RecSetup.recorderLogin      = "******";
            RecSetup.recorderPassword   = "******";
            RecSetup.recorderArchiveDir = @"F:\cam_arch";

            File.WriteAllText(@RECORDER_DATA_FILE, JsonConvert.SerializeObject(RecSetup, Formatting.Indented));
        }
    private void Initialize(int port, RecorderSetup RECORDER_DATA, recorder_CAMS[] RECORDER_CAMS, EventLog EVENT_LOG, string CURRENT_DIR, string CURRENT_INT_DIR)
    {
        this.CURRENT_DIR     = CURRENT_DIR;
        this.CURRENT_INT_DIR = CURRENT_INT_DIR;
        this.EVENT_LOG       = EVENT_LOG;
        this.RECORDER_CAMS   = RECORDER_CAMS;
        this.REC_FOLDER      = RECORDER_DATA.recorderArchiveDir;
        this.RECORDER_LIBDIR = new DirectoryInfo(Path.Combine(CURRENT_DIR, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));

        this._port = port;

        _serverThread = new Thread(this.Listen);
        _serverThread.Start();
    }
Example #3
0
        private void GetData()
        {
            try
            {
                CamsSetup[] cams = ST.GetCamsArray();
                RECORDER_DATA = ST.GetRecorderSetup();

                string log = "";
                log += "------------------------------------------\n";
                log += "данные регистратора\n";
                log += "------------------------------------------\n";
                log += "Архив - " + RECORDER_DATA.recorderArchiveDir + "\n";
                log += "Адрес веб сервера - " + RECORDER_DATA.recorderURL + "\n";
                log += "Порт веб сервера - " + RECORDER_DATA.recorderURLPort + "\n";

                if (cams.Length > 0)
                {
                    log += "------------------------------------------\n";
                    log += "данные по камерам\n";
                    log += "------------------------------------------\n";

                    foreach (CamsSetup cam in cams)
                    {
                        log += "Камера - " + cam.CamName + ", адрес: " + cam.CamIP + ", идентификатор: " + cam.CamID + "\nОписание: " + cam.CamDescription + "\n\n";
                    }
                }

                EVENT_LOG.WriteEntry(log);

                RECORDER_CAMS = new recorder_CAMS[cams.Length];
                for (int i = 0; i < cams.Length; i++)
                {
                    recorder_CAMS _cam = new recorder_CAMS();
                    _cam.camName        = cams[i].CamName;
                    _cam.camIP          = cams[i].CamIP;
                    _cam.camDescription = cams[i].CamDescription;
                    _cam.camLogin       = cams[i].CamLogin;
                    _cam.camPassword    = cams[i].CamPassword;
                    Uri    URL_data      = new Uri(cams[i].CamIP);
                    string camIPwithAuth = URL_data.Scheme + "://" + _cam.camLogin + ":" + _cam.camPassword + "@" + URL_data.Host + URL_data.PathAndQuery;
                    _cam.CamClient   = new rtsp_client(camIPwithAuth, 0, RECORDER_DATA.recorderArchiveDir, EVENT_LOG, cams[i].CamName, cams[i].camAutoRecconect);
                    RECORDER_CAMS[i] = _cam;
                }
            }
            catch (Exception ex)
            {
                EVENT_LOG.WriteEntry("Ошибка чтения настроек - " + ex.ToString());
            }
        }
    public SimpleHTTPServer(RecorderSetup RECORDER_DATA, recorder_CAMS[] RECORDER_CAMS, EventLog EVENT_LOG, string CURRENT_DIR, string CURRENT_INT_DIR)
    {
        int port = RECORDER_DATA.recorderURLPort;

        if (port <= 0)
        {
            //get an empty port
            TcpListener l = new TcpListener(IPAddress.Loopback, 0);
            l.Start();
            port = ((IPEndPoint)l.LocalEndpoint).Port;
            l.Stop();
            EVENT_LOG.WriteEntry("Не удалось получить порт - " + RECORDER_DATA.recorderURLPort + ", использован порт - " + port);
        }

        this.Initialize(port, RECORDER_DATA, RECORDER_CAMS, EVENT_LOG, CURRENT_DIR, CURRENT_INT_DIR);
    }
        //Приватные функции

        /*private void DB_insert_RecorderSetup(string Recorder_Data, bool async = false)
         * {
         *  var Collection = DB.GetCollection<BsonDocument>("RecorderSetup");
         *  var doc = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(Recorder_Data);
         *  if (async)
         *  {
         *      Collection.InsertOneAsync(doc);
         *  }
         *  else
         *  {
         *      Collection.InsertOne(doc);
         *  }
         * }
         * private void DB_insert_CameraSetup(string Cam_Data, bool async = false)
         * {
         *  var Collection = DB.GetCollection<BsonDocument>("CamsSetup");
         *  var doc = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(Cam_Data);
         *  if (async)
         *  {
         *      Collection.InsertOneAsync(doc);
         *  }
         *  else
         *  {
         *      Collection.InsertOne(doc);
         *  }
         * }*/
        private bool RecDataChecked()
        {
            bool   check = false;
            string json  = File.ReadAllText(RECORDER_DATA_FILE);

            try
            {
                RecorderSetup RecSetup = JsonConvert.DeserializeObject <RecorderSetup>(json);
                if (RecSetup.recorderURLPort != null && !RecSetup.recorderArchiveDir.Equals(""))
                {
                    check = true;
                }
            }
            catch (Exception Error)
            {
                //TODO log
            }

            return(check);
        }
Example #6
0
        static void Main(string[] args)
        {
            db = new LiteDatabase(@PROGRAM_DIR + @"\data.dat");
            IEnumerable <string> collections = db.GetCollectionNames();
            int c = collections.Count();

            if (c == 0)
            {
                var _RecorderSetup = db.GetCollection <RecorderSetup>("RecorderSetup");
                // Create unique index in SetupName field
                _RecorderSetup.EnsureIndex(x => x.SetupName, true);

                var set_recorderURL = new RecorderSetup
                {
                    SetupName      = "recorderURL",
                    SetupValstring = ""
                };
                _RecorderSetup.Insert(set_recorderURL);
                var set_recorderURLPort = new RecorderSetup
                {
                    SetupName   = "recorderURLPort",
                    SetupValint = 8085
                };
                _RecorderSetup.Insert(set_recorderURLPort);
                var set_recorderLogin = new RecorderSetup
                {
                    SetupName      = "recorderLogin",
                    SetupValstring = "admin"
                };
                _RecorderSetup.Insert(set_recorderLogin);
                var set_recorderPassword = new RecorderSetup
                {
                    SetupName      = "recorderPassword",
                    SetupValstring = ""
                };
                _RecorderSetup.Insert(set_recorderPassword);
                var set_recorderArchiveDir = new RecorderSetup
                {
                    SetupName      = "recorderArchiveDir",
                    SetupValstring = @"F:\cam_arch"
                };
                _RecorderSetup.Insert(set_recorderArchiveDir);

                //Потом удалить нахуй!!! только для теста
                var _CamsSetup = db.GetCollection <CamsSetup>("CamsSetup");
                // Create unique index in SetupName field
                _CamsSetup.EnsureIndex(x => x.CamID, true);
                var set_Cam = new CamsSetup
                {
                    CamID            = Guid.NewGuid().ToString(),
                    CamName          = "Camera1",
                    CamIP            = "rtsp://192.168.1.16",
                    CamDescription   = "Camera1 - подвал",
                    CamLogin         = "******",
                    CamPassword      = "******",
                    camAutoRecconect = false
                };
                _CamsSetup.Insert(set_Cam);
                set_Cam = new CamsSetup
                {
                    CamID            = Guid.NewGuid().ToString(),
                    CamName          = "Camera2",
                    CamIP            = "rtsp://192.168.1.17",
                    CamDescription   = "Camera2 - подвал",
                    CamLogin         = "******",
                    CamPassword      = "******",
                    camAutoRecconect = true
                };
                _CamsSetup.Insert(set_Cam);
                //Потом удалить нахуй!!! только для теста
            }
            else
            {
                Console.WriteLine("Данные регистратора");
                Console.WriteLine("----------------------------------------------------------");
                var RecorderSetup = db.GetCollection <RecorderSetup>("RecorderSetup");
                var query         = RecorderSetup.FindAll();
                foreach (var setup in query)
                {
                    switch (setup.SetupName)
                    {
                    case "recorderURL":
                        Console.WriteLine("recorderURL - " + setup.SetupValstring);
                        break;

                    case "recorderURLPort":
                        Console.WriteLine("recorderURLPort - " + setup.SetupValint);
                        break;

                    case "recorderLogin":
                        Console.WriteLine("recorderLogin - " + setup.SetupValstring);
                        break;

                    case "recorderPassword":
                        Console.WriteLine("recorderPassword - " + setup.SetupValstring);
                        break;

                    case "recorderArchiveDir":
                        Console.WriteLine("recorderArchiveDir - " + setup.SetupValstring);
                        break;

                    default:
                        break;
                    }
                }

                Console.WriteLine("----------------------------------------------------------");
                Console.WriteLine("Данные камер");
                Console.WriteLine("----------------------------------------------------------");
                var CamsSetup = db.GetCollection <CamsSetup>("CamsSetup");
                var cam_query = CamsSetup.FindAll();
                int i         = 0;

                foreach (var _cam in cam_query)
                {
                    Console.WriteLine("Камера " + (i + 1));
                    Console.WriteLine("CamUID - " + _cam.CamID);
                    Console.WriteLine("CamName - " + _cam.CamName);
                    Console.WriteLine("CamIP - " + _cam.CamIP);
                    Console.WriteLine("CamDescription - " + _cam.CamDescription);
                    Console.WriteLine("CamLogin - " + _cam.CamLogin);
                    Console.WriteLine("CamPassword - " + _cam.CamPassword);
                    Console.WriteLine("camAutoRecconect - " + _cam.camAutoRecconect);
                    Console.WriteLine("----------------------------------------------------------");
                    i++;
                }
            }

            String readline = null;

            while (readline == null)
            {
                readline = Console.ReadLine();
                if (readline == null)
                {
                    Thread.Sleep(500);
                }
            }
        }