VersionNumber is for handling version numbers in major.minor form.
Inheritance: IComparable, ICloneable
Beispiel #1
0
        public void VersionNumber_Constructor()
		{
			//-- teljes értelmezési tartomány

			VersionNumber target = new VersionNumber(123, 456);
			Assert.IsTrue(target.Major == 123 && target.Minor == 456);
		}
 private static string FormatMessage(Exception inner, int nodeId, string path, int versionId, VersionNumber versionNumber, long timestamp)
 {
     string message = null;
     if (inner != null)
         message = inner.Message;
     if (String.IsNullOrEmpty(message))
         message = "Node is out of date";
     return String.Format("{0} NodeId: {1}, VersionId: {2}, Version: {3}, Path: {4}, Invalid timestamp: {5}", message, nodeId, path, versionId, versionNumber, timestamp);
 }
Beispiel #3
0
        //======================================= Construction =======================================

        internal NodeToken(int nodeId, int nodeTypeId, int contentListId, int contentListTypeId, int versionId, VersionNumber version)
        {
            this.NodeId = nodeId;
            this.NodeTypeId = nodeTypeId;
            this.ContentListId = contentListId;
            this.ContentListTypeId = contentListTypeId;
            this.VersionId = versionId;
            this.VersionNumber = version;
        }
Beispiel #4
0
            public NodeVersion(VersionNumber versionNumber, int versionId)
            {
                if (versionNumber == null)
                    throw new ArgumentNullException("versionNumber");
                if (versionId == 0)
                    throw new ArgumentException("VersionId cannot be 0.");

                VersionNumber = versionNumber;
                VersionId = versionId;
            }
Beispiel #5
0
        public void VersionNumber_Clone()
		{
			int major = 1;
			int minor = 2;

			VersionNumber source = new VersionNumber(major, minor);
			VersionNumber target = source.Clone();

			Assert.IsFalse(Object.ReferenceEquals(source, target), "VersionNumber.Clone #1");
			Assert.IsTrue(source == target, "VersionNumber.Clone #2");
		}
Beispiel #6
0
		private void CompareToTestAssert(VersionNumber v1, VersionNumber v2, int expectedValue)
		{
			Assert.AreEqual(v1.CompareTo(v2), expectedValue,
				String.Format("VersionNumber.CompareTo: [{0}].CompareTo([{1}]) returned {2}. Expected: {3}",
				v1.ToString(), v2.ToString(), v1.CompareTo(v2), expectedValue));
		}
Beispiel #7
0
        /// <summary>
        /// Parses the specified version string. Valid format is the following:
        /// ((['V'|'v'])?[majornumber][.][minornumber]([.][*]+)?)|'lastmajor'|'lastminor'
        /// For example: V1.0, 2.3, v12.3456, lastmajor
        /// </summary>
        /// <param name="versionString">The version string</param>
        /// <param name="version">Parsed VersionNumber if conversion was successful.</param>
        /// <returns>True if versionString was converted successfully; otherwise, false.</returns>
        public static bool TryParse(string versionString, out VersionNumber version)
        {
            version = null;
            var input = versionString.ToLower();
            if (input == "lastmajor")
            {
                version = VersionNumber.LastMajor;
                return true;
            }
            if (input == "lastminor")
            {
                version = VersionNumber.LastMinor;
                return true;
            }
            if (input[0] == 'v')
                input = input.Substring(1);
            var sa = input.Split('.');
            if (sa.Length < 2)
                return false;
            int major, minor;
            if (!int.TryParse(sa[0], out major))
                return false;
            if (!int.TryParse(sa[1], out minor))
                return false;
            if (sa.Length == 2)
            {
                version = new VersionNumber(major, minor);
                return true;
            }

            VersionStatus status;
            switch (sa[2])
            {
                case "a":
                case "approved": status = VersionStatus.Approved; break;
                case "l":
                case "locked": status = VersionStatus.Locked; break;
                case "d":
                case "draft": status = VersionStatus.Draft; break;
                case "r":
                case "rejected": status = VersionStatus.Rejected; break;
                case "p":
                case "pending": status = VersionStatus.Pending; break;
                default:
                    return false;
            }
            version = new VersionNumber(major, minor, status);
            return true;
        }
        private static string FormatMessage(Exception inner, int nodeId, string path, int versionId, VersionNumber versionNumber, long timestamp)
        {
            string message = null;

            if (inner != null)
            {
                message = inner.Message;
            }
            if (String.IsNullOrEmpty(message))
            {
                message = "Node is out of date";
            }
            return(String.Format("{0} NodeId: {1}, VersionId: {2}, Version: {3}, Path: {4}, Invalid timestamp: {5}", message, nodeId, versionId, versionNumber, path, timestamp));
        }
 public NodeIsOutOfDateException(int nodeId, string path, int versionId, VersionNumber versionNumber, Exception inner, long timestamp)
     : base(FormatMessage(inner, nodeId, path, versionId, versionNumber, timestamp), inner)
 {
 }
