Esempio n. 1
0
        /// <summary>
        /// 编辑摄像头参数配置方案,并保存
        /// 注意:如果想要将该摄像头参数配置设置为默认,
        /// 在实体中赋值DefaultSetting是没有用的,
        /// 请通过赋值方法第二个参数值AsDefault来进行操作
        /// 如果存在什么错误,会通过异常抛出
        /// </summary>
        /// <param name="settingEntity">要修改的配置</param>
        /// <param name="AsDefault">是否设置为默认的摄像头配置</param>
        public void EditVideoSetting(VideoSettingEntity settingEntity, bool AsDefault = false)
        {
            List <VideoSettingEntity> settings = GetAllVideoSettings();

            if (settings == null)
            {
                settings = new List <VideoSettingEntity>();
            }

            //找到旧的配置方案
            VideoSettingEntity oldSettingEntity = settings.Find(m => m.VideoSettingName == settingEntity.VideoSettingName);

            //判断是否找到旧的配置方案
            if (oldSettingEntity == null)
            {
                throw new Exception("未找到该配置方案的旧方案,无法修改");
            }

            //移除旧的配置方案
            settings.Remove(oldSettingEntity);

            //赋值新的配置方案的是否为默认配置
            if (AsDefault)
            {
                settings.ForEach(m => m.DefaultSetting = false);
            }
            settingEntity.DefaultSetting = AsDefault;

            //将修改后的配置方案保存到方案集合中
            settings.Add(settingEntity);

            //持久化到文件中
            FlushDataToXmlFile(settings);
        }
Esempio n. 2
0
        /// <summary>
        /// 保存摄像头参数配置方案
        /// 如果存在什么错误,会通过异常抛出
        /// </summary>
        /// <param name="setting">要保存的摄像头参数配置</param>
        /// <param name="AsDefault">是否将此摄像头参数配置设为默认配置</param>
        public void SaveVideoSetting(VideoSettingEntity setting, bool AsDefault = false)
        {
            List <VideoSettingEntity> settings = GetAllVideoSettings();

            if (settings == null)
            {
                settings = new List <VideoSettingEntity>();
            }

            //判断配置名称字段是否赋值
            if (string.IsNullOrEmpty(setting.VideoSettingName))
            {
                throw new Exception("必须赋值配置名称字段(VideoSettingName)");
            }

            //判断是否已经存在同名的配置方案
            if (settings.Find(m => m.VideoSettingName == setting.VideoSettingName) != null)
            {
                throw new Exception("已经存在同名的配置了");
            }

            //如果要将保存的视频信息设为默认
            if (AsDefault)
            {
                settings.ForEach(m => m.DefaultSetting = false);
                setting.DefaultSetting = true;
            }
            //将摄像头参数配置保存到文件中
            if (setting != null)
            {
                settings.Add(setting);
            }
            FlushDataToXmlFile(settings);
        }
