Exemple #1
0
 void m_changeGroups_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
     {
         foreach (var v in e.NewItems)
         {
             DualChangeGroupViewModel changeGroup = v as DualChangeGroupViewModel;
             if (changeGroup.ChangeGroupHeight > MaxHeight)
             {
                 MaxHeight = changeGroup.ChangeGroupHeight;
             }
         }
     }
 }
Exemple #2
0
        void m_worker_DoWork(object sender, DoWorkEventArgs e)
        {
            // migration instruction status
            int analysisMIStatus            = (int)ChangeStatus.AnalysisMigrationInstruction;
            int pendingStatus               = (int)ChangeStatus.Pending;
            int inProgressStatus            = (int)ChangeStatus.InProgress;
            int pendingConflictDetectStatus = (int)ChangeStatus.PendingConflictDetection;
            int completedStatus             = (int)ChangeStatus.Complete;

            RaisePropertyChangedEvent("CanGetNext", null, null);
            int numToTake = (int)e.Argument;

            m_worker.ReportProgress(-1);

            long lastChangeGroupTaken;

            if (numToTake > 0)
            {
                lastChangeGroupTaken = ChangeGroups.Select(x => x.MigrationInstructions.Id).LastOrDefault();
            }
            else
            {
                lastChangeGroupTaken = ChangeGroups.Select(x => x.MigrationInstructions.Id).FirstOrDefault();
            }

            IQueryable <RTChangeGroup> migrationInstructionsQuery;

            if (lastChangeGroupTaken == 0) // haven't gotten anything yet
            {
                long pendingChangeGroup = (from cg in m_context.RTChangeGroupSet
                                           where cg.SourceUniqueId.Equals(m_oneWaySession.Target.UniqueId) &&
                                           cg.SessionUniqueId.Equals(m_oneWaySession.Session.SessionUniqueId) &&
                                           (cg.Status == (int)ChangeStatus.Pending || cg.Status == (int)ChangeStatus.InProgress) &&
                                           !cg.ContainsBackloggedAction
                                           orderby cg.Id ascending
                                           select cg.Id).FirstOrDefault();
                int lastSessionRunId = 0;
                if (pendingChangeGroup == 0)
                {
                    lastSessionRunId = (from cg in m_context.RTChangeGroupSet
                                        where cg.SourceUniqueId.Equals(m_oneWaySession.Target.UniqueId) &&
                                        cg.SessionUniqueId.Equals(m_oneWaySession.Session.SessionUniqueId) &&
                                        (cg.Status == (int)ChangeStatus.Pending || cg.Status == (int)ChangeStatus.InProgress) &&
                                        !cg.ContainsBackloggedAction
                                        select cg.SessionRun.Id).FirstOrDefault();

                    if (lastSessionRunId == 0)
                    {
                        var lastSessionRunQuery = (from cg in m_context.RTChangeGroupSet
                                                   where cg.SessionUniqueId.Equals(m_oneWaySession.Session.SessionUniqueId) &&
                                                   cg.SourceUniqueId.Equals(m_oneWaySession.Source.UniqueId)
                                                   orderby cg.SessionRun.Id descending
                                                   select cg.SessionRun.Id).Take(Math.Abs(numToTake));
                        if (lastSessionRunQuery.Count() != 0)
                        {
                            lastSessionRunId = lastSessionRunQuery.Min();
                        }
                    }
                }

                migrationInstructionsQuery = from cg in m_context.RTChangeGroupSet
                                             where cg.SourceUniqueId.Equals(m_oneWaySession.Target.UniqueId) &&
                                             cg.SessionUniqueId.Equals(m_oneWaySession.Session.SessionUniqueId) &&
                                             (cg.Status == analysisMIStatus || cg.Status == pendingStatus ||
                                              cg.Status == inProgressStatus || cg.Status == pendingConflictDetectStatus ||
                                              cg.Status == completedStatus) &&
                                             cg.Id >= pendingChangeGroup &&
                                             cg.SessionRun.Id >= lastSessionRunId
                                             select cg;
            }
            else if (numToTake > 0)
            {
                migrationInstructionsQuery = from cg in m_context.RTChangeGroupSet
                                             where cg.SourceUniqueId.Equals(m_oneWaySession.Target.UniqueId) &&
                                             cg.SessionUniqueId.Equals(m_oneWaySession.Session.SessionUniqueId) &&
                                             (cg.Status == analysisMIStatus || cg.Status == pendingStatus ||
                                              cg.Status == inProgressStatus || cg.Status == pendingConflictDetectStatus ||
                                              cg.Status == completedStatus) &&
                                             cg.Id > lastChangeGroupTaken
                                             orderby cg.Id ascending
                                             select cg;
            }
            else
            {
                migrationInstructionsQuery = from cg in m_context.RTChangeGroupSet
                                             where cg.SourceUniqueId.Equals(m_oneWaySession.Target.UniqueId) &&
                                             cg.SessionUniqueId.Equals(m_oneWaySession.Session.SessionUniqueId) &&
                                             (cg.Status == analysisMIStatus || cg.Status == pendingStatus ||
                                              cg.Status == inProgressStatus || cg.Status == pendingConflictDetectStatus ||
                                              cg.Status == completedStatus) &&
                                             cg.Id < lastChangeGroupTaken
                                             orderby cg.Id descending
                                             select cg;
            }

            int migrationInstructionsCount = migrationInstructionsQuery.Count();

            var migrationInstructionsSubset = migrationInstructionsQuery.Take(Math.Abs(numToTake));

            int total;

            if (migrationInstructionsCount < Math.Abs(numToTake))
            {
                total    = migrationInstructionsCount;
                e.Result = false; // do not refresh afterwards
            }
            else
            {
                total    = numToTake;
                e.Result = true; // try to refresh afterwards
            }

            if (numToTake > 0)
            {
                // dt means deltaTables
                var pairs = from mi in migrationInstructionsSubset
                            join dt in m_context.RTChangeGroupSet
                            on mi.ReflectedChangeGroupId equals dt.Id
                            join ca in m_context.RTChangeActionSet
                            on dt.Id equals ca.ChangeGroupId into j
                            orderby dt.Id ascending
                            select new
                {
                    Left  = dt,
                    Right = mi,
                    Count = j.Count()
                };

                int currentProgress = 0;
                int counter         = 0;
                foreach (var entry in pairs)
                {
                    DualChangeGroupViewModel changeGroup = new DualChangeGroupViewModel(entry.Left, entry.Right, entry.Count);
                    if (changeGroup.Bucket > maxBucket)
                    {
                        maxBucket = changeGroup.Bucket;
                        if (ChangeGroups.Count == 0)
                        {
                            minBucket = maxBucket;
                        }
                        else
                        {
                            if (counter > 10)
                            {
                                changeGroup.IsMilestone = true;
                                counter = 0;
                            }
                        }
                    }
                    counter++;
                    m_dispatcher.BeginInvoke(new UpdateProgressDelegate(delegate { ChangeGroups.AddLast(changeGroup); }), changeGroup);
                    currentProgress++;
                    m_worker.ReportProgress((int)((double)currentProgress / (double)total * 100));
                }
            }
            else
            {
                // dt means deltaTables
                var pairs = from mi in migrationInstructionsSubset
                            join dt in m_context.RTChangeGroupSet
                            on mi.ReflectedChangeGroupId equals dt.Id
                            join ca in m_context.RTChangeActionSet
                            on dt.Id equals ca.ChangeGroupId into j
                            orderby dt.Id descending
                            select new
                {
                    Left  = dt,
                    Right = mi,
                    Count = j.Count()
                };

                int currentProgress = 0;
                DualChangeGroupViewModel lastChangeGroup = null;
                int counter = 0;
                foreach (var entry in pairs)
                {
                    DualChangeGroupViewModel changeGroup = new DualChangeGroupViewModel(entry.Left, entry.Right, entry.Count);
                    if (changeGroup.Bucket != 0 && changeGroup.Bucket < minBucket)
                    {
                        minBucket = changeGroup.Bucket;
                        if (lastChangeGroup != null)
                        {
                            if (counter > 10)
                            {
                                lastChangeGroup.IsMilestone = true;
                                counter = 0;
                            }
                        }
                    }
                    counter++;
                    m_dispatcher.BeginInvoke(new UpdateProgressDelegate(delegate { ChangeGroups.AddFirst(changeGroup); }), changeGroup);
                    currentProgress++;
                    m_worker.ReportProgress((int)((double)currentProgress / (double)total * 100));

                    lastChangeGroup = changeGroup;
                }
            }
            m_worker.ReportProgress(100);
        }