private void ImageAnalyzer_AnalyzeImage(object sender, AnalyzeCompletedEventArgs e)
        {
            switch (e.SourceDevice)
            {
            case DeviceType.WebCam:
                if (WebCamState.ErrorsList == null)
                {
                    WebCamState.ErrorsList = new List <AnalyzeImageResultType>();
                }
                WebCamState.ErrorsList.AddRange(e.ErrorsList);
                WebCamState.ErrorsList   = WebCamState.ErrorsList.Distinct().ToList();
                WebCamState.ErrorMessage = e.Message;
                //ChangeWebCamState();
                //WebCamProcessErrors(this, e);

                return;

            case DeviceType.Scanner:
                ScannerState.ErrorsList   = e.ErrorsList;
                ScannerState.ErrorMessage = e.Message;
                SaveImages(e);
                ChangeScannerState();
                ScanProcessErrors(this, e);
                return;
            }
        }
        private string PreviewImgToBase64(AnalyzeCompletedEventArgs args)
        {
            string result = string.Empty;

            if (args != null && args.PreviewImage != null)
            {
                result = args.PreviewImage.ToBase64();
            }

            return(result);
        }
        private void SaveImages(AnalyzeCompletedEventArgs e, string postfix = "")
        {
            //  save images
            var dt = DateTime.Now;

            postfix = string.IsNullOrEmpty(postfix) ? "" : "_" + postfix;
            var scFileNamePreview = string.Format("{4}Image_{0}_{1}_{2}_{3}{5}.png", dt.ToString("yyyy-MM-dd_HH_mm_ss"), TaskImageIdents.WmfId, TaskImageIdents.IIN.GetHashCode(), "preview", e.SourceDevice, postfix);
            var scFileNameFull    = string.Format("{4}Image_{0}_{1}_{2}_{3}{5}.png", dt.ToString("yyyy-MM-dd_HH_mm_ss"), TaskImageIdents.WmfId, TaskImageIdents.IIN.GetHashCode(), "fullframe", e.SourceDevice, postfix);

            if (e.IsSuccess())
            {
                e.FullImage.Save(Path.Combine(MediaDirectory, scFileNameFull));
                e.PreviewImage.Save(Path.Combine(MediaDirectory, scFileNamePreview));
            }
        }
        private void Scanner_Error(object sender, HWErrorEventArgs e)
        {
            var errors = new List <AnalyzeImageResultType>
            {
                AnalyzeImageResultType.ScannerError
            };
            var eArgs = new AnalyzeCompletedEventArgs(DeviceType.Scanner, errors)
            {
                Message = e.Message
            };

            ScannerState.ErrorsList   = errors;
            ScannerState.ErrorMessage = e.Message;
            ScannerState = ScannerState.ChangeState();

            ScanProcessErrors(this, eArgs);
        }
        private void ImageAnalyzer_AnalyzeCompleted(object sender, AnalyzeCompletedEventArgs e)
        {
            //this.ImageAnalyzer = new ImageAnalyzer(PythonPath);
            //this.ImageAnalyzer.AnalyzeCompleted -= ImageAnalyzer_AnalyzeCompleted;
            //this.ImageAnalyzer.AnalyzeImage -= ImageAnalyzer_AnalyzeImage;

            // мы нашли подходящее изображение
            switch (e.SourceDevice)
            {
            case DeviceType.Scanner:
                //if (ScannerAnalyzeResult == null)
                //{

                if (e.IsSuccess())
                {
                    ScannerAnalyzeResult = e;
                    SaveImages(e);
                }
                else
                {
                    //UpdateRetry(DeviceType.Scanner);
                    //не отсылаем последнее удачное фото на главную форму...
                    //if (ScannerAnalyzeResult != null) //если есть чего возращать, давайте вернем..
                    //{
                    //    ChangeScannerState();
                    //    AnalyzeCompletedEventArgs LastSuccess = new AnalyzeCompletedEventArgs(e.SourceDevice, e.ErrorsList, ScannerAnalyzeResult.FullImage, ScannerAnalyzeResult.PreviewImage);
                    //    ScannerImageAnalyzeCompleted(this, LastSuccess);
                    //    break;
                    //}
                }
                ChangeScannerState();
                ScannerImageAnalyzeCompleted(this, e);
                //e.FullImage.Save(DateTime.Now.ToString("yyyy-MM-dd-hh-mm") + ".jpg");
                //}

                break;

            case DeviceType.WebCam:

                //if (this.WebCamAnalyzeResult == null)
                //    Console.WriteLine("ImageAnalyzer_AnalyzeCompleted webCam entering NULL");
                //else
                //    Console.WriteLine("ImageAnalyzer_AnalyzeCompleted webCam entering " + WebCamAnalyzeResult.ToString() + "  " + WebCamAnalyzeResult.IsSuccess().ToString());

                //if (WebCamAnalyzeResult == null || WebCamAnalyzeResult.IsSuccess() == false)
                //{
                //    lock (webCamLockObject)
                //    {
                //        if (WebCamAnalyzeResult == null || WebCamAnalyzeResult.IsSuccess() == false)
                //        {
                webCam.Stop();
                //создадим в куче копию найденных изображений
                if (e.IsSuccess())
                {
                    WebCamAnalyzeResult = e;     //получаем результаты работы камеры и СОХРАНЯЕМ ИХ
                    SaveImages(e);
                }
                else
                {
                    //UpdateRetry(DeviceType.WebCam);
                    // if (WebCamAnalyzeResult != null) //если есть чего возращать, давайте вернем..
                    //{
                    //    ChangeWebCamState();
                    //    AnalyzeCompletedEventArgs LastSuccess = new AnalyzeCompletedEventArgs(e.SourceDevice, e.ErrorsList, WebCamAnalyzeResult.FullImage, WebCamAnalyzeResult.PreviewImage);
                    //    WebCamImageAnalyzeCompleted(this, LastSuccess);
                    //    break;
                    //}
                }
                ChangeWebCamState();
                WebCamImageAnalyzeCompleted(this, e);
                //if (WebCamState.ErrorsList == null)
                //{
                //    WebCamState.ErrorsList = new List<AnalyzeImageResultType>();
                //}

                //if (e.ErrorsList != null)
                //{
                //    WebCamState.ErrorsList.AddRange(e.ErrorsList);
                //    WebCamState.ErrorsList = WebCamState.ErrorsList.Distinct().ToList();
                //}



                var Analyser = (Tevian.Analyser)ImageAnalyzer;
                Analyser.StopCamAnalyze();
                //        }
                //    }
                //}
                break;
            }
        }