1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System;
- using System.Collections.Generic;
- namespace Wayne.Lib
- {
- /// <summary>
- /// Provides a version for the application.
- /// </summary>
- public class VersionProvider : IVersionProvider
- {
- ///<summary>
- /// Constructor
- ///</summary>
- public VersionProvider()
- {
- ReleaseComponentVersion = new VersionNumber("0.0.0");
- }
- ///<summary>
- /// Main component version for the running process. Should be set in code as early as possible in the program.
- ///</summary>
- public VersionNumber ReleaseComponentVersion { get; set; }
- private readonly Dictionary<object, VersionNumber> internalDictionary = new Dictionary<object, VersionNumber>();
- private readonly object internalDictionaryLock = new object();
- /// <summary>
- /// Gets the version for a sub component.
- /// </summary>
- /// <typeparam name="TVersionIdentifier"></typeparam>
- /// <param name="versionIdentifier"></param>
- /// <returns></returns>
- public VersionNumber GetVersion<TVersionIdentifier>(TVersionIdentifier versionIdentifier)
- {
- VersionNumber result;
- lock (internalDictionary)
- {
- if (internalDictionary.TryGetValue(versionIdentifier, out result))
- return result;
-
- return new VersionNumber("0.0.0");
- }
- }
- ///<summary>
- /// Sets the version for a sub component
- ///</summary>
- ///<param name="versionIdentifier"></param>
- ///<param name="versionNumber"></param>
- ///<typeparam name="TVersionIdentifier"></typeparam>
- public void SetVersion<TVersionIdentifier>(TVersionIdentifier versionIdentifier, VersionNumber versionNumber)
- {
- lock (internalDictionaryLock)
- {
- internalDictionary[versionIdentifier] = versionNumber;
- }
- }
- }
- }
|