Esempio n. 1
0
        public IEnumerable <IChange> Update(bool detectDataChanges)
        {
            var changes = new ConcurrentBag <IChange>();

            var progress = new UpdateProgress {
                CurrentOperation = "Structure",
                TotalSteps       = (detectDataChanges ? 2 : 1) * Previous.SheetDefinitions.Count
            };

            var sheetLock = new object();

            Parallel.ForEach(Previous.SheetDefinitions, prevSheetDef =>
            {
                progress.CurrentFile = prevSheetDef.Name;
                _Progress.Report(progress);

                if (!_Updated.SheetExists(prevSheetDef.Name))
                {
                    changes.Add(new SheetRemoved(prevSheetDef.Name));
                    return;
                }

                IRelationalSheet prevSheet, updatedSheet;
                SheetDefinition updatedSheetDef;
                lock (sheetLock)
                {
                    prevSheet       = _Previous.GetSheet(prevSheetDef.Name);
                    updatedSheet    = _Updated.GetSheet(prevSheetDef.Name);
                    updatedSheetDef = Updated.GetOrCreateSheet(prevSheetDef.Name);
                }

                var sheetUpdater = new SheetUpdater(prevSheet, prevSheetDef, updatedSheet, updatedSheetDef);
                var sheetUpdates = MemoryGuard(() => sheetUpdater.Update().ToArray());
                foreach (var change in sheetUpdates)
                {
                    changes.Add(change);
                }

                progress.IncrementStep();
            });

            Updated.Compile();

            if (detectDataChanges)
            {
                progress.CurrentOperation = "Data";

                Parallel.ForEach(Previous.SheetDefinitions, prevSheetDef =>
                {
                    progress.CurrentFile = prevSheetDef.Name;
                    _Progress.Report(progress);

                    if (!_Updated.SheetExists(prevSheetDef.Name))
                    {
                        return;
                    }

                    IRelationalSheet prevSheet, updatedSheet;
                    SheetDefinition updatedSheetDef;
                    lock (sheetLock)
                    {
                        prevSheet       = _Previous.GetSheet(prevSheetDef.Name);
                        updatedSheet    = _Updated.GetSheet(prevSheetDef.Name);
                        updatedSheetDef = Updated.GetOrCreateSheet(prevSheetDef.Name);
                    }

                    var sheetComparer = new SheetComparer(prevSheet, prevSheetDef, updatedSheet, updatedSheetDef);
                    var sheetChanges  = MemoryGuard(() => sheetComparer.Compare().ToArray());
                    foreach (var change in sheetChanges)
                    {
                        changes.Add(change);
                    }

                    progress.IncrementStep();
                });
            }

            progress.CurrentOperation = "Finished";
            progress.CurrentFile      = null;
            _Progress.Report(progress);

            return(changes);
        }
Esempio n. 2
0
        public IEnumerable <IChange> Update(bool detectDataChanges)
        {
            var changes = new List <IChange>();

            var progress = new UpdateProgress {
                CurrentOperation = "Structure",
                CurrentStep      = 0,
                TotalSteps       = (detectDataChanges ? 2 : 1) * Previous.SheetDefinitions.Count
            };

            {
                foreach (var prevSheetDef in Previous.SheetDefinitions)
                {
                    progress.CurrentFile = prevSheetDef.Name;
                    _Progress.Report(progress);

                    if (!_Updated.SheetExists(prevSheetDef.Name))
                    {
                        changes.Add(new SheetRemoved(prevSheetDef.Name));
                        continue;
                    }

                    var prevSheet = _Previous.GetSheet(prevSheetDef.Name);

                    var updatedSheet    = _Updated.GetSheet(prevSheetDef.Name);
                    var updatedSheetDef = Updated.GetOrCreateSheet(prevSheetDef.Name);

                    var sheetUpdater = new SheetUpdater(prevSheet, prevSheetDef, updatedSheet, updatedSheetDef);
                    changes.AddRange(sheetUpdater.Update());

                    GC.Collect();

                    ++progress.CurrentStep;
                }

                Updated.Compile();
            }

            if (detectDataChanges)
            {
                progress.CurrentOperation = "Data";

                foreach (var prevSheetDef in Previous.SheetDefinitions)
                {
                    progress.CurrentFile = prevSheetDef.Name;
                    _Progress.Report(progress);

                    if (!_Updated.SheetExists(prevSheetDef.Name))
                    {
                        continue;
                    }

                    var prevSheet = _Previous.GetSheet(prevSheetDef.Name);

                    var updatedSheet    = _Updated.GetSheet(prevSheetDef.Name);
                    var updatedSheetDef = Updated.GetOrCreateSheet(prevSheetDef.Name);

                    var sheetComparer = new SheetComparer(prevSheet, prevSheetDef, updatedSheet, updatedSheetDef);
                    changes.AddRange(sheetComparer.Compare());

                    GC.Collect();

                    ++progress.CurrentStep;
                }
            }

            progress.CurrentStep      = progress.TotalSteps;
            progress.CurrentOperation = "Finished";
            progress.CurrentFile      = null;
            _Progress.Report(progress);

            return(changes);
        }