コード例 #1
0
        public Camera BuildCamera(CameraProfile profile, CameraConfig config, byte[] thumbnail)
        {
            lock (_accessLock)
            {
                // 检查给定的源是否存在
                if (profile.FilterType == FilterType.LocalCamera ||
                    profile.FilterType == FilterType.LocalDesktop)
                {
                    if (!Locator.Get <IFilterManager>().IsFilterExist(profile.FilterType, profile.FilterId))
                    {
                        throw new FilterNotFoundException(string.Format(CultureInfo.InvariantCulture,
                                                                        "Cannot find filter by type [{0}] and id [{1}].",
                                                                        profile.FilterType, profile.FilterId));
                    }
                }

                Camera camera = _cameras.Find(c => c.Id == profile.Id);
                if (camera == null)
                {
                    camera = CameraBuilder.Create(profile, config);
                    _cameras.Add(camera);

                    camera.Thumbnail = thumbnail;
                }

                return(camera);
            }
        }
コード例 #2
0
        public Camera CreateCamera(CameraProfile profile, CameraConfig config)
        {
            lock (_accessLock)
            {
                // 检查给定的源是否存在
                if (profile.FilterType == FilterType.LocalCamera ||
                    profile.FilterType == FilterType.LocalDesktop)
                {
                    if (!Locator.Get <IFilterManager>().IsFilterExist(profile.FilterType, profile.FilterId))
                    {
                        throw new FilterNotFoundException(string.Format(CultureInfo.InvariantCulture,
                                                                        "Cannot find filter by type [{0}] and id [{1}].",
                                                                        profile.FilterType, profile.FilterId));
                    }
                }
                else if (profile.FilterType == FilterType.LocalAVIFile)
                {
                    if (!File.Exists(profile.FilterId))
                    {
                        throw new FilterNotFoundException(string.Format(CultureInfo.InvariantCulture,
                                                                        "Cannot find filter by type [{0}] and id [{1}].",
                                                                        profile.FilterType, profile.FilterId));
                    }
                }

                // 构造摄像机
                Camera camera = _cameras.Find(c => c.Id == profile.Id);
                if (camera == null)
                {
                    camera = CameraBuilder.Create(profile, config);
                    _cameras.Add(camera);

                    camera.Thumbnail = Locator.Get <IStreamingManager>().GetCameraSnapshot(camera.Id);

                    Locator.Get <ICameraRepository>().Save(CameraBuilder.Translate(camera));
                }

                return(camera);
            }
        }