Example #1
0
        public static async Task <ICollection <string> > AddAllMeasurementsToDatabase()
        {
            //var list = new CinnamonList("ExpeditionList").Parameters;
            //list.Reverse();
            //list.Remove("X376");
            //list.Remove("X372");
            //list.Remove("X371");
            //list.Remove("X368");
            //list.Remove("X367");
            //list.Remove("X366"); //Need to upload RGB
            //list.Remove("X362"); //Need to upload RGB
            //list.Remove("X361"); //Need to upload RGB
            //list.Remove("X360"); //Need to delete then add all measurements; Issue with disposing with DBcontext
            //list.Remove("X359");
            //list.Remove("X356");
            //list.Remove("X355");

            var list = new List <string>()
            {
                "X375", "X374", "X363", "X351", "X324"
            };


            ICollection <string> ErrorFiles = new HashSet <string>();


            foreach (var expedition in list)
            {
                FileCollection fileCollection = new FileCollection();
                string         fileDirectory  = $@"C:\Users\vperc\Desktop\All Hard Drive Files\DESC_DATAMINE\AGU2019\{expedition}\data";
                fileCollection.AddFiles(fileDirectory, "*.csv");

                foreach (var file in fileCollection.Filenames)
                {
                    Log.Information($"{file}: Trying to add measurements to database");
                    try
                    {
                        var uploadSuccessful = await Workflow.UploadMeasurementsFromFileToDatabaseAsync(file).ConfigureAwait(true);

                        if (uploadSuccessful)
                        {
                            Log.Information($"{file}: Successfully added measurements database");
                        }
                        else
                        {
                            Log.Information($"{file}: The file was not successfully uploaded. Either the all the measurments have been previously uploaded");
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Warning($"{file}: Could not add measurement file to database");
                        Log.Warning(ex.Message);
                        Log.Warning(ex.StackTrace);
                        ErrorFiles.Add(file);
                    }

                    Thread.Sleep(1000);
                }
            }

            return(ErrorFiles);
        }
Example #2
0
        private static void ProcessData(FileCollection DescriptionFileCollection, FileCollection MeasurementFileCollection)
        {
            #region ImportDescriptionData

            DescriptionFileCollection.Filenames.ForEach(fileName => Console.WriteLine(fileName.ToString()));

            var lithologyWorkflowHandler = new CSVLithologyWorkflowHandler();
            lithologyWorkflowHandler.FileCollection  = DescriptionFileCollection;
            lithologyWorkflowHandler.ExportDirectory = DescriptionFileCollection.ExportDirectory;

            var SectionCollection = new SectionInfoCollection();

            var lithologyCache = lithologyWorkflowHandler.ImportCache(SectionCollection);

            if (ProgramSettings.SendDataToDESCDataBase)
            {
                DatabaseWorkflowHandler.SendLithologiesToDatabase(lithologyCache);
            }
            if (ProgramSettings.SendDataToLithologyDataBase)
            {
                //Need to specify which columns to keep, ex is for x375
                List <string> acceptableColumns = new List <string>()
                {
                    "LITHOLOGY PREFIX", "Lithology principal name", "Lithology SUFFIX"
                };
                LithologyDatabaseWorkflowHandler.SendLithologiesToDataBase(lithologyCache, acceptableColumns);
            }

            var LithCache = CacheReconfigurer.CreateDescriptionSearchHierarchy(lithologyCache);

            #endregion

            #region ImportMeasurementData

            if (ProgramSettings.ProcessMeaurements == false)
            {
                Console.WriteLine("Finished processing files at: " + DateTime.Now.ToString());
                return;
            }
            var measurementWorkFlowHandler = new CSVMeasurementWorkFlowHandler();
            measurementWorkFlowHandler.FileCollection = new FileCollection();

            foreach (string path in MeasurementFileCollection.Filenames)
            {
                Console.WriteLine("Processing measurement file: " + path);

                measurementWorkFlowHandler.FileCollection.RemoveFiles();
                measurementWorkFlowHandler.FileCollection.Filenames.Add(path);

                var measurementCache = measurementWorkFlowHandler.ImportCache(SectionCollection);

                Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Processing {0} measurements", measurementCache.Count.ToString(CultureInfo.CurrentCulture)));

                measurementWorkFlowHandler.UpdateMeasurementCacheWithLithologicDescriptions(measurementCache, LithCache);

                if (ProgramSettings.SendDataToDESCDataBase)
                {
                    DatabaseWorkflowHandler.SendMeasurementsToDatabase(measurementCache);
                }

                if (ProgramSettings.ExportCachesToFiles)
                {
                    measurementWorkFlowHandler.ExportDirectory = MeasurementFileCollection.ExportDirectory;
                    measurementWorkFlowHandler.ExportToFile(measurementCache);
                }

                measurementCache = null;
                GC.Collect();


                Console.WriteLine("The total section count is: " + SectionCollection.Sections.Count);
            }
            #endregion

            Console.WriteLine("Finished processing measurement files at: " + DateTime.Now.ToString());
        }