public Type GetEntityType(string EntityName) { EntityStructure x = GetEntityStructure(EntityName, false); DMTypeBuilder.CreateNewObject(EntityName, EntityName, x.Fields); return(DMTypeBuilder.myType); }
public Type GetEntityType(string EntityName) { string filenamenoext = EntityName; DMTypeBuilder.CreateNewObject(EntityName, EntityName, Entities.Where(x => x.EntityName == EntityName).FirstOrDefault().Fields); return(DMTypeBuilder.myType); }
public Type GetEntityType(string entityname) { EntityStructure dh = Entities[EntityListIndex(entityname)]; Type retval; switch (dh.Viewtype) { case ViewType.Table: retval = GetDataSourceObject(entityname).GetEntityType(entityname); break; case ViewType.Query: case ViewType.Code: case ViewType.File: case ViewType.Url: default: DMTypeBuilder.CreateNewObject(entityname, entityname, dh.Fields); retval = DMTypeBuilder.myType; break; } return(retval); }
public List <object> GetListByDataTable(DataTable dt, string NameSpace, string Entityname) { List <EntityField> flds = new List <EntityField>(); // Create type from Table foreach (DataColumn item in dt.Columns) { EntityField field = new EntityField(); field.EntityName = dt.TableName; field.fieldname = item.ColumnName; field.fieldtype = item.DataType.ToString(); flds.Add(field); // properties[item.ColumnName].SetValue(x, row[item.ColumnName], null); } DMTypeBuilder.CreateNewObject(Entityname, NameSpace, Entityname, flds); Type type = DMTypeBuilder.myType; // string f = ""; List <object> Records = new List <object>(); Dictionary <string, PropertyInfo> properties = new Dictionary <string, PropertyInfo>(); foreach (DataColumn item in dt.Columns) { properties.Add(item.ColumnName, type.GetProperty(item.ColumnName)); // properties[item.ColumnName].SetValue(x, row[item.ColumnName], null); } //for (int i = 0; i <= enttype.Fields.Count - 1; i++) //{ // properties.Add(enttype.Fields[i].fieldname, type.GetProperty(enttype.Fields[i].fieldname)); //} //for (int i = 0; i <= enttype.Fields.Count - 1; i++) //{} foreach (DataRow row in dt.Rows) { // dynamic x = TypeHelpers.GetInstance(type); dynamic x = Activator.CreateInstance(type); // var v = (dynamic)null; foreach (DataColumn item in dt.Columns) { if (row[item.ColumnName] != DBNull.Value) { string st = row[item.ColumnName].ToString(); if (!string.IsNullOrEmpty(st) && !string.IsNullOrWhiteSpace(st)) { properties[item.ColumnName].SetValue(x, row[item.ColumnName], null); } } } Records.Add(x); } return(Records); }
public Type GetEntityType(string EntityName) { Openconnection(); if (ConnectionStatus == ConnectionState.Open) { GetEntitesList(); string filenamenoext = EntityName; DMTypeBuilder.CreateNewObject(EntityName, EntityName, Entities.Where(x => x.EntityName == EntityName).FirstOrDefault().Fields); return(DMTypeBuilder.myType); } return(null); }
public Type GetEntityType(string EntityName) { if (Entities != null) { if (Entities.Count == 0) { if (Entities[0].Fields.Count == 0) { Getfields(); } } } else { Entities = new List <EntityStructure>(); Getfields(); } DMTypeBuilder.CreateNewObject(Entities.FirstOrDefault().EntityName, Entities.FirstOrDefault().EntityName, Entities.FirstOrDefault().Fields); return(DMTypeBuilder.myType); }
public Type GetEntityType(string EntityName, List <EntityField> Fields) { DMTypeBuilder.CreateNewObject(EntityName, EntityName, Fields); return(DMTypeBuilder.myType); }
private List <object> GetData(int nrofrows) { try { if (Entities != null) { if (Entities.Count == 0) { if (Entities[0].Fields.Count == 0) { Getfields(); } } } else { Entities = new List <EntityStructure>(); Getfields(); } Records = new List <object>(); if (Entities != null) { fieldParser = new CsvTextFieldParser(Path.Combine(Dataconnection.ConnectionProp.FilePath, Dataconnection.ConnectionProp.FileName)); fieldParser.SetDelimiter(','); DMTypeBuilder.CreateNewObject(DatasourceName, DatasourceName, Entities[0].Fields); Dictionary <string, PropertyInfo> properties = new Dictionary <string, PropertyInfo>(); foreach (EntityField item in Entities[0].Fields) { properties.Add(item.fieldname, DMTypeBuilder.myType.GetProperty(item.fieldname)); // properties[item.ColumnName].SetValue(x, row[item.ColumnName], null); } string[] r = fieldParser.ReadFields(); while ((fieldParser.EndOfData == false)) { dynamic x = Activator.CreateInstance(DMTypeBuilder.myType); r = fieldParser.ReadFields(); for (int i = 0; i < Entities[0].Fields.Count; i++) { try { string st = r[i].ToString(); if (!string.IsNullOrEmpty(st) && !string.IsNullOrWhiteSpace(st)) { properties[Entities[0].Fields[i].fieldname].SetValue(x, Convert.ChangeType(st, DMEEditor.Utilfunction.GetTypeCode(Type.GetType(Entities[0].Fields[i].fieldtype))), null); } } catch (Exception fieldex) { } } Records.Add(x); } } fieldParser.Close(); return(Records); } catch (Exception ex) { fieldParser.Close(); DMEEditor.AddLogMessage("Fail", $"Error : Could not Get Data from File {DatasourceName}- {ex.Message}", DateTime.Now, 0, null, Errors.Failed); return(null); } }
private void GetTypeForSheetsFile(string pSheetname) { List <EntityField> flds = GetSheetColumns(pSheetname); DMTypeBuilder.CreateNewObject(pSheetname, pSheetname, flds); }
private IErrorsInfo RunCopyEntityScript(ref SyncEntity sc, IDataSource sourceds, IDataSource destds, string srcentity, string destentity, IProgress <PassedArgs> progress, CancellationToken token, bool CreateMissingEntity = true) { try { int errorcount = 0; EntityStructure item = sourceds.GetEntityStructure(srcentity, true); if (item != null) { if (destds.Category == DatasourceCategory.RDBMS) { IRDBSource rDB = (IRDBSource)destds; rDB.DisableFKConstraints(item); } if (destds.CheckEntityExist(item.EntityName)) { object srcTb; string entname; var src = Task.Run(() => { return(sourceds.GetEntity(item.EntityName, null)); }); src.Wait(); srcTb = src.Result; List <object> srcList = new List <object>(); if (src.Result != null) { DMTypeBuilder.CreateNewObject(item.EntityName, item.EntityName, item.Fields); if (srcTb.GetType().FullName.Contains("DataTable")) { srcList = DMEEditor.Utilfunction.GetListByDataTable((DataTable)srcTb, DMTypeBuilder.myType, item); } if (srcTb.GetType().FullName.Contains("List")) { srcList = (List <object>)srcTb; } if (srcTb.GetType().FullName.Contains("IEnumerable")) { srcList = (List <object>)srcTb; } ScriptCount += srcList.Count(); //if (progress != null) //{ // PassedArgs ps = new PassedArgs { ParameterInt1 = CurrentScriptRecord, ParameterInt2 = ScriptCount }; // progress.Report(ps); //} foreach (var r in srcList) { CurrentScriptRecord += 1; DMEEditor.ErrorObject = destds.InsertEntity(item.EntityName, r); token.ThrowIfCancellationRequested(); if (DMEEditor.ErrorObject.Flag == Errors.Failed) { SyncErrorsandTracking tr = new SyncErrorsandTracking(); errorcount++; tr.errormessage = DMEEditor.ErrorObject.Message; tr.errorsInfo = DMEEditor.ErrorObject; tr.rundate = DateTime.Now; tr.sourceEntityName = item.EntityName; tr.currenrecordindex = CurrentScriptRecord; tr.sourceDataSourceName = item.DataSourceID; tr.parentscriptid = sc.id; sc.Tracking.Add(tr); if (progress != null) { PassedArgs ps = new PassedArgs { EventType = "Update", ParameterInt1 = CurrentScriptRecord, ParameterInt2 = ScriptCount, ParameterString3 = DMEEditor.ErrorObject.Message }; progress.Report(ps); } if (errorcount >= StopErrorCount) { stoprun = true; PassedArgs ps = new PassedArgs { EventType = "Stop", ParameterInt1 = CurrentScriptRecord, ParameterInt2 = ScriptCount, ParameterString3 = DMEEditor.ErrorObject.Message }; progress.Report(ps); } } else { if (progress != null) { PassedArgs ps = new PassedArgs { EventType = "NA", ParameterInt1 = CurrentScriptRecord, ParameterInt2 = ScriptCount, ParameterString3 = DMEEditor.ErrorObject.Message }; progress.Report(ps); } } } } if (progress != null) { PassedArgs ps = new PassedArgs { ParameterString1 = $"Ended Copying Data from {srcentity} on {sourceds.DatasourceName} to {srcentity} on {destds.DatasourceName} ", ParameterInt1 = CurrentScriptRecord, ParameterInt2 = ScriptCount }; progress.Report(ps); } } else { DMEEditor.AddLogMessage("Copy Data", $"Error Could not Copy Entity Date {srcentity} on {sourceds.DatasourceName} to {srcentity} on {destds.DatasourceName} ", DateTime.Now, 0, null, Errors.Failed); } if (destds.Category == DatasourceCategory.RDBMS) { IRDBSource rDB = (IRDBSource)destds; rDB.EnableFKConstraints(item); } } else { DMEEditor.AddLogMessage("Copy Data", $"Error Could not Find Entity {srcentity} on {sourceds.DatasourceName} to {srcentity} on {destds.DatasourceName} ", DateTime.Now, 0, null, Errors.Failed); } } catch (Exception ex) { DMEEditor.AddLogMessage("Fail", $"Error copying Data {srcentity} on {sourceds.DatasourceName} to {srcentity} on {destds.DatasourceName} ({ex.Message})", DateTime.Now, -1, "CopyDatabase", Errors.Failed); } return(DMEEditor.ErrorObject); }
public IErrorsInfo CopyEntityData(IDataSource sourceds, IDataSource destds, string srcentity, string destentity, IProgress <PassedArgs> progress, CancellationToken token, bool CreateMissingEntity = true) { try { int errorcount = 0; EntityStructure item = sourceds.GetEntityStructure(srcentity, true); if (item != null) { if (destds.Category == DatasourceCategory.RDBMS) { IRDBSource rDB = (IRDBSource)destds; rDB.DisableFKConstraints(item); } if (destds.CreateEntityAs(item)) { object srcTb; string entname; var src = Task.Run(() => { return(sourceds.GetEntity(item.EntityName, null)); }); src.Wait(); srcTb = src.Result; List <object> srcList = new List <object>(); if (src.Result != null) { DMTypeBuilder.CreateNewObject(item.EntityName, item.EntityName, item.Fields); if (srcTb.GetType().FullName.Contains("DataTable")) { srcList = DMEEditor.Utilfunction.GetListByDataTable((DataTable)srcTb, DMTypeBuilder.myType, item); } if (srcTb.GetType().FullName.Contains("List")) { srcList = (List <object>)srcTb; } if (srcTb.GetType().FullName.Contains("IEnumerable")) { srcList = (List <object>)srcTb; } ScriptCount += srcList.Count(); //if (progress != null) //{ // PassedArgs ps = new PassedArgs { ParameterInt1 = CurrentScriptRecord, ParameterInt2 = ScriptCount }; // progress.Report(ps); //} foreach (var r in srcList) { CurrentScriptRecord += 1; DMEEditor.ErrorObject = destds.InsertEntity(item.EntityName, r); token.ThrowIfCancellationRequested(); if (progress != null) { PassedArgs ps = new PassedArgs { ParameterInt1 = CurrentScriptRecord, ParameterInt2 = ScriptCount, ParameterString3 = DMEEditor.ErrorObject.Message }; progress.Report(ps); } } } //var dst = Task.Run<IErrorsInfo>(() => { return destds.UpdateEntities(destentity, srcTb,progress); }); //dst.Wait(); if (progress != null) { PassedArgs ps = new PassedArgs { ParameterString1 = $"Ended Copying Data from {srcentity} on {sourceds.DatasourceName} to {srcentity} on {destds.DatasourceName} ", ParameterInt1 = CurrentScriptRecord, ParameterInt2 = ScriptCount }; progress.Report(ps); } // DMEEditor.AddLogMessage("Copy Data", $"Ended Copying Data from {srcentity} on {sourceds.DatasourceName} to {srcentity} on {destds.DatasourceName} ", DateTime.Now, 0, null, Errors.Ok); } else { DMEEditor.AddLogMessage("Copy Data", $"Error Could not Copy Entity Date {srcentity} on {sourceds.DatasourceName} to {srcentity} on {destds.DatasourceName} ", DateTime.Now, 0, null, Errors.Failed); } if (destds.Category == DatasourceCategory.RDBMS) { IRDBSource rDB = (IRDBSource)destds; rDB.EnableFKConstraints(item); } } else { DMEEditor.AddLogMessage("Copy Data", $"Error Could not Find Entity {srcentity} on {sourceds.DatasourceName} to {srcentity} on {destds.DatasourceName} ", DateTime.Now, 0, null, Errors.Failed); } } catch (Exception ex) { DMEEditor.AddLogMessage("Fail", $"Error copying Data {srcentity} on {sourceds.DatasourceName} to {srcentity} on {destds.DatasourceName} ({ex.Message})", DateTime.Now, -1, "CopyDatabase", Errors.Failed); } return(DMEEditor.ErrorObject); }