Beispiel #10
0
		private void EqualsTestAssert(VersionNumber v1, VersionNumber v2, bool expectedValue)
		{
			Assert.AreEqual(v1.Equals(v2), expectedValue,
				String.Format("VersionNumber.Equals: [{0}].Equals([{1}]) returned {2}. Expected: {3}",
				v1.ToString(), v2.ToString(), v1.Equals(v2), expectedValue));
		}
Beispiel #11
0
        /// <summary>
        /// Gets the VersionId that belongs to the given version. If no such version exists, 0 is returned.
        /// </summary>
		internal int GetVersionId(VersionNumber version)
		{
            foreach (var v in Versions)
            {
                if (v.VersionNumber == version)
                    return v.VersionId;
            }
            return 0;
		}
Beispiel #12
0
        //---- when create new
        internal static NodeData CreateNewNodeData(Node parent, NodeType nodeType, ContentListType listType, int listId)
        {
            var listTypeId = listType == null ? 0 : listType.Id;
            var parentId = parent == null ? 0 : parent.Id;
            var userId = AccessProvider.Current.GetOriginalUser().Id;
            var name = String.Concat(nodeType.Name, "-", DateTime.Now.ToString("yyyyMMddHHmmss")); //Guid.NewGuid().ToString();
            var path = (parent == null) ? "/" + name : RepositoryPath.Combine(parent.Path, name);
            var now = DateTime.Now;
            var versionNumber = new VersionNumber(1, 0, VersionStatus.Approved);
            //---- when create new
            var privateData = new NodeData(nodeType, listType)
            {
                IsShared = false,
                SharedData = null,

                Id = 0,
                NodeTypeId = nodeType.Id,
                ContentListTypeId = listTypeId,
                ContentListId = listId,

                ParentId = parentId,
                Name = name,
                Path = path,
                Index = 0,
                IsDeleted = false,
                IsInherited = true,

                NodeCreationDate = now,
                NodeModificationDate = now,
                NodeCreatedById = userId,
                NodeModifiedById = userId,

                VersionId = 0,
                Version = versionNumber,
                CreationDate = now,
                ModificationDate = now,
                CreatedById = userId,
                ModifiedById = userId,

                Locked = false,
                LockedById = 0,
                ETag = null,
                LockType = 0,
                LockTimeout = 0,
                LockDate = DataProvider.Current.DateTimeMinValue,
                LockToken = null,
                LastLockUpdate = DataProvider.Current.DateTimeMinValue,
            };
            privateData.ModificationDateChanged = false;
            privateData.ModifiedByIdChanged = false;
            privateData.NodeModificationDateChanged = false;
            privateData.NodeModifiedByIdChanged = false;
            return privateData;
        }
Beispiel #13
0
		public void VersionNumber_EqualsNull()
		{
			VersionNumber v10 = new VersionNumber(1, 0);
			VersionNumber nullVersion = null;
			Assert.IsTrue(v10 != nullVersion);
			Assert.IsTrue(nullVersion != v10);
			v10 = null;
			Assert.IsTrue(v10 == nullVersion);
			Assert.IsTrue(nullVersion == v10);

		}
Beispiel #14
0
		private void GreaterThanOrEqualTestAssert(VersionNumber v1, VersionNumber v2, bool expectedValue)
		{
			Assert.AreEqual(v1 >= v2, expectedValue,
				String.Format("VersionNumber.GreaterThanOrEqualTest: [{0}] >= ([{1}]) returned {2}. Expected: {3}",
				v1.ToString(), v2.ToString(), v1 >= v2, expectedValue));
		}
Beispiel #15
0
        public void VersionNumber_GreaterThanOrEqual()
		{
			VersionNumber v1 = new VersionNumber(1, 1);
			VersionNumber v2 = new VersionNumber(1, 2);
			VersionNumber v3 = new VersionNumber(1, 2);
			VersionNumber v4 = new VersionNumber(2, 1);
			VersionNumber v5 = new VersionNumber(2, 1);

			GreaterThanOrEqualTestAssert(v1, v2, false);
			GreaterThanOrEqualTestAssert(v2, v1, true);

			GreaterThanOrEqualTestAssert(v1, v4, false);
			GreaterThanOrEqualTestAssert(v2, v4, false);
			GreaterThanOrEqualTestAssert(v3, v4, false);
			GreaterThanOrEqualTestAssert(v4, v1, true);
			GreaterThanOrEqualTestAssert(v4, v2, true);
			GreaterThanOrEqualTestAssert(v4, v3, true);

			GreaterThanOrEqualTestAssert(v2, v3, true);
			GreaterThanOrEqualTestAssert(v3, v2, true);
			GreaterThanOrEqualTestAssert(v4, v5, true);
			GreaterThanOrEqualTestAssert(v5, v4, true);
		}
Beispiel #16
0
		private void LessThanTestAssert(VersionNumber v1, VersionNumber v2, bool expectedValue)
		{
			Assert.AreEqual(v1 < v2, expectedValue,
				String.Format("VersionNumber.LessThanTest: [{0}] < ([{1}]) returned {2}. Expected: {3}",
				v1.ToString(), v2.ToString(), v1 < v2, expectedValue));
		}
Beispiel #17
0
        public void VersionNumber_LessThan()
		{
			VersionNumber v1 = new VersionNumber(1, 1);
			VersionNumber v2 = new VersionNumber(1, 2);
			VersionNumber v3 = new VersionNumber(1, 2);
			VersionNumber v4 = new VersionNumber(2, 1);
			VersionNumber v5 = new VersionNumber(2, 1);

			LessThanTestAssert(v1, v2, true);
			LessThanTestAssert(v2, v1, false);

			LessThanTestAssert(v1, v4, true);
			LessThanTestAssert(v2, v4, true);
			LessThanTestAssert(v3, v4, true);
			LessThanTestAssert(v4, v1, false);
			LessThanTestAssert(v4, v2, false);
			LessThanTestAssert(v4, v3, false);

			LessThanTestAssert(v2, v3, false);
			LessThanTestAssert(v3, v2, false);
			LessThanTestAssert(v4, v5, false);
			LessThanTestAssert(v5, v4, false);
		}
Beispiel #18
0
        public void VersionNumber_Equality()
		{
			VersionNumber v1 = new VersionNumber(1, 1);
			VersionNumber v2 = new VersionNumber(1, 2);
			VersionNumber v3 = new VersionNumber(1, 2);
			VersionNumber v4 = new VersionNumber(2, 1);
			VersionNumber v5 = new VersionNumber(2, 1);

			EqualityTestAssert(v1, v2, false);
			EqualityTestAssert(v2, v1, false);
			EqualityTestAssert(v1, v4, false);
			EqualityTestAssert(v2, v4, false);
			EqualityTestAssert(v3, v4, false);
			EqualityTestAssert(v4, v1, false);
			EqualityTestAssert(v4, v2, false);
			EqualityTestAssert(v4, v3, false);

			EqualityTestAssert(v2, v3, true);
			EqualityTestAssert(v3, v2, true);
			EqualityTestAssert(v4, v5, true);
			EqualityTestAssert(v5, v4, true);
		}
Beispiel #19
0
		private void InequalityTestAssert(VersionNumber v1, VersionNumber v2, bool expectedValue)
		{
			Assert.AreEqual(v1 != v2, expectedValue,
				String.Format("VersionNumber.InequalityTest: [{0}] != ([{1}]) returned {2}. Expected: {3}",
				v1.ToString(), v2.ToString(), v1 != v2, expectedValue));
		}
 public NodeIsOutOfDateException(int nodeId, string path, int versionId, VersionNumber versionNumber, Exception inner, long timestamp)
     : base(FormatMessage(inner, nodeId, path, versionId, versionNumber, timestamp), inner) { }
Beispiel #21
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;
            }
        }
 private Node LoadNode(NodeHead head, VersionNumber version)
 {
     var nodeAcc = new PrivateType(typeof(Node));
     var node = (Node)nodeAcc.InvokeStatic("LoadNode", head, version);
     return node;
 }
Beispiel #23
0
 internal NodeToken(int nodeId, int nodeTypeId, int contentListId, int contentListTypeId, int versionId, VersionNumber version)
 {
     this.NodeId            = nodeId;
     this.NodeTypeId        = nodeTypeId;
     this.ContentListId     = contentListId;
     this.ContentListTypeId = contentListTypeId;
     this.VersionId         = versionId;
     this.VersionNumber     = version;
 }
Beispiel #24
0
        private ContentAccessor VersionTest(string contentTypeName)
        {
            VersionNumber originalValue;
            VersionNumber currentValue;
            string handlerValue;
            string fieldName = "VersionNumber";
            VersionNumber defaultValue = null;
            VersionNumber testValue = new VersionNumber(5, 6, VersionStatus.Draft);
            string defaultHandlerValue = (string)PropertyType.GetDefaultValue(DataType.String);
            string testHandlerValue = testValue.ToString();

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#1");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#2");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#4");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            handlerValue = (string)content.ContentHandler[fieldName];
            //Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "####13: Storage2: Expected: [null], current: [empty]");

            return contentAcc;
        }
Beispiel #25
0
 private static VersionNumber GetNextPublicVersion(VersionNumber version, VersionStatus status)
 {
     var major = version.Major + 1;
     return new VersionNumber(major, 0, status);
 }
Beispiel #26
0
        public void VersionNumber_Equals()
		{
			//-- invalid objektumra nincs teszt

			VersionNumber v1 = new VersionNumber(1, 1);
			VersionNumber v2 = new VersionNumber(1, 2);
			VersionNumber v3 = new VersionNumber(1, 2);
			VersionNumber v4 = new VersionNumber(2, 1);
			VersionNumber v5 = new VersionNumber(2, 1);

			EqualsTestAssert(v1, v2, false);
			EqualsTestAssert(v2, v1, false);
			EqualsTestAssert(v2, v3, true);
			EqualsTestAssert(v3, v2, true);

			EqualsTestAssert(v4, v1, false);
			EqualsTestAssert(v4, v2, false);
			EqualsTestAssert(v4, v3, false);
			EqualsTestAssert(v4, v1, false);
			EqualsTestAssert(v4, v2, false);
			EqualsTestAssert(v4, v3, false);

			EqualsTestAssert(v4, v5, true);
			EqualsTestAssert(v5, v4, true);
		}
 private List<Node> LoadNodes(IEnumerable<NodeHead> heads, VersionNumber version)
 {
     var nodeAcc = new PrivateType(typeof(Node));
     var nodes = (List<Node>)nodeAcc.InvokeStatic("LoadNodes", heads, version);
     return nodes;
 }
Beispiel #28
0
        public void VersionNumber_CompareTo()
		{
			//-- invalid objektumra nincs teszt

			VersionNumber v1 = new VersionNumber(1, 1);
			VersionNumber v2 = new VersionNumber(1, 2);
			VersionNumber v3 = new VersionNumber(1, 2);
			VersionNumber v4 = new VersionNumber(2, 1);

			CompareToTestAssert(v1, v2, -1);
			CompareToTestAssert(v2, v3, 0);
			CompareToTestAssert(v3, v1, 1);
			CompareToTestAssert(v1, v4, -1);
			CompareToTestAssert(v3, v4, -1);
			CompareToTestAssert(v4, v1, 1);
			CompareToTestAssert(v4, v1, 1);

		}
Beispiel #29
0
        /// <summary>
        /// Parses the specified version string. Valid format is the following:
        /// ((['V'|'v'])?[majornumber][.][minornumber]([.][*]+)?)|'lastmajor'|'lastminor'
        /// For example: V1.0, 2.3, v12.3456, lastmajor
        /// </summary>
        /// <param name="versionString">The version string</param>
        /// <param name="version">Parsed VersionNumber if conversion was successful.</param>
        /// <returns>True if versionString was converted successfully; otherwise, false.</returns>
        public static bool TryParse(string versionString, out VersionNumber version)
        {
            version = null;
            var input = versionString.ToLower();

            if (input == "lastmajor")
            {
                version = VersionNumber.LastMajor;
                return(true);
            }
            if (input == "lastminor")
            {
                version = VersionNumber.LastMinor;
                return(true);
            }
            if (input[0] == 'v')
            {
                input = input.Substring(1);
            }
            var sa = input.Split('.');

            if (sa.Length < 2)
            {
                return(false);
            }
            int major, minor;

            if (!int.TryParse(sa[0], out major))
            {
                return(false);
            }
            if (!int.TryParse(sa[1], out minor))
            {
                return(false);
            }
            if (sa.Length == 2)
            {
                version = new VersionNumber(major, minor);
                return(true);
            }

            VersionStatus status;

            switch (sa[2])
            {
            case "a":
            case "approved": status = VersionStatus.Approved; break;

            case "l":
            case "locked": status = VersionStatus.Locked; break;

            case "d":
            case "draft": status = VersionStatus.Draft; break;

            case "r":
            case "rejected": status = VersionStatus.Rejected; break;

            case "p":
            case "pending": status = VersionStatus.Pending; break;

            default:
                return(false);
            }
            version = new VersionNumber(major, minor, status);
            return(true);
        }
Beispiel #30
0
        private VersionNumber GetNextVersion(VersionNumber version, VersionStatus status)
        {
            var major = version.Major;
            var minor = version.Minor;
            if (this.VersioningMode == VersioningMode.Full)
            {
                minor++;
            }
            else
            {
                major++;
                minor = 0;
            }

            return new VersionNumber(major, minor, status);
        }