Esempio n. 1
0
 public IErrorsInfo CopyEntityStructure(IDataSource sourceds, IDataSource destds, string srcentity, string destentity, IProgress <PassedArgs> progress, CancellationToken token, bool CreateMissingEntity = true)
 {
     try
     {
         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))
             {
                 DMEEditor.AddLogMessage("Success", $"Creating Entity  {item.EntityName} on {destds.DatasourceName}", DateTime.Now, 0, null, Errors.Ok);
             }
             else
             {
                 DMEEditor.AddLogMessage("Fail", $"Error : Could not Create  Entity {item.EntityName} on {destds.DatasourceName}", DateTime.Now, 0, null, Errors.Failed);
             }
             if (destds.Category == DatasourceCategory.RDBMS)
             {
                 IRDBSource rDB = (IRDBSource)destds;
                 rDB.EnableFKConstraints(item);
             }
         }
     }
     catch (Exception ex)
     {
         DMEEditor.AddLogMessage("Fail", $"Error Could not Create  Entity {srcentity} on {destds.DatasourceName} ({ex.Message})", DateTime.Now, -1, "CopyDatabase", Errors.Failed);
     }
     return(DMEEditor.ErrorObject);
 }
Esempio n. 2
0
        private void ValidateFKbutton_Click(object sender, EventArgs e)
        {
            string schemaname = "";

            ds = DMEEditor.GetDataSource(dataSourceIDComboBox.Text);
            IRDBSource rdb = null;

            if (ds.Category == DatasourceCategory.RDBMS)
            {
                rdb        = (IRDBSource)SourceConnection;
                schemaname = rdb.GetSchemaName();
                EntityStructure.Relations = rdb.GetEntityforeignkeys(EntityName.ToUpper(), schemaname);
                dataHierarchyBindingSource.ResetBindings(false);
            }
        }
Esempio n. 3
0
        public IErrorsInfo SyncDatabase(IDataSource src, IRDBSource dest)
        {
            DMEEditor.ErrorObject.Flag = Errors.Ok;
            try
            {
                DMEEditor.Logger.WriteLog($"Successed in Syncing Database ");
            }
            catch (System.Exception ex)
            {
                DMEEditor.ErrorObject.Flag = Errors.Failed;
                DMEEditor.ErrorObject.Ex   = ex;
                DMEEditor.Logger.WriteLog($"Error in Syncing Database ({ex.Message})");
            }

            return(DMEEditor.ErrorObject);
        }
Esempio n. 4
0
        private EntityStructure SetupEntityInView(IDMDataView v, List <EntityStructure> Rootnamespacelist, string childtable, string parenttable, string childcolumn, string parentcolumn, int pid, string Datasourcename)
        {
            EntityStructure a;
            int             pkid       = NextHearId();
            IDataSource     ds         = DMEEditor.GetDataSource(Datasourcename);
            string          schemaname = "";

            if (ds.Category == DatasourceCategory.RDBMS)
            {
                IRDBSource rdb = (IRDBSource)ds;
                schemaname = rdb.GetSchemaName();
            }

            if (!Rootnamespacelist.Where(f => f.ParentId == pid && f.EntityName.Equals(childtable, StringComparison.OrdinalIgnoreCase)).Any())//f => f.Id == childtable &&
            {
                //a = new EntityStructure() { Id = pkid, ParentId = pid, EntityName = childtable.ToUpper(), ViewID = v.ViewID };
                //a.DataSourceID = v.Entities.Where(x => x.Id == pid).FirstOrDefault().DataSourceID;
                //a.DatasourceEntityName = childtable;
                //a.Relations = ds.GetEntityforeignkeys(childtable.ToUpper(), schemaname);

                a          = (EntityStructure)ds.GetEntityStructure(childtable, true).Clone();
                a.ParentId = pid;
                a.Id       = NextHearId();
                Rootnamespacelist.Add(a);
            }
            else
            {
                a = Rootnamespacelist.Where(f => f.ParentId == pid && f.EntityName.Equals(childtable, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); //f.Id == childtable &&
                //  a.DataSourceID = DatasourceName;
                a.DatasourceEntityName = childtable;
                a.Relations.Add(new RelationShipKeys {
                    EntityColumnID = childcolumn.ToUpper(), ParentEntityColumnID = parentcolumn.ToUpper(), ParentEntityID = parenttable.ToUpper()
                });
            }
            return(a);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }