private void btnOK_Click(object sender, EventArgs e)
        {
            Dictionary <string, object> dictSettings = new Dictionary <string, object>();

            foreach (Pair <string, object> item in (DictionaryBindingList <string, object>)propertyGrid.DataSource)
            {
                dictSettings.Add(item.Key, item.Value);
            }

            //string fname = Directory.GetCurrentDirectory() + "\\settings\\SkyImagesAnalyzerSettings.xml";
            ServiceTools.WriteDictionaryToXml(dictSettings, fNamePropertiesXMLfile, false);

            this.Close();
        }
Ejemplo n.º 2
0
 private void saveDefaultProperties()
 {
     ServiceTools.WriteDictionaryToXml(defaultProperties, defaultPropertiesXMLfileName, false);
 }
Ejemplo n.º 3
0
        private void btnCorrectGPSdata_Click(object sender, EventArgs e)
        {
            string infoFilesPath    = rtbPath.Text;
            string navdataFilesPath = rtbVesselNavDataDirectoryPath.Text;

            infoFilesPath += ((infoFilesPath.Substring(infoFilesPath.Length - 1) == "\\") ? ("") : ("\\"));
            string bcpFilesPath = infoFilesPath + "backup\\";

            if (infoFilesPath == "")
            {
                return;
            }
            if (!Directory.Exists(infoFilesPath))
            {
                return;
            }
            if (navdataFilesPath == "")
            {
                return;
            }
            if (!Directory.Exists(navdataFilesPath))
            {
                return;
            }

            DirectoryInfo dirConcurrentDataFiles = new DirectoryInfo(infoFilesPath);

            FileInfo[] concurrentDataFilesList = dirConcurrentDataFiles.GetFiles("*.xml", SearchOption.TopDirectoryOnly);
            //string[] sConcurrentInfoFilenames = Directory.GetFiles(rtbPath.Text, "*.xml");
            if (!concurrentDataFilesList.Any())
            {
                return;
            }
            if (!ServiceTools.CheckIfDirectoryExists(bcpFilesPath))
            {
                return;
            }

            CultureInfo provider = CultureInfo.InvariantCulture;

            foreach (FileInfo concurrentInfoFileInfo in concurrentDataFilesList)
            {
                Dictionary <string, object> dictSavedData = ServiceTools.ReadDictionaryFromXML(concurrentInfoFileInfo.FullName);
                DateTime computerDateTime = DateTime.ParseExact((string)dictSavedData["DateTime"], "o", provider).ToUniversalTime();

                DateTime gpsDateTime = DateTime.ParseExact((string)dictSavedData["GPSDateTimeUTC"], "o", provider).ToUniversalTime();

                if (Math.Abs((gpsDateTime - computerDateTime).TotalSeconds) > 300)
                {
                    //надо корректировать по данным судовой навигации
                    File.Copy(concurrentInfoFileInfo.FullName, bcpFilesPath + concurrentInfoFileInfo.Name);
                    dictSavedData["GPSdata"] = "$GPGGA," + computerDateTime.Hour.ToString("D02") +
                                               computerDateTime.Minute.ToString("D02") +
                                               computerDateTime.Second.ToString("D02") + ".00";

                    IoffeVesselDualNavDataConverted ioffeNavdata =
                        IoffeVesselNavDataReader.GetNavDataByDatetime(navdataFilesPath, computerDateTime);
                    if (ioffeNavdata == null)
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "couldn`t find vessel nav data for file: " + Environment.NewLine +
                                                             concurrentInfoFileInfo.FullName);
                        continue;
                    }

                    dictSavedData["GPSLat"]         = ioffeNavdata.gps.Lat;
                    dictSavedData["GPSLon"]         = ioffeNavdata.gps.Lon;
                    dictSavedData["GPSDateTimeUTC"] = ioffeNavdata.gps.dateTimeUTC.ToString("o");

                    ServiceTools.WriteDictionaryToXml(dictSavedData, concurrentInfoFileInfo.FullName);
                }
            }
        }
Ejemplo n.º 4
0
        // private List<bool> bgwFinished = new List<bool>();
        public void CollectPositioningData()
        {
#if DEBUG
            int concurrentFilesProcessingCount = 1;
#else
            int concurrentFilesProcessingCount = 2;
            try
            {
                concurrentFilesProcessingCount = Convert.ToInt32(defaultProperties["MaxConcurrentFilesProcessingCount"]);
            }
            catch (Exception ex)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "ERROR! exception thrown: " + ex.Message + Environment.NewLine +
                                                     "MaxConcurrentFilesProcessingCount value can`t be read. " + Environment.NewLine +
                                                     "Using default value = " + concurrentFilesProcessingCount);
            }
#endif



            theLogWindow = ServiceTools.LogAText(theLogWindow, "started on " + DateTime.UtcNow.ToString("s"));


            string        strImagesDir = ParentForm.richTextBox1.Text;
            DirectoryInfo imagesDir    = new DirectoryInfo(strImagesDir);

            if (!imagesDir.Exists)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "Операция не выполнена. Не найдена директория:" + Environment.NewLine + strImagesDir +
                                                     Environment.NewLine, true);
                return;
            }


            // оказалось, что маска - case-insensitive
            lImagesFileInfos = new List <FileInfo>(imagesDir.GetFiles("*.jpg", SearchOption.TopDirectoryOnly));

            List <FileInfo> lImagesFileInfoWithExistingSunDiskInfo = lImagesFileInfos.ConvertAll <FileInfo>(fInfoSrc =>
            {
                string sunDiskInfoFileName = fInfoSrc.DirectoryName + "\\" +
                                             Path.GetFileNameWithoutExtension(fInfoSrc.FullName) + "-SunDiskInfo.xml";
                if (File.Exists(sunDiskInfoFileName))
                {
                    return(fInfoSrc);
                }
                else
                {
                    return(null);
                }
            });
            lImagesFileInfoWithExistingSunDiskInfo.RemoveAll(fInfo => fInfo == null);

            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                 "files already processed before: " + lImagesFileInfoWithExistingSunDiskInfo.Count);

            lImagesFileInfos.RemoveAll(fInfo => lImagesFileInfoWithExistingSunDiskInfo.Contains(fInfo));
            int filesCountToProcess        = lImagesFileInfos.Count;
            int filesCountAlreadyProcessed = lImagesFileInfoWithExistingSunDiskInfo.Count;

            lImagesFileInfos.AddRange(lImagesFileInfoWithExistingSunDiskInfo);



            //List<BackgroundWorker> bgwList = new List<BackgroundWorker>();
            //for (int i = 0; i < 2; i++)
            //{
            //    //bgwFinished.Add(true);
            //    //bgwList.Add(null);
            //}

            int currDataIdx = 1;

            foreach (FileInfo finfo in lImagesFileInfos)
            {
                //int currentBgwID = -1;
                while ((cbgBgwList.Count >= concurrentFilesProcessingCount) && (!hasToStopCollecting))
                {
                    Application.DoEvents();
                    Thread.Sleep(0);
                }

                //while ((bgwFinished.Sum(boolVal => (boolVal) ? ((int)0) : ((int)1)) == bgwFinished.Count) && (!hasToStopCollecting))
                //{
                //    Application.DoEvents();
                //    Thread.Sleep(0);
                //}
                if (hasToStopCollecting)
                {
                    break;
                }

                //for (int i = 0; i < concurrentFilesProcessingCount; i++)
                //{
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "" + currDataIdx + " / " + filesCountToProcess + " (+ " + filesCountAlreadyProcessed +
                                                     " processed before)");
                theLogWindow = ServiceTools.LogAText(theLogWindow, Environment.NewLine + "starting: " + finfo.Name);


                //object[] BGWorker2Args = new object[] { finfo, defaultProperties, currentBgwID };
                object[] BGWorker2Args = new object[] { finfo, defaultProperties };

                BackgroundWorker currBgw = new BackgroundWorker();
                // bgwList[currentBgwID] = currBgw;
                currBgw.DoWork             += currBgw_DoWork;
                currBgw.RunWorkerCompleted += currBgw_RunWorkerCompleted;
                currBgw.RunWorkerAsync(BGWorker2Args);

                cbgBgwList.Add(finfo.FullName);

                if (filesCountToProcess > 0)
                {
                    int progress = Convert.ToInt32(100.0d * (double)currDataIdx / (double)filesCountToProcess);
                    ThreadSafeOperations.UpdateProgressBar(ParentForm.pbUniversalProgressBar, progress);
                    Interlocked.Increment(ref currDataIdx);
                }
            }


            while (cbgBgwList.Count > 0)
            {
                Application.DoEvents();
                Thread.Sleep(0);
            }

            if (hasToStopCollecting)
            {
                return;
            }



            // сохраним на будущее
            string   strMedianPerc5StatsXMLFileName = (string)defaultProperties["DefaultMedianPerc5StatsXMLFile"];
            FileInfo MedianPerc5StatsXMLFileInfo    = new FileInfo(strMedianPerc5StatsXMLFileName);
            string   strMedianPerc5StatsXMLFilePath = MedianPerc5StatsXMLFileInfo.DirectoryName;
            strMedianPerc5StatsXMLFilePath += (strMedianPerc5StatsXMLFilePath.Last() == '\\') ? ("") : ("\\");
            string computedDeviationsXMLfilesPath = strMedianPerc5StatsXMLFilePath + "azimuth-dev-stats\\";
            if (!ServiceTools.CheckIfDirectoryExists(computedDeviationsXMLfilesPath))
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "couldn`t locate or create directory " + computedDeviationsXMLfilesPath);
                return;
            }

            string computedAzimuthDeviationsXMLFile = computedDeviationsXMLfilesPath + "PreComputedSunAnglesDeviationsData.xml";

            List <AngleSunDeviationCalcResult> lResList =
                new List <AngleSunDeviationCalcResult>(cbAnglesSunDeviationCalcResults);
            ServiceTools.WriteObjectToXML(lResList, computedAzimuthDeviationsXMLFile);
            ServiceTools.WriteDictionaryToXml(defaultProperties, defaultPropertiesXMLfileName, false);


            // теперь посчитаем статистику
            List <AngleSunDeviationCalcResult> azimuthResults = new List <AngleSunDeviationCalcResult>(lResList);
            List <AngleSunDeviationCalcResult> zenithResults  = new List <AngleSunDeviationCalcResult>(lResList);
            azimuthResults.RemoveAll(
                azimuthSunDeviationCalcResult =>
                ((!azimuthSunDeviationCalcResult.calculationSucceeded) ||
                 (!azimuthSunDeviationCalcResult.AzimuthDeviationCanBeComputed)));
            zenithResults.RemoveAll(
                sunDeviationCalcResult =>
                ((!sunDeviationCalcResult.calculationSucceeded) ||
                 (!sunDeviationCalcResult.ZenithDeviationCanBeComputed)));

            List <double> azimuthDevValues =
                azimuthResults.ConvertAll <double>(
                    azimuthSunDeviationCalcResult => azimuthSunDeviationCalcResult.computedAzimuthDeviationDeg);

            List <double> zenithDevValues =
                zenithResults.ConvertAll <double>(
                    azimuthSunDeviationCalcResult => azimuthSunDeviationCalcResult.computedZenithDeviationDeg);


            ServiceTools.ExecMethodInSeparateThread(ParentForm, delegate()
            {
                HistogramDataAndProperties histAzimuthData =
                    new HistogramDataAndProperties(DenseVector.OfEnumerable(azimuthDevValues), 100);
                HistogramCalcAndShowForm hAzimuthForm = new HistogramCalcAndShowForm("azimuth sun angle deviations (deg.)",
                                                                                     defaultProperties);
                hAzimuthForm.HistToRepresent = histAzimuthData;
                hAzimuthForm.Show();
                hAzimuthForm.Represent();
            });



            ServiceTools.ExecMethodInSeparateThread(ParentForm, delegate()
            {
                HistogramDataAndProperties histZenithData =
                    new HistogramDataAndProperties(DenseVector.OfEnumerable(zenithDevValues), 100);
                HistogramCalcAndShowForm hZenithForm = new HistogramCalcAndShowForm("zenith sun angle deviations (deg.)",
                                                                                    defaultProperties);
                hZenithForm.HistToRepresent = histZenithData;
                hZenithForm.Show();
                hZenithForm.Represent();
            });



            ThreadSafeOperations.UpdateProgressBar(ParentForm.pbUniversalProgressBar, 0);
        }