/// <summary>
        /// 添加组选区
        /// </summary>
        public ARESULT AddNewGroupSelection(string data, ref long id)
        {
            SelectionGroup groupSelection = new SelectionGroup();

            if (groupSelection == null)
            {
                return(ARESULT.E_OUTOFMEMORY);
            }

            if (ARESULT.AFAILED(groupSelection.Deserialize(data)))
            {
                return(ARESULT.E_INVALIDARG);
            }

            long groupSelectionId = -1;

            if (ARESULT.AFAILED(GroupSelectionDAO.AddNewGroupSelection(mCell.mCellId, data, ref groupSelectionId)))
            {
                return(ARESULT.E_FAIL);
            }

            groupSelection.mId = groupSelectionId;
            groupSelection.mTemperatureData.mGroupId = groupSelectionId;
            id = groupSelectionId;

            lock (mSelectionGroups) {
                mSelectionGroups.Add(groupSelection);
            }

            return(ARESULT.S_OK);
        }
        /// <summary>
        /// 添加选区
        /// </summary>
        /// <param name="data">选区信息</param>
        /// <param name="id">选区索引</param>
        /// <returns>是否成功</returns>
        public ARESULT AddSelection(string data, ref long id)
        {
            var type = Selection.GetType(data);

            if (type == SelectionType.Unknown)
            {
                return(ARESULT.E_INVALIDARG);
            }

            var selection = CreateSelection(type);

            if (ARESULT.AFAILED(selection.Deserialize(data)))
            {
                return(ARESULT.E_INVALIDARG);
            }

            if (ARESULT.AFAILED(SelectionDAO.AddSelection(mCell.mCellId, data, selection.mIsGlobalSelection, ref id)))
            {
                return(ARESULT.E_FAIL);
            }

            lock (mSelections) {
                mSelections.Add(selection.SetId(id));
            }

            return(ARESULT.S_OK);
        }
