-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Qvision.PollIt.Constants | ||
{ | ||
internal class AppSettings | ||
{ | ||
/// <summary> | ||
/// Amount of answers per question | ||
/// </summary> | ||
public const string AmountOfAnswers = "pollIt:AmountOfAnswers"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
namespace Qvision.PollIt | ||
{ | ||
using System.Configuration; | ||
|
||
using Umbraco.Core; | ||
|
||
/// <summary> | ||
/// The Poll-it Context | ||
/// </summary> | ||
public class PollItContext | ||
{ | ||
/// <summary> | ||
/// The current instance. | ||
/// </summary> | ||
private static PollItContext instance; | ||
|
||
/// <summary> | ||
/// Prevents a default instance of the <see cref="PollItContext"/> class from being created. | ||
/// </summary> | ||
private PollItContext() | ||
{ | ||
this.AmountOfAnswers = this.GetAppSetting<int>(Constants.AppSettings.AmountOfAnswers, 6); | ||
instance = this; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the current context | ||
/// </summary> | ||
public static PollItContext Current => instance ?? new PollItContext(); | ||
|
||
// Amount of answers | ||
public int AmountOfAnswers { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the value of app setting | ||
/// </summary> | ||
/// <param name="key">The key.</param> | ||
/// <typeparam name="T">The return type</typeparam> | ||
/// <returns>The <see cref="T"/>.</returns> | ||
private T GetAppSetting<T>(string key, T defaultValue) | ||
{ | ||
var setting = ConfigurationManager.AppSettings[key]; | ||
|
||
if (setting != null) | ||
{ | ||
var attempConvert = setting.TryConvertTo<T>(); | ||
|
||
if (attempConvert.Success) | ||
{ | ||
return attempConvert.Result; | ||
} | ||
} | ||
|
||
return defaultValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters