cleanup, renaming and so on...

This commit is contained in:
Holger Börchers 2018-03-27 11:28:30 +02:00
parent 64a2c35c0c
commit c4132b4061
9 changed files with 64 additions and 49 deletions

View File

@ -144,7 +144,7 @@ namespace KattekerCreator
var pathToFile = Path.Combine(_tempDir, Constants.KattekerConfig);
var kattekerConfig = new KattekerConfig
{
PublishDir = _appArguments.PublishDir ?? _appArguments.OutputDir,
Publish = _appArguments.PublishDir ?? _appArguments.OutputDir,
Changelog = _appArguments.ChangeLog
};
kattekerConfig.WriteToFile(pathToFile);

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonMark.NET" version="0.15.1" targetFramework="net45" />
</packages>

View File

@ -1,5 +1,8 @@
namespace Katteker
{
/// <summary>
/// A bunch of constants.
/// </summary>
public static class Constants
{
/// <summary>

View File

@ -49,7 +49,7 @@
<Compile Include="ReleaseEntry.cs" />
<Compile Include="Releases.cs" />
<Compile Include="Utility.cs" />
<Compile Include="VersionExtension.cs" />
<Compile Include="VersionUtils.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -4,16 +4,31 @@ using System.Runtime.Serialization.Json;
namespace Katteker
{
/// <summary>
/// Configuration of a Katteker-Deployment
/// </summary>
[DataContract]
public class KattekerConfig
{
/// <summary>
/// Publish path
/// </summary>
[DataMember]
public string PublishDir { get; set; }
public string Publish { get; set; }
/// <summary>
/// Name of the changelog file.
/// </summary>
[DataMember]
public string Changelog { get; set; }
/// <summary>
/// Read file and deserialize content.
/// </summary>
/// <param name="path">path of the file.</param>
/// <returns>this object</returns>
/// <exception cref="FileNotFoundException"></exception>
public static KattekerConfig ReadFromFile(string path)
{
if (!File.Exists(path)) throw new FileNotFoundException();
@ -25,6 +40,10 @@ namespace Katteker
}
}
/// <summary>
/// Serialize object and write to file.
/// </summary>
/// <param name="path">path of the file.</param>
public void WriteToFile(string path)
{
if (File.Exists(path)) File.Delete(path);

View File

@ -10,7 +10,7 @@ namespace Katteker
public UpdateInfo(string applicationName, Releases releases)
{
CurrentlyInstalledVersion = new ReleaseEntry(applicationName, VersionExtension.GetCurrentVersion);
CurrentlyInstalledVersion = new ReleaseEntry(applicationName, VersionUtils.GetCurrentVersion());
foreach (var release in releases)
{
if (applicationName.Equals(release.ApplicationName) && release.Version > CurrentlyInstalledVersion.Version)

View File

@ -53,7 +53,7 @@ namespace Katteker
public static UpdateManager Create(string urlOrPath = null, string applicationName = null, string rootDirectory = null)
{
_config = ReadConfigFile();
urlOrPath = urlOrPath ?? _config.PublishDir;
urlOrPath = urlOrPath ?? _config.Publish;
var appName = applicationName ?? Utility.GetApplicationName();
var rootAppDirectory = Path.Combine(rootDirectory ?? Utility.GetLocalAppDataDirectory(), appName);
return new UpdateManager(urlOrPath, appName, rootAppDirectory);

View File

@ -1,40 +0,0 @@
using System;
using System.Reflection;
using Semver;
namespace Katteker
{
/// <summary>
/// Extension methods for the App-Version.
/// </summary>
public static class VersionExtension
{
/// <summary>
/// Get the current Version of Application.
/// </summary>
public static SemVersion GetCurrentVersion
{
get
{
var assemblyVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(3);
var getCurrentVersion = SemVersion.Parse(assemblyVersion);
var informalVersion = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
if (informalVersion != null && SemVersion.TryParse(informalVersion, out var semVersion))
return semVersion;
return getCurrentVersion;
}
}
/// <summary>
/// Convert to cenventional System.Version instance.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static Version ToSystemVersion(this SemVersion value) => new Version(value.Major, value.Minor, value.Patch, 0);
/// <summary>
/// Get the current Version of Application.
/// </summary>
public static string GetFullVersion => GetCurrentVersion.ToString();
}
}

37
Katteker/VersionUtils.cs Normal file
View File

@ -0,0 +1,37 @@
using System;
using System.Reflection;
using Semver;
namespace Katteker
{
/// <summary>
/// Utils for the App-Version.
/// </summary>
public static class VersionUtils
{
/// <summary>
/// Get the current Version of Application.
/// </summary>
public static SemVersion GetCurrentVersion()
{
var assemblyVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(3);
var getCurrentVersion = SemVersion.Parse(assemblyVersion);
var informalVersion = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
if (informalVersion != null && SemVersion.TryParse(informalVersion, out var semVersion))
return semVersion;
return getCurrentVersion;
}
/// <summary>
/// Get the System.Version representation of a semantic version.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static Version ToSystemVersion(this SemVersion value) => new Version(value.Major, value.Minor, value.Patch, 0);
/// <summary>
/// Get the current Version of Application.
/// </summary>
public static string GetFullVersion => GetCurrentVersion().ToString();
}
}