Example #1
0
        public void GetServices(EventHandler <AsyncWorkerCallbackEventArgs <IList <MediaService> > > callback)
        {
            try
            {
                AsyncWorkerHandle <IList <MediaService> > handle = AsyncWorkerHelper.DoWork <IList <MediaService> >(
                    delegate(object sender, DoWorkEventArgs e)
                {
                    List <MediaService> services = new List <MediaService>();

                    foreach (var item in ServiceProvider.GetServices <IDeviceConnectorService>())
                    {
                        services.Add(new MediaService()
                        {
                            Id           = item.Value.Uri.ToString(),
                            Name         = item.Value.Name,
                            ContractName = item.Value.Name,
                            HostName     = item.Value.HostName,
                            Uri          = item.Value.Uri,
                        });
                    }

                    e.Result = services;
                },
                    null, callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Example #2
0
        public void SearchCameras(string searchText, EventHandler <AsyncWorkerCallbackEventArgs <IList <Camera> > > callback)
        {
            try
            {
                AsyncWorkerHandle <IList <Camera> > handle = AsyncWorkerHelper.DoWork <IList <Camera> >(
                    delegate(object sender, DoWorkEventArgs e)
                {
                    List <Camera> matches = new List <Camera>();

                    foreach (var item in GetCamerasSync())
                    {
                        if (string.IsNullOrEmpty(searchText) || item.Name.Contains(searchText))
                        {
                            matches.Add(item as Camera);
                        }
                    }

                    e.Result = matches;
                },
                    null, callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Example #3
0
        public void Login(string serverIPAddress, string userName, string password, EventHandler <AsyncWorkerCallbackEventArgs <bool> > callback)
        {
            try
            {
                AsyncWorkerHandle <bool> handle = AsyncWorkerHelper.DoWork <bool>(
                    (sender, e) =>
                {
                    //LoginRequest request = new LoginRequest()
                    //{
                    //  UserName = userName,
                    //  Password = password
                    //};

                    //LoginResponse response = MessageSender.Send<ILoginService, LoginResponse, LoginRequest>(
                    //  (contract, argument) =>
                    //  {
                    //    return contract.Login(request);
                    //  },
                    //  request);

                    //e.Result = response.LoginResult;
                    e.Result = true; // always true for testing
                },
                    callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Example #4
0
        public void DeleteCamera(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)
                {
                    DeleteCameraRequest request = new DeleteCameraRequest();
                    request.CameraId            = camera.Id;

                    DeleteCameraResponse response =
                        ServiceProvider.GetService <IDeviceConnectorService, IDeviceConnectorCallbackService>(
                            ViewModelLocator.ServiceClient,
                            ViewModelLocator.SelectedService.HostName,
                            ViewModelLocator.SelectedService.Uri.ToString()
                            ).DeleteCamera(request);

                    e.Result = true;
                },
                    null, callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Example #5
0
        public void GetCameraFilters(EventHandler <AsyncWorkerCallbackEventArgs <IList <CameraFilter> > > callback)
        {
            try
            {
                AsyncWorkerHandle <IList <CameraFilter> > handle = AsyncWorkerHelper.DoWork <IList <CameraFilter> >(
                    delegate(object sender, DoWorkEventArgs e)
                {
                    List <CameraFilter> filters = new List <CameraFilter>();

                    GetCameraFiltersRequest request   = new GetCameraFiltersRequest();
                    GetCameraFiltersResponse response =
                        ServiceProvider.GetService <IDeviceConnectorService, IDeviceConnectorCallbackService>(
                            ViewModelLocator.ServiceClient,
                            ViewModelLocator.SelectedService.HostName,
                            ViewModelLocator.SelectedService.Uri.ToString()
                            ).GetCameraFilters(request);

                    if (response.Filters != null)
                    {
                        foreach (var item in response.Filters)
                        {
                            CameraFilter filter = new CameraFilter(item.Name, item.Uri);
                            filters.Add(filter);
                        }
                    }

                    e.Result = filters;
                },
                    null, callback);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Example #6
0
 public void GetPublishedCameras(EventHandler <AsyncWorkerCallbackEventArgs <IList <PublishedCamera> > > callback)
 {
     try
     {
         AsyncWorkerHandle <IList <PublishedCamera> > handle = AsyncWorkerHelper.DoWork <IList <PublishedCamera> >(
             delegate(object sender, DoWorkEventArgs e)
         {
             e.Result = GetPublishedCamerasSync();
         },
             null, callback);
     }
     catch (Exception ex)
     {
         ExceptionHandler.Handle(ex);
     }
 }
Example #7
0
 public void UnpublishCamera(string hostUri, PublishedCamera camera, EventHandler <AsyncWorkerCallbackEventArgs <bool> > callback)
 {
     try
     {
         AsyncWorkerHandle <bool> handle = AsyncWorkerHelper.DoWork <bool>(
             delegate(object sender, DoWorkEventArgs e)
         {
             e.Result = UnpublishCameraSync(hostUri, camera);
         },
             null, callback);
     }
     catch (Exception ex)
     {
         ExceptionHandler.Handle(ex);
     }
 }
Example #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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);
            }
        }