Exemplo n.º 1
0
        public static void MakeMergeTables(
            DAL master,
            IEnumerable <MergeTableCommandBuilder> commandBuilders,
            CancellationToken cancellation,
            IProgress <int> progress,
            IMergeLog log)
        {
            log?.StartJob();
            var unitsOfWork = commandBuilders.Count();

            master.BeginTransaction();
            try
            {
                var i = 0;
                foreach (MergeTableCommandBuilder cmdBldr in commandBuilders)
                {
                    log?.PostStatus("Create " + cmdBldr.MergeTableName);

                    master.Execute("DROP TABLE IF EXISTS " + cmdBldr.MergeTableName + ";");
                    master.Execute(cmdBldr.MakeMergeTableCommand);
                    progress?.Report((++i * 100) / unitsOfWork);
                }

                master.CommitTransaction();
            }
            catch
            {
                master.RollbackTransaction();
                throw;
            }
        }
Exemplo n.º 2
0
 public static void StartJob(this IMergeLog @this, [CallerMemberName] string name = "")
 {
     //if (_stopwatch != null) { _stopwatch.Stop(); }
     //_stopwatch = Stopwatch.StartNew();
     @this.PostStatus("Starting " + name);
     Debug.WriteLine("Started job component " + name);
 }
Exemplo n.º 3
0
        public static void ProcessMergeTable(DAL master,
                                             MergeTableCommandBuilder commandBuider,
                                             IEnumerable <ComponentFile> components,
                                             IMergeLog log)
        {
            log?.PostStatus("Processing " + commandBuider.MergeTableName);

            //run various comparisons
            ProcessComparisons(master, commandBuider);

            //ProcessInvalidMatchs(mergeDB, commandBuider);
            ProcessFullMatchs(master, commandBuider);
            SetPartialMatches(master, commandBuider);

            IdentifySiblingRecords(master, commandBuider);
            FindNaturalSiblingMatches(master, commandBuider);

            if (commandBuider.HasRowVersion)
            {
                SetMasterRowVersion(master, commandBuider);//master row version is used to determine which file has the changes in the case where the master can update the component.
            }

            if (commandBuider.MergeNewFromMaster)
            {
                ProcessMasterNew(master, commandBuider, components);//add merge records for records that are new on the master side
            }
        }
Exemplo n.º 4
0
        public static void ProcessMergeTables(DAL master,
                                              IEnumerable <ComponentFile> components,
                                              IEnumerable <MergeTableCommandBuilder> commandBuilders,
                                              CancellationToken cancellation,
                                              IProgress <int> progress,
                                              IMergeLog log)
        {
            log?.StartJob();
            master.BeginTransaction();
            try
            {
                foreach (MergeTableCommandBuilder cmdBldr in commandBuilders)
                {
                    cancellation.ThrowIfCancellationRequested();
                    ProcessMergeTable(master, cmdBldr, components, log);
                }

                master.CommitTransaction();
                log?.EndJob();
            }
            catch
            {
                master.RollbackTransaction();
                throw;
            }
        }
Exemplo n.º 5
0
 public static void EndJob(this IMergeLog @this, [CallerMemberName] string name = "")
 {
     //if (_stopwatch != null)
     //{
     //    _stopwatch.Stop();
     //    Debug.WriteLine("Ended job component " + _currentJobName + " in " + _stopwatch.ElapsedMilliseconds + "mSec");
     //}
     @this.PostStatus(name + ": done");
 }
Exemplo n.º 6
0
 public static Task DoWorkAsync(
     DAL master,
     IEnumerable <ComponentFile> components,
     IEnumerable <MergeTableCommandBuilder> commandBuilders,
     CancellationToken cancellation,
     IProgress <int> progress,
     IMergeLog log)
 {
     return(Task.Run(() => DoWork(master, components, commandBuilders, cancellation, progress, log)));
 }
Exemplo n.º 7
0
        public static void DoWork(
            DAL master,
            IEnumerable <ComponentFile> components,
            IEnumerable <MergeTableCommandBuilder> commandBuilders,
            CancellationToken cancellation,
            IProgress <int> progress,
            IMergeLog log)
        {
            ExecuteMaintenanceScript(new AssignGuidsScript(), (DAL)null, components, log);
            ExecuteMaintenanceScript(new ConsolidateCountTreeScript(), master, components, log);

            MakeMergeTables(master, commandBuilders, cancellation, progress, log);
            PopulateMergeTables(master, components, commandBuilders, cancellation, progress, log);
            ProcessMergeTables(master, components, commandBuilders, cancellation, progress, log);
        }
Exemplo n.º 8
0
        public static void PopulateMergeTables(
            DAL master,
            IEnumerable <ComponentFile> components,
            IEnumerable <MergeTableCommandBuilder> commandBuilders,
            CancellationToken cancellation,
            IProgress <int> progress,
            IMergeLog log)
        {
            log?.StartJob();

            foreach (var comp in components)
            {
                PopulateMergeTables(master, comp, commandBuilders, cancellation, progress, log);
            }
            log?.EndJob();
        }
Exemplo n.º 9
0
        public static void PopulateMergeTables(
            DAL master,
            ComponentFile comp,
            IEnumerable <MergeTableCommandBuilder> commandBuilders,
            CancellationToken cancellation,
            IProgress <int> progress,
            IMergeLog log)
        {
            var compNumber = comp.Component_CN;

            master.AttachDB(comp.Database, COMP_ALIAS); //may throw exception
            master.BeginTransaction();
            try
            {
                var unitsOfWork = commandBuilders.Count();
                var i           = 0;
                foreach (var cmdBldr in commandBuilders)
                {
                    cancellation.ThrowIfCancellationRequested();

                    var comp_CN = (int)comp.Component_CN.Value;

                    master.Execute(cmdBldr.GetPopulateMergeTableCommand(comp_CN));
                    master.Execute(cmdBldr.GetPopulateDeletedRecordsCommand(comp_CN));
                    progress?.Report((++i * 100) / unitsOfWork);
                }

                master.CommitTransaction();
                log?.PostStatus("Imported Merge Info For Component #" + compNumber);
            }
            catch
            {
                master.RollbackTransaction();
                throw;
            }
            finally
            {
                master.DetachDB(COMP_ALIAS);
            }
        }
Exemplo n.º 10
0
 private static void ExecuteMaintenanceScript(
     ISimpleSQLScript maintenanceScript,
     DAL master,
     IEnumerable <ComponentFile> components,
     IMergeLog log)
 {
     if (master != null && maintenanceScript.CheckCanExecute(master))
     {
         log?.PostStatus($"Applying {maintenanceScript.Name} To Master");
         maintenanceScript.Execute(master);
     }
     if (components != null)
     {
         foreach (var comp in components)
         {
             if (maintenanceScript.CheckCanExecute(comp.Database))
             {
                 log?.PostStatus($"Applying {maintenanceScript.Name} Fix To " + comp.FileName);
                 maintenanceScript.Execute(comp.Database);
             }
         }
     }
 }