BExIS.Dlm.Services.Data.DatasetManager.GetDatasetVersion C# (CSharp) Method

GetDatasetVersion() public method

Returns the dataset version specified by the version identifier versionId. If the requested version is the latest but the dataset is checked-out an exception is thrown.
The method throws an exception in the following cases: /// /// The provided version is is greater than the latest version identifier /// The provided version identifier is not associated with any version. /// The identifier is pointing to a version, but the version is not associated to any dataset (orphan version). /// The version is associated to a dataset which is marked as deleted. /// The identifier is pointing to a working copy, which means the dataset is checked out and the identifier is pointing to the latest (not committed working copy). /// ///
public GetDatasetVersion ( System.Int64 versionId ) : DatasetVersion
versionId System.Int64 The identifier of the dataset version requested.
return BExIS.Dlm.Entities.Data.DatasetVersion
        public DatasetVersion GetDatasetVersion(Int64 versionId)
        {
            /// check whether the version id is in fact the latest? the latest checked in version should be returned. if dataset is checked out, the latest stored version is hidden yet.
            /// If the dataset is marked as deleted its like that it is not there at all
            /// get the latest version from the Versions property, or run a direct query on the db
            /// get the latest version by querying Tuples table for records with version <= latest version

            // the requested version is earlier than the latest regardless of check-in/ out status or its the latest version and the dataset is checked in.
            DatasetVersion dsVersion = DatasetVersionRepo.Query(p =>
                                        p.Id == versionId
                                        && (
                                                    (p.Dataset.Status == DatasetStatus.CheckedIn && p.Status == DatasetVersionStatus.CheckedIn)
                                                || (p.Dataset.Status != DatasetStatus.Deleted && p.Status == DatasetVersionStatus.Old)
                                            )
                                        )
                                      .FirstOrDefault();
            if (dsVersion != null)
                return (dsVersion);

            // else there is a problem, try to find and report it
            Dataset dataset = DatasetVersionRepo.Get(versionId).Dataset; // it would be nice to not fetch the dataset!

            if (dataset.Status == DatasetStatus.Deleted)
                throw new Exception(string.Format("Dataset version {0} is not associated with any dataset.", versionId));
            if (dataset.Status == DatasetStatus.Deleted)
                throw new Exception(string.Format("Dataset {0} is deleted", dataset.Id));
            Int64 latestVersionId = dataset.Versions.Where(p => p.Status == DatasetVersionStatus.CheckedIn).Select(p => p.Id).First();// .OrderByDescending(t => t.Timestamp).First().Id;
            if (versionId > latestVersionId)
                throw new Exception(string.Format("Invalid version id. The version id {0} is greater than the latest version number!", versionId));

            if (latestVersionId.Equals(versionId) && dataset.Status == DatasetStatus.CheckedOut) // its a request for the working copy which is hidden
                throw new Exception(string.Format("Invalid version is requested. The version {0} points to the working copy!", versionId));
            return null;
        }

Usage Example

示例#1
0
 private void getEffectiveTuples(Int64 versionId)
 {
     DatasetManager dm = new DatasetManager();
     DatasetVersion workingCopy = dm.GetDatasetVersion(versionId);
     var changed = dm.GetDatasetVersionEffectiveTuples(workingCopy);
 }
All Usage Examples Of BExIS.Dlm.Services.Data.DatasetManager::GetDatasetVersion