Example #1
0
        private static void Main()
        {
            _consoleManager       = new ConsoleManager();
            _excelLogger          = new ExcelLogger();
            _filePerVehicleLogger = new FilePerVehicleLogger(_consoleManager);
            _htmlLogger           = new HtmlLogger(_filePerVehicleLogger, _consoleManager);
            _jsonLogger           = new JsonLogger(_filePerVehicleLogger, _consoleManager);
            _webCrawler           = new WebCrawler(_consoleManager);
            _stringHelper         = new StringHelper();
            _logger              = new Logger(_jsonLogger, _htmlLogger, _stringHelper, _consoleManager);
            _dataProcessor       = new DataProcessor(_consoleManager, _stringHelper, _webCrawler, _excelLogger, _logger);
            _groundForcesScraper = new GroundForcesScraper(_webCrawler);

            try
            {
                OverallStopwatch.Start();

                _consoleManager.WriteProgramTitleVersionAndInitialBlurb();
                _consoleManager.WriteInputInstructionsAndAwaitUserInput(ConsoleColor.Yellow, ConsoleKey.Enter, "Press ENTER to begin.");

                // Load Wiki Home page
                HtmlDocument groundForcesWikiHomePage = _groundForcesScraper.GetGroundForcesWikiHomePage();

                // Crawl ground forces
                // TODO: Some of these parameters can be moved into DataProcessor as they aren't used again
                _dataProcessor.CrawlWikiSectionPagesForData(groundForcesWikiHomePage);

                OverallStopwatch.Stop();

                TimeSpan elapsedTime = OverallStopwatch.Elapsed;

                // TODO: Add console manage method for this
                _consoleManager.WriteTextLine($"Completed in {elapsedTime.Hours:00}:{elapsedTime.Minutes:00}:{elapsedTime.Seconds:00}");
                _consoleManager.WriteExitInstructions();
            }
            catch (Exception ex)
            {
                _consoleManager.WriteException($"The following exception was encounted: {ex.Message}\r\nException details: {ex.StackTrace}");
            }
        }
Example #2
0
        /// <summary>
        /// Split String get from buffer and Save to database.
        /// </summary>
        public void _setDatabase()
        {
            try
            {
                //Box Model Object.
                mBox _mBox = new mBox();

                //model Shipment Save
                mShipmant _mSHNum = new mShipmant();

                //Log
                logFile.Add("_setDatabase Function Call start", "_setDatabase(0)");

                // stringFromTOLEDO = _serialPort.ReadLine();
                Thread.Sleep(1000);
                //Split the string from TOLEDO and return measurement Objects.
                Measures _tempMeasures = new Measures();
                _tempMeasures = stringFromTOLEDO.SplitTOLEDOstring();
                try
                {
                    //split string to Measurement class format.
                    try
                    {
                        _measures = stringFromTOLEDO.SplitTOLEDOstring();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("String Split Error");
                        logFile.Add("String Split Error", "_setDatabase(0)");
                    }

                    //Measurement Object Passed to the Save Database Fucntion That save the Measurements to Packing ID.
                    Boolean _savedFlag = false;
                    if (Global.IsBoxNumber)
                    {
                        _savedFlag = _mBox.setPackageInfo(_measures);
                        logFile.Add("_save", "Data Save '" + _savedFlag + "'");
                    }
                    else
                    {
                        _savedFlag = _mSHNum.setPackageInfo(_measures);
                        logFile.Add("_save", "Data Save '" + _savedFlag + "'");
                    }



                    //Save Log to the Ecxel File.
                    try
                    {
                        ExcelLogger Exel = new ExcelLogger(stringFromTOLEDO, _savedFlag);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Excel file writing");
                        logFile.Add("Excel file writing", "_setDatabase(0)");
                    }

                    Console.WriteLine("\nPackageID= " + _tempMeasures.BOXNUM.ToString() + Environment.NewLine + "Box length= " + _tempMeasures.BoxLength + Environment.NewLine + "Box Width= " + _tempMeasures.BoxWidth + Environment.NewLine + "Box heigh=" + _tempMeasures.BoxHeight + Environment.NewLine + "Box Weight=" + _tempMeasures.BoxWeight);
                    if (_savedFlag == false)
                    {
                        Console.WriteLine(Environment.NewLine + "**Error: Record saving in database fail because of incorrect packing ID");
                        Console.WriteLine("-------------------------------------------------------------------");
                        mEmail.Send("String From Toledo : " + stringFromTOLEDO + Environment.NewLine + "\nPackageID= " + _tempMeasures.BOXNUM.ToString() + Environment.NewLine + "Box length= " + _tempMeasures.BoxLength + Environment.NewLine + "Box Width= " + _tempMeasures.BoxWidth + Environment.NewLine + "Box heigh=" + _tempMeasures.BoxHeight + Environment.NewLine + "Box Weight=" + _tempMeasures.BoxWeight);
                    }
                    else
                    {
                        Console.WriteLine("-----------------------Record saved. ------------------------------");
                    }
                }
                catch (NullReferenceException)
                { //Log
                    logFile.Add("NullReferenceException", " Catch call in _setDatabase");
                    try
                    {
                        _measures = stringFromTOLEDO.SplitTOLEDOstring();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("String Split Error @ Chach Null Rererence");
                        logFile.Add("String Split Error", "_setDatabase(1)");
                    }

                    //Measurement Object Passed to the Save Database Fucntion That save the Measurements to Packing ID.

                    Boolean _savedFlag = false;

                    //save in Shipment diamention table or Box Information table depend on Global.IsBoxNum;
                    if (Global.IsBoxNumber)
                    {
                        _savedFlag = _mBox.setPackageInfo(_measures);
                        logFile.Add("_save", "Data Save '" + _savedFlag + "'");
                    }
                    else
                    {
                        _savedFlag = _mSHNum.setPackageInfo(_measures);
                        logFile.Add("_save", "Data Save '" + _savedFlag + "'");
                    }


                    logFile.Add("_save", "Data Save '" + _savedFlag + "'");

                    try
                    {
                        ExcelLogger Exel = new ExcelLogger(stringFromTOLEDO, _savedFlag);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Excel file writing");
                        logFile.Add("Excel file writing", "_setDatabase(1)");
                    }

                    Console.WriteLine("\nBOX NUMBER = " + _tempMeasures.BOXNUM.ToString() + Environment.NewLine + "Box length= " + _tempMeasures.BoxLength + Environment.NewLine + "Box Width= " + _tempMeasures.BoxWidth + Environment.NewLine + "Box heigh=" + _tempMeasures.BoxHeight + Environment.NewLine + "Box Weight=" + _tempMeasures.BoxWeight);
                    if (_savedFlag == false)
                    {
                        Console.WriteLine(Environment.NewLine + "**Error: Record saving in database fail because of incorrect BOX NUMBER");
                        Console.WriteLine("------------------------------------------------------------------");
                        mEmail.Send("String From Toledo : " + stringFromTOLEDO + Environment.NewLine + "\nPackageID= " + _tempMeasures.BOXNUM.ToString() + Environment.NewLine + "Box length= " + _tempMeasures.BoxLength + Environment.NewLine + "Box Width= " + _tempMeasures.BoxWidth + Environment.NewLine + "Box heigh=" + _tempMeasures.BoxHeight + Environment.NewLine + "Box Weight=" + _tempMeasures.BoxWeight);
                    }
                    else
                    {
                        Console.WriteLine("-----------------------Record saved. ------------------------------");
                    }
                }
            }
            catch (Exception)
            { }
        }