public void SaveClusteringData(string filenameTemplate)
        {
            FileInfo fInfo = new FileInfo(filenameTemplate);
            string   dir   = fInfo.DirectoryName;

            if (!ServiceTools.CheckIfDirectoryExists(dir))
            {
                return;
            }
            if (fInfo.Exists)
            {
                // не трогаем уже существующий файл
                return;
            }
            if (foundClassesContours.Count == 0)
            {
                return;
            }

            Rectangle  gridRect     = new Rectangle(0, 0, dmDensityMesh.ColumnCount, dmDensityMesh.RowCount);
            RectangleF realDataRect = new RectangleF((float)minXval, (float)minYval, (float)(maxXval - minXval),
                                                     (float)(maxYval - minYval));

            foreach (Contour <Point> foundClassContour in foundClassesContours)
            {
                ClusteringData currClusteringData = new ClusteringData(foundClassContour, gridRect, realDataRect);
                string         currClassFName     = filenameTemplate +
                                                    "-X" + currClusteringData.ptdClusterMassCenter.X.ToString("e").Replace(",", "_") +
                                                    "-Y" + currClusteringData.ptdClusterMassCenter.Y.ToString("e").Replace(",", "_") + ".xml";
                ServiceTools.WriteObjectToXML(currClusteringData, currClassFName);
            }
        }
        public EventsDensityAnalysisForm(List <PointD> lInPoints, Dictionary <string, object> properties, int inSpaceDiscretization = 512)
        {
            InitializeComponent();

            defaultProperties  = properties;
            strOutputDirectory = (string)defaultProperties["DefaultDataFilesLocation"];
            if (!ServiceTools.CheckIfDirectoryExists(strOutputDirectory))
            {
                strOutputDirectory = "";
            }

            lPointsArray        = new List <PointD>(lInPoints);
            spaceDiscretization = inSpaceDiscretization;
            minXval             = lPointsArray.Min(pt => pt.X);
            maxXval             = lPointsArray.Max(pt => pt.X);
            minYval             = lPointsArray.Min(pt => pt.Y);
            maxYval             = lPointsArray.Max(pt => pt.Y);

            minXval = Math.Min(minXval, minYval);
            minYval = minXval;
            maxXval = Math.Max(maxXval, maxYval);
            maxYval = maxXval;
            CalculateDensityMesh();
        }
        private void readDefaultProperties()
        {
            defaultProperties            = new Dictionary <string, object>();
            defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() +
                                           Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar +
                                           Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) +
                                           "-Settings.xml";
            if (!File.Exists(defaultPropertiesXMLfileName))
            {
                Console.WriteLine("couldn`t find settings XML file: " + Environment.NewLine +
                                  defaultPropertiesXMLfileName);
            }
            else
            {
                defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName);
            }


            bool bDefaultPropertiesHasBeenUpdated = false;

            string CurDir = Directory.GetCurrentDirectory();

            // ImagesBasePath
            if (defaultProperties.ContainsKey("ImagesBasePath"))
            {
                ImagesBasePath = (string)defaultProperties["ImagesBasePath"];
            }
            else
            {
                ImagesBasePath = CurDir + Path.DirectorySeparatorChar + "images" + Path.DirectorySeparatorChar;
                defaultProperties.Add("ImagesBasePath", ImagesBasePath);
                bDefaultPropertiesHasBeenUpdated = true;
            }


            // IncomingImagesBasePath
            if (defaultProperties.ContainsKey("IncomingImagesBasePath"))
            {
                IncomingImagesBasePath = (string)defaultProperties["IncomingImagesBasePath"];
            }
            else
            {
                IncomingImagesBasePath = CurDir + Path.DirectorySeparatorChar + "IncomingImages" + Path.DirectorySeparatorChar;
                defaultProperties.Add("IncomingImagesBasePath", IncomingImagesBasePath);

                ServiceTools.CheckIfDirectoryExists(IncomingImagesBasePath);

                bDefaultPropertiesHasBeenUpdated = true;
            }



            // ConcurrentDataXMLfilesBasePath
            if (defaultProperties.ContainsKey("ConcurrentDataXMLfilesBasePath"))
            {
                ConcurrentDataXMLfilesBasePath = (string)defaultProperties["ConcurrentDataXMLfilesBasePath"];
            }
            else
            {
                ConcurrentDataXMLfilesBasePath = "";
                defaultProperties.Add("ConcurrentDataXMLfilesBasePath", ConcurrentDataXMLfilesBasePath);
                bDefaultPropertiesHasBeenUpdated = true;
            }


            // YRGBstatsXMLdataFilesDirectory
            if (defaultProperties.ContainsKey("YRGBstatsXMLdataFilesDirectory"))
            {
                YRGBstatsXMLdataFilesDirectory = (string)defaultProperties["YRGBstatsXMLdataFilesDirectory"];
            }
            else
            {
                YRGBstatsXMLdataFilesDirectory = "";
                defaultProperties.Add("YRGBstatsXMLdataFilesDirectory", YRGBstatsXMLdataFilesDirectory);
                bDefaultPropertiesHasBeenUpdated = true;
            }



            //RadiometersDataPath
            if (defaultProperties.ContainsKey("RadiometersDataPath"))
            {
                RadiometersDataPath = (string)defaultProperties["RadiometersDataPath"];
            }
            else
            {
                RadiometersDataPath = @"C:\Program Files (x86)\Theodor Friedrichs\Comgraph32\";
                defaultProperties.Add("RadiometersDataPath", RadiometersDataPath);
                bDefaultPropertiesHasBeenUpdated = true;
            }


            // tgrm_token
            if (defaultProperties.ContainsKey("tgrm_token"))
            {
                tgrm_token = (string)defaultProperties["tgrm_token"];
            }
            else
            {
                tgrm_token = "";
                defaultProperties.Add("tgrm_token", tgrm_token);
                bDefaultPropertiesHasBeenUpdated = true;
            }



            // R2SLufftUMBappPath
            if (defaultProperties.ContainsKey("R2SLufftUMBappPath"))
            {
                R2SLufftUMBappPath = (string)defaultProperties["R2SLufftUMBappPath"];
            }
            else
            {
                R2SLufftUMBappPath = "";
                defaultProperties.Add("R2SLufftUMBappPath", R2SLufftUMBappPath);
                bDefaultPropertiesHasBeenUpdated = true;
            }


            // VentusLufftUMBappPath
            if (defaultProperties.ContainsKey("VentusLufftUMBappPath"))
            {
                VentusLufftUMBappPath = (string)defaultProperties["VentusLufftUMBappPath"];
            }
            else
            {
                VentusLufftUMBappPath = "";
                defaultProperties.Add("VentusLufftUMBappPath", VentusLufftUMBappPath);
                bDefaultPropertiesHasBeenUpdated = true;
            }



            // WSLufftUMBappPath
            if (defaultProperties.ContainsKey("WSLufftUMBappPath"))
            {
                WSLufftUMBappPath = (string)defaultProperties["WSLufftUMBappPath"];
            }
            else
            {
                WSLufftUMBappPath = "";
                defaultProperties.Add("WSLufftUMBappPath", WSLufftUMBappPath);
                bDefaultPropertiesHasBeenUpdated = true;
            }



            if (bDefaultPropertiesHasBeenUpdated)
            {
                saveDefaultProperties();
            }
        }
        private async Task Run()
        {
            if (tgrm_token == "")
            {
                Console.WriteLine("telegram token for channel is not set. Processing will not proceed.");
                Console.WriteLine("Finished. Press any key...");
                Console.ReadKey();
                return;
            }
            var Bot = new Api(tgrm_token);

            var me = await Bot.GetMe();

            Console.WriteLine("Hello my name is {0}", me.Username);

            var offset = 0;

            while (true)
            {
                var updates = await Bot.GetUpdates(offset);

                foreach (var update in updates)
                {
                    if (update.Message.Type == MessageType.TextMessage)
                    {
                        if (ServiceTools.CheckIfDirectoryExists(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "logs"))
                        {
                            ServiceTools.logToTextFile(logFilename,
                                                       "" + update.Message.Chat.Id + " : " + update.Message.Text + Environment.NewLine, true, true);
                        }



                        if (update.Message.Text == "/current_image")
                        {
                            string            FilenameToSend   = "";
                            Image <Bgr, byte> lastImagesCouple = CurrentImagesCouple(out FilenameToSend);
                            string            tmpFNameToSave   = Path.GetTempPath();
                            tmpFNameToSave += (tmpFNameToSave.Last() == Path.DirectorySeparatorChar)
                                ? ("")
                                : (Path.DirectorySeparatorChar.ToString());
                            tmpFNameToSave += FilenameToSend;
                            lastImagesCouple.Save(tmpFNameToSave);
                            var     fileStream  = File.Open(tmpFNameToSave, FileMode.Open);
                            Message sentMessage = await Bot.SendPhoto(update.Message.Chat.Id, new FileToSend(FilenameToSend, fileStream));

                            File.Delete(tmpFNameToSave);
                        }
                        else if (update.Message.Text == "/concurrent_info")
                        {
                            string lastConcurrentInfoFileName = GetLastConcurrentInfo();

                            Message sentMessage =
                                await
                                Bot.SendTextMessage(update.Message.Chat.Id, lastConcurrentInfoFileName, true, false,
                                                    update.Message.MessageId);
                        }
                        else if (update.Message.Text == "/current_cc")
                        {
                            Task <string> tskObtainCC = ObtainLastImageCC();

                            //Message sentMessage1 =
                            //    await
                            //        Bot.SendTextMessage(update.Message.Chat.Id,
                            //            "Started calculations. Be patient please, it may take a few minutes.", true,
                            //            false, update.Message.MessageId);

                            string strReply = await tskObtainCC;

                            Message sentMessage2 =
                                await
                                Bot.SendTextMessage(update.Message.Chat.Id, strReply, true, false,
                                                    update.Message.MessageId);
                        }
                        else if (update.Message.Text == "/meteo_info")
                        {
                            string strCurrentMeteoParametersString = await ObtainLatestMeteoParameters();

                            Message sentMessage =
                                await
                                Bot.SendTextMessage(update.Message.Chat.Id, strCurrentMeteoParametersString, true, false,
                                                    update.Message.MessageId);
                        }
                        //else if (update.Message.Text == "/solar_irradiation")
                        //{
                        //    string strCurrentRadiometersString = await ObtainLatestRadiometersParameters();
                        //    Message sentMessage =
                        //        await
                        //            Bot.SendTextMessage(update.Message.Chat.Id, strCurrentRadiometersString, true, false,
                        //                update.Message.MessageId);

                        //}
                        else if (update.Message.Text == "/start")
                        {
                            string strStartMessage =
                                ServiceTools.ReadTextFromFile(Directory.GetCurrentDirectory() +
                                                              Path.DirectorySeparatorChar + "settings" +
                                                              Path.DirectorySeparatorChar + "BotStartMessage.txt");
                            Message sentMessage =
                                await
                                Bot.SendTextMessage(update.Message.Chat.Id, strStartMessage, true, false,
                                                    update.Message.MessageId);

                            Console.WriteLine("Echo Message: {0}", update.Message.Text);
                        }
                        else
                        {
                            // await Bot.SendChatAction(update.Message.Chat.Id, ChatAction.Typing);
                            // await Task.Delay(200);
                            var t = await Bot.SendTextMessage(update.Message.Chat.Id, "I can`t get your request. Please try again.");

                            Console.WriteLine("Echo Message: {0}", update.Message.Text);
                        }
                    }

                    if (update.Message.Type == MessageType.PhotoMessage)
                    {
                        var file = await Bot.GetFile(update.Message.Photo.LastOrDefault()?.FileId);

                        Console.WriteLine("Received Photo: {0}", file.FilePath);

                        var filename = IncomingImagesBasePath + file.FileId + "." + file.FilePath.Split('.').Last();

                        using (var profileImageStream = File.Open(filename, FileMode.Create))
                        {
                            await file.FileStream.CopyToAsync(profileImageStream);
                        }

                        Console.WriteLine("Photo saved to: {0}", filename);

                        if (ServiceTools.CheckIfDirectoryExists(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "logs"))
                        {
                            ServiceTools.logToTextFile(logFilename,
                                                       "" + update.Message.Chat.Id + " : Received Photo: " + file.FilePath + Environment.NewLine + "\t\tSaved to file: " + filename + Environment.NewLine, true, true);
                        }
                    }

                    offset = update.Id + 1;
                }

                await Task.Delay(200);

                if (NeedToStopFlag)
                {
                    break;
                }
            }
        }
        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);
                }
            }
        }
