Skip to content

Commit

Permalink
Merge pull request #309 from kmycode/develop
Browse files Browse the repository at this point in the history
v5.0.0-alpha
  • Loading branch information
kmycode authored May 21, 2024
2 parents ea08ed3 + 9e94a4e commit e58ec34
Show file tree
Hide file tree
Showing 236 changed files with 37,631 additions and 10,558 deletions.
3 changes: 0 additions & 3 deletions KmyKeiba.Data/Db/BornHorseData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ public class BornHorseData : DataBase<BornHorse>
[StringLength(40)]
public string InviteFrom { get; set; } = string.Empty;

[StringLength(10)]
public string ProducingCode { get; set; } = string.Empty;

[StringLength(10)]
public string OwnerCode { get; set; } = string.Empty;

Expand Down
1 change: 1 addition & 0 deletions KmyKeiba.Data/Db/CheckHorseData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class CheckHorseData : AppDataBase
public string Key { get; set; } = string.Empty;

[StringLength(20)]
[Obsolete("V5.0.0以降使わないが、データベースマイグレーションの関係で削除すると古いデータが残る可能性あり")]
public string Code { get; set; } = string.Empty;

public string Memo { get; set; } = string.Empty;
Expand Down
215 changes: 215 additions & 0 deletions KmyKeiba.Data/Db/DownloaderTaskData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -12,17 +13,228 @@ public class DownloaderTaskData : AppDataBase

public string Parameter { get; set; } = string.Empty;

public int Progress { get; set; }

public int ProgressMax { get; set; }

public bool IsFinished { get; set; }

public bool IsCanceled { get; set; }

public bool IsInterrupted { get; set; }

public bool IsStarted { get; set; }

public int ProcessId { get; set; }

public DownloaderError Error { get; set; }

public string Result { get; set; } = string.Empty;

public List<string> SkipFiles { get; } = new();

private static readonly string[] separators = ["\r\n", "\r", "\n"];

public static DownloaderTaskData? LoadFile(string filePath)
{
if (!File.Exists(filePath)) return null;

try
{
return FromString(File.ReadAllText(filePath));
}
catch (Exception ex)
{
throw new LoadDownloaderTaskDataException("タスクファイルの読み込みに失敗", ex);
}
}

public static void SaveFile(string filePath, DownloaderTaskData data)
{
try
{
File.WriteAllText(filePath, ToString(data));
}
catch (Exception ex)
{
throw new SaveDownloaderTaskDataException("タスクファイルへの書き込みに失敗", ex);
}
}

private static DownloaderTaskData FromString(string data)
{
var result = new DownloaderTaskData();

static bool ToBoolean(string val) => val.ToLower() == "true";

foreach (var pair in data
.Split(separators, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Select(l => l.Split('='))
.Where(l => l.Length == 2))
{
var key = pair[0];
var value = pair[1];

switch (key)
{
case "Command":
{
if (int.TryParse(value, out int command))
{
result.Command = (DownloaderCommand)command;
}
}
break;
case "Parameter":
result.Parameter = value;
break;
case "IsFinished":
result.IsFinished = ToBoolean(value);
break;
case "IsCanceled":
result.IsCanceled = ToBoolean(value);
break;
case "IsStarted":
result.IsStarted = ToBoolean(value);
break;
case "IsInterrupted":
result.IsInterrupted = ToBoolean(value);
break;
case "Progress":
{
if (int.TryParse(value, out int progress))
{
result.Progress = progress;
}
}
break;
case "ProgressMax":
{
if (int.TryParse(value, out int progressMax))
{
result.ProgressMax = progressMax;
}
}
break;
case "ProcessId":
{
if (int.TryParse(value, out int processId))
{
result.ProcessId = processId;
}
}
break;
case "Error":
{
if (int.TryParse(value, out int err))
{
result.Error = (DownloaderError)err;
}
}
break;
case "Result":
result.Result = value;
break;
case "SkipFiles":
result.SkipFiles.AddRange(value.Split(','));
break;
}
}

return result;
}

private static string ToString(DownloaderTaskData data) =>
$@"Command={(int)data.Command}
Parameter={data.Parameter}
IsFinished={data.IsFinished}
IsCanceled={data.IsCanceled}
IsInterrupted={data.IsInterrupted}
IsStarted={data.IsStarted}
Progress={data.Progress}
ProgressMax={data.ProgressMax}
ProcessId={data.ProcessId}
Error={(int)data.Error}
Result={data.Result}
SkipFiles={string.Join(',', data.SkipFiles)}";

public DownloadParameter GetDownloadParameter()
=> new DownloadParameter(this.Parameter);

public void SetDownloadParameter(DownloadParameter parameter)
{
this.Parameter = parameter.ToString();
}

public class DownloadParameter
{
public int StartYear { get; set; }

public int StartMonth { get; set; }

public LinkSoftware LinkSoftware { get; set; }

public string Mode { get; set; } = string.Empty;

public DownloadParameter(string parameter)
{
var parameters = parameter.Split(',');
if (parameters.Length <= 1) return;

int.TryParse(parameters[0], out var startYear);
this.StartYear = startYear;
if (parameters.Length == 1) return;

int.TryParse(parameters[1], out var startMonth);
this.StartMonth = startMonth;
if (parameters.Length == 2) return;

this.LinkSoftware = parameters[2] == "central" ? LinkSoftware.Central : LinkSoftware.Local;
if (parameters.Length == 3) return;

this.Mode = parameters[3];
if (parameters.Length == 4) return;
}

public override string ToString()
=> $"{this.StartYear},{this.StartMonth},{(this.LinkSoftware == LinkSoftware.Central ? "central" : "local")},{this.Mode}";
}
}

