예제 #1
0
        public void ComputeChanges_SetsAllEntriesToUnmodified()
        {
            //Arrange
            ChangeTracker ct    = new ChangeTracker();
            var           phot  = GetPhotographer();
            var           phot2 = GetPhotographer();
            var           phot3 = GetPhotographer();
            var           phot4 = GetPhotographer();

            ct.Insert(phot);
            ct.Track(phot2);
            ct.Track(phot3);
            ct.Insert(phot4);
            ct.Delete(phot2);
            phot3.Name = "OtherName";

            //Act
            var changes = ct.DetectChanges();

            ct.ComputeChanges();
            var changes2 = ct.DetectChanges();

            //Assert
            Assert.Equal(4, changes.Count);
            Assert.Empty(changes2);

            //Cleanup
            ct.Clear();
        }
예제 #2
0
파일: FViewer.cs 프로젝트: damieng/naps2
        private async Task DeleteCurrentImage()
        {
            // Need to dispose the bitmap first to avoid file access issues
            tiffViewer1.Image?.Dispose();
            // Actually delete the image
            ImageList.Delete(Enumerable.Range(ImageIndex, 1));
            // Update FDesktop in the background
            DeleteCallback();

            if (ImageList.Images.Any())
            {
                changeTracker.Made();
                // Update the GUI for the newly displayed image
                if (ImageIndex >= ImageList.Images.Count)
                {
                    await GoTo(ImageList.Images.Count - 1);
                }
                else
                {
                    await UpdateImage();
                }
                lblPageTotal.Text = string.Format(MiscResources.OfN, ImageList.Images.Count);
            }
            else
            {
                changeTracker.Clear();
                // No images left to display, so no point keeping the form open
                Close();
            }
        }
예제 #3
0
        public void Track_DoNotDetectChanges()
        {
            //Arrange
            ChangeTracker ct   = new ChangeTracker();
            var           phot = GetPhotographer();

            //Act
            ct.Track(phot);
            var changes = ct.DetectChanges();

            //Assert
            Assert.Empty(changes);

            //Cleanup
            ct.Clear();
        }
예제 #4
0
        public void Insert_DetectsChangesAsAdded()
        {
            //Arrange
            ChangeTracker ct   = new ChangeTracker();
            var           phot = GetPhotographer();

            //Act
            ct.Insert(phot);
            var changes = ct.DetectChanges();

            //Assert
            Assert.Single(changes);
            Assert.Equal(ChangeTrackerEntry.States.Added, changes[0].State);

            //Cleanup
            ct.Clear();
        }
예제 #5
0
        public void Dispose()
        {
            if (!IsDisposed)
            {
                IsDisposed = true;

                ChangeTracker.Clear();
                ChangeTracker = null;
                TypesManager  = null;
                EntityManager = null;
                Interceptors.Clear();
                Interceptors   = null;
                ObjectWalker   = null;
                ProxyGenerator = null;

                Runner.Dispose();
            }
        }
예제 #6
0
        public void ChangeTracker_BaseCollection( )
        {
            var baseCollection = new List <string>
            {
                "a",
                "b",
                "c"
            };

            var tracker = new ChangeTracker <string>(baseCollection)
            {
                "a",
                "b",
                "c"
            };

            Assert.AreEqual(6, tracker.Count, "Invalid count.");
            Assert.IsTrue(tracker.Contains("a"), "Invalid contents.");
            Assert.IsTrue(tracker.Contains("b"), "Invalid contents.");
            Assert.IsTrue(tracker.Contains("c"), "Invalid contents.");

            tracker.Remove("a");

            Assert.AreEqual(5, tracker.Count, "Invalid count.");
            Assert.IsTrue(tracker.Contains("a"), "Invalid contents.");
            Assert.IsTrue(tracker.Contains("b"), "Invalid contents.");
            Assert.IsTrue(tracker.Contains("c"), "Invalid contents.");

            tracker.Add("a");

            Assert.AreEqual(6, tracker.Count, "Invalid count.");
            Assert.IsTrue(tracker.Contains("a"), "Invalid contents.");
            Assert.IsTrue(tracker.Contains("b"), "Invalid contents.");
            Assert.IsTrue(tracker.Contains("c"), "Invalid contents.");

            tracker.Clear( );

            Assert.AreEqual(0, tracker.Count, "Invalid count.");
            Assert.AreEqual(0, tracker.Added.Count( ), "Invalid Added count.");
            Assert.IsTrue(tracker.Removed.Contains("a"), "Invalid contents.");
            Assert.IsTrue(tracker.Removed.Contains("b"), "Invalid contents.");
            Assert.IsTrue(tracker.Removed.Contains("c"), "Invalid contents.");
        }
