BExIS.Dlm.Services.Data.DatasetManager.undoCheckout C# (CSharp) Метод

undoCheckout() приватный Метод

Undo checkout, removes the checked out version of specified dataset and compensates all the tuples deleted, changed or created from the last check-in. It does not check-in the dataset meaning the caller should CheckInDataset after calling Undo
private undoCheckout ( System.Int64 datasetId, string username, bool adminMode, bool commit = true ) : void
datasetId System.Int64
username string
adminMode bool
commit bool in some cases, rollback is called on a set of datasets. In these cases its better to not commit at each rollback, but at the end
Результат void
        private void undoCheckout(Int64 datasetId, string username, bool adminMode, bool commit = true)
        {
            // maybe its required to pass the caller's repo in order to the rollback changes to be visible to the caller function and be able to commit them
            // bring back the historical tuples. recover deleted ones/ editedVersion ones. throw away created ones.
            // remove the version after the processes are finished
            // take the dataset back to the checked in state
            // check for admin mode
            DateTime timestamp = DateTime.UtcNow;

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Dataset> repo = uow.GetRepository<Dataset>();
                Dataset ds = null;
                if (adminMode)
                    ds = repo.Get(p => p.Id == datasetId && p.Status == DatasetStatus.CheckedOut).FirstOrDefault();
                else
                    ds = repo.Get(p => p.Id == datasetId && p.Status == DatasetStatus.CheckedOut && p.CheckOutUser.Equals(getUserIdentifier(username))).FirstOrDefault();

                if (ds != null)
                {
                    if (ds.Versions.Count() > 0)
                    {
                        //remove the version from the dataset, it should cause the version to be removed.
                        DatasetVersion dsv = ds.Versions.OrderByDescending(t => t.Timestamp).First(p => p.Status == DatasetVersionStatus.CheckedOut);
                        // handle tuples here
                        undoTupleChanges(dsv);
                        ds.Versions.Remove(dsv);
                    }

                    //// take the dataset back to the checked in status
                    //ds.Status = DatasetStatus.CheckedIn;
                    ////var previous = ds.Versions.OrderByDescending(t => t.Timestamp).FirstOrDefault(p => p.Status == DatasetVersionStatus.CheckedIn);
                    //ds.LastCheckIOTimestamp = timestamp;
                    //ds.CheckOutUser = string.Empty;

                    if (commit)
                    {
                        repo.Put(ds);
                        uow.Commit();
                    }
                }
            }
        }