Example #1
0
        private void GetAllFilesInDirectory(string filePath)
        {
            #region Ingest

            ConvertDep.FileEntries = Directory.GetFiles(filePath);
            var location = Assembly.GetExecutingAssembly( ).Location;
            if (location != null)
            {
                ConvertDep.IngestDirectory = Path.Combine(
                    Path.GetDirectoryName(location), @"Ingest\");
            }
            foreach (var fileLocation in ConvertDep.FileEntries)
            {
                ConvertDep.CurrentFileName      = "";
                ConvertDep.CurrentIngestedtFile = string.Empty;
                ConvertDep.Words           = new[] { string.Empty };
                ConvertDep.CurrentFileName = Path.GetFileName(fileLocation);

                //substring
                if (ConvertDep.CurrentFileName != null)
                {
                    var trimName = ConvertDep.CurrentFileName.Split('.')[0];

                    var name = Regex.Split(trimName, "-");
                    //Extract Data From FileName
                    if (name.Length == 5)
                    {
                        //method #1
                        ConvertDep.Polarization = ConvertDep.CurrentFileName.Split('(', ')')[1];
                        var tiltVal = name[1];
                        ConvertDep.TiltValue = tiltVal.Split('T', '-')[1];
                    }

                    //fileName
                    var pathToCheck = $"{ConvertDep.IngestDirectory}{ConvertDep.CurrentFileName}";

                    if (File.Exists(pathToCheck))
                    {
                        var fileObj   = new FileStream(pathToCheck, FileMode.Open, FileAccess.Read);
                        var readerObj = new StreamReader(fileObj);
                        var text      = readerObj.ReadToEnd( );
                        readerObj.Close( );

                        ConvertDep.CurrentIngestedtFile = text;
                    }
                    try
                    {
                        if (!File.Exists(pathToCheck))
                        {
                            File.Copy(fileLocation, ConvertDep.IngestDirectory + ConvertDep.CurrentFileName);
                            var fileObj = new FileStream(ConvertDep.IngestDirectory + ConvertDep.CurrentFileName,
                                                         FileMode.Open, FileAccess.Read);

                            var readerObj = new StreamReader(fileObj);
                            var text      = readerObj.ReadToEnd( );
                            readerObj.Close( );
                            fileObj.Close( );

                            ConvertDep.CurrentIngestedtFile = text;
                            ConvertDep.FileCount++;
                        }
                    }
                    catch (FileNotFoundException db)
                    {
                        ConvertDep.ErrorLog.Add($"Encountered an error\n" +
                                                $"Please check {ConvertDep.CurrentFileName} is valid\n" +
                                                db.Message);
                    }
                }

                #endregion

                #region Convert / Download

                try
                {
                    if (AircomCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        AirC.ConvertToAircomBatch( );
                        AirC.DownloadAircom( );
                    }
                    if (AtollCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        Atoll.ConvertToAtollBatch( );
                    }
                    if (Ce4CheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        C4.ConvertToCe4Batch( );
                        if (Ce4TxtRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            C4.DownloadCe4Txt( );
                        }
                        if (Ce4VwaRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            C4.DownloadCe4Vwa( );
                        }
                    }
                    if (CelCadCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        CelC.ConvertToCelCadBatchDownload( );
                    }
                    if (CelPlanCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        CelP.ConvertToCelPlanBatch( );
                        CelP.DownloadCelPlanBatch( );
                    }

                    if (GeoplanCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        GeoP.ConvertToGeoPlanBatch( );
                        if (GeoPlanVwaRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            GeoP.DownloadGeoPlanVwa( );
                        }
                        if (GeoPlanTxtRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            GeoP.DownloadGeoPlanTxt( );
                        }
                    }
                    if (GranetCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        GraN.ConvertToGranetBatch( );
                        if (GranetPatRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            GraN.DownloadGranetPat( );
                        }
                        if (GranetTxtRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            GraN.DownloadGranetTxt( );
                        }
                    }
                    if (HodiaxCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        HodX.ConvertToHodiaxBatch( );

                        if (HodiaxHodRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            HodX.DownloadHodiaxHorizontalBatchHod( );
                            HodX.DownloadHodiaxVerticalBatchHod( );
                        }

                        if (HodiaxTxtRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            HodX.DownloadHodiaxHorizontalBatchTxt( );
                            HodX.DownloadHodiaxVerticalBatchTxt( );
                        }
                    }
                    if (HydraCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        HyD.ConvertToHydraBatch( );
                        if (HydraAdfRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            HyD.DownloadHydraAdf( );
                        }
                        if (HydraTxtRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            HyD.DownloadHydraTxt( );
                        }
                    }
                    if (LccNetCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        LccN.ConvertToLccBatchTest( );
                        if (LccAntRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            LccN.DownloadLccBatchAnt( );
                        }
                        if (LccTxtRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            LccN.DownloadLccBatchTxt( );
                        }
                    }
                    if (NetplanCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        NetP.ConvertToNetPlanBatch( );
                        NetP.DownloadNetPlanBatch( );
                    }
                    if (OdesseyCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        Ody.ConvertToOdysseyBatch( );
                        Ody.DownloadOdysseyBatch( );
                    }
                    if (PathLossCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        PathL.ConvertToPathLossBatch( );
                        if (PathLossTxtRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            PathL.DownloadPathLossBatchTxt( );
                        }
                        if (PathLossAdfRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            PathL.DownloadPathLossBatchAdf( );
                        }
                    }
                    if (WizardCheckBox.IsChecked.GetValueOrDefault( ))
                    {
                        Wiz.ConvertToWizardBatch( );
                        if (WizardApfRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            Wiz.DownloadWizardBatchApf( );
                        }
                        if (WizardTxtRadioButton.IsChecked.GetValueOrDefault( ))
                        {
                            Wiz.DownLoadWizardBatchTxt( );
                        }
                    }

                    #endregion
                }
                catch (InvalidOperationException db)
                {
                    ConvertDep.ErrorLog.Add($"Error encountered with File Ingest || download\n" +
                                            $"Please try again || restart the application\n" +
                                            $"Validate working directories are clean"
                                            + db.Message);
                }
            }
            var s = ConvertDep.SuccessLog.Aggregate(string.Empty, (current, entry) => current + (entry + "\r\n"));
            var e = ConvertDep.ErrorLog.Aggregate(string.Empty, (current, entry) => current + (entry + "\r\n"));

            SuccessResults.Text = s += $"\nTotal Files Ingested : {ConvertDep.FileCount}" +
                                       $"\nTotal Files Affected: {ConvertDep.SuccessLog.Count}";

            ErrorResults.Text = e;
        }