-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly bind link uri command to package quality control option; re…
…factor SIPackages
- Loading branch information
1 parent
5ebee7a
commit 9c6f488
Showing
52 changed files
with
887 additions
and
1,152 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
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
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,32 @@ | ||
namespace SIPackages.Helpers; | ||
|
||
internal static class InfoOwnerExtensions | ||
{ | ||
/// <summary> | ||
/// Copies info from source object. | ||
/// </summary> | ||
/// <param name="target">Target object.</param> | ||
/// <param name="infoOwner">Source object.</param> | ||
internal static void SetInfoFromOwner(this InfoOwner target, InfoOwner infoOwner) | ||
{ | ||
foreach (string s in infoOwner.Info.Authors) | ||
{ | ||
target.Info.Authors.Add(s); | ||
} | ||
|
||
foreach (string s in infoOwner.Info.Sources) | ||
{ | ||
target.Info.Sources.Add(s); | ||
} | ||
|
||
target.Info.Comments.Text = infoOwner.Info.Comments.Text; | ||
|
||
if (infoOwner.Info.ShowmanComments != null) | ||
{ | ||
target.Info.ShowmanComments ??= new Comments(); | ||
target.Info.ShowmanComments.Text = infoOwner.Info.ShowmanComments.Text; | ||
} | ||
|
||
target.Info.Extension = infoOwner.Info.Extension; | ||
} | ||
} |
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,25 @@ | ||
namespace SIPackages.Helpers; | ||
|
||
/// <summary> | ||
/// Provides package helper methods. | ||
/// </summary> | ||
public static class PackageExtensions | ||
{ | ||
/// <summary> | ||
/// Creates a new round. | ||
/// </summary> | ||
/// <param name="package">Package.</param> | ||
/// <param name="type">Round type.</param> | ||
/// <param name="name">Round name.</param> | ||
public static Round CreateRound(this Package package, string type, string? name) | ||
{ | ||
var round = new Round | ||
{ | ||
Name = name ?? (package.Rounds.Count + 1).ToString(), | ||
Type = type | ||
}; | ||
|
||
package.Rounds.Add(round); | ||
return round; | ||
} | ||
} |
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,19 @@ | ||
namespace SIPackages.Helpers; | ||
|
||
/// <summary> | ||
/// Provides extension methods for rounds. | ||
/// </summary> | ||
public static class RoundExtensions | ||
{ | ||
/// <summary> | ||
/// Creates a new theme. | ||
/// </summary> | ||
/// <param name="round">Round.</param> | ||
/// <param name="name">Theme name.</param> | ||
public static Theme CreateTheme(this Round round, string? name) | ||
{ | ||
var theme = new Theme { Name = name ?? "" }; | ||
round.Themes.Add(theme); | ||
return theme; | ||
} | ||
} |
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,70 @@ | ||
using SIPackages.Core; | ||
|
||
namespace SIPackages.Helpers; | ||
|
||
/// <summary> | ||
/// Provides extension methods for the <see cref="Theme"/> class. | ||
/// </summary> | ||
public static class ThemeExtensions | ||
{ | ||
/// <summary> | ||
/// Creates a new question in the theme. | ||
/// </summary> | ||
/// <param name="theme">Theme.</param> | ||
/// <param name="price">Question price.</param> | ||
/// <param name="isFinal">Does the question belong to the final round.</param> | ||
/// <param name="text">Question text.</param> | ||
public static Question CreateQuestion(this Theme theme, int price = -1, bool isFinal = false, string text = "") | ||
{ | ||
int qPrice = DetectQuestionPrice(theme, price, isFinal); | ||
|
||
var quest = new Question | ||
{ | ||
Price = qPrice | ||
}; | ||
|
||
quest.Parameters[QuestionParameterNames.Question] = new StepParameter | ||
{ | ||
Type = StepParameterTypes.Content, | ||
ContentValue = new List<ContentItem> | ||
{ | ||
new() { Type = ContentTypes.Text, Value = text }, | ||
} | ||
}; | ||
|
||
quest.Right.Add(""); | ||
theme.Questions.Add(quest); | ||
|
||
return quest; | ||
} | ||
|
||
private static int DetectQuestionPrice(Theme theme, int price, bool isFinal) | ||
{ | ||
if (price != -1) | ||
{ | ||
return price; | ||
} | ||
|
||
var validQuestions = theme.Questions.Where(q => q.Price != Question.InvalidPrice).ToList(); | ||
|
||
var questionCount = validQuestions.Count; | ||
|
||
if (questionCount > 1) | ||
{ | ||
var stepValue = validQuestions[1].Price - validQuestions[0].Price; | ||
return Math.Max(0, validQuestions[questionCount - 1].Price + stepValue); | ||
} | ||
|
||
if (questionCount > 0) | ||
{ | ||
return validQuestions[0].Price * 2; | ||
} | ||
|
||
if (isFinal) | ||
{ | ||
return 0; | ||
} | ||
|
||
return 100; | ||
} | ||
} |
Oops, something went wrong.