Permalink
Browse files

use .NET's resource files now that there's a working implementation i…

…n .NET Core
  • Loading branch information...
christianspecht committed Nov 30, 2016
1 parent 76177ea commit ca9678d6befbd604b2247157033573a77150d451

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -1,23 +1,13 @@
using ScmBackup.Hosters;
using ScmBackup.Http;
using ScmBackup.Resources;
using SimpleInjector;
using System.Globalization;
using System.Linq;
using System.Reflection;

namespace ScmBackup.CompositionRoot
{
public class Bootstrapper
{
public static void SetupResources()
{
// TODO: determine current culture
var culture = new CultureInfo("en-US");

Resource.Initialize(new ResourceProvider(), culture);
}

/// <summary>
/// Registers IoC dependencies and returns the initialized container
/// </summary>
@@ -17,7 +17,7 @@ public List<HosterRepository> GetRepositoryList(ConfigSource config)
{
if (config == null)
{
throw new ArgumentNullException(Resource.GetString("ConfigSourceIsNull"));
throw new ArgumentNullException(Resource.ConfigSourceIsNull);
}

var hoster = this.factory.Create(config.Hoster);
@@ -22,7 +22,7 @@ public void Register(Type type)
{
if (!typeof(IHoster).IsAssignableFrom(type))
{
throw new InvalidOperationException(string.Format(Resource.GetString("TypeIsNoIHoster"), type.ToString()));
throw new InvalidOperationException(string.Format(Resource.TypeIsNoIHoster, type.ToString()));
}

var attribute = type.GetTypeInfo().GetCustomAttribute<HosterAttribute>();
@@ -37,7 +37,7 @@ public IHoster Create(string hosterName)

if (!this.TryGetValue(hosterName, out type))
{
throw new InvalidOperationException(string.Format(Resource.GetString("HosterDoesntExist"), hosterName));
throw new InvalidOperationException(string.Format(Resource.HosterDoesntExist, hosterName));
}

return (IHoster)this.container.GetInstance(type);
@@ -15,7 +15,7 @@ public ValidationResult Validate(ConfigSource source)
{
if (source == null)
{
throw new ArgumentNullException(Resource.GetString("ConfigSourceIsNull"));
throw new ArgumentNullException(Resource.ConfigSourceIsNull);
}

var hoster = this.factory.Create(source.Hoster);
@@ -13,7 +13,7 @@ public Context()
var assembly = typeof(ScmBackup).GetTypeInfo().Assembly;
this.VersionNumber = assembly.GetName().Version;
this.VersionNumberString= assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
this.AppTitle = Resource.GetString("AppTitle") + " " + this.VersionNumberString;
this.AppTitle = Resource.AppTitle + " " + this.VersionNumberString;
}

public Version VersionNumber { get; private set; }
@@ -35,12 +35,12 @@ public void Run()

try
{
this.logger.Log(ErrorLevel.Debug, Resource.GetString("ReadingConfig"), className);
this.logger.Log(ErrorLevel.Debug, Resource.ReadingConfig, className);
config = this.conf.ReadConfig();

if (config != null)
{
this.logger.Log(ErrorLevel.Debug, Resource.GetString("StartingBackup"), className);
this.logger.Log(ErrorLevel.Debug, Resource.StartingBackup, className);
this.backup.Run();
ok = true;
}
@@ -61,8 +61,8 @@ public void Run()
seconds = config.WaitSecondsOnError;
}

this.logger.Log(ErrorLevel.Error, Resource.GetString("BackupFailed"));
this.logger.Log(ErrorLevel.Error, Resource.GetString("EndSeconds"), seconds);
this.logger.Log(ErrorLevel.Error, Resource.BackupFailed);
this.logger.Log(ErrorLevel.Error, Resource.EndSeconds, seconds);
Task.Delay(TimeSpan.FromSeconds(seconds)).Wait();
}
}
@@ -36,7 +36,7 @@ public List<HosterRepository> GetRepositoryList(ConfigSource config)
request.AddHeader("Accept", "application/vnd.github.v3+json");

// https://developer.github.com/v3/#user-agent-required
request.AddHeader("User-Agent", Resource.GetString("AppTitle"));
request.AddHeader("User-Agent", Resource.AppTitle);

bool isAuthenticated = !String.IsNullOrWhiteSpace(config.AuthName) && !String.IsNullOrWhiteSpace(config.Password);
if (isAuthenticated)
@@ -69,7 +69,7 @@ public List<HosterRepository> GetRepositoryList(ConfigSource config)
break;
}

this.logger.Log(ErrorLevel.Info, Resource.GetString("ApiGettingUrl"), className, request.HttpClient.BaseAddress.ToString() + url);
this.logger.Log(ErrorLevel.Info, Resource.ApiGettingUrl, className, request.HttpClient.BaseAddress.ToString() + url);
this.LastResult = request.Execute(url).Result;

if (this.LastResult.IsSuccessStatusCode)
@@ -86,11 +86,11 @@ public List<HosterRepository> GetRepositoryList(ConfigSource config)
switch (this.LastResult.Status)
{
case HttpStatusCode.Unauthorized:
throw new AuthenticationException(string.Format(Resource.GetString("ApiAuthenticationFailed"), config.AuthName));
throw new AuthenticationException(string.Format(Resource.ApiAuthenticationFailed, config.AuthName));
case HttpStatusCode.Forbidden:
throw new SecurityException(Resource.GetString("ApiMissingPermissions"));
throw new SecurityException(Resource.ApiMissingPermissions);
case HttpStatusCode.NotFound:
throw new InvalidOperationException(string.Format(Resource.GetString("ApiInvalidUsername"), config.Name));
throw new InvalidOperationException(string.Format(Resource.ApiInvalidUsername, config.Name));
}
}

