private async void ConvertImage(ImageStatsCollectingData srcData)
        {
            Interlocked.Increment(ref totalFilesProcessed);
            int perc = Convert.ToInt32(100.0d * (double)totalFilesProcessed / (double)totalFilesCountToProcess);

            Console.WriteLine(DateTime.Now.ToString("s") + " : " + perc + "% : started processing file " + Environment.NewLine + srcData.filename);

            Dictionary <string, object> taskParameters = new Dictionary <string, object>();

            foreach (string key in defaultProperties.Keys)
            {
                taskParameters.Add(key, defaultProperties[key]);
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            taskParameters.Add("Stopwatch", sw);
            taskParameters.Add("logFileName", errorLogFilename);
            taskParameters.Add("currentFullFileName", srcData.filename);


            ImageStatsDataCalculationResult currImageConversionResult = await ConvertImageTask(taskParameters);


            #region process result

            currImageConversionResult.stopwatch.Stop();

            if (currImageConversionResult.calcResult)
            {
                string currentFullFileName = currImageConversionResult.imgFilename;
                string strPerfCountersData = currentFullFileName + ";" +
                                             currImageConversionResult.stopwatch.ElapsedMilliseconds + ";" +
                                             (currImageConversionResult.procTotalProcessorTimeEnd -
                                              currImageConversionResult.procTotalProcessorTimeStart).TotalMilliseconds +
                                             Environment.NewLine;
                ServiceTools.logToTextFile(strPerformanceCountersStatsFile, strPerfCountersData, true);


                ImageStatsCollectingData foundDataObj =
                    lStatsCalculation.Find(obj => obj.filename == currentFullFileName);
                foundDataObj.State = ImageStatsCollectingState.Finished;


                Console.WriteLine(DateTime.Now.ToString("s") + " : finished processing file " + Environment.NewLine + currentFullFileName);
            }
            else
            {
                string currentFullFileName            = currImageConversionResult.imgFilename;
                ImageStatsCollectingData foundDataObj =
                    lStatsCalculation.Find(obj => obj.filename == currentFullFileName);
                foundDataObj.State = ImageStatsCollectingState.Error;
                Console.WriteLine("ERROR processing file " + Path.GetFileName(currentFullFileName));
                try
                {
                    #region report error

                    ServiceTools.logToTextFile(errorLogFilename,
                                               "Error processing file: " + Environment.NewLine + currentFullFileName +
                                               Environment.NewLine + "message: " +
                                               ServiceTools.GetExceptionMessages(currImageConversionResult.exception) + Environment.NewLine +
                                               ServiceTools.CurrentCodeLineDescription() + Environment.NewLine + "Stack trace: " + Environment.NewLine +
                                               Environment.StackTrace + Environment.NewLine + Environment.NewLine, true, true);

                    #endregion report error
                }
                catch (Exception ex)
                {
                    return;
                }
            }

            #endregion process result
        }
Esempio n. 2
0
        private void ProcessImage(ImageStatsCollectingData srcData)
        {
            Interlocked.Increment(ref totalFilesProcessed);
            int perc = Convert.ToInt32(100.0d * (double)totalFilesProcessed / (double)totalFilesCountToProcess);

            Console.WriteLine(DateTime.Now.ToString("s") + " : " + perc + "% : started processing file " + Environment.NewLine + srcData.filename);

            Dictionary <string, object> optionalParameters = new Dictionary <string, object>();

            optionalParameters.Add("ImagesRoundMasksXMLfilesMappingList", ImagesRoundMasksXMLfilesMappingList);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            optionalParameters.Add("Stopwatch", sw);
            optionalParameters.Add("logFileName", errorLogFilename);

            ImageStatsDataCalculationResult currImageProcessingResult =
                ImageProcessing.CalculateImageStatsData(srcData.filename, optionalParameters);

            currImageProcessingResult.stopwatch.Stop();
            if (currImageProcessingResult.calcResult)
            {
                string currentFullFileName = currImageProcessingResult.imgFilename;
                string strPerfCountersData = currentFullFileName + ";" +
                                             currImageProcessingResult.stopwatch.ElapsedMilliseconds + ";" +
                                             (currImageProcessingResult.procTotalProcessorTimeEnd -
                                              currImageProcessingResult.procTotalProcessorTimeStart).TotalMilliseconds +
                                             Environment.NewLine;
                ServiceTools.logToTextFile(strPerformanceCountersStatsFile, strPerfCountersData, true);



                //string strImageGrIxMedianP5DataFileName =
                //    ConventionalTransitions.ImageGrIxMedianP5DataFileName(currentFullFileName, imageMP5statsXMLdataFilesDirectory);
                //ServiceTools.WriteObjectToXML(currImageProcessingResult.mp5Result, strImageGrIxMedianP5DataFileName);
                string strImageGrIxYRGBDataFileName =
                    ConventionalTransitions.ImageGrIxYRGBstatsDataFileName(currentFullFileName, imageYRGBstatsXMLdataFilesDirectory, true, currPath2Process);
                ServiceTools.WriteObjectToXML(currImageProcessingResult.grixyrgbStatsData, strImageGrIxYRGBDataFileName);


                ImageStatsCollectingData foundDataObj =
                    lStatsCalculation.Find(obj => obj.filename == currentFullFileName);
                foundDataObj.State           = ImageStatsCollectingState.Finished;
                foundDataObj.GrIxMedianValue = currImageProcessingResult.mp5Result.GrIxStatsMedian;
                foundDataObj.GrIxPerc5Value  = currImageProcessingResult.mp5Result.GrIxStatsPerc5;


                Console.WriteLine(DateTime.Now.ToString("s") + " : finished processing file " + Environment.NewLine + currentFullFileName);
            }
            else
            {
                string currentFullFileName            = currImageProcessingResult.imgFilename;
                ImageStatsCollectingData foundDataObj =
                    lStatsCalculation.Find(obj => obj.filename == currentFullFileName);
                foundDataObj.State = ImageStatsCollectingState.Error;
                Console.WriteLine("ERROR processing file " + Path.GetFileName(currentFullFileName));
                try
                {
                    //report full error to error log file
                    #region report error
#if (DEBUG && MONO)
                    ServiceTools.logToTextFile(errorLogFilename,
                                               "Error processing file: " + Environment.NewLine + currentFullFileName +
                                               Environment.NewLine + "messages: " +
                                               ServiceTools.GetExceptionMessages(currImageProcessingResult.exception) + Environment.NewLine +
                                               "Stack trace: " + Environment.NewLine +
                                               Environment.StackTrace + Environment.NewLine + Environment.NewLine, true, true);
#else
#if MONO
                    ServiceTools.logToTextFile(errorLogFilename,
                                               "Error processing file: " + Environment.NewLine + currentFullFileName +
                                               Environment.NewLine + "messages: " +
                                               ServiceTools.GetExceptionMessages(currImageProcessingResult.exception) + Environment.NewLine +
                                               "Stack trace: " + Environment.NewLine +
                                               Environment.StackTrace + Environment.NewLine + Environment.NewLine, true, true);
#else
                    ServiceTools.logToTextFile(errorLogFilename,
                                               "Error processing file: " + Environment.NewLine + currentFullFileName +
                                               Environment.NewLine + "message: " +
                                               ServiceTools.GetExceptionMessages(currImageProcessingResult.exception) + Environment.NewLine +
                                               ServiceTools.CurrentCodeLineDescription() + Environment.NewLine + "Stack trace: " + Environment.NewLine +
                                               Environment.StackTrace + Environment.NewLine + Environment.NewLine, true, true);
#endif
#endif
                    #endregion report error
                }
                catch (Exception ex)
                {
                    return;
                }
            }
        }