Exemplo n.º 1
0
        protected override int TrackPosition(ITextVersion targetVersion)
        {
            // Compute the new position on the requested snapshot.
            //
            // This method can be called simultaneously from multiple threads, and must be fast.
            //
            // We are relying on the atomicity of pointer copies (this.cachedPosition might change after we've
            // fetched it but we will always get a self-consistent VersionPosition). This ensures we
            // have proper behavior when called from multiple threads--multiple threads may all track and update the
            // cached value if called at inconvenient times, but they will return consistent results.
            // ForwardFidelity points do not support tracking backward, so consistency is not guaranteed in that case.

            VersionPosition cached = this.cachedPosition;
            int             targetPosition;

            if (targetVersion == cached.Version)
            {
                targetPosition = cached.Position;
            }
            else if (targetVersion.VersionNumber > cached.Version.VersionNumber)
            {
                // Roll the cached version forward to the requested version.
                targetPosition = Tracking.TrackPositionForwardInTime(this.trackingMode, cached.Position, cached.Version, targetVersion);

                // Cache new cached version.
                this.cachedPosition = new VersionPosition(targetVersion, targetPosition);
            }
            else
            {
                // Roll backwards from the cached version.
                targetPosition = Tracking.TrackPositionBackwardInTime(this.trackingMode, cached.Position, cached.Version, targetVersion);
            }
            return(targetPosition);
        }
        internal static JsonObject Generate(VersionPosition versionPosition)
        {
            string posValue;

            switch (versionPosition)
            {
            case VersionPosition.First:
                posValue = "First";
                break;

            case VersionPosition.Last:
                posValue = "Last";
                break;

            case VersionPosition.Earlier:
                posValue = "Earlier";
                break;

            case VersionPosition.Later:
                posValue = "Later";
                break;

            default:
                throw new ArgumentException("Invalid version position value", "versionPosition");
            }

            return(new JsonObject {
                { "position", posValue }
            });
        }
        internal static JsonObject Generate(VersionPosition versionPosition)
        {
            string posValue;

            switch (versionPosition)
            {
                case VersionPosition.First:
                    posValue = "First";
                    break;

                case VersionPosition.Last:
                    posValue = "Last";
                    break;

                case VersionPosition.Earlier:
                    posValue = "Earlier";
                    break;

                case VersionPosition.Later:
                    posValue = "Later";
                    break;

                default:
                    throw new ArgumentException("Invalid version position value", "versionPosition");
            }

            return new JsonObject { { "position", posValue } };
        }
Exemplo n.º 4
0
        public override string ToString()
        {
            VersionPosition c = this.cachedPosition;

            return(ToString(c.Version, c.Position, this.trackingMode));
        }
Exemplo n.º 5
0
 public ForwardFidelityTrackingPoint(ITextVersion version, int position, PointTrackingMode trackingMode)
     : base(version, position, trackingMode)
 {
     this.cachedPosition = new VersionPosition(version, position);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Moves selected version to another position.
        /// If version already occupies given position (e.g. is the last version and we want to move to a later position or to the last position) then such call does not change anything.
        /// </summary>
        /// <param name="versionUri">The URI of the version to move.</param>
        /// <param name="versionPosition">Defines a new position of the selected version.</param>
        /// <returns>Detailed information of the version that has just been moved.</returns>
        /// <exception cref="WebServiceException">If the version does not exist, or the calling user does not have permission to modify versions in the project.</exception>
        public JiraVersion MoveVersion(Uri versionUri, VersionPosition versionPosition)
        {
            var json = VersionPositionInputJsonGenerator.Generate(versionPosition);

            return(client.Post <JiraVersion>(GetMoveVersionUri(versionUri), json));
        }