@@ -11,29 +11,29 @@ public ValidationResult Validate(ConfigSource config)

if (config.Hoster != "github")
{
result.AddMessage(ErrorLevel.Error, string.Format(Resource.GetString("WrongHoster"), config.Hoster));
result.AddMessage(ErrorLevel.Error, string.Format(Resource.WrongHoster, config.Hoster));
}

if (config.Type != "user" && config.Type != "org")
{
result.AddMessage(ErrorLevel.Error, string.Format(Resource.GetString("WrongType"), config.Type));
result.AddMessage(ErrorLevel.Error, string.Format(Resource.WrongType, config.Type));
}

if (string.IsNullOrWhiteSpace(config.Name))
{
result.AddMessage(ErrorLevel.Error, Resource.GetString("NameEmpty"));
result.AddMessage(ErrorLevel.Error, Resource.NameEmpty);
}

bool authNameEmpty = string.IsNullOrWhiteSpace(config.AuthName);
bool passwordEmpty = string.IsNullOrWhiteSpace(config.Password);

if (authNameEmpty != passwordEmpty)
{
result.AddMessage(ErrorLevel.Error, Resource.GetString("AuthNameOrPasswortEmpty"));
result.AddMessage(ErrorLevel.Error, Resource.AuthNameOrPasswortEmpty);
}
else if (authNameEmpty && passwordEmpty)
{
result.AddMessage(ErrorLevel.Warn, Resource.GetString("AuthNameAndPasswortEmpty"));
result.AddMessage(ErrorLevel.Warn, Resource.AuthNameAndPasswortEmpty);
}

return result;
@@ -37,11 +37,11 @@ public async Task<HttpResult> Execute(string url)
{
string className = this.GetType().Name;

this.logger.Log(ErrorLevel.Debug, Resource.GetString("HttpRequest"), url);
this.logger.Log(ErrorLevel.Debug, Resource.HttpRequest, url);
var result = await this.request.Execute(url);

this.logger.Log(ErrorLevel.Debug, Resource.GetString("HttpHeaders"), result.Headers.ToString());
this.logger.Log(ErrorLevel.Debug, Resource.GetString("HttpResult"), result.Content);
this.logger.Log(ErrorLevel.Debug, Resource.HttpHeaders, result.Headers.ToString());
this.logger.Log(ErrorLevel.Debug, Resource.HttpResult, result.Content);

return result;
}
@@ -6,8 +6,6 @@ public class Program
{
public static void Main(string[] args)
{
Bootstrapper.SetupResources();

var container = Bootstrapper.BuildContainer();
container.GetInstance<IScmBackup>().Run();
}
Oops, something went wrong.

0 comments on commit ca9678d

Please sign in to comment.