public enum LinkSoftware
{
Unknown = 0,
Central = 1,
Local = 2,
}

public class DownloaderTaskDataException : Exception
{
protected DownloaderTaskDataException(string message, Exception original) : base(message, original)
{
}

protected DownloaderTaskDataException(string message) : base(message)
{
}
}

public class LoadDownloaderTaskDataException : DownloaderTaskDataException
{
public LoadDownloaderTaskDataException(string message, Exception original) : base(message, original)
{
}
}

public class SaveDownloaderTaskDataException : DownloaderTaskDataException
{
public SaveDownloaderTaskDataException(string message, Exception original) : base(message, original)
{
}

public SaveDownloaderTaskDataException(string message) : base(message)
{
}
}

public enum DownloaderCommand : short
Expand Down Expand Up @@ -130,6 +342,9 @@ public enum DownloaderError : short

[DownloaderError("ダウンローダが異常停止しました")]
NotRunningDownloader = 20,

[DownloaderError("操作は中断されました")]
Interrupted = 21,
}

internal class DownloaderCommandAttribute : Attribute
Expand Down
80 changes: 80 additions & 0 deletions KmyKeiba.Data/Db/FinderColumnData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KmyKeiba.Data.Db
{
public class FinderColumnData : AppDataBase
{
public uint TabGroup { get; set; }

public uint Order { get; set; }

public FinderColumnProperty Property { get; set; }
}

public enum FinderColumnProperty : short
{
RaceSubject = 1,
RaceName = 2,
StartTime = 3,
Course = 4,
CourseInfo = 5,
HorseName = 6,
Popular = 7,
ResultOrder = 8,
ResultTime = 9,
After3HalongTime = 10,
RunningStyle = 11,
CornerOrders = 12,
RiderName = 13,
Before3HalongTime = 14,
Before3HalongTimeNormalized = 15,
Before4HalongTime = 16,
After4HalongTime = 17,
Pci = 18,
Rpci = 19,
Pci3 = 20,
SinglePayoff = 21,
FramePayoff = 22,
QuinellaPayoff = 23,
ExactaPayoff = 24,
TrioPayoff = 25,
TrifectaPayoff = 26,
LapTime1 = 27,
LapTime2 = 28,
LapTime3 = 29,
LapTime4 = 30,
LapTime5 = 31,
LapTime6 = 32,
LapTime7 = 33,
LapTime8 = 34,
LapTime9 = 35,
LapTime10 = 36,
LapTime11 = 37,
LapTime12 = 38,
LapTime13 = 39,
LapTime14 = 40,
LapTime15 = 41,
LapTime16 = 42,
LapTime17 = 43,
LapTime18 = 44,
Empty = 45,
HorseMark = 46,
Weight = 47,
WeightDiff = 48,
RiderWeight = 49,
Age = 50,
Sex = 51,
HorsesCount = 52,
Weather = 53,
Condition = 54,
GoalOrder = 55,
SingleOdds = 56,
PlaceOddsMin = 57,
PlaceOddsMax = 58,
RacePace = 59,
}
}
2 changes: 2 additions & 0 deletions KmyKeiba.Data/Db/FinderConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public class FinderConfigData : AppDataBase
public string Name { get; set; } = string.Empty;

public string Config { get; set; } = string.Empty;

public uint Order { get; set; }
}
}
2 changes: 1 addition & 1 deletion KmyKeiba.Data/Db/HorseData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace KmyKeiba.Data.Db
{
[Index(nameof(Code), nameof(MFBreedingCode))]
[Index(nameof(Code))]
public class HorseData : DataBase<Horse>
{
[StringLength(16)]
Expand Down
Loading

0 comments on commit e58ec34

Please sign in to comment.