@ -288,7 +288,7 @@ namespace Gremlin.GremlinData.DBClasses
ImportProducts ( mappingTable ) ;
break ;
case "CustomDescription" :
ImportCustomDescriptions ( mappingTable ) ;
ImportCustomDescriptions ( ) ; // mappingTable) ;
break ;
default :
return false ;
@ -303,7 +303,7 @@ namespace Gremlin.GremlinData.DBClasses
return ImportFile ( ) ;
}
private static bool ImportCustomDescriptions ( Dictionary < string , int > mappingTable )
private static bool ImportCustomDescriptions ( ) //Dictionary<string, int> mappingTable )
{
List < CustomDescription > CDsReadFromFile = new ( 2500 ) ;
Encoding = Encoding . GetEncoding ( "UTF-8" ) ; //Custom-Descriptions-CSV hat festes Encoding.
@ -987,36 +987,36 @@ namespace Gremlin.GremlinData.DBClasses
return true ;
}
private static void SetProperty ( object gremlinEntity , PropertyInfo propertyInfo , string value )
{
propertyInfo . SetValue ( gremlinEntity , value ) ;
}
//private static void SetProperty(object gremlinEntity, PropertyInfo propertyInfo, string value )
// {
// propertyInfo.SetValue(gremlinEntity, value);
// }
private static Array GetNewGremlinTypeArray ( Assembly assembly , string detectedDataType , int length )
{
Type GremlinType = GetNewGremlinType ( assembly , detectedDataType ) . GetType ( ) ;
//Create an one-dimensional array with n+1 or n+2 elements (n = number of datasets, plus heading and/or emptyline at EOF):
return Array . CreateInstance ( GremlinType , length ) ;
//private static Array GetNewGremlinTypeArray(Assembly assembly, string detectedDataType, int length )
// {
// Type GremlinType = GetNewGremlinType(assembly, detectedDataType).GetType();
// //Create an one-dimensional array with n+1 or n+2 elements (n = number of datasets, plus heading and/or emptyline at EOF):
// return Array.CreateInstance(GremlinType, length);
//Das geht alles nicht:
//List<GremlinType> test = new();
//List<typeof(GremlinType)> test = new();
//List<GremlinType.GetType()> test = new();
// //Das geht alles nicht:
// //List<GremlinType> test = new();
// //List<typeof(GremlinType)> test = new();
// //List<GremlinType.GetType()> test = new();
////Das geht:
////Create iList:
//Type listType = typeof(List<>).MakeGenericType(GremlinType);
//var list = (IList)Activator.CreateInstance(listType);
//list.Add(new Account() { AccountName = "Test" });
//list.Add(GremlinClassObject);
// ////Das geht:
// ////Create iList:
// //Type listType = typeof(List<>).MakeGenericType(GremlinType);
// //var list = (IList)Activator.CreateInstance(listType);
// //list.Add(new Account() { AccountName = "Test" });
// //list.Add(GremlinClassObject);
}
// }
private static object GetNewGremlinType ( Assembly Gremlin , string detectedDataType )
{
return Activator . CreateInstance ( Gremlin . ToString ( ) , "Gremlin." + detectedDataType ) . Unwrap ( ) ;
}
//private static object GetNewGremlinType(Assembly Gremlin, string detectedDataType )
// {
// return Activator.CreateInstance(Gremlin.ToString(), "Gremlin." + detectedDataType).Unwrap();
// }
public static Dictionary < string , string > ReadMappingDictionaryFromFile ( )
{
@ -1053,171 +1053,171 @@ namespace Gremlin.GremlinData.DBClasses
return result ;
}
private static void BasimodosCodeDump ( )
{
//Unfertiger, generischer Code aus der ImportFile() Methode.
//Aufbewahren für später, wenn Zeit ist, das ordentlich zu machen.
//private static void BasimodosCodeDump( )
// {
// //Unfertiger, generischer Code aus der ImportFile() Methode.
// //Aufbewahren für später, wenn Zeit ist, das ordentlich zu machen.
//while (!csvParser.EndOfData)
//{
// //read
// //new data instance
// //convert
// //validate
// //set metadata: SetMetadataForImport(IMetadata)
// //add to list
// //while (!csvParser.EndOfData)
// //{
// // //read
// // //new data instance
// // //convert
// // //validate
// // //set metadata: SetMetadataForImport(IMetadata)
// // //add to list
// fields = csvParser.ReadFields(); // Read current line fields, pointer moves to the next line.
// if (fields[0] == "") break; // Am Ende hängt eine leere Zeile, die im Parser einen Fehler auslösen würde.
// // fields = csvParser.ReadFields(); // Read current line fields, pointer moves to the next line.
// // if (fields[0] == "") break; // Am Ende hängt eine leere Zeile, die im Parser einen Fehler auslösen würde.
// //TO DO: vor der foreach "Account" bevorzugt behandeln (Sonderfall bei LSAG: Liste deduplizieren, und als erstes importieren, da sonst keine Contacts importiert werden können).
// // //TO DO: vor der foreach "Account" bevorzugt behandeln (Sonderfall bei LSAG: Liste deduplizieren, und als erstes importieren, da sonst keine Contacts importiert werden können).
// foreach (string detectedDataType in detectedDataTypes)
// {
// //"Account" überspringen, da das vor der foreach schon verarbeitet worden ist.
// if (detectedDataType == "Account") continue;
// // foreach (string detectedDataType in detectedDataTypes)
// // {
// // //"Account" überspringen, da das vor der foreach schon verarbeitet worden ist.
// // if (detectedDataType == "Account") continue;
// Array GremlinTypeArray = GetNewGremlinTypeArray(Gremlin, detectedDataType, numberOfLines);
// Type GremlinType = GetNewGremlinType(Gremlin, detectedDataType).GetType();
// PropertyInfo[] GremlinTypeProperties = GremlinType.GetProperties();
// // Array GremlinTypeArray = GetNewGremlinTypeArray(Gremlin, detectedDataType, numberOfLines);
// // Type GremlinType = GetNewGremlinType(Gremlin, detectedDataType).GetType();
// // PropertyInfo[] GremlinTypeProperties = GremlinType.GetProperties();
// foreach (PropertyInfo property in GremlinTypeProperties)
// {
// if (mappingTable.TryGetValue(property.Name, out int columnNumber))
// {
// //convert:
// GremlinTypeConverter.Convert(fields[columnNumber]);
// }
// }
// }
// // foreach (PropertyInfo property in GremlinTypeProperties)
// // {
// // if (mappingTable.TryGetValue(property.Name, out int columnNumber))
// // {
// // //convert:
// // GremlinTypeConverter.Convert(fields[columnNumber]);
// // }
// // }
// // }
//}
// //}
//using (GremlinContext db = new())
//{
// //add to context
// //savechanges
//}
}
// //using (GremlinContext db = new())
// //{
// // //add to context
// // //savechanges
// //}
// }
//#########################################################################################
//Kann gelöscht werden, sobald die generische Funktion zuverlässig funktioniert:
//#########################################################################################
private static string RecognizeDataStatic ( Dictionary < string , int > mappingDictionary )
{
//Logik zur Kategorisierung des Datensatzes:
//Alle verpflichtenden Angaben zu einer Klasse vorhanen?
//Alle vom Importer erwarteten Angaben vorhanden?
//Bei den Enums zusätzlich noch proüfem, dass nur zwei Spalten vorhanden sind, sonst könnten LSAG-Daten falsch identifiziert werden.
/ /
/ /
//Products
if ( //required by DB:
mappingDictionary . ContainsKey ( "ProductNumber" )
& & mappingDictionary . ContainsKey ( "ListPrice" )
//required by importer:
& & mappingDictionary . ContainsKey ( "Weight" )
//unique identifier:
& & mappingDictionary . ContainsKey ( "BreakRangeFrom" )
)
{
return "Product" ;
}
//LSAG Contact List Tool List
if ( //required by DB:
mappingDictionary . ContainsKey ( "SAPAccountNumber" )
& & mappingDictionary . ContainsKey ( "SAPContactNumber" )
& & mappingDictionary . ContainsKey ( "AccountTypeCode" )
& & mappingDictionary . ContainsKey ( "SubMarketCode" )
& & mappingDictionary . ContainsKey ( "LastName" )
& & mappingDictionary . ContainsKey ( "AccountName" )
//required by importer:
//unique identifier:
& & mappingDictionary . ContainsKey ( "MA_ProductInterests" )
)
{
return "LSAG Contact List Tool List" ;
}
//Accounts
if ( //required by DB:
mappingDictionary . ContainsKey ( "AccountName" )
& & mappingDictionary . ContainsKey ( "Street" )
& & mappingDictionary . ContainsKey ( "ZIP" )
& & mappingDictionary . ContainsKey ( "City" )
& & mappingDictionary . ContainsKey ( "PhoneNumber" )
& & mappingDictionary . ContainsKey ( "SAPAccountNumber" )
& & mappingDictionary . ContainsKey ( "AccountCreatedInSAPOn" )
& & mappingDictionary . ContainsKey ( "AccountTypeCode" )
& & mappingDictionary . ContainsKey ( "SubMarketCode" )
//required by importer:
)
{
return "Account" ;
}
//Contacts
if ( //required by DB:
mappingDictionary . ContainsKey ( "LastName" )
& & mappingDictionary . ContainsKey ( "SAPContactNumber" )
//required by importer:
& & mappingDictionary . ContainsKey ( "FirstName" )
& & mappingDictionary . ContainsKey ( "Gender" )
)
{
return "Contact" ;
}
//Custom Description
if ( //required by DB:
mappingDictionary . ContainsKey ( "Heading" )
//required by importer:
& & mappingDictionary . ContainsKey ( "ProductNumber" )
& & mappingDictionary . ContainsKey ( "OptionNumber" )
& & mappingDictionary . ContainsKey ( "DescriptionText" )
//unique identifier:
& & mappingDictionary . ContainsKey ( "CoverletterText" )
)
{
return "CustomDescription" ;
}
//Pseudo-Enums AccountTypes, SubMarkets, ProductLines for DB-initializing
if ( mappingDictionary . Count = = 2 )
{
if ( mappingDictionary . ContainsKey ( "AccountTypeCode" )
& & mappingDictionary . ContainsKey ( "AccountTypeDescription" )
& & mappingDictionary . Count = = 2 )
{
return "AccountType" ;
}
if ( mappingDictionary . ContainsKey ( "SubMarketCode" )
& & mappingDictionary . ContainsKey ( "SubMarketDescription" )
& & mappingDictionary . Count = = 2 )
{
return "SubMarket" ;
}
if ( mappingDictionary . ContainsKey ( "ProductLineCode" )
& & mappingDictionary . ContainsKey ( "ProductLineDescription" )
& & mappingDictionary . Count = = 2 )
{
return "ProductLine" ;
}
}
return "No entity type unambigiously identified!" ;
//private static string RecognizeDataStatic(Dictionary<string, int> mappingDictionary )
// {
// //Logik zur Kategorisierung des Datensatzes:
// //Alle verpflichtenden Angaben zu einer Klasse vorhanen?
// //Alle vom Importer erwarteten Angaben vorhanden?
// //Bei den Enums zusätzlich noch proüfem, dass nur zwei Spalten vorhanden sind, sonst könnten LSAG-Daten falsch identifiziert werden.
// //
// //
// //Products
// if (//required by DB:
// mappingDictionary.ContainsKey("ProductNumber")
// && mappingDictionary.ContainsKey("ListPrice")
// //required by importer:
// && mappingDictionary.ContainsKey("Weight")
// //unique identifier:
// && mappingDictionary.ContainsKey("BreakRangeFrom")
// )
// {
// return "Product";
// }
// //LSAG Contact List Tool List
// if (//required by DB:
// mappingDictionary.ContainsKey("SAPAccountNumber")
// && mappingDictionary.ContainsKey("SAPContactNumber")
// && mappingDictionary.ContainsKey("AccountTypeCode")
// && mappingDictionary.ContainsKey("SubMarketCode")
// && mappingDictionary.ContainsKey("LastName")
// && mappingDictionary.ContainsKey("AccountName")
// //required by importer:
// //unique identifier:
// && mappingDictionary.ContainsKey("MA_ProductInterests")
// )
// {
// return "LSAG Contact List Tool List";
// }
// //Accounts
// if (//required by DB:
// mappingDictionary.ContainsKey("AccountName")
// && mappingDictionary.ContainsKey("Street")
// && mappingDictionary.ContainsKey("ZIP")
// && mappingDictionary.ContainsKey("City")
// && mappingDictionary.ContainsKey("PhoneNumber")
// && mappingDictionary.ContainsKey("SAPAccountNumber")
// && mappingDictionary.ContainsKey("AccountCreatedInSAPOn")
// && mappingDictionary.ContainsKey("AccountTypeCode")
// && mappingDictionary.ContainsKey("SubMarketCode")
// //required by importer:
// )
// {
// return "Account";
// }
// //Contacts
// if (//required by DB:
// mappingDictionary.ContainsKey("LastName")
// && mappingDictionary.ContainsKey("SAPContactNumber")
// //required by importer:
// && mappingDictionary.ContainsKey("FirstName")
// && mappingDictionary.ContainsKey("Gender")
// )
// {
// return "Contact";
// }
// //Custom Description
// if (//required by DB:
// mappingDictionary.ContainsKey("Heading")
// //required by importer:
// && mappingDictionary.ContainsKey("ProductNumber")
// && mappingDictionary.ContainsKey("OptionNumber")
// && mappingDictionary.ContainsKey("DescriptionText")
// //unique identifier:
// && mappingDictionary.ContainsKey("CoverletterText")
// )
// {
// return "CustomDescription";
// }
// //Pseudo-Enums AccountTypes, SubMarkets, ProductLines for DB-initializing
// if (mappingDictionary.Count == 2)
// {
// if (mappingDictionary.ContainsKey("AccountTypeCode")
// && mappingDictionary.ContainsKey("AccountTypeDescription")
// && mappingDictionary.Count == 2)
// {
// return "AccountType";
// }
// if (mappingDictionary.ContainsKey("SubMarketCode")
// && mappingDictionary.ContainsKey("SubMarketDescription")
// && mappingDictionary.Count == 2)
// {
// return "SubMarket";
// }
// if (mappingDictionary.ContainsKey("ProductLineCode")
// && mappingDictionary.ContainsKey("ProductLineDescription")
// && mappingDictionary.Count == 2)
// {
// return "ProductLine";
// }
// }
// return "No entity type unambigiously identified!";
}
// }
}
}