Example #1
0
 public void PublishCamera(string hostUri, PublishedCameraProfile profile, PublishedDestination destination, EventHandler <AsyncWorkerCallbackEventArgs <bool> > callback)
 {
     try
     {
         AsyncWorkerHandle <bool> handle = AsyncWorkerHelper.DoWork <bool>(
             delegate(object sender, DoWorkEventArgs e)
         {
             e.Result = PublishCameraSync(hostUri, profile, destination);
         },
             null, callback);
     }
     catch (Exception ex)
     {
         ExceptionHandler.Handle(ex);
     }
 }
Example #2
0
 public void GetCameras(EventHandler <AsyncWorkerCallbackEventArgs <IList <Camera> > > callback)
 {
     try
     {
         AsyncWorkerHandle <IList <Camera> > handle = AsyncWorkerHelper.DoWork <IList <Camera> >(
             delegate(object sender, DoWorkEventArgs e)
         {
             e.Result = GetCamerasSync();
         },
             null, callback);
     }
     catch (Exception ex)
     {
         ExceptionHandler.Handle(ex);
     }
 }
Example #3
0
 public void KeepPublishedCameraAlive(Camera camera, string address, int port)
 {
     try
     {
         AsyncWorkerHandle <Camera> handle = AsyncWorkerHelper.DoWork <Camera>(
             delegate(object sender, DoWorkEventArgs e)
         {
             e.Result = KeepPublishedCameraAliveSync(camera, address, port);
         },
             null, null);
     }
     catch (Exception ex)
     {
         ExceptionHandler.Handle(ex);
     }
 }
Example #4
0
        public void CheckPortAvailable(string hostUri, int port, EventHandler <AsyncWorkerCallbackEventArgs <bool> > callback)
        {
            if (port <= 0)
            {
                throw new ArgumentNullException("port");
            }

            try
            {
                AsyncWorkerHandle <bool> handle = AsyncWorkerHelper.DoWork <bool>(
                    delegate(object sender, DoWorkEventArgs e)
                {
                    e.Result = true; // check here, true is available, false is not available

                    MediaService service = GetMediaPublisherServiceSync(hostUri);

                    GetPublishedCamerasRequest request   = new GetPublishedCamerasRequest();
                    GetPublishedCamerasResponse response =
                        ServiceProvider
                        .GetService <IMediaPublisherService>(service.HostName, service.Uri.ToString())
                        .GetPublishedCameras(request);

                    if (response.PublishedCameras != null)
                    {
                        foreach (var item in response.PublishedCameras)
                        {
                            if (item.Destination.Port == port)
                            {
                                e.Result = false; // find this port is in using, so it's not available
                                break;
                            }
                        }
                    }
                },
                    null, callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Example #5
0
        public void CheckCameraName(Camera camera, EventHandler <AsyncWorkerCallbackEventArgs <bool> > callback)
        {
            if (camera == null)
            {
                throw new ArgumentNullException("camera");
            }

            try
            {
                AsyncWorkerHandle <bool> handle = AsyncWorkerHelper.DoWork <bool>(
                    delegate(object sender, DoWorkEventArgs e)
                {
                    e.Result = true; // check here, true is available, false is in using

                    GetCamerasRequest request   = new GetCamerasRequest();
                    GetCamerasResponse response =
                        ServiceProvider.GetService <IDeviceConnectorService, IDeviceConnectorCallbackService>(
                            ViewModelLocator.ServiceClient,
                            ViewModelLocator.SelectedService.HostName,
                            ViewModelLocator.SelectedService.Uri.ToString()
                            ).GetCameras(request);
                    if (response.Cameras != null)
                    {
                        foreach (var item in response.Cameras)
                        {
                            if (item.Profile.Name == camera.Name)
                            {
                                e.Result = false;
                                break;
                            }
                        }
                    }
                },
                    null, callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Example #6
0
        public void GetDesktopFilters(EventHandler <AsyncWorkerCallbackEventArgs <IList <DesktopFilter> > > callback)
        {
            try
            {
                AsyncWorkerHandle <IList <DesktopFilter> > handle = AsyncWorkerHelper.DoWork <IList <DesktopFilter> >(
                    delegate(object sender, DoWorkEventArgs e)
                {
                    List <DesktopFilter> filters = new List <DesktopFilter>();

                    GetDesktopFiltersRequest request   = new GetDesktopFiltersRequest();
                    GetDesktopFiltersResponse response =
                        ServiceProvider.GetService <IDeviceConnectorService, IDeviceConnectorCallbackService>(
                            ViewModelLocator.ServiceClient,
                            ViewModelLocator.SelectedService.HostName,
                            ViewModelLocator.SelectedService.Uri.ToString()
                            ).GetDesktopFilters(request);

                    if (response.Filters != null)
                    {
                        foreach (var item in response.Filters)
                        {
                            DesktopFilter filter = new DesktopFilter(item.Name, item.Index)
                            {
                                Primary = item.IsPrimary,
                                Bounds  = item.Bounds
                            };
                            filters.Add(filter);
                        }
                    }

                    e.Result = filters;
                },
                    null, callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Example #7
0
        public void UpdateCamera(Camera camera, EventHandler <AsyncWorkerCallbackEventArgs <Camera> > callback)
        {
            if (camera == null)
            {
                throw new ArgumentNullException("camera");
            }

            try
            {
                AsyncWorkerHandle <Camera> handle = AsyncWorkerHelper.DoWork <Camera>(
                    delegate(object sender, DoWorkEventArgs e)
                {
                    UpdateCameraRequest request = new UpdateCameraRequest();
                    request.CameraId            = camera.Id;
                    request.CameraName          = camera.Name;
                    request.Description         = camera.Description;
                    request.Tags = camera.Tags;

                    UpdateCameraResponse response =
                        ServiceProvider.GetService <IDeviceConnectorService, IDeviceConnectorCallbackService>(
                            ViewModelLocator.ServiceClient,
                            ViewModelLocator.SelectedService.HostName,
                            ViewModelLocator.SelectedService.Uri.ToString()
                            ).UpdateCamera(request);
                    if (response.Camera != null)
                    {
                        e.Result = camera;
                    }
                },
                    null, callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Example #8
0
        protected override void BindCommands()
        {
            OKCommand = new RelayCommand(() =>
            {
                Camera camera = MakeCamera();
                if (camera != null)
                {
                    Status = ViewModelStatus.Loading;
                    Model.CheckCameraName(camera, CheckCameraNameCallback);

                    // 异步顺序执行两个操作
                    AsyncWorkerHandle <bool> handle = AsyncWorkerHelper.DoWork <bool>(
                        delegate(object sender, DoWorkEventArgs e)
                    {
                        _syncWork.WaitOne(); // 等待上一个操作的完成

                        if (CheckCameraNameResult == CheckNameExistedResultType.NotExisted)
                        {
                            Status = ViewModelStatus.Saving;
                            Model.CreateCamera(camera, CreateCameraCallback);
                        }
                    });
                }
            });

            CancelCommand = new RelayCommand(() =>
            {
                Messenger.Default.Send(new NotificationMessage(UIMessageType.DeviceConfiguration_CancelCameraEvent));
            });

            CheckCameraNameCommand = new RelayCommand(() =>
            {
                Camera camera = MakeCheckedCamera();
                if (camera != null)
                {
                    Status = ViewModelStatus.Loading;
                    Model.CheckCameraName(camera, CheckCameraNameCallback);
                }
            });

            #region SelectVideoSourceCommand

            SelectVideoSourceCommand = new RelayCommand(() =>
            {
                if (this.SelectedVideoSourceDescription == null || string.IsNullOrEmpty(this.SelectedVideoSourceDescription.OriginalSourceString))
                {
                    Messenger.Default.Send(new NotificationMessage <VideoSourceDescription>(
                                               UIMessageType.DeviceConfiguration_NavigateVideoSourceEvent, null));
                }
                else
                {
                    switch (this.SelectedVideoSourceDescription.SourceType)
                    {
                    case VideoSourceType.Mock:
                        break;

                    case VideoSourceType.LocalCamera:
                        Status = ViewModelStatus.Initializing;
                        CameraFilterModel.GetCameraFilters(GetCameraFiltersCallback);
                        break;

                    case VideoSourceType.LocalAVIFile:
                        Messenger.Default.Send(new NotificationMessage <VideoSourceDescription>(
                                                   UIMessageType.DeviceConfiguration_UpdateLocalAVIFileVideoSourceEvent, this.SelectedVideoSourceDescription));
                        break;

                    case VideoSourceType.LocalDesktop:
                        Status = ViewModelStatus.Initializing;
                        DesktopFilterModel.GetDesktopFilters(GetDesktopFiltersCallback);
                        break;

                    case VideoSourceType.NetworkJPEG:
                        Messenger.Default.Send(new NotificationMessage <VideoSourceDescription>(
                                                   UIMessageType.DeviceConfiguration_UpdateNetworkJPEGVideoSourceEvent, this.SelectedVideoSourceDescription));
                        break;

                    case VideoSourceType.NetworkMJPEG:
                        Messenger.Default.Send(new NotificationMessage <VideoSourceDescription>(
                                                   UIMessageType.DeviceConfiguration_UpdateNetworkMJPEGVideoSourceEvent, this.SelectedVideoSourceDescription));
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }
            });

            #endregion
        }
Example #9
0
        public void GetCameras(EventHandler <AsyncWorkerCallbackEventArgs <IList <Camera> > > callback)
        {
            try
            {
                AsyncWorkerHandle <IList <Camera> > handle = AsyncWorkerHelper.DoWork <IList <Camera> >(
                    delegate(object sender, DoWorkEventArgs e)
                {
                    List <Camera> cameras = new List <Camera>();

                    GetCamerasRequest request   = new GetCamerasRequest();
                    GetCamerasResponse response =
                        ServiceProvider.GetService <IDeviceConnectorService, IDeviceConnectorCallbackService>(
                            ViewModelLocator.ServiceClient,
                            ViewModelLocator.SelectedService.HostName,
                            ViewModelLocator.SelectedService.Uri.ToString()
                            ).GetCameras(request);

                    if (response.Cameras != null)
                    {
                        foreach (var item in response.Cameras)
                        {
                            Camera camera = new Camera()
                            {
                                Id          = item.Profile.Id,
                                Name        = item.Profile.Name,
                                Description = item.Profile.Description,
                                Tags        = item.Profile.Tags,
                                Thumbnail   = item.Thumbnail
                            };

                            camera.VideoSourceDescription = new VideoSourceDescription()
                            {
                                FriendlyName         = item.Config.FriendlyName,
                                OriginalSourceString = item.Config.OriginalSourceString,
                                SourceString         = item.Config.SourceString,
                                FrameInterval        = item.Config.FrameInterval,
                                FrameRate            = item.Config.FrameRate,
                                UserName             = item.Config.UserName,
                                Password             = item.Config.Password,
                                UserAgent            = item.Config.UserAgent,
                            };

                            if (item.Config.Resolution != null)
                            {
                                camera.VideoSourceDescription.Resolution = new Resolution()
                                {
                                    Width = item.Config.Resolution.Width, Height = item.Config.Resolution.Height
                                };
                            }

                            switch (item.Profile.FilterType)
                            {
                            case FilterTypeData.LocalCamera:
                                camera.VideoSourceDescription.SourceType = VideoSourceType.LocalCamera;
                                break;

                            case FilterTypeData.LocalDesktop:
                                camera.VideoSourceDescription.SourceType = VideoSourceType.LocalDesktop;
                                break;

                            case FilterTypeData.LocalAVIFile:
                                camera.VideoSourceDescription.SourceType = VideoSourceType.LocalAVIFile;
                                break;

                            case FilterTypeData.NetworkJPEG:
                                camera.VideoSourceDescription.SourceType = VideoSourceType.NetworkJPEG;
                                break;

                            case FilterTypeData.NetworkMJPEG:
                                camera.VideoSourceDescription.SourceType = VideoSourceType.NetworkMJPEG;
                                break;

                            default:
                                break;
                            }

                            camera.HostName = ViewModelLocator.SelectedService.HostName;
                            camera.HostUri  = ViewModelLocator.SelectedService.Uri.ToString();

                            cameras.Add(camera);
                        }
                    }

                    e.Result = cameras;
                },
                    null, callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Example #10
0
        public void CreateCamera(Camera camera, EventHandler <AsyncWorkerCallbackEventArgs <Camera> > callback)
        {
            if (camera == null)
            {
                throw new ArgumentNullException("camera");
            }

            try
            {
                AsyncWorkerHandle <Camera> handle = AsyncWorkerHelper.DoWork <Camera>(
                    delegate(object sender, DoWorkEventArgs e)
                {
                    CreateCameraRequest request = new CreateCameraRequest();
                    request.Camera = new CameraData();

                    request.Camera.Profile             = new CameraProfileData();
                    request.Camera.Profile.Id          = camera.Id;
                    request.Camera.Profile.Name        = camera.Name;
                    request.Camera.Profile.Description = camera.Description;
                    request.Camera.Profile.Tags        = camera.Tags;

                    request.Camera.Profile.FilterType = FilterTypeData.None;
                    switch (camera.VideoSourceDescription.SourceType)
                    {
                    case VideoSourceType.Mock:
                        break;

                    case VideoSourceType.LocalAVIFile:
                        request.Camera.Profile.FilterType = FilterTypeData.LocalAVIFile;
                        request.Camera.Profile.FilterId   = camera.VideoSourceDescription.OriginalSourceString;
                        break;

                    case VideoSourceType.LocalCamera:
                        request.Camera.Profile.FilterType = FilterTypeData.LocalCamera;
                        request.Camera.Profile.FilterId   = camera.VideoSourceDescription.OriginalSourceString;
                        break;

                    case VideoSourceType.LocalDesktop:
                        request.Camera.Profile.FilterType = FilterTypeData.LocalDesktop;
                        request.Camera.Profile.FilterId   = camera.VideoSourceDescription.OriginalSourceString;
                        break;

                    case VideoSourceType.NetworkJPEG:
                        request.Camera.Profile.FilterType = FilterTypeData.NetworkJPEG;
                        request.Camera.Profile.FilterId   = camera.VideoSourceDescription.OriginalSourceString;
                        break;

                    case VideoSourceType.NetworkMJPEG:
                        request.Camera.Profile.FilterType = FilterTypeData.NetworkMJPEG;
                        request.Camera.Profile.FilterId   = camera.VideoSourceDescription.OriginalSourceString;
                        break;

                    default:
                        break;
                    }

                    request.Camera.Config = new CameraConfigData()
                    {
                        FriendlyName         = camera.VideoSourceDescription.FriendlyName,
                        OriginalSourceString = camera.VideoSourceDescription.OriginalSourceString,
                        SourceString         = camera.VideoSourceDescription.SourceString,
                        FrameInterval        = camera.VideoSourceDescription.FrameInterval,
                        FrameRate            = camera.VideoSourceDescription.FrameRate,
                        UserName             = camera.VideoSourceDescription.UserName,
                        Password             = camera.VideoSourceDescription.Password,
                        UserAgent            = camera.VideoSourceDescription.UserAgent,
                    };

                    if (camera.VideoSourceDescription.Resolution != null)
                    {
                        request.Camera.Config.Resolution = new ResolutionData()
                        {
                            Width  = camera.VideoSourceDescription.Resolution.Width,
                            Height = camera.VideoSourceDescription.Resolution.Height
                        };
                    }

                    // 默认请求超时时间为1分钟
                    CreateCameraResponse response =
                        ServiceProvider.GetService <IDeviceConnectorService, IDeviceConnectorCallbackService>(
                            ViewModelLocator.ServiceClient,
                            ViewModelLocator.SelectedService.HostName,
                            ViewModelLocator.SelectedService.Uri.ToString()
                            ).CreateCamera(request);
                    if (response.Camera != null)
                    {
                        e.Result = camera;
                    }
                },
                    null, callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }