Example #1
0
        private async Task <CameraResult> ProcessCameraAsync(CameraConfig cameraConf, DateTime periodStart, DateTime periodEnd)
        {
            var result = new CameraResult(
                new CameraDTO
            {
                Alias             = cameraConf.Alias,
                DestinationFolder = cameraConf.DestinationFolder,
                IpAddress         = cameraConf.IpAddress,
                PortNumber        = cameraConf.PortNumber,
                UserName          = cameraConf.UserName,
            });

            try
            {
                using (this.client = this.clientFactory.Create(cameraConf))
                {
                    this.client.InitializeClient();
                    this.cancelTokenSource.Token.ThrowIfCancellationRequested();

                    if (this.client.Login())
                    {
                        this.CheckClientHardDriveStatus(result);

                        this.cancelTokenSource.Token.ThrowIfCancellationRequested();
                        var videos = await this.DownloadVideos(periodStart, periodEnd);

                        result.DownloadedVideos.AddRange(videos);

                        if (cameraConf.DownloadPhotos)
                        {
                            var photos = await this.DownloadPhotos(periodStart, periodEnd);

                            result.DownloadedPhotos.AddRange(photos);
                        }

                        this.PrintStatistic(cameraConf.DestinationFolder);
                    }
                    else
                    {
                        this.logger.Warn("Unable to login");
                    }
                }
            }
            catch (OperationCanceledException ex)
            {
                ex.Data.Add("Camera", cameraConf);
                throw;
            }
            catch (Exception ex)
            {
                result.Failed = true;
                ex.Data.Add("Camera", cameraConf);
                this.HandleException(ex);
            }

            return(result);
        }
Example #2
0
 private void ForceExit()
 {
     this.client?.ForceExit();
     this.client = null;
 }