Ejemplo n.º 1
0
        private void ProcessFile(RouteOptions routing, string fileName)
        {
            string importTag = "import"; // used to make friendly export filename

            try
            {
                TextFile   tf = new TextFile(fileName);
                SeriesList sl = new SeriesList();

                if (HydrometInstantSeries.IsValidDMS3(tf))
                {
                    importTag = "decodes";
                    sl        = HydrometInstantSeries.HydrometDMS3DataToSeriesList(tf);
                }
                else if (HydrometDailySeries.IsValidArchiveFile(tf))
                {
                    importTag = "htools";
                    sl        = HydrometDailySeries.HydrometDailyDataToSeriesList(tf);
                }
                else if (LoggerNetFile.IsValidFile(tf))
                {
                    LoggerNetFile lf = new LoggerNetFile(tf);

                    if (lf.IsValid && Array.IndexOf(validSites, lf.SiteName) >= 0)
                    {
                        importTag = lf.SiteName;
                        sl        = lf.ToSeries(validPcodes);
                    }
                }
                //else if (DecodesRawFile.IsValidFile(tf))
                //{
                //    DecodesRawFile df = new DecodesRawFile(tf);
                //    importTag = "raw";
                //    sl = df.ToSeries();
                //}
                else
                {
                    Logger.WriteLine("skipped Unknown File Format: " + fileName);
                    return;
                }

                m_importer = new TimeSeriesImporter(m_db, routing, m_saveOption);
                Console.WriteLine("Found " + sl.Count + " series in " + fileName);
                foreach (var item in sl)
                {
                    Logger.WriteLine(item.Table.TableName);
                }

                if (sl.Count > 0)
                {
                    m_importer.Import(sl, m_computeDependencies, m_computeDailyDependencies, importTag);
                    FileUtility.MoveToSubDirectory(Path.GetDirectoryName(fileName), "attic", fileName);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Error:" + ex.Message);
                Console.WriteLine("Error:  skipping file, will move to error subdirectory " + fileName);
                FileUtility.MoveToSubDirectory(Path.GetDirectoryName(fileName), "error", fileName);
            }
        }
Ejemplo n.º 2
0
        private void ProcessFile(string fileName)
        {
            Logger.WriteLine("ProcessFile('" + fileName + "')");
            string importTag = "import"; // used to make friendly export filename

            try
            {
                TextFile   tf = new TextFile(fileName);
                SeriesList sl = new SeriesList();

                if (HydrometInstantSeries.IsValidDMS3(tf))
                {
                    importTag = "decodes";
                    sl        = HydrometInstantSeries.HydrometDMS3DataToSeriesList(tf);
                }
                else if (HydrometDailySeries.IsValidArchiveFile(tf))
                {
                    importTag = "htools";
                    sl        = HydrometDailySeries.HydrometDailyDataToSeriesList(tf);
                }
                else if (LoggerNetFile.IsValidFile(tf))
                {
                    LoggerNetFile lf = new LoggerNetFile(tf);

                    if (lf.IsValid && Array.IndexOf(validSites, lf.SiteName) >= 0)
                    {
                        importTag = lf.SiteName;
                        sl        = lf.ToSeries(validPcodes);
                    }
                }
                else if (CsvScadaFile.IsValidFile(tf))
                {
                    importTag = "scada";
                    m_db.GetSiteCatalog();
                    var scada = new CsvScadaFile(fileName);
                    sl = scada.ToSeries();
                }
                else if (XConnectTextFile.IsValidFile(tf))
                {
                    importTag = "xc";
                    var xc = new XConnectTextFile(tf);
                    sl = xc.ToSeries();
                }
                else if (HydrometMonthlySeries.IsValidFile(tf))
                {
                    sl = HydrometMonthlySeries.FileToSeriesList(tf);
                }
                else
                {
                    Logger.WriteLine("skipped Unknown File Format: " + fileName);
                    return;
                }

                if (m_importer == null)
                {
                    m_importer = new TimeSeriesImporter(m_db, m_saveOption);
                }
                Console.WriteLine("Found " + sl.Count + " series in " + fileName);
                foreach (var item in sl)
                {
                    Logger.WriteLine(item.Table.TableName);
                }

                if (sl.Count > 0)
                {
                    m_importer.Import(sl, m_computeDependencies, m_computeDailyDependencies, importTag);
                    FileUtility.MoveToSubDirectory(Path.GetDirectoryName(fileName), "attic", fileName);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Error:" + ex.Message);
                Console.WriteLine("Error:  skipping file, will move to error subdirectory " + fileName);
                FileUtility.MoveToSubDirectory(Path.GetDirectoryName(fileName), "error", fileName);
            }
        }