From 1531151259d2475ae556bc899eb2c70847909c97 Mon Sep 17 00:00:00 2001 From: Thomas Hounsell Date: Sun, 21 Aug 2016 00:09:56 +0100 Subject: [PATCH] Rename Model Classes; HTTP2 push; New date index --- BuildFeed.Model/Build-Group.cs | 42 +-- BuildFeed.Model/Build-Lab.cs | 18 +- BuildFeed.Model/Build-Source.cs | 8 +- BuildFeed.Model/Build-Version.cs | 22 +- BuildFeed.Model/Build-Year.cs | 20 +- BuildFeed.Model/Build.cs | 368 +++++++++------------ BuildFeed.Model/BuildFeed.Model.csproj | 4 +- BuildFeed.Model/BuildModel.cs | 197 ----------- BuildFeed.Model/BuildRepository.cs | 254 ++++++++++++++ BuildFeed.Model/MetaItem.cs | 4 +- BuildFeed.Model/MongoConfig.cs | 2 +- BuildFeed.Model/View/FrontPage.cs | 6 +- BuildFeed/Controllers/apiController.cs | 18 +- BuildFeed/Controllers/frontController.cs | 32 +- BuildFeed/Controllers/rssController.cs | 14 +- BuildFeed/Controllers/supportController.cs | 8 +- BuildFeed/Views/front/editBuild.cshtml | 2 +- BuildFeed/Views/front/viewBuild.cshtml | 2 +- BuildFeed/Views/front/viewGroup.cshtml | 4 +- BuildFeed/Views/front/viewLab.cshtml | 4 +- BuildFeed/Views/front/viewSource.cshtml | 4 +- BuildFeed/Views/front/viewVersion.cshtml | 4 +- BuildFeed/Views/front/viewYear.cshtml | 4 +- BuildFeed/Views/shared/_default.cshtml | 11 +- 24 files changed, 528 insertions(+), 524 deletions(-) delete mode 100644 BuildFeed.Model/BuildModel.cs create mode 100644 BuildFeed.Model/BuildRepository.cs diff --git a/BuildFeed.Model/Build-Group.cs b/BuildFeed.Model/Build-Group.cs index 6965bf0..cbbacb7 100644 --- a/BuildFeed.Model/Build-Group.cs +++ b/BuildFeed.Model/Build-Group.cs @@ -7,7 +7,7 @@ namespace BuildFeed.Model { - public partial class Build + public partial class BuildRepository { public async Task SelectAllGroups(int limit = -1, int skip = 0) { @@ -16,12 +16,12 @@ public async Task SelectAllGroups(int limit = -1, int skip = new BsonElement("_id", new BsonDocument { - new BsonElement(nameof(BuildGroup.Major), $"${nameof(BuildModel.MajorVersion)}"), - new BsonElement(nameof(BuildGroup.Minor), $"${nameof(BuildModel.MinorVersion)}"), - new BsonElement(nameof(BuildGroup.Build), $"${nameof(BuildModel.Number)}"), - new BsonElement(nameof(BuildGroup.Revision), $"${nameof(BuildModel.Revision)}") + new BsonElement(nameof(BuildGroup.Major), $"${nameof(Build.MajorVersion)}"), + new BsonElement(nameof(BuildGroup.Minor), $"${nameof(Build.MinorVersion)}"), + new BsonElement(nameof(BuildGroup.Build), $"${nameof(Build.Number)}"), + new BsonElement(nameof(BuildGroup.Revision), $"${nameof(Build.Revision)}") }), - new BsonElement("date", new BsonDocument("$max", $"${nameof(BuildModel.BuildTime)}")), + new BsonElement("date", new BsonDocument("$max", $"${nameof(Build.BuildTime)}")), new BsonElement("count", new BsonDocument("$sum", 1)) }).Sort(new BsonDocument { @@ -60,26 +60,26 @@ public async Task SelectAllGroupsCount() new BsonElement("_id", new BsonDocument { - new BsonElement(nameof(BuildGroup.Major), $"${nameof(BuildModel.MajorVersion)}"), - new BsonElement(nameof(BuildGroup.Minor), $"${nameof(BuildModel.MinorVersion)}"), - new BsonElement(nameof(BuildGroup.Build), $"${nameof(BuildModel.Number)}"), - new BsonElement(nameof(BuildGroup.Revision), $"${nameof(BuildModel.Revision)}") + new BsonElement(nameof(BuildGroup.Major), $"${nameof(Build.MajorVersion)}"), + new BsonElement(nameof(BuildGroup.Minor), $"${nameof(Build.MinorVersion)}"), + new BsonElement(nameof(BuildGroup.Build), $"${nameof(Build.Number)}"), + new BsonElement(nameof(BuildGroup.Revision), $"${nameof(Build.Revision)}") }) }).ToListAsync(); return grouping.Count; } - public async Task> SelectGroup(BuildGroup group, int limit = -1, int skip = 0) + public async Task> SelectGroup(BuildGroup group, int limit = -1, int skip = 0) { - IFindFluent query = _buildCollection.Find(new BsonDocument + IFindFluent query = _buildCollection.Find(new BsonDocument { - new BsonElement(nameof(BuildModel.MajorVersion), group.Major), - new BsonElement(nameof(BuildModel.MinorVersion), group.Minor), - new BsonElement(nameof(BuildModel.Number), group.Build), - new BsonElement(nameof(BuildModel.Revision), group.Revision) + new BsonElement(nameof(Build.MajorVersion), group.Major), + new BsonElement(nameof(Build.MinorVersion), group.Minor), + new BsonElement(nameof(Build.Number), group.Build), + new BsonElement(nameof(Build.Revision), group.Revision) }).Sort(new BsonDocument { - new BsonElement(nameof(BuildModel.BuildTime), 1) + new BsonElement(nameof(Build.BuildTime), 1) }).Skip(skip); if (limit > 0) @@ -92,10 +92,10 @@ public async Task> SelectGroup(BuildGroup group, int limit = -1 public async Task SelectGroupCount(BuildGroup group) => await _buildCollection.CountAsync(new BsonDocument { - new BsonElement(nameof(BuildModel.MajorVersion), @group.Major), - new BsonElement(nameof(BuildModel.MinorVersion), @group.Minor), - new BsonElement(nameof(BuildModel.Number), @group.Build), - new BsonElement(nameof(BuildModel.Revision), @group.Revision) + new BsonElement(nameof(Build.MajorVersion), @group.Major), + new BsonElement(nameof(Build.MinorVersion), @group.Minor), + new BsonElement(nameof(Build.Number), @group.Build), + new BsonElement(nameof(Build.Revision), @group.Revision) }); } } \ No newline at end of file diff --git a/BuildFeed.Model/Build-Lab.cs b/BuildFeed.Model/Build-Lab.cs index 23b2250..b1399d0 100644 --- a/BuildFeed.Model/Build-Lab.cs +++ b/BuildFeed.Model/Build-Lab.cs @@ -7,11 +7,11 @@ namespace BuildFeed.Model { - public partial class Build + public partial class BuildRepository { public async Task SelectAllLabs(int limit = -1, int skip = 0) { - IAggregateFluent query = _buildCollection.Aggregate().Group(new BsonDocument("_id", $"${nameof(BuildModel.Lab)}")).Sort(new BsonDocument("_id", 1)).Skip(skip); + IAggregateFluent query = _buildCollection.Aggregate().Group(new BsonDocument("_id", $"${nameof(Build.Lab)}")).Sort(new BsonDocument("_id", 1)).Skip(skip); if (limit > 0) { @@ -29,9 +29,9 @@ public async Task SelectLabsForVersion(int major, int minor) { IAggregateFluent query = _buildCollection.Aggregate().Match(new BsonDocument { - new BsonElement(nameof(BuildModel.MajorVersion), major), - new BsonElement(nameof(BuildModel.MinorVersion), minor) - }).Group(new BsonDocument("_id", $"${nameof(BuildModel.Lab)}")).Sort(new BsonDocument("_id", 1)); + new BsonElement(nameof(Build.MajorVersion), major), + new BsonElement(nameof(Build.MinorVersion), minor) + }).Group(new BsonDocument("_id", $"${nameof(Build.Lab)}")).Sort(new BsonDocument("_id", 1)); List grouping = await query.ToListAsync(); @@ -52,16 +52,16 @@ public async Task> SearchLabs(string search) public async Task SelectAllLabsCount() { - IAggregateFluent query = _buildCollection.Aggregate().Group(new BsonDocument("_id", new BsonDocument(nameof(BuildModel.Lab), $"${nameof(BuildModel.Lab)}"))).Sort(new BsonDocument("_id", 1)); + IAggregateFluent query = _buildCollection.Aggregate().Group(new BsonDocument("_id", new BsonDocument(nameof(Build.Lab), $"${nameof(Build.Lab)}"))).Sort(new BsonDocument("_id", 1)); List grouping = await query.ToListAsync(); return grouping.Count; } - public async Task> SelectLab(string lab, int limit = -1, int skip = 0) + public async Task> SelectLab(string lab, int limit = -1, int skip = 0) { - IFindFluent query = _buildCollection.Find(new BsonDocument(nameof(BuildModel.LabUrl), lab)).Sort(sortByCompileDate).Skip(skip); + IFindFluent query = _buildCollection.Find(new BsonDocument(nameof(Build.LabUrl), lab)).Sort(sortByCompileDate).Skip(skip); if (limit > 0) { @@ -71,6 +71,6 @@ public async Task> SelectLab(string lab, int limit = -1, int sk return await query.ToListAsync(); } - public async Task SelectLabCount(string lab) => await _buildCollection.CountAsync(new BsonDocument(nameof(BuildModel.LabUrl), lab)); + public async Task SelectLabCount(string lab) => await _buildCollection.CountAsync(new BsonDocument(nameof(Build.LabUrl), lab)); } } \ No newline at end of file diff --git a/BuildFeed.Model/Build-Source.cs b/BuildFeed.Model/Build-Source.cs index 29ad5fa..5ab73fe 100644 --- a/BuildFeed.Model/Build-Source.cs +++ b/BuildFeed.Model/Build-Source.cs @@ -6,15 +6,15 @@ namespace BuildFeed.Model { - public partial class Build + public partial class BuildRepository { public Task SelectAllSources(int limit = -1, int skip = 0) => Task.Run(() => Enum.GetValues(typeof(TypeOfSource)) as TypeOfSource[]); public Task SelectAllSourcesCount() => Task.Run(() => Enum.GetValues(typeof(TypeOfSource)).LongLength); - public async Task> SelectSource(TypeOfSource source, int limit = -1, int skip = 0) + public async Task> SelectSource(TypeOfSource source, int limit = -1, int skip = 0) { - IFindFluent query = _buildCollection.Find(new BsonDocument(nameof(BuildModel.SourceType), source)).Sort(sortByOrder).Skip(skip); + IFindFluent query = _buildCollection.Find(new BsonDocument(nameof(Build.SourceType), source)).Sort(sortByOrder).Skip(skip); if (limit > 0) { @@ -24,6 +24,6 @@ public async Task> SelectSource(TypeOfSource source, int limit return await query.ToListAsync(); } - public async Task SelectSourceCount(TypeOfSource source) => await _buildCollection.CountAsync(new BsonDocument(nameof(BuildModel.SourceType), source)); + public async Task SelectSourceCount(TypeOfSource source) => await _buildCollection.CountAsync(new BsonDocument(nameof(Build.SourceType), source)); } } \ No newline at end of file diff --git a/BuildFeed.Model/Build-Version.cs b/BuildFeed.Model/Build-Version.cs index 63ab60e..3d44b98 100644 --- a/BuildFeed.Model/Build-Version.cs +++ b/BuildFeed.Model/Build-Version.cs @@ -6,15 +6,15 @@ namespace BuildFeed.Model { - public partial class Build + public partial class BuildRepository { public async Task SelectAllVersions(int limit = -1, int skip = 0) { IAggregateFluent query = _buildCollection.Aggregate().Group(new BsonDocument("_id", new BsonDocument { - new BsonElement(nameof(BuildVersion.Major), $"${nameof(BuildModel.MajorVersion)}"), - new BsonElement(nameof(BuildVersion.Minor), $"${nameof(BuildModel.MinorVersion)}") + new BsonElement(nameof(BuildVersion.Major), $"${nameof(Build.MajorVersion)}"), + new BsonElement(nameof(BuildVersion.Minor), $"${nameof(Build.MinorVersion)}") })).Sort(new BsonDocument { new BsonElement($"_id.{nameof(BuildVersion.Major)}", -1), @@ -41,18 +41,18 @@ public async Task SelectAllVersionsCount() List query = await _buildCollection.Aggregate().Group(new BsonDocument("_id", new BsonDocument { - new BsonElement(nameof(BuildVersion.Major), $"${nameof(BuildModel.MajorVersion)}"), - new BsonElement(nameof(BuildVersion.Minor), $"${nameof(BuildModel.MinorVersion)}") + new BsonElement(nameof(BuildVersion.Major), $"${nameof(Build.MajorVersion)}"), + new BsonElement(nameof(BuildVersion.Minor), $"${nameof(Build.MinorVersion)}") })).ToListAsync(); return query.Count; } - public async Task> SelectVersion(uint major, uint minor, int limit = -1, int skip = 0) + public async Task> SelectVersion(uint major, uint minor, int limit = -1, int skip = 0) { - IFindFluent query = _buildCollection.Find(new BsonDocument + IFindFluent query = _buildCollection.Find(new BsonDocument { - new BsonElement(nameof(BuildModel.MajorVersion), major), - new BsonElement(nameof(BuildModel.MinorVersion), minor) + new BsonElement(nameof(Build.MajorVersion), major), + new BsonElement(nameof(Build.MinorVersion), minor) }).Sort(sortByOrder).Skip(skip); if (limit > 0) @@ -65,8 +65,8 @@ public async Task> SelectVersion(uint major, uint minor, int li public async Task SelectVersionCount(uint major, uint minor) => await _buildCollection.CountAsync(new BsonDocument { - new BsonElement(nameof(BuildModel.MajorVersion), major), - new BsonElement(nameof(BuildModel.MinorVersion), minor) + new BsonElement(nameof(Build.MajorVersion), major), + new BsonElement(nameof(Build.MinorVersion), minor) }); } } \ No newline at end of file diff --git a/BuildFeed.Model/Build-Year.cs b/BuildFeed.Model/Build-Year.cs index b312b97..3b1b4c3 100644 --- a/BuildFeed.Model/Build-Year.cs +++ b/BuildFeed.Model/Build-Year.cs @@ -7,14 +7,14 @@ namespace BuildFeed.Model { - public partial class Build + public partial class BuildRepository { public async Task SelectAllYears(int limit = -1, int skip = 0) { IAggregateFluent query = _buildCollection.Aggregate() - .Match(Builders.Filter.Ne(b => b.BuildTime, null)) - .Group(new BsonDocument("_id", new BsonDocument("$year", $"${nameof(BuildModel.BuildTime)}"))) + .Match(Builders.Filter.Ne(b => b.BuildTime, null)) + .Group(new BsonDocument("_id", new BsonDocument("$year", $"${nameof(Build.BuildTime)}"))) .Sort(new BsonDocument("_id", -1)) .Skip(skip); @@ -32,16 +32,16 @@ public async Task SelectAllYears(int limit = -1, int skip = 0) public async Task SelectAllYearsCount() { - List query = await _buildCollection.Aggregate().Match(Builders.Filter.Ne(b => b.BuildTime, null)).Group(new BsonDocument("_id", new BsonDocument("$year", $"${nameof(BuildModel.BuildTime)}"))).ToListAsync(); + List query = await _buildCollection.Aggregate().Match(Builders.Filter.Ne(b => b.BuildTime, null)).Group(new BsonDocument("_id", new BsonDocument("$year", $"${nameof(Build.BuildTime)}"))).ToListAsync(); return query.Count; } - public async Task> SelectYear(int year, int limit = -1, int skip = 0) + public async Task> SelectYear(int year, int limit = -1, int skip = 0) { - IFindFluent query = - _buildCollection.Find(Builders.Filter.And(Builders.Filter.Gte(b => b.BuildTime, new DateTime(year, 1, 1, 0, 0, 0, DateTimeKind.Utc)), - Builders.Filter.Lte(b => b.BuildTime, new DateTime(year, 12, 31, 23, 59, 59, DateTimeKind.Utc)))).Sort(sortByCompileDate).Skip(skip); + IFindFluent query = + _buildCollection.Find(Builders.Filter.And(Builders.Filter.Gte(b => b.BuildTime, new DateTime(year, 1, 1, 0, 0, 0, DateTimeKind.Utc)), + Builders.Filter.Lte(b => b.BuildTime, new DateTime(year, 12, 31, 23, 59, 59, DateTimeKind.Utc)))).Sort(sortByCompileDate).Skip(skip); if (limit > 0) { @@ -54,7 +54,7 @@ public async Task> SelectYear(int year, int limit = -1, int ski public async Task SelectYearCount(int year) => await - _buildCollection.CountAsync(Builders.Filter.And(Builders.Filter.Gte(b => b.BuildTime, new DateTime(year, 1, 1, 0, 0, 0, DateTimeKind.Utc)), - Builders.Filter.Lte(b => b.BuildTime, new DateTime(year, 12, 31, 23, 59, 59, DateTimeKind.Utc)))); + _buildCollection.CountAsync(Builders.Filter.And(Builders.Filter.Gte(b => b.BuildTime, new DateTime(year, 1, 1, 0, 0, 0, DateTimeKind.Utc)), + Builders.Filter.Lte(b => b.BuildTime, new DateTime(year, 12, 31, 23, 59, 59, DateTimeKind.Utc)))); } } \ No newline at end of file diff --git a/BuildFeed.Model/Build.cs b/BuildFeed.Model/Build.cs index d88a1d2..3ab3823 100644 --- a/BuildFeed.Model/Build.cs +++ b/BuildFeed.Model/Build.cs @@ -1,249 +1,187 @@ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Configuration; -using System.Linq; -using System.Threading.Tasks; -using BuildFeed.Model.View; -using MongoDB.Bson; -using MongoDB.Driver; +using System.ComponentModel.DataAnnotations; +using System.Globalization; +using System.Text; +using System.Web.Mvc; +using BuildFeed.Local; +using HtmlAgilityPack; +using MongoDB.Bson.Serialization.Attributes; +using Required = System.ComponentModel.DataAnnotations.RequiredAttribute; namespace BuildFeed.Model { - public partial class Build + [DataObject, BsonIgnoreExtraElements] + public class Build { - private const string BUILD_COLLECTION_NAME = "builds"; - private static readonly BsonDocument sortByAddedDate = new BsonDocument(nameof(BuildModel.Added), -1); - private static readonly BsonDocument sortByCompileDate = new BsonDocument(nameof(BuildModel.BuildTime), -1); - private static readonly BsonDocument sortByLeakedDate = new BsonDocument(nameof(BuildModel.LeakDate), -1); + [Key, BsonId] + public Guid Id { get; set; } - private static readonly BsonDocument sortByOrder = new BsonDocument + public long? LegacyId { get; set; } + + [@Required] + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MajorVersion))] + public uint MajorVersion { get; set; } + + [@Required] + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MinorVersion))] + public uint MinorVersion { get; set; } + + [@Required] + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildNumber))] + public uint Number { get; set; } + + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Revision))] + [DisplayFormat(ConvertEmptyStringToNull = true)] + public uint? Revision { get; set; } + + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LabString))] + public string Lab { get; set; } + + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildTime))] + [DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true, DataFormatString = "{0:yyMMdd-HHmm}")] + public DateTime? BuildTime { get; set; } + + + [@Required] + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Added))] + public DateTime Added { get; set; } + + [@Required] + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Modified))] + public DateTime Modified { get; set; } + + [@Required] + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceType))] + [EnumDataType(typeof(TypeOfSource))] + public TypeOfSource SourceType { get; set; } + + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceDetails))] + [AllowHtml] + public string SourceDetails { get; set; } + + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LeakDate))] + [DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true)] + public DateTime? LeakDate { get; set; } + + public string LabUrl { get; set; } + + public bool IsLeaked => SourceType == TypeOfSource.PublicRelease || SourceType == TypeOfSource.InternalLeak || SourceType == TypeOfSource.UpdateGDR || SourceType == TypeOfSource.UpdateLDR; + + public string FullBuildString { - new BsonElement(nameof(BuildModel.MajorVersion), -1), - new BsonElement(nameof(BuildModel.MinorVersion), -1), - new BsonElement(nameof(BuildModel.Number), -1), - new BsonElement(nameof(BuildModel.Revision), -1), - new BsonElement(nameof(BuildModel.BuildTime), -1) - }; - - private readonly IMongoCollection _buildCollection; - private readonly IMongoDatabase _buildDatabase; - private readonly MongoClient _dbClient; - - public Build() - { - _dbClient = new MongoClient(new MongoClientSettings + get { - Server = new MongoServerAddress(MongoConfig.Host, MongoConfig.Port) - }); + StringBuilder sb = new StringBuilder(); + sb.Append($"{MajorVersion}.{MinorVersion}.{Number}"); - _buildDatabase = _dbClient.GetDatabase(MongoConfig.Database); - _buildCollection = _buildDatabase.GetCollection(BUILD_COLLECTION_NAME); - } - - public async Task SetupIndexes() - { - List indexes = await (await _buildCollection.Indexes.ListAsync()).ToListAsync(); - if (indexes.All(i => i["name"] != "_idx_group")) - { - await - _buildCollection.Indexes.CreateOneAsync( - Builders.IndexKeys.Combine(Builders.IndexKeys.Descending(b => b.MajorVersion), - Builders.IndexKeys.Descending(b => b.MinorVersion), - Builders.IndexKeys.Descending(b => b.Number), - Builders.IndexKeys.Descending(b => b.Revision)), - new CreateIndexOptions - { - Name = "_idx_group" - }); - } - - if (indexes.All(i => i["name"] != "_idx_legacy")) - { - await _buildCollection.Indexes.CreateOneAsync(Builders.IndexKeys.Ascending(b => b.LegacyId), - new CreateIndexOptions - { - Name = "_idx_legacy" - }); - } - - if (indexes.All(i => i["name"] != "_idx_lab")) - { - await _buildCollection.Indexes.CreateOneAsync(Builders.IndexKeys.Ascending(b => b.Lab), - new CreateIndexOptions - { - Name = "_idx_lab" - }); - } - } - - [DataObjectMethod(DataObjectMethodType.Select, true)] - public async Task> Select() => await _buildCollection.Find(new BsonDocument()).ToListAsync(); - - [DataObjectMethod(DataObjectMethodType.Select, false)] - public async Task SelectById(Guid id) => await _buildCollection.Find(Builders.Filter.Eq(b => b.Id, id)).SingleOrDefaultAsync(); - - [DataObjectMethod(DataObjectMethodType.Select, false)] - public async Task SelectByLegacyId(long id) => await _buildCollection.Find(Builders.Filter.Eq(b => b.LegacyId, id)).SingleOrDefaultAsync(); - - [DataObjectMethod(DataObjectMethodType.Select, false)] - public async Task> SelectBuildsByOrder(int limit = -1, int skip = 0) - { - IFindFluent query = _buildCollection.Find(new BsonDocument()).Sort(sortByOrder).Skip(skip); - - if (limit > 0) - { - query = query.Limit(limit); - } - - return await query.ToListAsync(); - } - - [DataObjectMethod(DataObjectMethodType.Select, false)] - public async Task SelectFrontPage() - { - FrontPage fp = new FrontPage(); - - IFindFluent query = _buildCollection.Find(new BsonDocument - { + if (Revision.HasValue) { - nameof(BuildModel.LabUrl), new BsonDocument - { - { "$in", new BsonArray(ConfigurationManager.AppSettings["site:OSGLab"].Split(';')) } - } + sb.Append($".{Revision}"); } - }).Sort(sortByCompileDate).Limit(1); - fp.CurrentCanary = await query.FirstOrDefaultAsync(); - - query = _buildCollection.Find(new BsonDocument - { + if (!string.IsNullOrWhiteSpace(Lab)) { - nameof(BuildModel.LabUrl), new BsonDocument - { - { "$in", new BsonArray(ConfigurationManager.AppSettings["site:InsiderLab"].Split(';')) } - } - }, - { - nameof(BuildModel.SourceType), new BsonDocument - { - { - "$in", new BsonArray - { - TypeOfSource.PublicRelease, - TypeOfSource.UpdateGDR - } - } - } + sb.Append($".{Lab}"); } - }).Sort(sortByCompileDate).Limit(1); - fp.CurrentInsider = await query.FirstOrDefaultAsync(); - - query = _buildCollection.Find(new BsonDocument - { + if (BuildTime.HasValue) { - nameof(BuildModel.LabUrl), new BsonDocument - { - { "$in", new BsonArray(ConfigurationManager.AppSettings["site:ReleaseLab"].Split(';')) } - } - }, - { - nameof(BuildModel.SourceType), new BsonDocument - { - { - "$in", new BsonArray - { - TypeOfSource.PublicRelease, - TypeOfSource.UpdateGDR - } - } - } + sb.Append($".{BuildTime.Value.ToString("yyMMdd-HHmm", CultureInfo.InvariantCulture.DateTimeFormat)}"); } - }).Sort(sortByCompileDate).Limit(1); - fp.CurrentRelease = await query.FirstOrDefaultAsync(); - - return fp; - } - - [DataObjectMethod(DataObjectMethodType.Select, false)] - public async Task> SelectBuildsByCompileDate(int limit = -1, int skip = 0) - { - IFindFluent query = _buildCollection.Find(new BsonDocument()).Sort(sortByCompileDate).Skip(skip); - - if (limit > 0) - { - query = query.Limit(limit); + return sb.ToString(); } - - return await query.ToListAsync(); } - [DataObjectMethod(DataObjectMethodType.Select, false)] - public async Task> SelectBuildsByAddedDate(int limit = -1, int skip = 0) + public ProjectFamily Family { - IFindFluent query = _buildCollection.Find(new BsonDocument()).Sort(sortByAddedDate).Skip(skip); - - if (limit > 0) + get { - query = query.Limit(limit); + if (Number >= 14800) + { + return ProjectFamily.Redstone2; + } + if (Number >= 11000) + { + return ProjectFamily.Redstone; + } + if (Number >= 10500) + { + return ProjectFamily.Threshold2; + } + if (Number >= 9700) + { + return ProjectFamily.Threshold; + } + if (Number >= 9250) + { + return ProjectFamily.Windows81; + } + if (Number >= 7650) + { + return ProjectFamily.Windows8; + } + if (Number >= 6020) + { + return ProjectFamily.Windows7; + } + if (MajorVersion == 6 + && Number >= 5000) + { + return ProjectFamily.WindowsVista; + } + if (MajorVersion == 6) + { + return ProjectFamily.Longhorn; + } + if (MajorVersion == 5 + && Number >= 3000) + { + return ProjectFamily.Server2003; + } + if (MajorVersion == 5 + && Number >= 2205) + { + return ProjectFamily.WindowsXP; + } + if (MajorVersion == 5 + && MinorVersion == 50) + { + return ProjectFamily.Neptune; + } + if (MajorVersion == 5) + { + return ProjectFamily.Windows2000; + } + return ProjectFamily.None; } - - return await query.ToListAsync(); } - [DataObjectMethod(DataObjectMethodType.Select, false)] - public async Task> SelectBuildsByLeakedDate(int limit = -1, int skip = 0) + public string SourceDetailsFiltered { - IFindFluent query = _buildCollection.Find(new BsonDocument()).Sort(sortByLeakedDate).Skip(skip); - - if (limit > 0) + get { - query = query.Limit(limit); + HtmlDocument hDoc = new HtmlDocument(); + hDoc.LoadHtml($"
{SourceDetails}
"); + + if (string.IsNullOrWhiteSpace(hDoc.DocumentNode.InnerText)) + { + return ""; + } + + if (Uri.IsWellFormedUriString(hDoc.DocumentNode.InnerText, UriKind.Absolute)) + { + Uri uri = new Uri(hDoc.DocumentNode.InnerText, UriKind.Absolute); + return $"{VariantTerms.Model_ExternalLink} "; + } + + return SourceDetails; } - - return await query.ToListAsync(); } - [DataObjectMethod(DataObjectMethodType.Insert, true)] - public async Task Insert(BuildModel item) - { - item.Id = Guid.NewGuid(); - item.LabUrl = item.GenerateLabUrl(); - await _buildCollection.InsertOneAsync(item); - } - - [DataObjectMethod(DataObjectMethodType.Insert, false)] - public async Task InsertAll(IEnumerable items) - { - List generatedItems = new List(); - foreach (BuildModel item in items) - { - item.Id = Guid.NewGuid(); - item.LabUrl = item.GenerateLabUrl(); - - generatedItems.Add(item); - } - - await _buildCollection.InsertManyAsync(generatedItems); - } - - [DataObjectMethod(DataObjectMethodType.Update, true)] - public async Task Update(BuildModel item) - { - BuildModel old = await SelectById(item.Id); - item.Added = old.Added; - item.Modified = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); - item.LabUrl = item.GenerateLabUrl(); - - await _buildCollection.ReplaceOneAsync(Builders.Filter.Eq(b => b.Id, item.Id), item); - } - - [DataObjectMethod(DataObjectMethodType.Delete, true)] - public async Task DeleteById(Guid id) - { - await _buildCollection.DeleteOneAsync(Builders.Filter.Eq(b => b.Id, id)); - } + public string GenerateLabUrl() => !string.IsNullOrEmpty(Lab) + ? Lab.Replace('/', '-').ToLower() + : ""; } } \ No newline at end of file diff --git a/BuildFeed.Model/BuildFeed.Model.csproj b/BuildFeed.Model/BuildFeed.Model.csproj index 0b941d0..db04956 100644 --- a/BuildFeed.Model/BuildFeed.Model.csproj +++ b/BuildFeed.Model/BuildFeed.Model.csproj @@ -95,9 +95,9 @@ - + - + diff --git a/BuildFeed.Model/BuildModel.cs b/BuildFeed.Model/BuildModel.cs deleted file mode 100644 index e2afa91..0000000 --- a/BuildFeed.Model/BuildModel.cs +++ /dev/null @@ -1,197 +0,0 @@ -using System; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Globalization; -using System.Text; -using System.Web.Mvc; -using BuildFeed.Local; -using HtmlAgilityPack; -using MongoDB.Bson.Serialization.Attributes; -using Required = System.ComponentModel.DataAnnotations.RequiredAttribute; - -namespace BuildFeed.Model -{ - [DataObject, BsonIgnoreExtraElements] - public class BuildModel - { - [Key, BsonId] - public Guid Id { get; set; } - - public long? LegacyId { get; set; } - - [@Required] - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MajorVersion))] - public uint MajorVersion { get; set; } - - [@Required] - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MinorVersion))] - public uint MinorVersion { get; set; } - - [@Required] - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildNumber))] - public uint Number { get; set; } - - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Revision))] - [DisplayFormat(ConvertEmptyStringToNull = true)] - public uint? Revision { get; set; } - - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LabString))] - public string Lab { get; set; } - - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildTime))] - [DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true, DataFormatString = "{0:yyMMdd-HHmm}")] - public DateTime? BuildTime { get; set; } - - - [@Required] - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Added))] - public DateTime Added { get; set; } - - [@Required] - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Modified))] - public DateTime Modified { get; set; } - - [@Required] - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceType))] - [EnumDataType(typeof(TypeOfSource))] - public TypeOfSource SourceType { get; set; } - - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceDetails))] - [AllowHtml] - public string SourceDetails { get; set; } - - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LeakDate))] - [DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")] - public DateTime? LeakDate { get; set; } - - public string LabUrl { get; set; } - - public bool IsLeaked - { - get - { - switch (SourceType) - { - case TypeOfSource.PublicRelease: - case TypeOfSource.InternalLeak: - case TypeOfSource.UpdateGDR: - case TypeOfSource.UpdateLDR: - return true; - default: - return false; - } - } - } - - public string FullBuildString - { - get - { - StringBuilder sb = new StringBuilder(); - sb.Append($"{MajorVersion}.{MinorVersion}.{Number}"); - - if (Revision.HasValue) - { - sb.Append($".{Revision}"); - } - - if (!string.IsNullOrWhiteSpace(Lab)) - { - sb.Append($".{Lab}"); - } - - if (BuildTime.HasValue) - { - sb.Append($".{BuildTime.Value.ToString("yyMMdd-HHmm", CultureInfo.InvariantCulture.DateTimeFormat)}"); - } - - return sb.ToString(); - } - } - - public ProjectFamily Family - { - get - { - if (Number >= 14800) - { - return ProjectFamily.Redstone2; - } - if (Number >= 11000) - { - return ProjectFamily.Redstone; - } - if (Number >= 10500) - { - return ProjectFamily.Threshold2; - } - if (Number >= 9700) - { - return ProjectFamily.Threshold; - } - if (Number >= 9250) - { - return ProjectFamily.Windows81; - } - if (Number >= 7650) - { - return ProjectFamily.Windows8; - } - if (Number >= 6020) - { - return ProjectFamily.Windows7; - } - if (MajorVersion == 6 - && Number >= 5000) - { - return ProjectFamily.WindowsVista; - } - if (MajorVersion == 6) - { - return ProjectFamily.Longhorn; - } - if (MajorVersion == 5 - && Number >= 3000) - { - return ProjectFamily.Server2003; - } - if (MajorVersion == 5 - && Number >= 2205) - { - return ProjectFamily.WindowsXP; - } - if (MajorVersion == 5 - && MinorVersion == 50) - { - return ProjectFamily.Neptune; - } - if (MajorVersion == 5) - { - return ProjectFamily.Windows2000; - } - return ProjectFamily.None; - } - } - - public string SourceDetailsFiltered - { - get - { - HtmlDocument hDoc = new HtmlDocument(); - hDoc.LoadHtml($"
{SourceDetails}
"); - if (string.IsNullOrWhiteSpace(hDoc.DocumentNode.InnerText)) - { - return ""; - } - if (Uri.IsWellFormedUriString(hDoc.DocumentNode.InnerText, UriKind.Absolute)) - { - Uri uri = new Uri(hDoc.DocumentNode.InnerText, UriKind.Absolute); - return $"{VariantTerms.Model_ExternalLink} "; - } - return SourceDetails; - } - } - - public string GenerateLabUrl() => (Lab ?? "").Replace('/', '-').ToLower(); - } -} \ No newline at end of file diff --git a/BuildFeed.Model/BuildRepository.cs b/BuildFeed.Model/BuildRepository.cs new file mode 100644 index 0000000..239b1b1 --- /dev/null +++ b/BuildFeed.Model/BuildRepository.cs @@ -0,0 +1,254 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Configuration; +using System.Linq; +using System.Threading.Tasks; +using BuildFeed.Model.View; +using MongoDB.Bson; +using MongoDB.Driver; + +namespace BuildFeed.Model +{ + public partial class BuildRepository + { + private const string BUILD_COLLECTION_NAME = "builds"; + private static readonly BsonDocument sortByAddedDate = new BsonDocument(nameof(Build.Added), -1); + private static readonly BsonDocument sortByCompileDate = new BsonDocument(nameof(Build.BuildTime), -1); + private static readonly BsonDocument sortByLeakedDate = new BsonDocument(nameof(Build.LeakDate), -1); + + private static readonly BsonDocument sortByOrder = new BsonDocument + { + new BsonElement(nameof(Build.MajorVersion), -1), + new BsonElement(nameof(Build.MinorVersion), -1), + new BsonElement(nameof(Build.Number), -1), + new BsonElement(nameof(Build.Revision), -1), + new BsonElement(nameof(Build.BuildTime), -1) + }; + + private readonly IMongoCollection _buildCollection; + + public BuildRepository() + { + MongoClient dbClient = new MongoClient(new MongoClientSettings + { + Server = new MongoServerAddress(MongoConfig.Host, MongoConfig.Port) + }); + + IMongoDatabase buildDatabase = dbClient.GetDatabase(MongoConfig.Database); + _buildCollection = buildDatabase.GetCollection(BUILD_COLLECTION_NAME); + } + + public async Task SetupIndexes() + { + List indexes = await (await _buildCollection.Indexes.ListAsync()).ToListAsync(); + + if (indexes.All(i => i["name"] != "_idx_group")) + { + await + _buildCollection.Indexes.CreateOneAsync( + Builders.IndexKeys.Combine(Builders.IndexKeys.Descending(b => b.MajorVersion), + Builders.IndexKeys.Descending(b => b.MinorVersion), + Builders.IndexKeys.Descending(b => b.Number), + Builders.IndexKeys.Descending(b => b.Revision)), + new CreateIndexOptions + { + Name = "_idx_group" + }); + } + + if (indexes.All(i => i["name"] != "_idx_legacy")) + { + await _buildCollection.Indexes.CreateOneAsync(Builders.IndexKeys.Ascending(b => b.LegacyId), + new CreateIndexOptions + { + Name = "_idx_legacy" + }); + } + + if (indexes.All(i => i["name"] != "_idx_lab")) + { + await _buildCollection.Indexes.CreateOneAsync(Builders.IndexKeys.Ascending(b => b.Lab), + new CreateIndexOptions + { + Name = "_idx_lab" + }); + } + + if (indexes.All(i => i["name"] != "_idx_date")) + { + await _buildCollection.Indexes.CreateOneAsync(Builders.IndexKeys.Descending(b => b.BuildTime), + new CreateIndexOptions + { + Name = "_idx_date" + }); + } + } + + [DataObjectMethod(DataObjectMethodType.Select, true)] + public async Task> Select() => await _buildCollection.Find(new BsonDocument()).ToListAsync(); + + [DataObjectMethod(DataObjectMethodType.Select, false)] + public async Task SelectById(Guid id) => await _buildCollection.Find(Builders.Filter.Eq(b => b.Id, id)).SingleOrDefaultAsync(); + + [DataObjectMethod(DataObjectMethodType.Select, false)] + public async Task SelectByLegacyId(long id) => await _buildCollection.Find(Builders.Filter.Eq(b => b.LegacyId, id)).SingleOrDefaultAsync(); + + [DataObjectMethod(DataObjectMethodType.Select, false)] + public async Task> SelectBuildsByOrder(int limit = -1, int skip = 0) + { + IFindFluent query = _buildCollection.Find(new BsonDocument()).Sort(sortByOrder).Skip(skip); + + if (limit > 0) + { + query = query.Limit(limit); + } + + return await query.ToListAsync(); + } + + [DataObjectMethod(DataObjectMethodType.Select, false)] + public async Task SelectFrontPage() + { + FrontPage fp = new FrontPage(); + + IFindFluent query = _buildCollection.Find(new BsonDocument + { + { + nameof(Build.LabUrl), new BsonDocument + { + { "$in", new BsonArray(ConfigurationManager.AppSettings["site:OSGLab"].Split(';')) } + } + } + }).Sort(sortByCompileDate).Limit(1); + fp.CurrentCanary = await query.FirstOrDefaultAsync(); + + query = _buildCollection.Find(new BsonDocument + { + { + nameof(Build.LabUrl), new BsonDocument + { + { "$in", new BsonArray(ConfigurationManager.AppSettings["site:InsiderLab"].Split(';')) } + } + }, + { + nameof(Build.SourceType), new BsonDocument + { + { + "$in", new BsonArray + { + TypeOfSource.PublicRelease, + TypeOfSource.UpdateGDR + } + } + } + } + }).Sort(sortByCompileDate).Limit(1); + fp.CurrentInsider = await query.FirstOrDefaultAsync(); + + query = _buildCollection.Find(new BsonDocument + { + { + nameof(Build.LabUrl), new BsonDocument + { + { "$in", new BsonArray(ConfigurationManager.AppSettings["site:ReleaseLab"].Split(';')) } + } + }, + { + nameof(Build.SourceType), new BsonDocument + { + { + "$in", new BsonArray + { + TypeOfSource.PublicRelease, + TypeOfSource.UpdateGDR + } + } + } + } + }).Sort(sortByCompileDate).Limit(1); + fp.CurrentRelease = await query.FirstOrDefaultAsync(); + + return fp; + } + + [DataObjectMethod(DataObjectMethodType.Select, false)] + public async Task> SelectBuildsByCompileDate(int limit = -1, int skip = 0) + { + IFindFluent query = _buildCollection.Find(new BsonDocument()).Sort(sortByCompileDate).Skip(skip); + + if (limit > 0) + { + query = query.Limit(limit); + } + + return await query.ToListAsync(); + } + + [DataObjectMethod(DataObjectMethodType.Select, false)] + public async Task> SelectBuildsByAddedDate(int limit = -1, int skip = 0) + { + IFindFluent query = _buildCollection.Find(new BsonDocument()).Sort(sortByAddedDate).Skip(skip); + + if (limit > 0) + { + query = query.Limit(limit); + } + + return await query.ToListAsync(); + } + + [DataObjectMethod(DataObjectMethodType.Select, false)] + public async Task> SelectBuildsByLeakedDate(int limit = -1, int skip = 0) + { + IFindFluent query = _buildCollection.Find(new BsonDocument()).Sort(sortByLeakedDate).Skip(skip); + + if (limit > 0) + { + query = query.Limit(limit); + } + + return await query.ToListAsync(); + } + + [DataObjectMethod(DataObjectMethodType.Insert, true)] + public async Task Insert(Build item) + { + item.Id = Guid.NewGuid(); + item.LabUrl = item.GenerateLabUrl(); + await _buildCollection.InsertOneAsync(item); + } + + [DataObjectMethod(DataObjectMethodType.Insert, false)] + public async Task InsertAll(IEnumerable items) + { + List generatedItems = new List(); + foreach (Build item in items) + { + item.Id = Guid.NewGuid(); + item.LabUrl = item.GenerateLabUrl(); + + generatedItems.Add(item); + } + + await _buildCollection.InsertManyAsync(generatedItems); + } + + [DataObjectMethod(DataObjectMethodType.Update, true)] + public async Task Update(Build item) + { + Build old = await SelectById(item.Id); + item.Added = old.Added; + item.Modified = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); + item.LabUrl = item.GenerateLabUrl(); + + await _buildCollection.ReplaceOneAsync(Builders.Filter.Eq(b => b.Id, item.Id), item); + } + + [DataObjectMethod(DataObjectMethodType.Delete, true)] + public async Task DeleteById(Guid id) + { + await _buildCollection.DeleteOneAsync(Builders.Filter.Eq(b => b.Id, id)); + } + } +} \ No newline at end of file diff --git a/BuildFeed.Model/MetaItem.cs b/BuildFeed.Model/MetaItem.cs index 1bde1f4..d9cc515 100644 --- a/BuildFeed.Model/MetaItem.cs +++ b/BuildFeed.Model/MetaItem.cs @@ -34,7 +34,7 @@ public class MetaItem private readonly MongoClient _dbClient; private readonly IMongoCollection _metaCollection; - private readonly Build bModel; + private readonly BuildRepository bModel; public MetaItem() { @@ -44,7 +44,7 @@ public MetaItem() }); _metaCollection = _dbClient.GetDatabase(MongoConfig.Database).GetCollection(_metaCollectionName); - bModel = new Build(); + bModel = new BuildRepository(); } [DataObjectMethod(DataObjectMethodType.Select, false)] diff --git a/BuildFeed.Model/MongoConfig.cs b/BuildFeed.Model/MongoConfig.cs index 3add5e9..9beaef2 100644 --- a/BuildFeed.Model/MongoConfig.cs +++ b/BuildFeed.Model/MongoConfig.cs @@ -29,7 +29,7 @@ static MongoConfig() public static void SetupIndexes() { - Build b = new Build(); + BuildRepository b = new BuildRepository(); b.SetupIndexes(); } } diff --git a/BuildFeed.Model/View/FrontPage.cs b/BuildFeed.Model/View/FrontPage.cs index 84062a8..13babbe 100644 --- a/BuildFeed.Model/View/FrontPage.cs +++ b/BuildFeed.Model/View/FrontPage.cs @@ -2,8 +2,8 @@ { public class FrontPage { - public BuildModel CurrentCanary { get; set; } - public BuildModel CurrentInsider { get; set; } - public BuildModel CurrentRelease { get; set; } + public Build CurrentCanary { get; set; } + public Build CurrentInsider { get; set; } + public Build CurrentRelease { get; set; } } } \ No newline at end of file diff --git a/BuildFeed/Controllers/apiController.cs b/BuildFeed/Controllers/apiController.cs index 937db40..2733b5a 100644 --- a/BuildFeed/Controllers/apiController.cs +++ b/BuildFeed/Controllers/apiController.cs @@ -14,13 +14,13 @@ namespace BuildFeed.Controllers { public class ApiController : System.Web.Http.ApiController { - private readonly Build _bModel; + private readonly BuildRepository _bModel; - public ApiController() { _bModel = new Build(); } + public ApiController() { _bModel = new BuildRepository(); } - public async Task GetBuilds(int limit = 20, int skip = 0) + public async Task GetBuilds(int limit = 20, int skip = 0) { - List builds = await _bModel.SelectBuildsByOrder(limit, skip); + List builds = await _bModel.SelectBuildsByOrder(limit, skip); return builds.ToArray(); } @@ -30,9 +30,9 @@ public async Task GetBuildGroups(int limit = 20, int skip = 0 return bgroups.ToArray(); } - public async Task GetBuildsForBuildGroup(uint major, uint minor, uint number, uint? revision = null) + public async Task GetBuildsForBuildGroup(uint major, uint minor, uint number, uint? revision = null) { - List builds = await _bModel.SelectGroup(new BuildGroup + List builds = await _bModel.SelectGroup(new BuildGroup { Major = major, Minor = minor, @@ -43,9 +43,9 @@ public async Task GetBuildsForBuildGroup(uint major, uint minor, u return builds.ToArray(); } - public async Task GetBuildsByLab(string lab, int limit = 20, int skip = 0) + public async Task GetBuildsByLab(string lab, int limit = 20, int skip = 0) { - List builds = await _bModel.SelectLab(lab, limit, skip); + List builds = await _bModel.SelectLab(lab, limit, skip); return builds.ToArray(); } @@ -67,7 +67,7 @@ public async Task AddWin10Builds(NewBuildPost apiModel) } if (Membership.ValidateUser(apiModel.Username, apiModel.Password)) { - await _bModel.InsertAll(apiModel.NewBuilds.Select(nb => new BuildModel + await _bModel.InsertAll(apiModel.NewBuilds.Select(nb => new Build { MajorVersion = nb.MajorVersion, MinorVersion = nb.MinorVersion, diff --git a/BuildFeed/Controllers/frontController.cs b/BuildFeed/Controllers/frontController.cs index 064f54e..1664e44 100644 --- a/BuildFeed/Controllers/frontController.cs +++ b/BuildFeed/Controllers/frontController.cs @@ -18,12 +18,12 @@ public class FrontController : BaseController { public const int PAGE_SIZE = 72; - private readonly Build _bModel; + private readonly BuildRepository _bModel; private readonly MetaItem _mModel; public FrontController() { - _bModel = new Build(); + _bModel = new BuildRepository(); _mModel = new MetaItem(); } @@ -71,7 +71,7 @@ public async Task ViewGroup(uint major, uint minor, uint number, u Revision = revision }; - List builds = await _bModel.SelectGroup(bg); + List builds = await _bModel.SelectGroup(bg); return builds.Count() == 1 ? RedirectToAction(nameof(ViewBuild), @@ -79,7 +79,7 @@ public async Task ViewGroup(uint major, uint minor, uint number, u { id = builds.Single().Id }) as ActionResult - : View(new Tuple>(bg, builds)); + : View(new Tuple>(bg, builds)); } [Route("build/{id:guid}/", Name = "Build")] @@ -88,7 +88,7 @@ public async Task ViewGroup(uint major, uint minor, uint number, u #endif public async Task ViewBuild(Guid id) { - BuildModel b = await _bModel.SelectById(id); + Build b = await _bModel.SelectById(id); if (b == null) { return new HttpNotFoundResult(); @@ -99,7 +99,7 @@ public async Task ViewBuild(Guid id) [Route("build/{id:long}/", Name = "Build (Legacy)")] public async Task ViewBuild(long id) { - BuildModel b = await _bModel.SelectByLegacyId(id); + Build b = await _bModel.SelectByLegacyId(id); if (b == null) { return new HttpNotFoundResult(); @@ -118,7 +118,7 @@ public async Task ViewBuild(long id) #endif public async Task TwitterCard(Guid id) { - BuildModel b = await _bModel.SelectById(id); + Build b = await _bModel.SelectById(id); if (b == null) { return new HttpNotFoundResult(); @@ -170,7 +170,7 @@ public async Task TwitterCard(Guid id) [Route("twitter/{id:long}/", Name = "Twitter (Legacy)")] public async Task TwitterCard(long id) { - BuildModel b = await _bModel.SelectByLegacyId(id); + Build b = await _bModel.SelectByLegacyId(id); if (b == null) { return new HttpNotFoundResult(); @@ -203,7 +203,7 @@ public async Task ViewLabPage(string lab, int page) Value = lab }); - List builds = await _bModel.SelectLab(lab, PAGE_SIZE, (page - 1) * PAGE_SIZE); + List builds = await _bModel.SelectLab(lab, PAGE_SIZE, (page - 1) * PAGE_SIZE); ViewBag.ItemId = builds.FirstOrDefault()?.Lab; ViewBag.PageNumber = page; @@ -239,7 +239,7 @@ public async Task ViewSourcePage(TypeOfSource source, int page) }); ViewBag.ItemId = MvcExtensions.GetDisplayTextForEnum(source); - List builds = await _bModel.SelectSource(source, PAGE_SIZE, (page - 1) * PAGE_SIZE); + List builds = await _bModel.SelectSource(source, PAGE_SIZE, (page - 1) * PAGE_SIZE); ViewBag.PageNumber = page; ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(await _bModel.SelectSourceCount(source)) / Convert.ToDouble(PAGE_SIZE)); @@ -274,7 +274,7 @@ public async Task ViewYearPage(int year, int page) }); ViewBag.ItemId = year.ToString(); - List builds = await _bModel.SelectYear(year, PAGE_SIZE, (page - 1) * PAGE_SIZE); + List builds = await _bModel.SelectYear(year, PAGE_SIZE, (page - 1) * PAGE_SIZE); ViewBag.PageNumber = page; ViewBag.PageCount = Math.Ceiling(await _bModel.SelectYearCount(year) / Convert.ToDouble(PAGE_SIZE)); @@ -310,7 +310,7 @@ public async Task ViewVersionPage(uint major, uint minor, int page }); ViewBag.ItemId = valueString; - List builds = await _bModel.SelectVersion(major, minor, PAGE_SIZE, (page - 1) * PAGE_SIZE); + List builds = await _bModel.SelectVersion(major, minor, PAGE_SIZE, (page - 1) * PAGE_SIZE); ViewBag.PageNumber = page; ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(await _bModel.SelectVersionCount(major, minor)) / Convert.ToDouble(PAGE_SIZE)); @@ -326,7 +326,7 @@ public async Task ViewVersionPage(uint major, uint minor, int page [Route("add/"), Authorize] public ActionResult AddBuild() { - BuildModel b = new BuildModel + Build b = new Build { SourceType = TypeOfSource.PrivateLeak }; @@ -334,7 +334,7 @@ public ActionResult AddBuild() } [Route("add/"), Authorize, HttpPost] - public async Task AddBuild(BuildModel build) + public async Task AddBuild(Build build) { if (ModelState.IsValid) { @@ -368,12 +368,12 @@ public async Task AddBuild(BuildModel build) [Route("edit/{id}/"), Authorize] public async Task EditBuild(Guid id) { - BuildModel b = await _bModel.SelectById(id); + Build b = await _bModel.SelectById(id); return View(b); } [Route("edit/{id}/"), Authorize, HttpPost] - public async Task EditBuild(Guid id, BuildModel build) + public async Task EditBuild(Guid id, Build build) { if (ModelState.IsValid) { diff --git a/BuildFeed/Controllers/rssController.cs b/BuildFeed/Controllers/rssController.cs index 29ce3e3..c057a1b 100644 --- a/BuildFeed/Controllers/rssController.cs +++ b/BuildFeed/Controllers/rssController.cs @@ -12,14 +12,14 @@ namespace BuildFeed.Controllers public class RssController : BaseController { private const int RSS_SIZE = 25; - private readonly Build _bModel; + private readonly BuildRepository _bModel; - public RssController() { _bModel = new Build(); } + public RssController() { _bModel = new BuildRepository(); } [Route("rss/compiled")] public async Task Index() { - List builds = await _bModel.SelectBuildsByCompileDate(RSS_SIZE); + List builds = await _bModel.SelectBuildsByCompileDate(RSS_SIZE); Feed feed = new Feed { @@ -49,7 +49,7 @@ public async Task Index() [Route("rss/added")] public async Task Added() { - List builds = await _bModel.SelectBuildsByAddedDate(RSS_SIZE); + List builds = await _bModel.SelectBuildsByAddedDate(RSS_SIZE); Feed feed = new Feed { @@ -79,7 +79,7 @@ public async Task Added() [Route("rss/leaked")] public async Task Leaked() { - List builds = await _bModel.SelectBuildsByLeakedDate(RSS_SIZE); + List builds = await _bModel.SelectBuildsByLeakedDate(RSS_SIZE); Feed feed = new Feed { @@ -109,7 +109,7 @@ public async Task Leaked() [Route("rss/version")] public async Task Version() { - List builds = await _bModel.SelectBuildsByOrder(RSS_SIZE); + List builds = await _bModel.SelectBuildsByOrder(RSS_SIZE); Feed feed = new Feed { @@ -138,7 +138,7 @@ public async Task Version() [Route("rss/lab/{lab}")] public async Task Lab(string lab) { - List builds = await _bModel.SelectLab(lab, RSS_SIZE); + List builds = await _bModel.SelectLab(lab, RSS_SIZE); Feed feed = new Feed { diff --git a/BuildFeed/Controllers/supportController.cs b/BuildFeed/Controllers/supportController.cs index 1c6a001..924362c 100644 --- a/BuildFeed/Controllers/supportController.cs +++ b/BuildFeed/Controllers/supportController.cs @@ -16,9 +16,9 @@ namespace BuildFeed.Controllers { public class SupportController : BaseController { - private readonly Build _bModel; + private readonly BuildRepository _bModel; - public SupportController() { _bModel = new Build(); } + public SupportController() { _bModel = new BuildRepository(); } [Route("login/")] public ActionResult Login() => View(); @@ -138,7 +138,7 @@ public async Task Rss() #endif public async Task Sitemap() { - List builds = await _bModel.SelectBuildsByOrder(); + List builds = await _bModel.SelectBuildsByOrder(); Dictionary actions = new Dictionary { { @@ -291,7 +291,7 @@ public async Task XmlSitemap() home.Add(new XElement(xn + "changefreq", "daily")); xlist.Add(home); - foreach (BuildModel b in await _bModel.Select()) + foreach (Build b in await _bModel.Select()) { XElement url = new XElement(xn + "url"); url.Add(new XElement(xn + "loc", diff --git a/BuildFeed/Views/front/editBuild.cshtml b/BuildFeed/Views/front/editBuild.cshtml index 1fcb3fa..59bcad4 100644 --- a/BuildFeed/Views/front/editBuild.cshtml +++ b/BuildFeed/Views/front/editBuild.cshtml @@ -1,5 +1,5 @@ @using BuildFeed.Model -@model BuildModel +@model Build @{ ViewBag.Title = (string)ViewContext.RouteData.Values["action"] == "addBuild" ? $"{VariantTerms.Common_AddBuild} | {InvariantTerms.SiteName}" diff --git a/BuildFeed/Views/front/viewBuild.cshtml b/BuildFeed/Views/front/viewBuild.cshtml index 7a91b98..2dd0c16 100644 --- a/BuildFeed/Views/front/viewBuild.cshtml +++ b/BuildFeed/Views/front/viewBuild.cshtml @@ -1,7 +1,7 @@ @using System.Globalization @using BuildFeed.Code @using BuildFeed.Controllers -@model BuildFeed.Model.BuildModel +@model BuildFeed.Model.Build @{ ViewBag.Title = $"{Model.FullBuildString} | {InvariantTerms.SiteName}"; diff --git a/BuildFeed/Views/front/viewGroup.cshtml b/BuildFeed/Views/front/viewGroup.cshtml index a754d50..093ac21 100644 --- a/BuildFeed/Views/front/viewGroup.cshtml +++ b/BuildFeed/Views/front/viewGroup.cshtml @@ -1,7 +1,7 @@ @using BuildFeed.Code @using BuildFeed.Model @using Humanizer -@model Tuple> +@model Tuple> @{ ViewBag.Title = $"{Model.Item1} | {InvariantTerms.SiteName}"; } @@ -10,7 +10,7 @@

@VariantTerms.Front_Listing

- @foreach (BuildModel build in Model.Item2) + @foreach (Build build in Model.Item2) {

diff --git a/BuildFeed/Views/front/viewLab.cshtml b/BuildFeed/Views/front/viewLab.cshtml index 5e8665f..a401dab 100644 --- a/BuildFeed/Views/front/viewLab.cshtml +++ b/BuildFeed/Views/front/viewLab.cshtml @@ -1,7 +1,7 @@ @using BuildFeed.Code @using BuildFeed.Model @using Humanizer -@model IEnumerable +@model IEnumerable @{ ViewBag.Title = string.Format("{0}{1} | {2}", string.Format(VariantTerms.Front_BuildsFrom, ViewBag.ItemId), ViewBag.PageNumber == 1 ? "" @@ -39,7 +39,7 @@

@VariantTerms.Front_Listing

- @foreach (BuildModel build in Model) + @foreach (Build build in Model) {

diff --git a/BuildFeed/Views/front/viewSource.cshtml b/BuildFeed/Views/front/viewSource.cshtml index 6ff5ca4..782b00d 100644 --- a/BuildFeed/Views/front/viewSource.cshtml +++ b/BuildFeed/Views/front/viewSource.cshtml @@ -1,7 +1,7 @@ @using BuildFeed.Code @using BuildFeed.Model @using Humanizer -@model IEnumerable +@model IEnumerable @{ ViewBag.Title = string.Format("{0}{1} | {2}", ViewBag.ItemId, ViewBag.PageNumber == 1 ? "" @@ -33,7 +33,7 @@

@VariantTerms.Front_Listing

- @foreach (BuildModel build in Model) + @foreach (Build build in Model) {

diff --git a/BuildFeed/Views/front/viewVersion.cshtml b/BuildFeed/Views/front/viewVersion.cshtml index 5aa9bf6..df3ed19 100644 --- a/BuildFeed/Views/front/viewVersion.cshtml +++ b/BuildFeed/Views/front/viewVersion.cshtml @@ -1,7 +1,7 @@ @using BuildFeed.Code @using BuildFeed.Model @using Humanizer -@model IEnumerable +@model IEnumerable @{ ViewBag.Title = $"{InvariantTerms.ProductName} {ViewBag.ItemId}{(ViewBag.PageNumber == 1 ? "" : string.Format(VariantTerms.Common_TitlePage, ViewBag.PageNumber))} | {InvariantTerms.SiteName}"; } @@ -31,7 +31,7 @@

@VariantTerms.Front_Listing

- @foreach (BuildModel build in Model) + @foreach (Build build in Model) {

diff --git a/BuildFeed/Views/front/viewYear.cshtml b/BuildFeed/Views/front/viewYear.cshtml index 18aab32..c116734 100644 --- a/BuildFeed/Views/front/viewYear.cshtml +++ b/BuildFeed/Views/front/viewYear.cshtml @@ -1,7 +1,7 @@ @using BuildFeed.Code @using BuildFeed.Model @using Humanizer -@model IEnumerable +@model IEnumerable @{ ViewBag.Title = string.Format("{0}{1} | {2}", string.Format(VariantTerms.Front_BuildsFrom, ViewBag.ItemId), ViewBag.PageNumber == 1 ? "" @@ -39,7 +39,7 @@

@VariantTerms.Front_Listing

- @foreach (BuildModel build in Model) + @foreach (Build build in Model) {

diff --git a/BuildFeed/Views/shared/_default.cshtml b/BuildFeed/Views/shared/_default.cshtml index 359f63d..9282971 100644 --- a/BuildFeed/Views/shared/_default.cshtml +++ b/BuildFeed/Views/shared/_default.cshtml @@ -3,6 +3,15 @@ @using BuildFeed.Controllers @{ bool isRtl = CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft; + + Response.PushPromise("/res/css/default.min.css"); + Response.PushPromise(VirtualPathUtility.ToAbsolute(((Theme)ViewBag.Theme).CssPath)); + if (isRtl) + { + Response.PushPromise("/res/css/rtl.min.css"); + } + + Response.PushPromise("/res/ts/bfs.min.js"); } - + @RenderSection("scripts", false)