1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
using System;
using System.Diagnostics.CodeAnalysis;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using StardewModdingAPI.Toolkit.Framework.UpdateData;
using StardewModdingAPI.Web.Framework.ModRepositories;
namespace StardewModdingAPI.Web.Framework.Caching.Mods
{
/// <summary>The model for cached mod data.</summary>
internal class CachedMod
{
/*********
** Accessors
*********/
/****
** Tracking
****/
/// <summary>The internal MongoDB ID.</summary>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Named per MongoDB conventions.")]
[BsonIgnoreIfDefault]
public ObjectId _id { get; set; }
/// <summary>When the data was last updated.</summary>
public DateTimeOffset LastUpdated { get; set; }
/// <summary>When the data was last requested through the web API.</summary>
public DateTimeOffset LastRequested { get; set; }
/****
** Metadata
****/
/// <summary>The mod site on which the mod is found.</summary>
public ModRepositoryKey Site { get; set; }
/// <summary>The mod's unique ID within the <see cref="Site"/>.</summary>
public string ID { get; set; }
/// <summary>The mod availability status on the remote site.</summary>
public RemoteModStatus FetchStatus { get; set; }
/// <summary>The error message providing more info for the <see cref="FetchStatus"/>, if applicable.</summary>
public string FetchError { get; set; }
/****
** Mod info
****/
/// <summary>The mod's display name.</summary>
public string Name { get; set; }
/// <summary>The mod's latest version.</summary>
public string MainVersion { get; set; }
/// <summary>The mod's latest optional or prerelease version, if newer than <see cref="MainVersion"/>.</summary>
public string PreviewVersion { get; set; }
/// <summary>The URL for the mod page.</summary>
public string Url { get; set; }
/// <summary>The license URL, if available.</summary>
public string LicenseUrl { get; set; }
/// <summary>The license name, if available.</summary>
public string LicenseName { get; set; }
/*********
** Accessors
*********/
/// <summary>Construct an instance.</summary>
public CachedMod() { }
/// <summary>Construct an instance.</summary>
/// <param name="site">The mod site on which the mod is found.</param>
/// <param name="id">The mod's unique ID within the <paramref name="site"/>.</param>
/// <param name="mod">The mod data.</param>
public CachedMod(ModRepositoryKey site, string id, ModInfoModel mod)
{
// tracking
this.LastUpdated = DateTimeOffset.UtcNow;
this.LastRequested = DateTimeOffset.UtcNow;
// metadata
this.Site = site;
this.ID = id;
this.FetchStatus = mod.Status;
this.FetchError = mod.Error;
// mod info
this.Name = mod.Name;
this.MainVersion = mod.Version;
this.PreviewVersion = mod.PreviewVersion;
this.Url = mod.Url;
this.LicenseUrl = mod.LicenseUrl;
this.LicenseName = mod.LicenseName;
}
/// <summary>Get the API model for the cached data.</summary>
public ModInfoModel GetModel()
{
return new ModInfoModel(name: this.Name, version: this.MainVersion, url: this.Url, previewVersion: this.PreviewVersion)
.SetLicense(this.LicenseUrl, this.LicenseName)
.SetError(this.FetchStatus, this.FetchError);
}
}
}
|