mirror of https://github.com/ErsatzTV/ErsatzTV.git
31 changed files with 14120 additions and 73 deletions
@ -0,0 +1,36 @@ |
|||||||
|
using ErsatzTV.Core.Interfaces.Scheduling; |
||||||
|
using NCalc; |
||||||
|
|
||||||
|
namespace ErsatzTV.Core.Scheduling; |
||||||
|
|
||||||
|
public static class CountExpression |
||||||
|
{ |
||||||
|
public static int Evaluate( |
||||||
|
string countExpression, |
||||||
|
IMediaCollectionEnumerator enumerator, |
||||||
|
Random random, |
||||||
|
CancellationToken cancellationToken) |
||||||
|
{ |
||||||
|
int enumeratorCount = enumerator is PlaylistEnumerator playlistEnumerator |
||||||
|
? playlistEnumerator.CountForRandom |
||||||
|
: enumerator.Count; |
||||||
|
var expression = new Expression(countExpression); |
||||||
|
expression.EvaluateParameter += (name, e) => |
||||||
|
{ |
||||||
|
e.Result = name switch |
||||||
|
{ |
||||||
|
"count" => enumeratorCount, |
||||||
|
"random" => enumeratorCount > 0 ? random.Next() % enumeratorCount : 0, |
||||||
|
_ => e.Result |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
object expressionResult = expression.Evaluate(cancellationToken); |
||||||
|
return expressionResult switch |
||||||
|
{ |
||||||
|
double doubleResult => (int)Math.Floor(doubleResult), |
||||||
|
int intResult => intResult, |
||||||
|
_ => 0 |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,38 @@ |
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||||
|
|
||||||
|
#nullable disable |
||||||
|
|
||||||
|
namespace ErsatzTV.Infrastructure.MySql.Migrations |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Change_ProgramScheduleItemMultipleCountString : Migration |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.AlterColumn<string>( |
||||||
|
name: "Count", |
||||||
|
table: "ProgramScheduleMultipleItem", |
||||||
|
type: "longtext", |
||||||
|
nullable: true, |
||||||
|
oldClrType: typeof(int), |
||||||
|
oldType: "int") |
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"); |
||||||
|
} |
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.AlterColumn<int>( |
||||||
|
name: "Count", |
||||||
|
table: "ProgramScheduleMultipleItem", |
||||||
|
type: "int", |
||||||
|
nullable: false, |
||||||
|
defaultValue: 0, |
||||||
|
oldClrType: typeof(string), |
||||||
|
oldType: "longtext", |
||||||
|
oldNullable: true) |
||||||
|
.OldAnnotation("MySql:CharSet", "utf8mb4"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,36 @@ |
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||||
|
|
||||||
|
#nullable disable |
||||||
|
|
||||||
|
namespace ErsatzTV.Infrastructure.Sqlite.Migrations |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Change_ProgramScheduleItemMultipleCountString : Migration |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.AlterColumn<string>( |
||||||
|
name: "Count", |
||||||
|
table: "ProgramScheduleMultipleItem", |
||||||
|
type: "TEXT", |
||||||
|
nullable: true, |
||||||
|
oldClrType: typeof(int), |
||||||
|
oldType: "INTEGER"); |
||||||
|
} |
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.AlterColumn<int>( |
||||||
|
name: "Count", |
||||||
|
table: "ProgramScheduleMultipleItem", |
||||||
|
type: "INTEGER", |
||||||
|
nullable: false, |
||||||
|
defaultValue: 0, |
||||||
|
oldClrType: typeof(string), |
||||||
|
oldType: "TEXT", |
||||||
|
oldNullable: true); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue