コード例 #1
0
        private void DeleteVersionsAndPreserveLastWorking()
        {
            if (VersioningMode != VersioningMode.None)
            {
                throw new NotSupportedException();
            }

            // Remove unnecessary working versions. Preserve the last approved or rejected row
            var lastApprovedOrRejectedVersion = GetLastApprovedOrRejectedVersion();

            ExpectedVersionId = CurrentVersionId;

            List <NodeHead.NodeVersion> irrelevantVersions;

            if (lastApprovedOrRejectedVersion == null)
            {
                irrelevantVersions = new List <NodeHead.NodeVersion>(VersionHistory);
                ExpectedVersion    = ComputeNewVersion();
            }
            else
            {
                if (lastApprovedOrRejectedVersion.VersionId == CurrentVersionId)
                {
                    ExpectedVersionId = 0;
                }
                irrelevantVersions = GetNewerVersions(lastApprovedOrRejectedVersion);
                ExpectedVersion    = GetNextVersion(lastApprovedOrRejectedVersion.VersionNumber, VersionStatus.Pending);
            }

            var irrelevantIds = irrelevantVersions.Select(x => x.VersionId);

            DeletableVersionIds.AddRange(irrelevantIds);
            DeletableVersionIds.Remove(CurrentVersionId); // remove this version
        }
コード例 #2
0
        private void DeleteVersionsAndApprove()
        {
            if (VersioningMode != VersioningMode.None)
            {
                throw new NotSupportedException();
            }

            // Remove unnecessary working versions. Preserve the last public version row
            // 1.0A	1.0A
            // 1.1D	1.1D
            // 2.0A	2.0A <--
            // 2.1D
            // 2.2L <--
            var workings   = GetLastWorkingVersions();
            var workingIds = workings.Select(x => x.VersionId);

            DeletableVersionIds.AddRange(workingIds);

            var lastApproved = GetLastApprovedVersion();

            if (lastApproved != null)
            {
                ExpectedVersion   = lastApproved.VersionNumber.ChangeStatus(VersionStatus.Approved);
                ExpectedVersionId = lastApproved.VersionId;
            }
            else
            {
                DeletableVersionIds.Remove(CurrentVersionId);
                ExpectedVersion   = new VersionNumber(1, 0, VersionStatus.Approved);
                ExpectedVersionId = CurrentVersionId;
            }
        }
コード例 #3
0
        public void Approve()
        {
            AssertValidAction(StateAction.Approve);

            if (HasApproving)
            {
                // Approving ON
                switch (VersioningMode)
                {
                case VersioningMode.None:
                    DeleteVersionsAndApprove();
                    break;

                case VersioningMode.Major:
                    var workingIds = GetLastWorkingVersions().Select(x => x.VersionId);

                    DeletableVersionIds.AddRange(workingIds);
                    DeletableVersionIds.Remove(CurrentVersionId);

                    var lastApproved = GetLastApprovedVersion();

                    ExpectedVersion = lastApproved == null?
                                      ComputeNewVersion().ChangeStatus(VersionStatus.Approved) :
                                          GetNextPublicVersion(lastApproved.VersionNumber, VersionStatus.Approved);

                    ExpectedVersionId = CurrentVersionId;
                    break;

                case VersioningMode.Full:
                    ExpectedVersion   = GetNextPublicVersion(VersionStatus.Approved);
                    ExpectedVersionId = this.CurrentVersionId;
                    break;
                }
            }
        }
コード例 #4
0
        public void CheckIn()
        {
            AssertValidAction(StateAction.CheckIn);

            if (!HasApproving)
            {
                // Approving OFF
                switch (VersioningMode)
                {
                case VersioningMode.None:
                    DeleteVersionsAndApprove();
                    break;

                case VersioningMode.Major:
                    // remove all working versions, except current
                    DeletableVersionIds.AddRange(GetLastWorkingVersions().Select(x => x.VersionId));
                    DeletableVersionIds.Remove(CurrentVersionId);

                    var lastApproved = GetLastApprovedVersion();
                    ExpectedVersion = lastApproved != null?
                                      GetNextPublicVersion(lastApproved.VersionNumber, VersionStatus.Approved) :
                                          ComputeNewVersion();

                    ExpectedVersionId = CurrentVersionId;
                    break;

                case VersioningMode.Full:
                    ExpectedVersion   = CurrentVersion.ChangeStatus(VersionStatus.Draft);
                    ExpectedVersionId = CurrentVersionId;
                    break;
                }
            }
            else
            {
                // Approving ON
                switch (VersioningMode)
                {
                case VersioningMode.None:
                    DeleteVersionsAndPreserveLastWorking();
                    break;

                case VersioningMode.Major:
                    ExpectedVersion   = CurrentVersion.ChangeStatus(VersionStatus.Pending);
                    ExpectedVersionId = CurrentVersionId;
                    break;

                case VersioningMode.Full:
                    ExpectedVersion   = CurrentVersion.ChangeStatus(VersionStatus.Draft);
                    ExpectedVersionId = CurrentVersionId;
                    break;
                }
            }

            // Unlock
            this.LockerUserId = 0;
        }
コード例 #5
0
        public void CheckOutAndSaveAndCheckIn()
        {
            if (CurrentVersion == null)
            {
                Create();
                return;
            }
            AssertValidAction(StateAction.SaveAndCheckIn);
            // Expected version
            if (!HasApproving)
            {
                // Approving OFF
                switch (VersioningMode)
                {
                case VersioningMode.None:
                    DeleteVersionsAndApprove();
                    break;

                case VersioningMode.Major:
                    // remove all working versions, except current
                    var irrelevantIds = GetLastWorkingVersions().Select(x => x.VersionId);

                    DeletableVersionIds.AddRange(irrelevantIds);
                    DeletableVersionIds.Remove(CurrentVersionId);

                    var lastApproved = GetLastApprovedVersion();

                    ExpectedVersion = lastApproved != null?
                                      GetNextPublicVersion(lastApproved.VersionNumber, VersionStatus.Approved) :
                                          ComputeNewVersion();

                    // preserve last working version
                    if (CurrentVersion.Status != VersionStatus.Approved && CurrentVersion.Status != VersionStatus.Rejected)
                    {
                        ExpectedVersionId = CurrentVersionId;
                    }

                    break;

                case VersioningMode.Full:
                    this.ExpectedVersion = GetNextNonpublicVersion(VersionStatus.Draft);
                    this.LockerUserId    = 0;
                    ExpectedVersionId    = 0;
                    break;
                }
            }
            else
            {
                // Approving ON
                switch (VersioningMode)
                {
                case VersioningMode.None:
                    DeleteVersionsAndPreserveLastWorking();
                    break;

                case VersioningMode.Major:
                    switch (CurrentVersion.Status)
                    {
                    case VersionStatus.Approved:         // raise
                    case VersionStatus.Rejected:         // raise
                        this.ExpectedVersion = GetNextNonpublicVersion(VersionStatus.Pending);
                        break;

                    case VersionStatus.Draft:            // preserve
                    case VersionStatus.Pending:          // preserve
                        ExpectedVersion   = CurrentVersion.ChangeStatus(VersionStatus.Pending);
                        ExpectedVersionId = CurrentVersionId;
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                    break;

                case VersioningMode.Full:
                    this.ExpectedVersion = GetNextNonpublicVersion(VersionStatus.Draft);
                    ExpectedVersionId    = 0;
                    break;
                }
            }

            // Unlock
            this.LockerUserId = 0;
        }