Example #1
0
        /// <summary>
        /// Loads version information from the specified state reader and asserts that the version name tag matches with the specified versioned artifact's.
        /// </summary>
        /// <param name="reader">Reader to read version state from.</param>
        /// <param name="versioned">Version artifact whose version name tag to compart to the version information read from the reader.</param>
        /// <returns>The version number read from the state reader.</returns>
        /// <exception cref="InvalidOperationException">Thrown if the state reader read a version name tag that doesn't match the name tag in the specified version artifact.</exception>
        public static Version LoadVersionInfo(this IOperatorStateReader reader, IVersioned versioned)
        {
            // The call to TryRead will only ever return false if the operator is transitioning.
            // Otherwise, the constructor call for the reader would have thrown.
            if (!reader.TryRead <string>(out string name) || (versioned is ITransitioningOperator && versioned.Name != name))
            {
                return(null);
            }

            if (versioned.Name != name)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Failed to restore state for artifact '{0}' with expected tag '{1}'. State tag is '{2}'.", versioned.ToString(), versioned.Name, name));
            }

            var major    = reader.Read <int>();
            var minor    = reader.Read <int>();
            var build    = reader.Read <int>();
            var revision = reader.Read <int>();

            return(Versioning.GetVersion(major, minor, build, revision));
        }