public static string GetTemplate(FileT file) { string TemplateFile = string.Empty; switch (file.TipoDBMS) { case ConfigFile.DB2_NAME: TemplateFile = ConfigFile.ERWIN_TEMPLATE_DB2; break; case ConfigFile.ORACLE: TemplateFile = ConfigFile.ERWIN_TEMPLATE_ORACLE; break; case ConfigFile.SQLSERVER: TemplateFile = ConfigFile.ERWIN_TEMPLATE_SQLSERVER; break; default: string fileName = file.SSA + "_" + file.Acronimo + "_" + file.NomeModello + "_" + file.TipoDBMS + "_" + file.Estensione; Logger.PrintLC(fileName + ": DB descriptor is invalid. Skipping it."); TemplateFile = null; break; } return(TemplateFile); }
public static List <string> ParseListOfFileNames(List <string> fileList) { List <string> result = new List <string>(); foreach (string file in fileList) { FileT parsedResult = ParseFileName(file); if (parsedResult != null) { result.Add(file); } } return(result); }
public static FileT ParseFileName(string fileName) { FileT file = new FileT(); FileInfo fileNameInfo = new FileInfo(fileName); string[] fileComponents; fileComponents = fileNameInfo.Name.Split(ConfigFile.DELIMITER_NAME_FILE); int length = fileComponents.Count(); if (length != 5) { Logger.PrintLC(fileName + " file name doesn't conform to the formatting standard <SSA>_<ACRONYM>_<MODELNAME>_<DBMSTYPE>.<extension>", 2); return(file = null); } if (!ConfigFile.DBS.Contains(fileComponents[3].ToUpper())) { Logger.PrintLC(fileName + " file name doesn't conform to the formatting standard <SSA>_<ACRONYM>_<MODELNAME>_<DBMSTYPE>.<extension>", 2); return(file = null); } try { file.SSA = fileComponents[0]; file.Acronimo = fileComponents[1]; file.NomeModello = fileComponents[2]; file.TipoDBMS = fileComponents[3]; file.Estensione = fileComponents[4]; } catch (Exception exp) { Logger.PrintLC(fileName + "produced an error while parsing its name: " + exp.Message, 2); return(file = null); } return(file); }
public static FileT ParseFileName(string fileName) { FileT file = new FileT(); FileInfo fileNameInfo = new FileInfo(fileName); string[] fileComponents; fileComponents = fileNameInfo.Name.Split(ConfigFile.DELIMITER_NAME_FILE); int length = fileComponents.Count(); string correct = Path.Combine(fileNameInfo.DirectoryName, Path.GetFileNameWithoutExtension(fileNameInfo.FullName) + "_OK.txt"); string error = Path.Combine(fileNameInfo.DirectoryName, Path.GetFileNameWithoutExtension(fileNameInfo.FullName) + "_KO.txt"); if (length != 5) { Logger.PrintLC(fileName + " file name doesn't conform to the formatting standard <SSA>_<ACRONYM>_<MODELNAME>_<DBMSTYPE>.<extension>.", 2, ConfigFile.ERROR); if (File.Exists(correct)) { File.Delete(correct); Logger.PrintF(error, "er_driveup – Caricamento Excel su ERwin", true); Logger.PrintF(error, "Colonne e Fogli formattati corretamente.", true); Logger.PrintF(error, "Formattazione del nome file errata.", true); } if (fileNameInfo.Extension.ToUpper() == ".XLS") { string fXLSX = Path.Combine(fileNameInfo.DirectoryName, Path.GetFileNameWithoutExtension(fileNameInfo.FullName) + ".xlsx"); if (File.Exists(fXLSX)) { File.Delete(fXLSX); } } return(file = null); } if (!ConfigFile.DBS.Contains(fileComponents[3].ToUpper())) { Logger.PrintLC(fileName + " file name doesn't conform to the formatting standard <SSA>_<ACRONYM>_<MODELNAME>_<DBMSTYPE>.<extension> . DB specified not present.", 2, ConfigFile.ERROR); if (File.Exists(correct)) { File.Delete(correct); Logger.PrintF(error, "er_driveup – Caricamento Excel su ERwin", true); Logger.PrintF(error, "Colonne e Fogli formattati corretamente.", true); Logger.PrintF(error, "DB specificato nel nome file non previsto.", true); } if (fileNameInfo.Extension.ToUpper() == ".XLS") { string fXLSX = Path.Combine(fileNameInfo.DirectoryName, Path.GetFileNameWithoutExtension(fileNameInfo.FullName) + ".xlsx"); if (File.Exists(fXLSX)) { File.Delete(fXLSX); } } return(file = null); } try { file.SSA = fileComponents[0]; file.Acronimo = fileComponents[1]; file.NomeModello = fileComponents[2]; file.TipoDBMS = fileComponents[3].ToUpper(); file.Estensione = fileComponents[4]; } catch (Exception exp) { Logger.PrintLC(fileName + "produced an error while parsing its name: " + exp.Message, 2, ConfigFile.ERROR); if (File.Exists(correct)) { File.Delete(correct); Logger.PrintF(error, "er_driveup – Caricamento Excel su ERwin", true); Logger.PrintF(error, "Colonne e Fogli formattati corretamente.", true); Logger.PrintF(error, "Errore: " + exp.Message, true); } if (fileNameInfo.Extension.ToUpper() == ".XLS") { string fXLSX = Path.Combine(fileNameInfo.DirectoryName, Path.GetFileNameWithoutExtension(fileNameInfo.FullName) + ".xlsx"); if (File.Exists(fXLSX)) { File.Delete(fXLSX); } } return(file = null); } return(file); }
/// <summary> /// MAIN process /// </summary> /// <returns></returns> public static int StartProcess() { try { string[] ElencoExcel = DirOps.GetFilesToProcess(ConfigFile.ROOT, "*.xls|.xlsx"); List <string> gg = FileOps.GetTrueFilesToProcess(ElencoExcel); //#################################### //Ciclo MAIN foreach (var file in gg) { string TemplateFile = null; if (ExcelOps.FileValidation(file)) { FileT fileT = Parser.ParseFileName(file); string destERFile = null; if (fileT != null) { switch (fileT.TipoDBMS) { case ConfigFile.DB2_NAME: TemplateFile = ConfigFile.ERWIN_TEMPLATE_DB2; break; case ConfigFile.ORACLE: TemplateFile = ConfigFile.ERWIN_TEMPLATE_ORACLE; break; default: TemplateFile = ConfigFile.ERWIN_TEMPLATE_DB2; break; } FileInfo origin = new FileInfo(file); string fileName = Path.GetFileNameWithoutExtension(file); destERFile = Path.Combine(ConfigFile.FOLDERDESTINATION, fileName + Path.GetExtension(TemplateFile)); if (!FileOps.CopyFile(TemplateFile, destERFile)) { continue; } } else { continue; } //Apertura connessione per il file attuale ConnMng connessione = new ConnMng(); if (!connessione.openModelConnection(destERFile)) { continue; } //Aggiornamento della struttura dati per il file attuale if (!connessione.SetRootObject()) { continue; } if (!connessione.SetRootCollection()) { continue; } FileInfo fInfo = new FileInfo(file); List <EntityT> DatiFile = ExcelOps.ReadXFileEntity(fInfo, fileT.TipoDBMS); foreach (var dati in DatiFile) { connessione.CreateEntity(dati, TemplateFile); } fInfo = new FileInfo(Path.Combine(ConfigFile.FOLDERDESTINATION, Path.GetFileNameWithoutExtension(file) + ".xlsx")); List <AttributeT> AttrFile = null; if (File.Exists(fInfo.FullName)) { AttrFile = ExcelOps.ReadXFileAttribute(fInfo, fileT.TipoDBMS); } //ATTRIBUTI - PASSAGGIO UNO //Aggiornamento dati struttura if (!connessione.SetRootObject()) { continue; } if (!connessione.SetRootCollection()) { continue; } //############################ foreach (var dati in AttrFile) { connessione.CreateAttributePassOne(dati, TemplateFile); } //ATTRIBUTI - PASSAGGIO DUE //Aggiornamento dati struttura if (!connessione.SetRootObject()) { continue; } if (!connessione.SetRootCollection()) { continue; } //############################ foreach (var dati in AttrFile) { connessione.CreateAttributePassTwo(dati, TemplateFile); } //Chiusura connessione per il file attuale. connessione.CloseModelConnection(); } } return(0); } catch (Exception exp) { //return exp.HResult; return(6); } return(6); }