Пример #1
0
 /// <summary>
 /// 更新相机
 /// </summary>
 public void UpdateCameras()
 {
     Cameras.Clear();
     if ((CameraFactory.Cameras?.Values != null) && (Scene?.VisionFrame?.IsEnableCamera == true))
     {
         CameraFactory.AddAllCamera();
         Cameras = new ObservableCollection <ICamera>(CameraFactory.Cameras.Values);
     }
 }
Пример #2
0
        private void RefreshCamera()
        {
            CloseSession();
            Cameras.Clear();
            foreach (var camera in CameraHandler.GetCameraList())
            {
                Cameras.Add(camera);
            }

            SelectedCamera = Cameras.FirstOrDefault();
        }
        public async Task <bool> Authenticate()
        {
            try
            {
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(GetCredentials())));

                var response = await _httpClient.GetAsync(string.Format("/Initialize?Latitude=0&Longitude=0&DeviceId={0}", Guid.NewGuid()));

                response.EnsureSuccessStatusCode();    // Throw if not a success code.

                var stream = await response.Content.ReadAsStreamAsync();

                var serializer  = new XmlSerializer(typeof(WebResponse));
                var webResponse = serializer.Deserialize(stream) as WebResponse;
                if (webResponse != null)
                {
                    if (webResponse.Header.Error == ErrorType.None)
                    {
                        _httpClient.DefaultRequestHeaders.Authorization = null; // Need to clear so following commands won't be treated as Initialize requests
                        SessionId = webResponse.Header.SessionId;

                        Cameras.Clear();
                        foreach (var camera in webResponse.Body.Cameras)
                        {
                            Utils.Trace(camera.Name + " " + camera.Id);
                            Cameras.Add(camera);
                        }
                        // We must periodically refresh the camera list, otherwise our session will timeout after 5*SRI if AutoLogoff set in AC
                        _camerasRefreshTimer.Interval = TimeSpan.FromSeconds(webResponse.Body.ClientConfiguration.StatusRefreshInterval).TotalMilliseconds;
                        _camerasRefreshTimer.Start();

                        return(true); // Authenticated successfully
                    }
                    Utils.Trace("UnitedVmsProvider Authenticate Error: " + webResponse.Header.Error);
                    var errorReason = webResponse.Header.Error == ErrorType.AuthorizationFailed
                        ? "Credenciales inválidas o licencia vencida."
                        : default(string);
                    throw new DvtelVmsException($"Dvtel Vms Authenticate Error: {webResponse.Header.Error}. {errorReason}", webResponse.Header.Error);
                }
            }
            catch (Exception ex)
            {
                if (ex is DvtelVmsException)
                {
                    throw;
                }

                Utils.Trace("UnitedVmsProvider Authenticate Error: " + ex.Message, ex);
                throw new DvtelVmsException("Dvtel Vms Authenticate Error: " + ErrorType.Unknown, ex);
            }
            throw new DvtelVmsException("Dvtel Vms Authenticate Error: Unserializable response.");
        }
        /// <summary>
        /// Gets all data sources (cameras) from the VideoXpert system and stores them in the <see cref="Cameras"/> list.
        /// </summary>
        /// <returns>The GetCameras Task.</returns>
        public static async Task GetCameras()
        {
            if (system == null)
            {
                return;
            }

            Cameras.Clear();
            var cameras = await Task.Run(() => system.DataSources);

            foreach (var camera in cameras)
            {
                Cameras.Add(camera);
            }
        }
        public async Task GetCameras()
        {
            try
            {
                if (SessionId != Guid.Empty)
                {
                    var response = await _httpClient.GetAsync("/GetCameras?SessionId=" + SessionId);

                    response.EnsureSuccessStatusCode(); // Throw if not a success code.

                    var stream = await response.Content.ReadAsStreamAsync();

                    var serializer  = new XmlSerializer(typeof(WebResponse));
                    var webResponse = serializer.Deserialize(stream) as WebResponse;
                    if (webResponse != null)
                    {
                        if (webResponse.Header.Error == ErrorType.None)
                        {
                            Cameras.Clear();
                            foreach (var camera in webResponse.Body.Cameras)
                            {
                                Utils.Trace(camera.Name + " " + camera.Id);
                                Cameras.Add(camera);
                            }
                            // Report to registered listeners the updated list of cameras
                            if (_cameraListUpdated != null)
                            {
                                _cameraListUpdated.Invoke(this, Cameras);
                            }
                        }
                        else
                        {
                            Utils.Trace("UnitedVmsProvider GetCameras Error: " + webResponse.Header.Error);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.Trace("UnitedVmsProvider GetCameras Error", ex);
            }
        }
        public async Task Logout()
        {
            try
            {
                _camerasRefreshTimer.Stop();

                if (SessionId != Guid.Empty)
                {
                    var response = await _httpClient.GetAsync("/Stop?SessionId=" + SessionId);

                    response.EnsureSuccessStatusCode(); // Throw if not a success code.

                    var stream = await response.Content.ReadAsStreamAsync();

                    var serializer  = new XmlSerializer(typeof(WebResponse));
                    var webResponse = serializer.Deserialize(stream) as WebResponse;
                    if (webResponse != null)
                    {
                        if (webResponse.Header.Error == ErrorType.None)
                        {
                            Cameras.Clear();
                            SessionId = Guid.Empty;
                        }
                        else
                        {
                            Utils.Trace("UnitedVmsProvider Logout Error: " + webResponse.Header.Error);
                            throw new DvtelVmsException("Dvtel Vms Logout Error: " + webResponse.Header.Error, webResponse.Header.Error);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is DvtelVmsException)
                {
                    throw;
                }

                Utils.Trace("UnitedVmsProvider Logout Error", ex);
                throw new DvtelVmsException("Dvtel Vms Logout Error", ex);
            }
        }
Пример #7
0
 public Task DeleteDatabaseIfExists()
 {
     Cameras.Clear();
     Cars.Clear();
     return(EmptyTask);
 }
Пример #8
0
 public override void Reset()
 {
     Cameras.Clear();
     CurrentCamera = 0;
 }