예제 #7
0
        public void Update_DetectsChangesAsModified()
        {
            //Arrange
            ChangeTracker ct   = new ChangeTracker();
            var           phot = GetPhotographer();

            ct.Insert(phot);
            ct.DetectChanges();
            ct.ComputeChanges();

            //Act
            phot.Name = "OtherName";
            var changes = ct.DetectChanges();

            //Assert
            Assert.Single(changes);
            Assert.Equal(ChangeTrackerEntry.States.Modified, changes[0].State);

            //Cleanup
            ct.Clear();
        }
 public void Clear()
 {
     ChangeTracker.Clear();
     SubEntityStaging.Clear();
 }
예제 #9
0
        private void FComment_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (closed)
            {
                return;
            }

            if (operationProgress.ActiveOperations.Any())
            {
                if (e.CloseReason == CloseReason.UserClosing)
                {
                    if (operationProgress.ActiveOperations.Any(x => !x.SkipExitPrompt))
                    {
                        var result = MessageBox.Show($"Do you want to exit with active operations?", $"Active Operations",
                                                     MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                        if (result != DialogResult.Yes)
                        {
                            e.Cancel = true;
                        }
                    }
                }
                else
                {
                }
            }
            else if (changeTracker.HasUnsavedChanges)
            {
                if (e.CloseReason == CloseReason.UserClosing)
                {
                    var result = MessageBox.Show($"Do you want to exit with unsaved changes?", $"Unsaved changes",
                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                    if (result == DialogResult.Yes)
                    {
                        changeTracker.Clear();
                    }
                    else
                    {
                        e.Cancel = true;
                    }
                }
            }

            if (!e.Cancel && operationProgress.ActiveOperations.Any())
            {
                operationProgress.ActiveOperations.ForEach(op => op.Cancel());
                e.Cancel = true;
                Hide();
                ShowInTaskbar = false;
                Task.Factory.StartNew(() =>
                {
                    var timeoutCts = new CancellationTokenSource();
                    timeoutCts.CancelAfter(TimeSpan.FromSeconds(60));
                    try
                    {
                        operationProgress.ActiveOperations.ForEach(op => op.Wait(timeoutCts.Token));
                    }
                    catch (OperationCanceledException)
                    {
                    }
                    closed = true;
                    SafeInvoke(Close);
                });
            }
        }
예제 #10
0
        public void SaveChanges()
        {
            try
            {
                IEnumerable <EntityChangeDescriptor> temp = ChangeTracker.GetChangeLog();

                List <Tuple <IOgmEntity, IEnumerable <string> > > creatingNodes = temp
                                                                                  .Where(p => p is EntityChangeNodeCreation)
                                                                                  .Select(p => new Tuple <IOgmEntity, IEnumerable <string> >(
                                                                                              p.Entity,
                                                                                              TypesManager.KnownTypes.ContainsKey(p.Entity.GetType()) ? TypesManager.KnownTypes[p.Entity.GetType()].IgnoredProperties.Select(q => q.Name) : null
                                                                                              )).ToList();

                List <IOgmEntity> deletingNodes = temp
                                                  .Where(p => p is EntityChangeNodeDeletion)
                                                  .Select(p => p.Entity).ToList();

                List <Tuple <IOgmEntity, IEnumerable <string> > > updatingNodes = temp
                                                                                  .Where(p => p is EntityChangeNodeUpdate)
                                                                                  .GroupBy(p => p.Entity)
                                                                                  .Select(p => new Tuple <IOgmEntity, IEnumerable <string> >(
                                                                                              p.Key,
                                                                                              p.Key.GetType().GetProperties().Select(q => q.Name).Except(p.Select(q => ((EntityChangeNodeUpdate)q).Property.Name))
                                                                                              .Union(
                                                                                                  TypesManager.KnownTypes.ContainsKey(p.Key.GetType()) ? TypesManager.KnownTypes[p.Key.GetType()].IgnoredProperties.Select(q => q.Name) : new string[0]
                                                                                                  )
                                                                                              )).ToList();

                List <Tuple <IOgmConnection, IEnumerable <string> > > creatingRels = temp
                                                                                     .Where(p => p is EntityChangeRelCreation)
                                                                                     .Select(p => new Tuple <IOgmConnection, IEnumerable <string> >(
                                                                                                 p.Entity as IOgmConnection,
                                                                                                 TypesManager.KnownTypes.ContainsKey(p.Entity.GetType()) ? TypesManager.KnownTypes[p.Entity.GetType()].IgnoredProperties.Select(q => q.Name) : null
                                                                                                 )).ToList();

                List <IOgmConnection> deletingRels = temp
                                                     .Where(p => p is EntityChangeRelDeletion)
                                                     .Select(p => p.Entity as IOgmConnection).ToList();

                List <Tuple <IOgmConnection, IEnumerable <string> > > updatingRels = temp
                                                                                     .Where(p => p is EntityChangeRelUpdate)
                                                                                     .GroupBy(p => p.Entity)
                                                                                     .Select(p => new Tuple <IOgmConnection, IEnumerable <string> >(
                                                                                                 p.Key as IOgmConnection,
                                                                                                 p.Key.GetType().GetProperties().Select(q => q.Name).Except(p.Select(q => ((EntityChangeRelUpdate)q).Property.Name))
                                                                                                 .Union(
                                                                                                     TypesManager.KnownTypes.ContainsKey(p.Key.GetType()) ? TypesManager.KnownTypes[p.Key.GetType()].IgnoredProperties.Select(q => q.Name) : new string[0]
                                                                                                     )
                                                                                                 )).ToList();

                List <Tuple <IOgmConnection, IEnumerable <string> > > mergingRels = temp
                                                                                    .Where(p => p is EntityChangeConnectionMerge)
                                                                                    .Select(p => new Tuple <IOgmConnection, IEnumerable <string> >(
                                                                                                p.Entity as IOgmConnection,
                                                                                                TypesManager.KnownTypes.ContainsKey(p.Entity.GetType()) ? TypesManager.KnownTypes[p.Entity.GetType()].IgnoredProperties.Select(q => q.Name) : null
                                                                                                )).ToList();

                List <IOgmEntity> createdNodes = EntityManager.CreateNodes(Runner, creatingNodes)?.ToList();
                EntityManager.UpdateNodes(Runner, updatingNodes);
                EntityManager.DeleteNodes(Runner, deletingNodes);

                for (int i = 0; i < (createdNodes?.Count ?? 0); i++)
                {
                    creatingNodes[i].Item1.EntityId = createdNodes[i].EntityId;
                }

                List <IOgmConnection> createdRels = EntityManager.CreateRels(Runner, creatingRels)?.ToList();

                List <IOgmConnection> mergedRels = EntityManager.MergeConnections(Runner, mergingRels)?.ToList();

                EntityManager.UpdateRels(Runner, updatingRels);
                EntityManager.DeleteRels(Runner, deletingRels);

                for (int i = 0; i < (createdRels?.Count ?? 0); i++)
                {
                    creatingRels[i].Item1.EntityId = createdRels[i].EntityId;
                }
                for (int i = 0; i < (mergedRels?.Count ?? 0); i++)
                {
                    mergingRels[i].Item1.EntityId = mergedRels[i].EntityId;
                }

                ChangeTracker.Clear();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public void IterationSetup()
 {
     _dbContext !.ChangeTracker.Clear();
 }
예제 #12
0
 public void ClearChangeTracker()
 {
     ChangeTracker.Clear();
 }