Beispiel #3
0
        /// <summary>
        /// 创建录像工作线程
        /// </summary>
        /// <param name="device">设备</param>
        /// <param name="channel">通道</param>
        /// <param name="uri">资源地址</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <param name="frameRate">帧率</param>
        /// <param name="eventName">事件名称</param>
        /// <returns>是否成功</returns>
        private bool CreateRecordingWorker(IDevice device, int channel, string uri, int width, int height, int frameRate, string eventName)
        {
            var worker = new RecordingWorker();

            if (ARESULT.AFAILED(worker.Initialize(new Dictionary <string, object>()
            {
                { "cell", this },
                { "device", device },
                { "channel", channel },
                { "uri", uri },
                { "width", width },
                { "height", height },
                { "frameRate", frameRate },
                { "eventName", eventName },
            })))
            {
                Tracker.LogE($"RecordingWorker initialize fail: {device.Model}");
                return(false);
            }

            if (ARESULT.AFAILED(worker.Start()))
            {
                Tracker.LogE($"RecordingWorker start fail: {device.Model}");
                return(false);
            }

            recordingWorkers.Add(worker);
            Tracker.LogE($"StartRecording succeed: {device.Model}");

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// 读取所有Cell数据
        /// </summary>
        public ARESULT LoadConfig()
        {
            List <Models.Cell> cellList = CellDAO.GetAllCells();

            if ((cellList == null) || (cellList.Count <= 0))
            {
                Tracker.LogI("LoadConfig FAILED");
                return(ARESULT.E_FAIL);
            }

            // 保存到全局上
            Global.gCellList = cellList;

            if (ARESULT.AFAILED(CheckConfig()))
            {
                Tracker.LogI("CheckOutConfig FAILED");
                return(ARESULT.E_FAIL);
            }

            Tracker.LogI(String.Format("LoadConfig SUCCEED, Cell Count Is ({0})", cellList.Count));

            foreach (Models.Cell item in cellList)
            {
                var service = new CellService();

                // 初始化设备单元服务
                if (ARESULT.AFAILED(service.Initialize(item)))
                {
                    Tracker.LogI(String.Format("IRService({0}) Initialize FAILED", item.mCellId));
                    return(ARESULT.E_FAIL);
                }

                Tracker.LogI(String.Format("IRService({0}) Initialize SUCCEED", item.mCellId));

                // 开启设备单元服务
                if (ARESULT.AFAILED(service.Start()))
                {
                    Tracker.LogI(String.Format("IRService({0}) Start FAILED", item.mCellId));
                    return(ARESULT.E_FAIL);
                }

                gIRServiceList.Add(service);
                Tracker.LogI(String.Format("IRService({0}) Start SUCCEED", item.mCellId));
            }

            return(ARESULT.S_OK);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            // 加载所有配置
            if (ARESULT.AFAILED(CellServiceManager.Instance.LoadConfig()))
            {
                Console.WriteLine("IRServiceManager初始化失败");
                Console.ReadLine();
                return;
            }

            var sessionManager = MQTTSessionManager.Instance;

            sessionManager.OnNewSessionCallback = (pipe) => {
                Tracker.LogNW($"OnNewSession: {pipe.SessionId}");
                pipe.Context = new SessionContext(pipe);
            };

            sessionManager.Initialize(new Dictionary <string, object>()
            {
                { "Server", Global.gCloudIP },
                { "Port", Global.gCloudPort },
                { "Topic", "Topic1" },
                { "ClientId", "1234" }
            });

            /*
             * ServiceInstanceManager manager = new ServiceInstanceManager();
             * if (ARESULT.AFAILED(manager.Start())) {
             *  Console.WriteLine("ServiceInstanceManager初始化失败");
             *  Console.ReadLine();
             *  return;
             * }
             *
             * SmsServiceWorker.Instance.Start();
             * SmsServiceWorker.Instance.Join();
             */

            while (true)
            {
                Thread.Sleep(3000);
            }
        }
        /// <summary>
        /// 删除选区组
        /// </summary>
        public ARESULT RemoveSelectionGroup(long id)
        {
            if (ARESULT.AFAILED(GroupSelectionDAO.RemoveGroupSelection(id)))
            {
                return(ARESULT.E_FAIL);
            }

            lock (mSelectionGroups) {
                foreach (SelectionGroup selectionGroup in mSelectionGroups)
                {
                    if (selectionGroup.mId == id)
                    {
                        ClearSelectionGroupAlarm(selectionGroup);
                        mSelectionGroups.Remove(selectionGroup);
                        return(ARESULT.S_OK);
                    }
                }
            }

            return(ARESULT.E_FAIL);
        }
Beispiel #7
0
        /// <summary>
        /// 温度处理
        /// </summary>
        private void ProcessTemperature(float[] buf)
        {
            var time          = DateTime.Now;
            var selectionData = "";
            var groupData     = "";

            int count = 0;

            lock (mSelectionList) {
                count = mSelectionList.Count;
            }

            for (var i = 0; i < count; i++)
            {
                try {
                    Selection selection;
                    lock (mSelectionList) {
                        selection = mSelectionList[i];
                    }

                    if (ARESULT.AFAILED(selection.CalcTemperature(buf, mWidth, mWidth, mHeight)))
                    {
                        continue;
                    }

                    if (selection.mIsGlobalSelection)
                    {
                        mMaxTemperature = selection.mTemperatureData.mMaxTemperature;
                        mMinTemperature = selection.mTemperatureData.mMinTemperature;

                        if (mNeedRealTemperatureSend)
                        {
                            OnSendRealTemperature?.Invoke(
                                time,
                                selection.mTemperatureData.mMaxTemperature,
                                selection.mTemperatureData.mMinTemperature,
                                selection.mTemperatureData.mAvgTemperature);
                        }
                    }

                    if (mNeedSampleSelction)   // 添加普通选区历史数据
                    {
                        OnAddSelectionTemperature?.Invoke(
                            selection.mSelectionId,
                            time,
                            selection.mTemperatureData.mMaxTemperature,
                            selection.mTemperatureData.mMinTemperature,
                            selection.mTemperatureData.mAvgTemperature);
                    }

                    if (mNeedReportSend && (!selection.mIsGlobalSelection))
                    {
                        OnSendReportData?.Invoke(selection.mSelectionId);
                    }

                    selectionData += JsonUtils.ObjectToJson(selection.mTemperatureData) + ",";
                }
                catch (Exception e) {
                    Tracker.LogE(e);
                    continue;
                }
            }

            count = 0;
            lock (mSelectionGroupList) {
                count = mSelectionGroupList.Count;
            }

            for (var i = 0; i < count; i++)
            {
                try {
                    SelectionGroup group;
                    lock (mSelectionGroupList) {
                        group = mSelectionGroupList[i];
                    }

                    lock (mSelectionList) {
                        if (ARESULT.AFAILED(group.CalcTemperature(mSelectionList)))
                        {
                            continue;
                        }
                    }

                    if (mNeedSampleGroup)   // 添加选区组历史数据
                    {
                        OnAddGroupSelectionTemperature?.Invoke(
                            group.mId,
                            time,
                            group.mTemperatureData.mMaxTemperature,
                            group.mTemperatureData.mTemperatureDif,
                            group.mTemperatureData.mTemperatureRise);
                    }
                    groupData += JsonUtils.ObjectToJson(group.mTemperatureData) + ",";
                }
                catch (Exception e) {
                    Tracker.LogE(e);
                    continue;
                }
            }

            // 选区温度信息实时回调
            if (!string.IsNullOrEmpty(selectionData))
            {
                selectionData = string.Format("[{0}]", selectionData.Remove(selectionData.Length - 1, 1));
            }

            if (!string.IsNullOrEmpty(groupData))
            {
                groupData = string.Format("[{0}]", groupData.Remove(groupData.Length - 1, 1));
            }

            OnRealtimeSelectionTemperature?.Invoke(selectionData, groupData);
        }
Beispiel #8
0
        /// <summary>
        /// 初始化设备
        /// </summary>
        /// <param name="instance">设备</param>
        /// <param name="device">设备配置</param>
        /// <returns>是否成功</returns>
        private bool InitializeDevice(IDevice instance, Configuration.Device device)
        {
            try {
                var category = Enum.Parse(typeof(DeviceType), device.category);
                switch (category)
                {
                case DeviceType.Camera:
                    // TODO: 启动服务线程并设置参数
                    if (!instance.Write(WriteMode.URI, device.uri))
                    {
                        Tracker.LogE($"Write parameters fail: {device.model}");
                        return(false);
                    }

                    if (!instance.Write(WriteMode.CameraParameters, device.cameraParameters))
                    {
                        Tracker.LogE($"Write parameters fail: {device.model}");
                        return(false);
                    }

                    break;

                case DeviceType.IrCamera:
                    // TODO: 启动服务线程并设置参数
                    if (!instance.Write(WriteMode.URI, device.uri))
                    {
                        Tracker.LogE($"Write parameters fail: {device.model}");
                        return(false);
                    }

                    if (!instance.Write(WriteMode.IrCameraParameters, device.irCameraParameters))
                    {
                        Tracker.LogE($"Write parameters fail: {device.model}");
                        return(false);
                    }

                    if (!instance.Write(WriteMode.CameraParameters, device.cameraParameters))
                    {
                        Tracker.LogE($"Write parameters fail: {device.model}");
                        return(false);
                    }

                    // 启动获取数据工作线程
                    var worker = new CaptureVideoWorker();
                    if (ARESULT.AFAILED(worker.Initialize(new Dictionary <string, object>()
                    {
                        { "device", instance }
                    })))
                    {
                        Tracker.LogE($"CaptureVideoWorker initialize fail: {device.model}");
                        return(false);
                    }

                    if (ARESULT.AFAILED(worker.Start()))
                    {
                        Tracker.LogE($"CaptureVideoWorker start fail: {device.model}");
                        return(false);
                    }

                    workers.Add(worker);

                    break;

                default:
                    return(false);
                }

                return(true);
            }
            catch (Exception e) {
                Tracker.LogE($"Initialize device fail: {device.model}", e);
                return(false);
            }
        }
Beispiel #9
0
        /// <summary>
        /// 获取手动录像记录
        /// </summary>
        public static List <Record> GetManualRecordList(
            DateTime startTime,
            DateTime endTime,
            String recordName,
            Int32 offset,
            Int32 count)
        {
            IDbHelper connection = DBConnection.Instance.GetConnection();

            if (connection == null)
            {
                return(null);
            }

            try {
                String sqlString = @"SELECT id, name, startTime, startRecordIndex, endRecordIndex FROM manualrecord WHERE
                                    startTime>=@startTime AND endTime<=@endTime
                                    and startRecordIndex<>-1 and endRecordIndex<>-1
                                    and (endTime IS NOT NULL) AND name LIKE @name
                                    ORDER BY id ASC LIMIT @count OFFSET @offset";

                // 模糊查询条件
                String fuzzy = null;
                if (String.IsNullOrEmpty(recordName))
                {
                    fuzzy = "%%";
                }
                else
                {
                    fuzzy = String.Format("%{0}%", recordName);
                }

                DataTable dt = DbFactory.Instance.CreateSqlHelper(connection, sqlString)
                               .SetParameter("startTime", startTime)
                               .SetParameter("endTime", endTime)
                               .SetParameter("name", fuzzy)
                               .SetParameter("count", count)
                               .SetParameter("offset", offset)
                               .ToDataTable();

                if ((dt == null) || (dt.Rows.Count <= 0))
                {
                    return(null);
                }

                List <Record> recordList = new List <Record>();

                sqlString = "SElECT * FROM record WHERE";
                foreach (DataRow dr in dt.Rows)
                {
                    Record info = new Record();
                    info.mType      = 0;
                    info.mId        = Int64.Parse(dr["id"].ToString());
                    info.mStartTime = Convert.ToDateTime(dr["startTime"]);
                    info.mStartId   = Convert.ToInt32(dr["startRecordIndex"]);
                    info.mEndId     = Convert.ToInt32(dr["endRecordIndex"]);
                    info.mName      = dr["name"].ToString();
                    if (info.mStartId > info.mEndId)
                    {
                        continue;
                    }

                    String condition = String.Format("(id BETWEEN {0} AND {1})", info.mStartId, info.mEndId);
                    sqlString = String.Format("{0} {1} OR", sqlString, condition);
                    recordList.Add(info);
                }

                sqlString = sqlString.Substring(0, sqlString.Length - 2);
                dt        = DbFactory.Instance.CreateSqlHelper(connection, sqlString)
                            .ToDataTable();

                if ((dt == null) || (dt.Rows.Count <= 0))
                {
                    return(null);
                }

                Dictionary <Int64, String> dict = new Dictionary <Int64, String>();
                foreach (DataRow dr in dt.Rows)
                {
                    Int64  id       = Int64.Parse(dr["id"].ToString());
                    String fileName = dr["infoFileName"].ToString();
                    dict.Add(id, fileName);
                }

                for (Int32 i = 0; i < recordList.Count; i++)
                {
                    Record        item  = recordList[i];
                    List <String> files = new List <String>();
                    for (Int64 j = item.mStartId; j <= item.mEndId; j++)
                    {
                        if (dict.ContainsKey(j) && (dict[j] != null))
                        {
                            files.Add(dict[j]);
                        }
                    }

                    if (ARESULT.AFAILED(RecordDAO.GetRecordMessage(files,
                                                                   ref item.mRecordTime, ref item.mImageData)))
                    {
                        recordList.RemoveAt(i);
                        i--;
                        continue;
                    }
                }

                return(recordList);
            }
            catch (Exception e) {
                Tracker.LogE(e);
                return(null);
            }
            finally {
                DBConnection.Instance.ReturnDBConnection(connection);
            }
        }
Beispiel #10
0
        /// <summary>
        /// 删除选区
        /// </summary>
        /// <param name="id">选区索引</param>
        /// <returns>是否成功</returns>
        public ARESULT RemoveSelection(long id)
        {
            try {
                if (ARESULT.AFAILED(SelectionDAO.RemoveSelection(id)))
                {
                    return(ARESULT.E_FAIL);
                }

                bool continueFlag = false;
                lock (mSelectionGroups) {
                    foreach (SelectionGroup groupSelection in mSelectionGroups)
                    {
                        lock (groupSelection) {
                            for (int i = 0; i < groupSelection.mSelectionIds.Count; i++)
                            {
                                if (groupSelection.mSelectionIds[i] == id)
                                {
                                    ClearSelectionGroupAlarm(groupSelection);

                                    if (groupSelection.mSelectionIds.Count == 1)
                                    {
                                        GroupSelectionDAO.RemoveGroupSelection(groupSelection.mId);
                                        mSelectionGroups.Remove(groupSelection);
                                    }
                                    else
                                    {
                                        for (int k = i; k < groupSelection.mSelectionIds.Count - 1; k++)
                                        {
                                            groupSelection.mSelectionIds[k] = groupSelection.mSelectionIds[k + 1];
                                        }

                                        string data = groupSelection.Serialize();
                                        if (data != null)
                                        {
                                            GroupSelectionDAO.UpdateGroupSelection(groupSelection.mId, data);
                                        }
                                    }

                                    continueFlag = true;
                                    break;
                                }
                            }
                        }

                        if (continueFlag)
                        {
                            break;
                        }
                    }
                }

                lock (mSelections) {
                    foreach (Selection selection in mSelections)
                    {
                        lock (selection) {
                            if (selection.mSelectionId == id)
                            {
                                ClearSelectionAlarm(selection);
                                mSelections.Remove(selection);
                                return(ARESULT.S_OK);
                            }
                        }
                    }
                }

                return(ARESULT.E_FAIL);
            }
            catch (Exception e) {
                Tracker.LogE(e);
                return(ARESULT.E_FAIL);
            }
        }