Ejemplo n.º 1
0
 /// <summary>
 /// Add an executable unit to the execution plan
 /// </summary>
 /// <param name="unit">Executable unit</param>
 /// <param name="slot">The slot where the unit is placed</param>
 public void AddUnit(ExecutionUnit unit, int slot)
 {
     if (!this.slots.ContainsKey(slot))
     {
         this.slots.Add(slot, new List <ExecutionUnit>());
     }
     this.slots[slot].Add(unit);
 }
Ejemplo n.º 2
0
        public ExecutionPlan GetExecutionPlan(IEnumerable <IExecutable> executables, IEnumerable <Table> tables)
        {
            this.tables = tables;
            var plan = new ExecutionPlan();

            executables = ExecutionPlan.RemoveDataProvidersIfSchema(executables);
            var sortedExecutables = DependencyGraph.TopologicalSort(executables);
            var passes            = DependencyGraph.CreatePasses(sortedExecutables);
            int slot = 0;

            foreach (var pass in passes)
            {
                //Add all schema executables to the current slot
                foreach (var e in pass.Where(e => e.IsSchema() || e.IsSQLRule()))
                {
                    ExecutionUnit unit = new ExecutionUnit(e);
                    plan.AddUnit(unit, slot);
                }

                var dataExes = pass.Where(e => e.IsData()).ToList();
                foreach (var table in tables)
                {
                    foreach (var dataE in dataExes)
                    {
                        if (((IDataExecutable)dataE).SkipTable(table) == false)
                        {
                            plan.AddUnit(new ExecutionUnit(dataE, table), slot);
                        }
                    }
                    slot++;
                }
                //Add finalizers
                dataExes.ForEach(e => plan.AddUnit(new ExecutionUnit(e)
                {
                    Finalize = true
                }, slot));
                if (plan[slot] != null)
                {
                    slot++;
                }
            }

            return(plan);
        }
Ejemplo n.º 3
0
        public ExecutionPlan GetExecutionPlan(IEnumerable <IExecutable> executables, IEnumerable <Table> tables)
        {
            var plan = new ExecutionPlan();

            executables = ExecutionPlan.RemoveDataProvidersIfSchema(executables);
            var executablesSorted = DependencyGraph.TopologicalSort(executables);
            var passes            = DependencyGraph.CreatePasses(executablesSorted);

            int slot = 0;

            foreach (Pass pass in passes)
            {
                foreach (var executable in pass)
                {
                    if (executable.IsSchema())
                    {
                        plan.AddUnit(new ExecutionUnit(executable), slot);
                    }
                    else
                    {
                        foreach (var table in tables)
                        {
                            if (((IDataExecutable)executable).SkipTable(table))
                            {
                                continue;
                            }
                            var unit = new ExecutionUnit(executable, table);
                            plan.AddUnit(unit, slot);
                        }
                    }
                }
                slot++;
                //Finalize all data executables in the previous slot
                pass.Where(e => e.IsData()).ToList().ForEach(e => plan.AddUnit(new ExecutionUnit(e)
                {
                    Finalize = true
                }, slot));
                slot++;
            }

            return(plan);
        }
Ejemplo n.º 4
0
        private void runExecutable(Object executableObject)
        {
            ExecutionUnit unit       = (ExecutionUnit)executableObject;
            var           executable = unit.Executable;

            if (unit.Finalize)
            {
                ((IDataExecutable)executable).Finalize(this.database, this.providerCollection);
                if (executable.IsProvider())
                {
                    this.providerCollection.AddProvider((IProvider)executable);
                }
                return;
            }

            if (executable.IsData() && unit.Table != null && unit.Table != this.currentTable)
            {
                this.currentTable = unit.Table;
                CurrentTableChanged(unit.Table);
                //Console.WriteLine("Finished: " + unit.Table.TableName);
            }

            var table = (DataTable)unit.Table;

            Stopwatch clock = new Stopwatch();

            clock.Start();
            FinishedStatus finishedStatus;

            //Execute (executables have different execute signatures)
#if !DEBUG
            try
            {
#endif
            if (executable.IsSchemaRule())
            {
                ISchemaRule rule = (ISchemaRule)executable;
                rule.Execute(this.database, this.issueCollector, this.providerCollection);
            }
            else if (executable.IsSQLRule())
            {
                SQLRule rule = (SQLRule)executable;
                rule.Execute(this.database, this.issueCollector);
            }
            else if (executable.IsDataRule())
            {
                IDataRule rule = (IDataRule)executable;
                rule.Execute(table, this.issueCollector, this.providerCollection);
            }
            else if (executable.IsSchemaProvider())
            {
                ISchemaProvider prov = (ISchemaProvider)executable;
                prov.Execute(this.database, this.providerCollection);
            }
            else if (executable.IsDataProvider())
            {
                IDataProvider prov = (IDataProvider)executable;
                prov.Execute(table, this.providerCollection);
            }

            if (executable is IProvider && executable.IsSchema())
            {
                this.providerCollection.AddProvider((IProvider)executable);
            }

            finishedStatus = FinishedStatus.Success;
#if !DEBUG
        }

        catch (Exception e)
        {
            Console.WriteLine(e.StackTrace);
            finishedStatus = FinishedStatus.Failed;
        }
#endif

            clock.Stop();
            executionSummaryLock.EnterWriteLock();
            if (executable.IsSchemaRule() || executable.IsSQLRule())
            {
                var         issues  = this.issueCollector.GetIssues((IRule)executable);
                RuleSummary summary = new RuleSummary((IRule)executable, issues, finishedStatus, clock.Elapsed);
                this.executionSummary.AddRuleSummary(summary);
            }
            else if (executable.IsDataRule())
            {
                IRule rule   = (IRule)executable;
                var   issues = this.issueCollector.GetIssues(rule);
                var   sum    = executionSummary.GetSummary(rule);
                if (sum == null)
                {
                    sum = new RuleSummary(rule, null, finishedStatus, new TimeSpan());
                    this.executionSummary.AddRuleSummary(sum);
                }
                sum.ExecutionTime.Add(clock.Elapsed);
                sum.Issues = issues;
            }

            int pbefore = this.progressTracker.Progress;
            this.progressTracker.UpdateProgress(executable, table);
            this.ProgressUpdated(this.progressTracker.Progress);
            int pafter = this.progressTracker.Progress;

            //if (pbefore != pafter)
            //    Console.WriteLine(pafter);

            executionSummaryLock.ExitWriteLock();
        }