Пример #1
0
        public void CreateScriptHeader(IDataSource Srcds, IProgress <PassedArgs> progress, CancellationToken token)
        {
            int i = 0;

            script = new SyncDataSource();
            script.scriptSource = Srcds.DatasourceName;
            List <EntityStructure> ls = new List <EntityStructure>();

            Srcds.GetEntitesList();
            foreach (string item in Srcds.EntitiesNames)
            {
                ls.Add(Srcds.GetEntityStructure(item, true));
            }
            DMEEditor.ETL.GetCreateEntityScript(Srcds, ls, progress, token);
            foreach (var item in ls)
            {
                SyncEntity upscript = new SyncEntity();
                upscript.sourcedatasourcename       = item.DataSourceID;
                upscript.sourceentityname           = item.EntityName;
                upscript.sourceDatasourceEntityName = item.DatasourceEntityName;

                upscript.destinationDatasourceEntityName = item.EntityName;
                upscript.destinationentityname           = item.EntityName;
                upscript.destinationdatasourcename       = Srcds.DatasourceName;
                upscript.scriptType = DDLScriptType.CopyData;
                script.Entities.Add(upscript);
                i += 1;
            }
        }
Пример #2
0
        //-----------------------
        public async Task <IErrorsInfo> RunChildScriptAsync(SyncEntity ParentScript, IDataSource srcds, IDataSource destds, IProgress <PassedArgs> progress, CancellationToken token)
        {
            if (ParentScript.CopyDataScripts.Count > 0)
            {
                //foreach (LScript sc in ParentScript.CopyDataScripts.Where(p=>p.scriptType==DDLScriptType.CopyData).ToList())
                for (int i = 0; i < ParentScript.CopyDataScripts.Count; i++)
                {
                    SyncEntity sc = ParentScript.CopyDataScripts[i];
                    destds = DMEEditor.GetDataSource(sc.destinationdatasourcename);
                    srcds  = DMEEditor.GetDataSource(sc.sourcedatasourcename);

                    if (destds != null && srcds != null)
                    {
                        DMEEditor.OpenDataSource(sc.destinationdatasourcename);
                        DMEEditor.OpenDataSource(sc.sourcedatasourcename);
                        if (destds.ConnectionStatus == System.Data.ConnectionState.Open)
                        {
                            if (sc.scriptType == DDLScriptType.CopyData)
                            {
                                await Task.Run(() =>
                                {
                                    sc.errorsInfo = RunCopyEntityScript(ref sc, srcds, destds, sc.sourceDatasourceEntityName, sc.destinationentityname, progress, token, true);  //t1.Result;//DMEEditor.ETL.CopyEntityData(srcds, destds, ScriptHeader.Scripts[i], true);
                                });

                                if (DMEEditor.ErrorObject.Flag == Errors.Failed)
                                {
                                    sc.errormessage = DMEEditor.ErrorObject.Message;
                                    sc.errorsInfo   = DMEEditor.ErrorObject;
                                    sc.Active       = false;

                                    if (progress != null)
                                    {
                                        PassedArgs ps = new PassedArgs {
                                            EventType = "Update", ParameterInt1 = CurrentScriptRecord, ParameterInt2 = ScriptCount, ParameterString3 = DMEEditor.ErrorObject.Message
                                        };
                                        progress.Report(ps);
                                    }
                                }
                            }
                            else
                            {
                                DMEEditor.ErrorObject.Flag    = Errors.Failed;
                                DMEEditor.ErrorObject.Message = $" Could not Connect to on the Data Dources {sc.destinationdatasourcename} or {sc.sourcedatasourcename}";
                            }
                            // Report progress as a percentage of the total task.
                            //    UpdateEvents(sc, highestPercentageReached, CurrentRecord, numberToCompute, destds);
                        }
                    }
                }
            }
            return(DMEEditor.ErrorObject);
        }
Пример #3
0
        private SyncEntity GenerateCopyScript(SyncEntity rt, EntityStructure item, string destSource)
        {
            SyncEntity upscript = new SyncEntity();

            upscript.sourcedatasourcename       = item.DataSourceID;
            upscript.sourceentityname           = item.EntityName;
            upscript.sourceDatasourceEntityName = item.DatasourceEntityName;

            upscript.destinationDatasourceEntityName = item.EntityName;
            upscript.destinationentityname           = item.EntityName;
            upscript.destinationdatasourcename       = destSource;
            upscript.scriptType = DDLScriptType.CopyData;


            return(upscript);
        }
Пример #4
0
        private List <SyncEntity> GenerateCopyScripts(List <SyncEntity> rt, EntityStructure item, string destSource)
        {
            List <SyncEntity> retval = new List <SyncEntity>();

            foreach (SyncEntity sc in rt)
            {
                SyncEntity upscript = new SyncEntity();
                upscript.sourcedatasourcename       = item.DataSourceID;
                upscript.sourceentityname           = item.EntityName;
                upscript.sourceDatasourceEntityName = item.DatasourceEntityName;

                upscript.destinationDatasourceEntityName = item.EntityName;
                upscript.destinationentityname           = item.EntityName;
                upscript.destinationdatasourcename       = destSource;
                upscript.scriptType = DDLScriptType.CopyData;
                retval.Add(upscript);
            }

            return(retval);
        }
Пример #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);
        }