/// <summary> /// Verify whether the expected versions from GetFileVersions are equal to the actual operation response. /// </summary> /// <param name="expect">The expected version from GetFileVersions method.</param> /// <param name="actual">The actual version from operation response.</param> /// <returns>The Boolean value that indicates whether the expected versions are equal to /// the actual operation response.</returns> public static bool AreVersionsResultEqual(string expect, VersionData[] actual) { string[] expectVersions = expect.Split(new string[] { "^" }, StringSplitOptions.RemoveEmptyEntries); if (expectVersions.Length != actual.Length) { return false; } Collection<string> expectVersionsCollection = new Collection<string>(); foreach (string expectVersion in expectVersions) { expectVersionsCollection.Add(expectVersion); } site.Log.Add( LogEntryKind.Debug, string.Format("The expected version number contains {0}.", expect.Replace("^", ","))); Collection<string> actualVersionsCollection = ConvertVersionDataArrayToVersionNumberCollection(actual); site.Log.Add( LogEntryKind.Debug, string.Format("The actual version number contains {0}.", ConvertVersionDataToString(actual))); return AreVersionNumberEqual(expectVersionsCollection, actualVersionsCollection); }
/// <summary> /// Verify whether the expected versions from GetVersions operation are equal to the responses of other operations. /// </summary> /// <param name="expect">The expected versions from GetVersions operation response.</param> /// <param name="actual">The actual versions from other operations response. </param> /// <returns>The Boolean value that indicates whether the expected versions /// from GetVersions operation are equal to the responses of other operations.</returns> public static bool AreVersionsResultEqual(VersionData[] expect, VersionData[] actual) { if (expect.Length != actual.Length) { return false; } Collection<string> expectVersions = ConvertVersionDataArrayToVersionNumberCollection(expect); site.Log.Add( LogEntryKind.Debug, string.Format("The expected version number contains {0}.", ConvertVersionDataToString(expect))); Collection<string> actualVersions = ConvertVersionDataArrayToVersionNumberCollection(actual); site.Log.Add( LogEntryKind.Debug, string.Format("The actual version number contains {0}.", ConvertVersionDataToString(actual))); return AreVersionNumberEqual(expectVersions, actualVersions); }
/// <summary> /// Convert an array of VersionData to string. /// </summary> /// <param name="versionDataArray">An array of VersionData object that will be converted.</param> /// <returns>A string indicates version information.</returns> private static string ConvertVersionDataToString(VersionData[] versionDataArray) { string versionsString = string.Empty; foreach (VersionData versionData in versionDataArray) { versionsString = versionsString + versionData.version + ","; } if (versionsString.Length > 0) { versionsString = versionsString.Substring(0, versionsString.Length - 1); } return versionsString; }
/// <summary> /// Convert an array of VersionData object to a version numbers collection. /// </summary> /// <param name="versionDataArray">An array of VersionData object that will be converted.</param> /// <returns>A Collection object indicates a collection of version number.</returns> private static Collection<string> ConvertVersionDataArrayToVersionNumberCollection(VersionData[] versionDataArray) { Collection<string> versions = new Collection<string>(); foreach (VersionData versionData in versionDataArray) { versions.Add(versionData.version); } return versions; }
/// <summary> /// Get the current version. /// </summary> /// <param name="versions">All the versions of file.</param> /// <returns>A string value indicates the current version of file.</returns> public static string GetCurrentVersion(VersionData[] versions) { // A string indicates the current version. // According to MS-OFCGLOS,the current version is the latest version of a document. // Then current version is the most recent version of the file. string currentVersion = versions[0].version; for (int i = 1; i < versions.Length; i++) { // Compare the version number with the value of currentVersion variable. if (CompareVersionNumber(currentVersion, versions[i].version) == 1) { // If the CompareVersionNumber method returns 1, then the version number is greater than the value of // currentVersion variable. // The version number will assigned to currentVersion variable. currentVersion = versions[i].version; } } return currentVersion; }
/// <summary> /// Verify whether the specified version exists in all the versions of the file. /// </summary> /// <param name="versions">All the versions of file.</param> /// <param name="version">The specified version number which will be checked.</param> /// <returns>A Boolean value indicates whether the specified version exists in all the version of the file.</returns> public static bool IsVersionExist(VersionData[] versions, string version) { bool isExist = false; foreach (VersionData versionData in versions) { if (CompareVersionNumber(versionData.version, version) == 0) { isExist = true; break; } } return isExist; }
/// <summary> /// Get the latest version that is less than the current version. /// </summary> /// <param name="versions">The versions of specified file.</param> /// <returns>A string indicates a version that only less than current version.</returns> public static string GetPreviousVersion(VersionData[] versions) { #region Sort of descending order of version number // The version numbers collection that sort of descending order. Collection<string> versionsSortCollection = new Collection<string>(); // Sort of descending order of version number foreach (VersionData versionData in versions) { // A Boolean value indicates whether this version number is smallest in the versionsSortCollection. bool isSmallest = true; for (int i = 0; i < versionsSortCollection.Count; i++) { if (CompareVersionNumber(versionsSortCollection[i], versionData.version) == 1) { // If find a version in versionsSortCollection that less than this version, // and then insert this version prior to the version that less than this version in the collection. versionsSortCollection.Insert(i, versionData.version); isSmallest = false; break; } } // If this version is the smallest one in the versionsSortCollection, add it to the end of // the versionsSortCollection. if (isSmallest == true) { versionsSortCollection.Add(versionData.version); } } #endregion // According to MS-OFCGLOS,the current version is the latest version of a document. // Then current version is the most recent version of the file. // So the first item in versionsSortCollection is current version and the second item is the version // that less than current version. return versionsSortCollection[1]; }