Beispiel #1
0
        private IErrorsInfo RunCopyDataBackWorker()
        {
            int tot = 0;
            int cur = 0;

            BackgroundWorker = new BackgroundWorker
            {
                WorkerSupportsCancellation = true,
                WorkerReportsProgress      = true
            };
            BackgroundWorker.WorkerReportsProgress = true;
            BackgroundWorker.ProgressChanged      += (sender, eventArgs) =>
            {
                IDataWorkFlowEventArgs passedArgs = new IDataWorkFlowEventArgs();
                ObjectItem             item       = new ObjectItem();
                item.obj  = eventArgs;
                item.Name = "backgroundworkerprogress";
                passedArgs.Objects.Add(item);

                WorkFlowStepRunning?.Invoke(this, passedArgs);
                DMEEditor.RaiseEvent(this, passedArgs);
                DMEEditor.AddLogMessage("Copy Data Action ", "Success in Copying Data " + eventArgs.ProgressPercentage + " out of " + tot, DateTime.Now, eventArgs.ProgressPercentage, "", Errors.Ok);
            };

            BackgroundWorker.DoWork += (sender, e) =>
            {
                IDataWorkFlowEventArgs passedArgs = new IDataWorkFlowEventArgs();
                ObjectItem             item1      = new ObjectItem();
                item1.obj  = e;
                item1.Name = "backgroundworkerstarted";
                passedArgs.Objects.Add(item1);

                WorkFlowStepStarted?.Invoke(this, passedArgs);
                //  OutData = await Inds.GetEntityDataAsTableAsync(OutParameters[0].Parameter, " 1=2 ");

                if (InParameters[1] != null)
                {
                    if (InParameters[1].Objects != null)
                    {
                        List <string> ents = (List <string>)InParameters[1].Objects.Where(c => c.Name == "ENTITIES").FirstOrDefault().obj;
                        if (ents != null)
                        {
                            EntitesNames = ents;
                        }
                    }
                }
                if (EntitesNames == null || EntitesNames.Count == 0)
                {
                    if (Inds.EntitiesNames.Count() == 0)
                    {
                        Inds.GetEntitesList();
                    }
                    EntitesNames = Inds.EntitiesNames;
                }

                //--------------------------------------------------
                DMEEditor.ErrorObject.Flag = Errors.Ok;


                foreach (string item in EntitesNames)
                {
                    cur += 1;

                    var t = Task.Run <object>(() => { return(Inds.RunQuery(item)); });
                    t.Wait();
                    InData = t.Result;
                    if (!Outds.CheckEntityExist(item))
                    {
                        Outds.CreateEntityAs(Inds.GetEntityStructure(item, true));
                    }
                    var t1 = Task.Run <IErrorsInfo>(() => { return(Outds.UpdateEntity(item, InData)); });
                    t1.Wait();
                    DMEEditor.ErrorObject = t1.Result;
                    ((BackgroundWorker)sender).ReportProgress(cur);
                    if (BackgroundWorker.CancellationPending)
                    {
                        break;
                    }
                }

                //--------------------------------------------------
                e.Result = ErrorObject;
            };
            BackgroundWorker.RunWorkerCompleted += (sender, eventArgs) =>
            {
                // do something on the UI thread, like
                // update status or display "result"
                IDataWorkFlowEventArgs passedArgs = new IDataWorkFlowEventArgs();
                ObjectItem             item       = new ObjectItem();
                item.obj  = eventArgs;
                item.Name = "backgroundworkerended";
                passedArgs.Objects.Add(item);

                WorkFlowStepEnded?.Invoke(this, passedArgs);
                DMEEditor.AddLogMessage("End of Copy Entity Action ", "Success in Coping entity " + cur + " out of " + tot, DateTime.Now, tot, "", Errors.Ok);
                DMEEditor.AddLogMessage("Copy Entity Action ", "Success in Coping entity " + cur + " out of " + tot, DateTime.Now, tot, "", Errors.Ok);
            };
            BackgroundWorker.RunWorkerAsync();

            return(ErrorObject);
        }