Esempio n. 6
0
        private void OrganizeFiles()
        {
            EnumerateFilesToProcess();


            int filesProcesseed = 0;
            int totalFilesCount = lFilesOrganizing.Count;

            foreach (FilesOrganizingData organizingData in lFilesOrganizing)
            {
                // extract date of file using filesDateMask
                filesProcesseed++;

                string strDateOfFile =
                    string.Concat(
                        Path.GetFileName(organizingData.filename)
                        .Zip(filesDateMask, (c, s) => (s == 'x') ? (c.ToString()) : (""))
                        .ToArray());

                string movetoDir = "";

                if (useFileCreationDateTime)
                {
                    DateTime dt      = new FileInfo(organizingData.filename).CreationTimeUtc;
                    DateTime dateDay = dt.Date;

                    movetoDir = OutputSubdirectoriesPrefix + dateDay.ToString("yyyy-MM-dd");
                }
                else
                {
                    /// TODO: сделать что-то, если по маске неверно получили строку даты
                    /// хотя бы чтобы все не падало

                    DateTime dt      = CommonTools.DateTimeOfString(strDateOfFile);
                    DateTime dateDay = dt.Date;

                    movetoDir = OutputSubdirectoriesPrefix + dateDay.ToString("yyyy-MM-dd");
                }


                movetoDir = outputBaseDirectory +
                            ((outputBaseDirectory.Last() == Path.DirectorySeparatorChar)
                                ? ("")
                                : (Path.DirectorySeparatorChar.ToString())) + movetoDir + Path.DirectorySeparatorChar;
                string movetoFullFilename = movetoDir + Path.GetFileName(organizingData.filename);

                if (!ServiceTools.CheckIfDirectoryExists(movetoDir))
                {
                    continue;
                }


                double perc = Math.Round(((double)filesProcesseed / (double)totalFilesCount) * 100.0d, 2);

                if (!File.Exists(movetoFullFilename))
                {
                    FileInfo fileinfo = new FileInfo(organizingData.filename);
                    fileinfo.MoveTo(movetoFullFilename);

                    Console.WriteLine("{0}% : moving {1}", perc, Path.GetFileName(organizingData.filename));
                }
                else
                {
                    Console.WriteLine("{0}% : skipping {1}", perc, Path.GetFileName(organizingData.filename));
                    organizingData.State = FilesOrganizingState.Skipped;
                }

                organizingData.MovedToFilename = movetoDir + Path.GetFileName(organizingData.filename);
            }

            Console.WriteLine("Moved {0} files", lFilesOrganizing.Count(fod => fod.State == FilesOrganizingState.Moved));
            Console.WriteLine("Skipped {0} files", lFilesOrganizing.Count(fod => fod.State == FilesOrganizingState.Skipped));
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        void currBgw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker            selfWorker        = sender as BackgroundWorker;
            FileInfo                    finfo             = ((object[])e.Argument)[0] as FileInfo;
            Dictionary <string, object> defaultProperties = ((object[])e.Argument)[1] as Dictionary <string, object>;
            //int currentBgwID = (int) ((object[]) e.Argument)[2];
            LogWindow currImageLogWindow = null;
            bool      showOnlyErrors     = false;

            string sunDiskInfoFileName = finfo.DirectoryName + "\\" +
                                         Path.GetFileNameWithoutExtension(finfo.FullName) + "-SunDiskInfo.xml";

            if (File.Exists(sunDiskInfoFileName))
            {
                showOnlyErrors = true;
            }

            try
            {
                if (finfo == null)
                {
                    e.Result = false;
                    return;
                }

                if (!showOnlyErrors)
                {
                    currImageLogWindow = ServiceTools.LogAText(currImageLogWindow, Environment.NewLine + "starting: " + finfo.Name);
                    currImageLogWindow = ServiceTools.LogAText(currImageLogWindow, "start processing image " + finfo.Name);
                }


                AngleSunDeviationCalcResult devCalcResDatum = CalculateDevDataForImage(finfo, defaultProperties, currImageLogWindow, showOnlyErrors);


                if (devCalcResDatum.calculationSucceeded)
                {
                    cbAnglesSunDeviationCalcResults.Add(devCalcResDatum);
                }


                if (!showOnlyErrors)
                {
                    currImageLogWindow = ServiceTools.LogAText(currImageLogWindow,
                                                               Environment.NewLine + "finished: " + Path.GetFileName(devCalcResDatum.fileName) +
                                                               " with result: " + devCalcResDatum.calculationSucceeded + Environment.NewLine +
                                                               devCalcResDatum.resultMessage);
                }


                if (currImageLogWindow != null)
                {
                    currImageLogWindow.Close();
                }
            }
            catch (Exception ex)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     Environment.NewLine + "ERROR. There exceptions has been thrown: " + Environment.NewLine + ex.Message);

                string strDirForFailedImages = Path.GetDirectoryName(finfo.FullName);
                strDirForFailedImages += (strDirForFailedImages.Last() == '\\') ? ("") : ("\\") + "failed-detections\\";
                try
                {
                    if (ServiceTools.CheckIfDirectoryExists(strDirForFailedImages))
                    {
                        File.Move(finfo.FullName, strDirForFailedImages + finfo.Name);
                    }
                }
                catch (Exception ex1)
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         Environment.NewLine + "ERROR. There exceptions has been thrown: " + Environment.NewLine +
                                                         ex1.Message);
                }


                if (currImageLogWindow != null)
                {
                    currImageLogWindow.Close();
                }
            }


            e.Result = new object[] { true };
        }
        private void BgwSnapshotsFilteringWithSunElevation_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker selfWorker = sender as BackgroundWorker;

            object[] bgwArgs                 = e.Argument as object[];
            string   SnapshotsBasePath       = bgwArgs[0] as string;
            string   concurrentDataFilesPath = bgwArgs[1] as string;
            string   directoryToMoveFilesTo  = bgwArgs[2] as string;

            DirectoryInfo srcDir = new DirectoryInfo(SnapshotsBasePath);

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


            List <FileInfo> lFileList2Process = srcDir.GetFiles("*.jpg", SearchOption.AllDirectories).ToList();
            List <FileInfoWithSnapshotDateTime> lSnapshotsInfos =
                lFileList2Process.ConvertAll(finfo => new FileInfoWithSnapshotDateTime(finfo));


            #region read concurrent data from XML files

            theLogWindow = ServiceTools.LogAText(theLogWindow, "started concurrent data reading");

            List <Tuple <string, ConcurrentData> > lImagesConcurrentData = new List <Tuple <string, ConcurrentData> >();

            List <string> filesListConcurrentData =
                new List <string>(Directory.EnumerateFiles(concurrentDataFilesPath,
                                                           ConventionalTransitions.ImageConcurrentDataFilesNamesPattern(), SearchOption.AllDirectories));

            int totalFilesCountToRead = filesListConcurrentData.Count;
            int filesRead             = 0;
            int currProgressPerc      = 0;
            selfWorker.ReportProgress(0);
            List <Dictionary <string, object> > lDictionariesConcurrentData = new List <Dictionary <string, object> >();
            foreach (string strConcDataXMLFile in filesListConcurrentData)
            {
                Dictionary <string, object> currDict = ServiceTools.ReadDictionaryFromXML(strConcDataXMLFile);
                currDict.Add("XMLfileName", Path.GetFileName(strConcDataXMLFile));

                lDictionariesConcurrentData.Add(currDict);

                #region calculate and report progress

                filesRead++;
                double progress = 100.0d * (double)filesRead / (double)totalFilesCountToRead;
                if (progress - (double)currProgressPerc > 1.0d)
                {
                    currProgressPerc = Convert.ToInt32(progress);
                    selfWorker.ReportProgress(currProgressPerc);
                }

                if (selfWorker.CancellationPending)
                {
                    return;
                }

                #endregion calculate and report progress
            }
            lDictionariesConcurrentData.RemoveAll(dict => dict == null);


            List <ConcurrentData> lConcurrentData =
                lDictionariesConcurrentData.ConvertAll <ConcurrentData>(dict =>
            {
                ConcurrentData retVal = null;
                try
                {
                    retVal = new ConcurrentData(dict);
                    GPSdata gpsOfGPSstring = new GPSdata((string)dict["GPSdata"], GPSdatasources.CloudCamArduinoGPS,
                                                         retVal.datetimeUTC.Date);
                    if (!gpsOfGPSstring.validGPSdata)
                    {
                        throw new Exception("invalid GPS data");
                    }
                }
                catch (Exception ex)
                {
                    string strError = "couldn`t parse XML file " + dict["XMLfileName"] + " : " +
                                      Environment.NewLine + ex.Message;
                    return(null);
                }

                if (retVal.gps.validGPSdata)
                {
                    return(retVal);
                }
                else
                {
                    return(null);
                }
            });
            lConcurrentData.RemoveAll(val => val == null);



            // map obtained concurrent data to images by its datetime
            theLogWindow = ServiceTools.LogAText(theLogWindow, "started concurrent data mapping");
            int totalrecordsToMap = lSnapshotsInfos.Count;
            int recordsMapped     = 0;
            currProgressPerc = 0;
            selfWorker.ReportProgress(0);
            foreach (FileInfoWithSnapshotDateTime info in lSnapshotsInfos)
            {
                DateTime currImgDT = info.dateTime;

                ConcurrentData nearestConcurrentData = lConcurrentData.Aggregate((cDt1, cDt2) =>
                {
                    TimeSpan tspan1 = new TimeSpan(Math.Abs((cDt1.datetimeUTC - currImgDT).Ticks));
                    TimeSpan tspan2 = new TimeSpan(Math.Abs((cDt2.datetimeUTC - currImgDT).Ticks));
                    return((tspan1 <= tspan2) ? (cDt1) : (cDt2));
                });


                if (new TimeSpan(Math.Abs((nearestConcurrentData.datetimeUTC - currImgDT).Ticks)) <=
                    TimeSpanForConcurrentDataMappingTolerance)
                {
                    info.concurrentData = nearestConcurrentData;
                }

                #region calculate and report progress

                recordsMapped++;
                double progress = 100.0d * (double)recordsMapped / (double)totalrecordsToMap;
                if (progress - (double)currProgressPerc > 1.0d)
                {
                    currProgressPerc = Convert.ToInt32(progress);
                    selfWorker.ReportProgress(currProgressPerc);
                }

                if (selfWorker.CancellationPending)
                {
                    return;
                }

                #endregion calculate and report progress
            }

            #endregion read concurrent data from XML files

            List <FileInfo> filesToMove = new List <FileInfo>();
            filesToMove.AddRange(
                lSnapshotsInfos.Where(inf => inf.concurrentData == null).ToList().ConvertAll(inf => inf.finfo));
            lSnapshotsInfos.RemoveAll(inf => inf.concurrentData == null);

            filesToMove.AddRange(lSnapshotsInfos.Where(inf =>
            {
                GPSdata currGPS = new GPSdata(inf.concurrentData.GPSdata, GPSdatasources.CloudCamArduinoGPS,
                                              inf.dateTime.Date);
                var spa = currGPS.SunZenithAzimuth();
                return(spa.ZenithAngle >= 85.0);
            }).ToList().ConvertAll(inf => inf.finfo));


            totalFilesCountToRead = filesToMove.Count;
            filesRead             = 0;
            currProgressPerc      = 0;
            selfWorker.ReportProgress(0);
            foreach (FileInfo inf in filesToMove)
            {
                #region calculate and report progress

                filesRead++;
                double progress = 100.0d * (double)filesRead / (double)totalFilesCountToRead;
                if (progress - (double)currProgressPerc > 1.0d)
                {
                    currProgressPerc = Convert.ToInt32(progress);
                    selfWorker.ReportProgress(currProgressPerc);
                }

                if (selfWorker.CancellationPending)
                {
                    return;
                }

                #endregion calculate and report progress

                string strFilenameMoveTo = directoryToMoveFilesTo +
                                           ((directoryToMoveFilesTo.Last() == Path.DirectorySeparatorChar)
                    ? ("")
                    : (Path.DirectorySeparatorChar.ToString()));

                string currImgFilenameRelPath = ConventionalTransitions.MakeRelativePath(inf.FullName, SnapshotsBasePath);
                strFilenameMoveTo += currImgFilenameRelPath;

                theLogWindow = ServiceTools.LogAText(theLogWindow, "moving " + inf.FullName);

                if (!ServiceTools.CheckIfDirectoryExists(strFilenameMoveTo))
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "Unable to move file " + Environment.NewLine + inf.FullName + Environment.NewLine + "to:" +
                                                         Environment.NewLine + strFilenameMoveTo + Environment.NewLine +
                                                         "Directory couldn`t be located or created");
                    continue;
                }

                File.Move(inf.FullName, strFilenameMoveTo);
            }

            selfWorker.ReportProgress(0);
        }
        private void bgwCopier_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker SelfWorker = sender as BackgroundWorker;

            object[] bgwArgs  = e.Argument as object[];
            string   fromPath = bgwArgs[0] as string;
            string   concurrentDataFilesPath = bgwArgs[1] as string;
            string   toPath = bgwArgs[2] as string;
            string   imagesStatsXMLfilesDir = bgwArgs[3] as string;

            DirectoryInfo dir           = new DirectoryInfo(fromPath);
            String        destDirectory = toPath +
                                          ((toPath.Last() == Path.DirectorySeparatorChar)
                                       ? ("")
                                       : (Path.DirectorySeparatorChar.ToString()));

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


            FileInfo[] FileList2Process = dir.GetFiles("*.jpg", SearchOption.AllDirectories);
            List <Tuple <string, string> > imagesStatsXMLfiles = new List <Tuple <string, string> >();

            if (Directory.Exists(imagesStatsXMLfilesDir))
            {
                imagesStatsXMLfiles =
                    (new DirectoryInfo(imagesStatsXMLfilesDir)).EnumerateFiles(
                        ConventionalTransitions.ImageGrIxYRGBstatsFileNamesPattern(), SearchOption.AllDirectories)
                    .ToList()
                    .ConvertAll(fInfo => new Tuple <string, string>(fInfo.Name, fInfo.FullName));
            }


            DirectoryInfo dirConcurrentDataFiles = new DirectoryInfo(concurrentDataFilesPath);
            List <Tuple <string, DateTime> > lConcurrentDataFiles =
                dirConcurrentDataFiles.EnumerateFiles(ConventionalTransitions.ImageConcurrentDataFilesNamesPattern(),
                                                      SearchOption.AllDirectories).ToList().ConvertAll(fInfo =>
            {
                // data-2015-12-15T06-12-56.0590302Z.xml
                string strDateTimeOfFile = Path.GetFileNameWithoutExtension(fInfo.Name).Substring(5, 28);
                strDateTimeOfFile        = strDateTimeOfFile.Substring(0, 11) +
                                           strDateTimeOfFile.Substring(11).Replace('-', ':');
                DateTime currFileDT = DateTime.Parse(strDateTimeOfFile, null, System.Globalization.DateTimeStyles.AdjustToUniversal);
                currFileDT          = DateTime.SpecifyKind(currFileDT, DateTimeKind.Utc);
                return(new Tuple <string, DateTime>(fInfo.FullName, currFileDT));
            });



            int filesCount = FileList2Process.Length;

            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                 "searching in directory: " + dir.FullName + Environment.NewLine);
            //ThreadSafeOperations.SetTextTB(tbLog, "searching in directory: " + dir.FullName + Environment.NewLine, true);
            theLogWindow = ServiceTools.LogAText(theLogWindow, "files found count: " + filesCount + Environment.NewLine);
            //ThreadSafeOperations.SetTextTB(tbLog, "files found count: " + filesCount + Environment.NewLine, true);

            String usedDateTimes = "";

            List <DateTime> listUsedHours = new List <DateTime>();

            int counter = 0;

            foreach (FileInfo fileInfo in FileList2Process)
            {
                if (SelfWorker.CancellationPending)
                {
                    break;
                }
                counter++;
                double percCounter = (double)counter * 1000.0d / (double)filesCount;
                SelfWorker.ReportProgress(Convert.ToInt32(percCounter));


                Image     anImage  = Image.FromFile(fileInfo.FullName);
                ImageInfo newIInfo = new ImageInfo(anImage);
                //ThreadSafeOperations.SetTextTB(tbLog, "processing file " + fileInfo.Name + Environment.NewLine, true);


                //String curDateTime = "";
                int minute = 0;
                //String dateTime = (String)newIInfo.getValueByKey("DateTime");
                String strDateTimeEXIF = (String)newIInfo.getValueByKey("ExifDTOrig");
                if (strDateTimeEXIF == null)
                {
                    //попробуем вытащить из имени файла
                    string strDateTime = fileInfo.Name;
                    strDateTime     = strDateTime.Substring(4, 19);
                    strDateTimeEXIF = strDateTime;
                }


                //curDateTime = dateTime;
                DateTime curImgDateTime;
                DateTime theHour = RoundToHour(DateTime.UtcNow);
                try
                {
                    //curImgDateTime = DateTimeOfString(strDateTimeEXIF);
                    curImgDateTime = ConventionalTransitions.DateTimeOfSkyImageFilename(fileInfo.Name);
                    theHour        = RoundToHour(curImgDateTime);
                }
                catch (Exception ex)
                {
                    continue;
                }


                //minute = Convert.ToInt32(strDateTimeEXIF.Substring(14, 2));

                //if ((minute == 0) && (!listUsedHours.Contains(theHour)))
                if (new TimeSpan(Math.Abs((theHour - curImgDateTime).Ticks)) <= filterTolerance)
                {
                    #region copy the image file itself
                    listUsedHours.Add(theHour);

                    string dateDirectorySuffix   = curImgDateTime.ToString("yyyy-MM-dd");
                    string currDateDestDirectory = destDirectory + dateDirectorySuffix + Path.DirectorySeparatorChar;
                    if (!ServiceTools.CheckIfDirectoryExists(currDateDestDirectory))
                    {
                        currDateDestDirectory = destDirectory;
                    }



                    String newFileName = currDateDestDirectory + fileInfo.Name;
                    File.Copy(fileInfo.FullName, newFileName);
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "COPY: " + fileInfo.FullName + "   >>>   " + newFileName + Environment.NewLine);
                    //ThreadSafeOperations.SetTextTB(tbLog, "COPY: " + fileInfo.FullName + "   >>>   " + newFileName + Environment.NewLine, true);
                    #endregion copy the image file itself


                    #region find and copy the GrIx,YRGB stats data file
                    if (imagesStatsXMLfiles.Any())
                    {
                        string xmlStatsFileName =
                            ConventionalTransitions.ImageGrIxYRGBstatsDataFileName(fileInfo.FullName, "", false);

                        Tuple <string, string> foundXMLfile =
                            imagesStatsXMLfiles.Find(tpl => tpl.Item1 == xmlStatsFileName);

                        if (foundXMLfile != null)
                        {
                            string sStatsXMLfilename   = foundXMLfile.Item2;
                            string newStatsXMLfilename = currDateDestDirectory + foundXMLfile.Item1;
                            File.Copy(sStatsXMLfilename, newStatsXMLfilename);
                            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                                 "COPY: " + sStatsXMLfilename + "   >>>   " + newStatsXMLfilename + Environment.NewLine);
                            //ThreadSafeOperations.SetTextTB(tbLog,
                            //    "COPY: " + sStatsXMLfilename + "   >>>   " + newStatsXMLfilename + Environment.NewLine,
                            //    true);
                        }
                        else
                        {
                            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                                 "========== ERROR: couldn`t find GrIx,YRGB stats XML file" + Environment.NewLine);
                            //ThreadSafeOperations.SetTextTB(tbLog,
                            //    "========== ERROR: couldn`t find GrIx,YRGB stats XML file" + Environment.NewLine, true);
                        }
                    }
                    #endregion find and copy the GrIx,YRGB stats data file


                    #region find and copy concurrent data XML file
                    if (lConcurrentDataFiles.Any())
                    {
                        //найдем ближайший по времени
                        List <Tuple <string, TimeSpan> > lCurrFileConcurrentDataNearest =
                            lConcurrentDataFiles.ConvertAll(
                                tpl =>
                                new Tuple <string, TimeSpan>(tpl.Item1,
                                                             new TimeSpan(Math.Abs((tpl.Item2 - curImgDateTime).Ticks))));
                        lCurrFileConcurrentDataNearest.Sort(new Comparison <Tuple <string, TimeSpan> >((tpl1, tpl2) =>
                        {
                            if (tpl1 == null)
                            {
                                if (tpl2 == null)
                                {
                                    return(0);
                                }
                                else
                                {
                                    return(-1);
                                }
                            }
                            else
                            {
                                if (tpl2 == null)
                                {
                                    return(1);
                                }
                                else
                                {
                                    return(tpl1.Item2.CompareTo(tpl2.Item2));
                                }
                            }
                        }));

                        GPSdata gps = new GPSdata();
                        Tuple <string, TimeSpan> nearestConcurrentDataFile = null;
                        int concurrentDataFileIdx = 0;

                        while (!gps.validGPSdata)
                        {
                            nearestConcurrentDataFile = lCurrFileConcurrentDataNearest[concurrentDataFileIdx];

                            Dictionary <string, object> dictSavedData = ServiceTools.ReadDictionaryFromXML(nearestConcurrentDataFile.Item1);

                            gps = new GPSdata((string)dictSavedData["GPSdata"],
                                              GPSdatasources.CloudCamArduinoGPS,
                                              DateTime.Parse((string)dictSavedData["GPSDateTimeUTC"], null,
                                                             System.Globalization.DateTimeStyles.RoundtripKind));

                            concurrentDataFileIdx++;
                        }

                        string currValidConcurrentDataFile         = nearestConcurrentDataFile.Item1;
                        string currValidConcurrentDataFileToCopyTo = currDateDestDirectory + "data-" +
                                                                     Path.GetFileNameWithoutExtension(fileInfo.FullName) + ".xml";
                        File.Copy(currValidConcurrentDataFile, currValidConcurrentDataFileToCopyTo);
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "COPY: " + currValidConcurrentDataFile + "   >>>   " + currValidConcurrentDataFileToCopyTo +
                                                             Environment.NewLine);
                        //ThreadSafeOperations.SetTextTB(tbLog,
                        //    "COPY: " + currValidConcurrentDataFile + "   >>>   " + currValidConcurrentDataFileToCopyTo +
                        //    Environment.NewLine, true);
                    }
                    else
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "========== ERROR: couldn`t find concurrent data file for " + fileInfo.FullName +
                                                             Environment.NewLine);
                        //ThreadSafeOperations.SetTextTB(tbLog, "========== ERROR: couldn`t find concurrent data file for " + fileInfo.FullName + Environment.NewLine, true);
                    }
                    #endregion find and copy concurrent data XML file


                    theLogWindow.ClearLog();
                }
            }
        }
        private void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
        {
            Message currMsg = e.Message;


            if (currMsg.Type == MessageType.TextMessage)
            {
                Console.WriteLine("{0} from {1} ({2})", currMsg.Text, currMsg.Chat.Id, currMsg.Chat.Username);


                if (ServiceTools.CheckIfDirectoryExists(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "logs"))
                {
                    ServiceTools.logToTextFile(logFilename,
                                               "" + currMsg.Chat.Id + " (" + currMsg.Chat.Username + ") : " + currMsg.Text + Environment.NewLine, true, true);
                }



                if ((currMsg.Text == "/current_image") || (currMsg.Text == "Image"))
                {
                    Task <string> taskA        = Task.Run(() => CurrentImagesCoupleImageFilename());
                    Task          continuation = taskA.ContinueWith(antecedent =>
                    {
                        string FilenameToSend = antecedent.Result;
                        var fileStream        = File.Open(FilenameToSend, FileMode.Open, FileAccess.Read, FileShare.Read);
                        Bot.SendPhotoAsync(currMsg.Chat.Id, new FileToSend(FilenameToSend, fileStream));
                    });
                }
                else if ((currMsg.Text == "/concurrent_info") || (currMsg.Text == "Info"))
                {
                    Task <string> taskA        = Task.Run(() => ReadLastConcurrentInfo());
                    Task          continuation = taskA.ContinueWith(antecedent =>
                    {
                        string strReply = antecedent.Result;
                        Bot.SendTextMessageAsync(currMsg.Chat.Id, strReply, true, false,
                                                 currMsg.MessageId, BasicKeyboard());
                    });
                }
                else if ((currMsg.Text == "/current_cc") || (currMsg.Text == "TCC_SDC"))
                {
                    Task <string> taskA        = Task.Run(ReadCurrentCCinfo);
                    Task          continuation = taskA.ContinueWith(antecedent =>
                    {
                        string strReply = antecedent.Result;
                        Bot.SendTextMessageAsync(currMsg.Chat.Id, strReply, true, false,
                                                 currMsg.MessageId, BasicKeyboard());
                    });
                }
                else if ((currMsg.Text == "/meteo_info") || (currMsg.Text == "Meteo"))
                {
                    Task <string> taskA        = Task.Run(ObtainLatestMeteoParameters);
                    Task          continuation = taskA.ContinueWith(antecedent =>
                    {
                        string strReply = antecedent.Result;
                        Bot.SendTextMessageAsync(currMsg.Chat.Id, strReply, true, false,
                                                 currMsg.MessageId, BasicKeyboard());
                    });
                }
                else if (currMsg.Text == "/start")
                {
                    Task taskA = Task.Run(() =>
                    {
                        string strStartMessage =
                            ServiceTools.ReadTextFromFile(Directory.GetCurrentDirectory() +
                                                          Path.DirectorySeparatorChar + "settings" +
                                                          Path.DirectorySeparatorChar + "BotStartMessage.txt");
                        Bot.SendTextMessageAsync(currMsg.Chat.Id, strStartMessage, true, false,
                                                 currMsg.MessageId, BasicKeyboard());
                        Console.WriteLine("Echo Message: {0}", currMsg.Text);
                    });
                }
                else if (currMsg.Text.Contains("/fix"))
                {
                    Console.WriteLine("Echo Message: {0}", currMsg.Text);

                    Task <bool> taskA = Task.Run(() => RegisterFixStage1(currMsg));
                }
                else if (currMsg.Text.Contains("/help") || currMsg.Text == "Help")
                {
                    Task taskA = Task.Run(() =>
                    {
                        string strStartMessage =
                            ServiceTools.ReadTextFromFile(Directory.GetCurrentDirectory() +
                                                          Path.DirectorySeparatorChar + "settings" +
                                                          Path.DirectorySeparatorChar + "BotHelpMessage.txt");
                        Bot.SendTextMessageAsync(currMsg.Chat.Id, strStartMessage, true, false,
                                                 currMsg.MessageId, BasicKeyboard());
                        Console.WriteLine("Echo Message: {0}", currMsg.Text);
                    });
                }
                else
                {
                    // await Bot.SendChatAction(update.Message.Chat.Id, ChatAction.Typing);
                    // await Task.Delay(200);

                    Task taskA = Task.Run(() =>
                    {
                        Bot.SendTextMessageAsync(currMsg.Chat.Id,
                                                 "Sorry, I can`t understand you. Please try again using the following list of commands:" +
                                                 Environment.NewLine + "/current_image" +
                                                 Environment.NewLine + "/concurrent_info" +
                                                 Environment.NewLine + "/current_cc" +
                                                 Environment.NewLine + "/meteo_info" +
                                                 Environment.NewLine + "/fix",
                                                 replyMarkup: BasicKeyboard());

                        Console.WriteLine("Echo Message: {0}", currMsg.Text);
                    });
                }
            }
        }