// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Data; using System.Text.RegularExpressions; namespace Spludlow.MetSat { public class ProductIdentify { private static Spludlow.Data.IDAL _Database; private static Dictionary _ProductMatches; private static Schema.DataProductsDataTable _DataProductsDataTable; /// /// Determine a product based on the filename /// static ProductIdentify() { _Database = Spludlow.Data.DAL.Create("@MetSat"); _ProductMatches = new Dictionary(); _DataProductsDataTable = new Schema.DataProductsDataTable(); _Database.Fill(_DataProductsDataTable, "SELECT * FROM DataProducts"); foreach (Schema.DataProductsRow row in _DataProductsDataTable.Rows) { if (row.Match.Length == 0) continue; _ProductMatches.Add(row.DataProductId, new Regex(row.Match)); } } public static string DetermineProduct(string filename) { string foundProductId = null; if (filename.StartsWith("L-") == true || filename.StartsWith("H-") == true) { if (filename.StartsWith("L-000-MSG3__-MSG3________") == true) // FTP LRIT return "EO_EUM_DAT_MSG_LRSEVIRI"; filename = filename.Substring(0, 35); foreach (string productId in _ProductMatches.Keys) { if (_ProductMatches[productId].IsMatch(filename) == true) { if (foundProductId == null) foundProductId = productId; else throw new ApplicationException("Multiple match for: " + filename); } } if (foundProductId != null) return foundProductId; return ""; } if (filename.StartsWith("IASI_SST_") == true) // FTP Metop/NOAA Global Data Services IASI Sea Surface Temperature L2PCore { return "EO_EUM_DAT_METOP_IASI_SST_"; // Made Up } if (filename.StartsWith("S-HSAF-") == true) { return "S_HSAF_" + filename.Substring(8, 2); } foreach (string productId in _ProductMatches.Keys) { if (_ProductMatches[productId].IsMatch(filename) == true) { if (foundProductId == null) foundProductId = productId; else throw new ApplicationException("Multiple match for: " + filename); } } if (foundProductId != null) return foundProductId; return ""; } } }