Esempio n. 3
0
        /// <summary>
        /// 将一个配置方案设置为默认配置,
        /// 该配置方案必须是已经存在的配置
        /// </summary>
        /// <param name="setting">要设为默认配置的摄像头配置</param>
        /// <returns>成功则返回true,失败则返回false</returns>
        public bool SetDefaultSettings(VideoSettingEntity setting)
        {
            List <VideoSettingEntity> settings = GetAllVideoSettings();

            if (settings == null)
            {
                settings = new List <VideoSettingEntity>();
            }
            //将所有的配置设置为非默认
            settings.ForEach(m => m.DefaultSetting = false);
            //找到要设置为默认的配置
            var defaultSetting = settings.Find(m => m.VideoSettingName == setting.VideoSettingName);

            defaultSetting.DefaultSetting = true;
            //持久化到文件中
            FlushDataToXmlFile(settings);
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// 删除一个摄像头配置
        /// 如果存在什么错误,会通过异常抛出
        /// </summary>
        /// <param name="settingEntity"></param>
        public void DeleteVideoSetting(VideoSettingEntity settingEntity)
        {
            List <VideoSettingEntity> settings = GetAllVideoSettings();

            if (settings == null)
            {
                settings = new List <VideoSettingEntity>();
            }

            //找到这个要删除的摄像头配置
            VideoSettingEntity deleteSettingEntity = settings.Find(m => m.VideoSettingName == settingEntity.VideoSettingName);

            //判断是否找到要删除的配置方案
            if (deleteSettingEntity == null)
            {
                throw new Exception("未找到该配置方案的旧方案,无法修改");
            }

            //删除这个配置方案
            settings.Remove(deleteSettingEntity);

            //持久化到文件中
            FlushDataToXmlFile(settings);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取当前用户保存的所有摄像头设置
        /// </summary>
        /// <returns>当前用户保存的所有摄像头设置</returns>
        public List <VideoSettingEntity> GetAllVideoSettings()
        {
            List <VideoSettingEntity> result = new List <VideoSettingEntity>();

            #region 读取文件
            if (!File.Exists(_VideoSettingRealPath))
            {
                return(null);
            }

            //先解密这个文件
            Base64Helper.Base64Decode4txtFile(_VideoSettingRealPath);

            XmlTextReader      reader  = new XmlTextReader(_VideoSettingRealPath);
            VideoSettingEntity setting = null;
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == nameof(VideoSettingEntity))
                    {
                        setting = new VideoSettingEntity();
                        result.Add(setting);
                    }
                    if (reader.Name == nameof(setting.VideoSettingName))
                    {
                        setting.VideoSettingName = reader.ReadElementContentAsString();
                    }
                    else if (reader.Name == nameof(setting.Brightness))
                    {
                        if (setting != null)
                        {
                            setting.Brightness = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoBrightness))
                    {
                        if (setting != null)
                        {
                            setting.AutoBrightness = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.ContrastRatio))
                    {
                        if (setting != null)
                        {
                            setting.ContrastRatio = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoContrastRatio))
                    {
                        if (setting != null)
                        {
                            setting.AutoContrastRatio = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.Saturation))
                    {
                        if (setting != null)
                        {
                            setting.Saturation = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoSaturation))
                    {
                        if (setting != null)
                        {
                            setting.AutoSaturation = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.DefaultSetting))
                    {
                        if (setting != null)
                        {
                            setting.DefaultSetting = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.Hue))
                    {
                        if (setting != null)
                        {
                            setting.Hue = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoHue))
                    {
                        if (setting != null)
                        {
                            setting.AutoHue = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.Sharpness))
                    {
                        if (setting != null)
                        {
                            setting.Sharpness = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoSharpness))
                    {
                        if (setting != null)
                        {
                            setting.AutoSharpness = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.Gamma))
                    {
                        if (setting != null)
                        {
                            setting.Gamma = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoGamma))
                    {
                        if (setting != null)
                        {
                            setting.AutoGamma = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.ColorEnable))
                    {
                        if (setting != null)
                        {
                            setting.ColorEnable = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.WhiteBalance))
                    {
                        if (setting != null)
                        {
                            setting.WhiteBalance = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoWhiteBalance))
                    {
                        if (setting != null)
                        {
                            setting.AutoWhiteBalance = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.BacklightCompensation))
                    {
                        if (setting != null)
                        {
                            setting.BacklightCompensation = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoBacklightCompensation))
                    {
                        if (setting != null)
                        {
                            setting.AutoBacklightCompensation = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.Gain))
                    {
                        if (setting != null)
                        {
                            setting.Gain = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoGain))
                    {
                        if (setting != null)
                        {
                            setting.AutoGain = reader.ReadElementContentAsBoolean();
                        }
                    }
                }
            }
            //关闭流
            reader.Close();
            reader = null;
            GC.Collect();
            #endregion
            //重新加密这个文件
            Base64Helper.Base64Encode4txtFile(_VideoSettingRealPath);
            return(result);
        }
 /// <summary>
 /// 切换摄像头配置为指定配置方案
 /// 配置方案可以由GetAllCameraSettings进行传参
 /// </summary>
 /// <param name="setting">摄像头配置方案</param>
 /// <param name="asDefault">是否将此配置设为默认配置</param>
 /// <returns></returns>
 public int ChangeCameraConfigToSetting(VideoSettingEntity setting, bool asDefault = false)
 {
     return(DirectShow.Instance.ChangeCameraConfigToSetting(setting, asDefault));
 }