More amends, inc a bit of Localisation

This commit is contained in:
Thomas Hounsell 2015-09-10 21:01:39 +01:00
parent d2521cdc8d
commit b17e622280
5 changed files with 300 additions and 140 deletions

View File

@ -1,4 +1,5 @@
using BuildFeed.Models;
using BuildFeed.Local;
using BuildFeed.Models;
using BuildFeed.Models.ApiModel;
using System;
using System.Collections.Generic;
@ -8,141 +9,147 @@
namespace BuildFeed.Controllers
{
public class apiController : ApiController
{
public IEnumerable<BuildModel> GetBuilds()
{
return new Build().SelectInBuildOrder();
}
public class apiController : ApiController
{
private Build bModel;
public IEnumerable<string> GetWin10Labs()
{
Build b = new Build();
List<string> labs = new List<string>();
labs.AddRange(b.SelectBuildLabs(6, 4));
labs.AddRange(b.SelectBuildLabs(10, 0));
public apiController() : base()
{
bModel = new Build();
}
return labs.GroupBy(l => l).Select(l => l.Key).Where(l => l.All(c => c != '(')).ToArray();
}
public IEnumerable<BuildModel> GetBuilds()
{
return bModel.SelectInBuildOrder();
}
[HttpPost]
public bool AddWin10Builds(NewBuild apiModel)
{
if (apiModel == null)
public IEnumerable<string> GetWin10Labs()
{
List<string> labs = new List<string>();
labs.AddRange(bModel.SelectBuildLabs(6, 4));
labs.AddRange(bModel.SelectBuildLabs(10, 0));
return labs.GroupBy(l => l).Select(l => l.Key).Where(l => l.All(c => c != '(')).ToArray();
}
[HttpPost]
public bool AddWin10Builds(NewBuild apiModel)
{
if (apiModel == null)
{
return false;
}
if (Membership.ValidateUser(apiModel.Username, apiModel.Password))
{
bModel.InsertAll(apiModel.NewBuilds.Select(nb => new BuildModel()
{
return false;
}
if (Membership.ValidateUser(apiModel.Username, apiModel.Password))
{
new Build().InsertAll(apiModel.NewBuilds.Select(nb => new BuildModel()
{
MajorVersion = nb.MajorVersion,
MinorVersion = nb.MinorVersion,
Number = nb.Number,
Revision = nb.Revision,
Lab = nb.Lab,
BuildTime = nb.BuildTime,
FlightLevel = nb.FlightLevel
}));
return true;
}
else
{
return false;
}
}
MajorVersion = nb.MajorVersion,
MinorVersion = nb.MinorVersion,
Number = nb.Number,
Revision = nb.Revision,
Lab = nb.Lab,
BuildTime = nb.BuildTime,
FlightLevel = nb.FlightLevel
}));
return true;
}
else
{
return false;
}
}
public IEnumerable<SearchResult> GetSearchResult(string query)
{
if (string.IsNullOrWhiteSpace(query))
{
return new SearchResult[0];
}
public IEnumerable<SearchResult> GetSearchResult(string query)
{
if (string.IsNullOrWhiteSpace(query))
{
return new SearchResult[0];
}
List<SearchResult> results = new List<SearchResult>();
List<SearchResult> results = new List<SearchResult>();
var sourceResults = from s in Enum.GetValues(typeof(TypeOfSource)).Cast<TypeOfSource>().Select(s => new { Text = DisplayHelpers.GetDisplayTextForEnum(s), Value = s })
where s.Text.ToLower().Contains(query.ToLower())
orderby s.Text.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) ascending
select new SearchResult()
{
Url = Url.Route("Source Root", new { controller = "front", action = "viewSource", source = s.Value }),
Label = s.Text.Replace(query, "<strong>" + query + "</strong>"),
Title = s.Text,
Group = "Source"
};
results.AddRange(sourceResults);
var versionResults = from v in new Build().SelectBuildVersions()
where $"{v.Major}.{v.Minor}".StartsWith(query)
orderby v.Major descending, v.Minor descending
select new SearchResult()
{
Url = Url.Route("Version Root", new { controller = "front", action = "viewVersion", major = v.Major, minor = v.Minor }),
Label = $"{v.Major}.{v.Minor}".Replace(query, "<strong>" + query + "</strong>"),
Title = "",
Group = "Version"
};
results.AddRange(versionResults);
var yearResults = from y in new Build().SelectBuildYears()
where y.ToString().Contains(query)
orderby y descending
select new SearchResult()
{
Url = Url.Route("Year Root", new { controller = "front", action = "viewYear", year = y }),
Label = y.ToString().Replace(query, "<strong>" + query + "</strong>"),
Title = "",
Group = "Year"
};
results.AddRange(yearResults);
var labResults = from l in new Build().SelectBuildLabs()
where l.ToLower().Contains(query.ToLower())
orderby l.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) ascending
var sourceResults = from s in Enum.GetValues(typeof(TypeOfSource)).Cast<TypeOfSource>().Select(s => new { Text = DisplayHelpers.GetDisplayTextForEnum(s), Value = s })
where s.Text.ToLower().Contains(query.ToLower())
orderby s.Text.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) ascending
select new SearchResult()
{
Url = Url.Route("Lab Root", new { controller = "front", action = "viewLab", lab = l }),
Label = l.Replace(query, "<strong>" + query + "</strong>"),
Title = l,
Group = "Lab"
Url = Url.Route("Source Root", new { controller = "front", action = "viewSource", source = s.Value }),
Label = s.Text.Replace(query, "<strong>" + query + "</strong>"),
Title = s.Text,
Group = Common.SearchSource
};
results.AddRange(labResults);
results.AddRange(sourceResults);
var buildResults = from b in new Build().Select()
where b.FullBuildString.ToLower().Contains(query.ToLower())
orderby b.FullBuildString.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) ascending,
b.BuildTime descending
select new SearchResult()
{
Url = Url.Route("Build", new { controller = "front", action = "viewBuild", id = b.Id }),
Label = b.FullBuildString.Replace(query, "<strong>" + query + "</strong>"),
Title = b.FullBuildString,
Group = "Build"
};
var versionResults = from v in bModel.SelectBuildVersions()
where $"{v.Major}.{v.Minor}".StartsWith(query)
orderby v.Major descending, v.Minor descending
select new SearchResult()
{
Url = Url.Route("Version Root", new { controller = "front", action = "viewVersion", major = v.Major, minor = v.Minor }),
Label = $"{v.Major}.{v.Minor}".Replace(query, "<strong>" + query + "</strong>"),
Title = "",
Group = Common.SearchVersion
};
results.AddRange(buildResults);
results.AddRange(versionResults);
if (results.Count == 0)
var yearResults = from y in bModel.SelectBuildYears()
where y.ToString().Contains(query)
orderby y descending
select new SearchResult()
{
Url = Url.Route("Year Root", new { controller = "front", action = "viewYear", year = y }),
Label = y.ToString().Replace(query, "<strong>" + query + "</strong>"),
Title = "",
Group = Common.SearchYear
};
results.AddRange(yearResults);
var labResults = from l in bModel.SearchBuildLabs(query)
orderby l.IndexOf(query.ToLower()) ascending,
l.Length ascending
select new SearchResult()
{
Url = Url.Route("Lab Root", new { controller = "front", action = "viewLab", lab = l }),
Label = l.Replace(query, $"<strong>{query}</strong>"),
Title = l,
Group = Common.SearchLab
};
results.AddRange(labResults);
var buildResults = from b in bModel.Select()
where b.FullBuildString.ToLower().Contains(query.ToLower())
orderby b.FullBuildString.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) ascending,
b.BuildTime descending
select new SearchResult()
{
Url = Url.Route("Build", new { controller = "front", action = "viewBuild", id = b.Id }),
Label = b.FullBuildString.Replace(query, $"<strong>{query}</strong>"),
Title = b.FullBuildString,
Group = Common.SearchBuild
};
results.AddRange(buildResults);
if (results.Count == 0)
{
results.Add(new SearchResult()
{
results.Add(new SearchResult()
{
Url = "/",
Label = "No Results found",
Group = ""
});
}
Url = "/",
Label = Common.SearchEmpty,
Group = ""
});
}
return results.Take(15);
}
}
return results.Take(15);
}
}
}

View File

@ -159,6 +159,15 @@ public static string Search {
}
}
/// <summary>
/// Looks up a localized string similar to Build.
/// </summary>
public static string SearchBuild {
get {
return ResourceManager.GetString("SearchBuild", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Search BuildFeed....
/// </summary>
@ -168,6 +177,24 @@ public static string SearchBuildFeed {
}
}
/// <summary>
/// Looks up a localized string similar to No results found.
/// </summary>
public static string SearchEmpty {
get {
return ResourceManager.GetString("SearchEmpty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Lab.
/// </summary>
public static string SearchLab {
get {
return ResourceManager.GetString("SearchLab", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Search query.
/// </summary>
@ -177,6 +204,33 @@ public static string SearchQuery {
}
}
/// <summary>
/// Looks up a localized string similar to Source.
/// </summary>
public static string SearchSource {
get {
return ResourceManager.GetString("SearchSource", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Version.
/// </summary>
public static string SearchVersion {
get {
return ResourceManager.GetString("SearchVersion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Year.
/// </summary>
public static string SearchYear {
get {
return ResourceManager.GetString("SearchYear", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sitemap.
/// </summary>

View File

@ -174,4 +174,22 @@
<data name="PageTitleSegment" xml:space="preserve">
<value>[!!! | Þáϱè {0} !!!]</value>
</data>
<data name="SearchBuild" xml:space="preserve">
<value>[!!! ßúïℓδ !!!]</value>
</data>
<data name="SearchEmpty" xml:space="preserve">
<value>[!!! Nô řèƨúℓƭƨ ƒôúñδ ℓôřè !!!]</value>
</data>
<data name="SearchLab" xml:space="preserve">
<value>[!!! £áβ !!!]</value>
</data>
<data name="SearchSource" xml:space="preserve">
<value>[!!! §ôúrçè l !!!]</value>
</data>
<data name="SearchVersion" xml:space="preserve">
<value>[!!! Vèřƨïôñ !!!]</value>
</data>
<data name="SearchYear" xml:space="preserve">
<value>[!!! Ýèář !!!]</value>
</data>
</root>

View File

@ -174,4 +174,22 @@
<data name="PageTitleSegment" xml:space="preserve">
<value>| Page {0}</value>
</data>
<data name="SearchBuild" xml:space="preserve">
<value>Build</value>
</data>
<data name="SearchEmpty" xml:space="preserve">
<value>No results found</value>
</data>
<data name="SearchLab" xml:space="preserve">
<value>Lab</value>
</data>
<data name="SearchSource" xml:space="preserve">
<value>Source</value>
</data>
<data name="SearchVersion" xml:space="preserve">
<value>Version</value>
</data>
<data name="SearchYear" xml:space="preserve">
<value>Year</value>
</data>
</root>

View File

@ -1,4 +1,5 @@
using BuildFeed.Local;
using BuildFeed.Models.ApiModel;
using BuildFeed.Models.ViewModel.Front;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
@ -350,45 +351,97 @@ public long SelectVersionCount(int major, int minor)
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public IEnumerable<BuildVersion> SelectBuildVersions()
public List<BuildVersion> SelectBuildVersions()
{
var task = _buildCollection.DistinctAsync(b => new BuildVersion() { Major = b.MajorVersion, Minor = b.MinorVersion }, b => true);
var task = _buildCollection.Aggregate()
.Group(b => new BuildVersion()
{
Major = b.MajorVersion,
Minor = b.MinorVersion,
},
// incoming bullshit hack
bg => new Tuple<BuildVersion>(bg.Key))
.SortByDescending(b => b.Item1.Major)
.ThenByDescending(b => b.Item1.Minor)
.ToListAsync();
task.Wait();
var outTask = task.Result.ToListAsync();
outTask.Wait();
return outTask.Result
.OrderByDescending(y => y.Major)
.ThenByDescending(y => y.Minor);
// work ourselves out of aforementioned bullshit hack
return task.Result.Select(b => b.Item1).ToList();
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public IEnumerable<int> SelectBuildYears()
{
var task = _buildCollection.DistinctAsync(b => b.BuildTime.Value.Year, b => b.BuildTime.HasValue);
var task = _buildCollection.Aggregate()
.Match(b => b.BuildTime != null)
.Group(b => ((DateTime)b.BuildTime).Year,
// incoming bullshit hack
bg => new Tuple<int>(bg.Key))
.SortByDescending(b => b.Item1)
.ToListAsync();
task.Wait();
var outTask = task.Result.ToListAsync();
outTask.Wait();
return outTask.Result.OrderBy(b => b);
// work ourselves out of aforementioned bullshit hack
return task.Result.Select(b => b.Item1).ToList();
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public List<string> SearchBuildLabs(string query)
{
var task = _buildCollection.Aggregate()
.Match(b => b.Lab != null)
.Match(b => b.Lab != "")
.Match(b => b.Lab.ToLower().Contains(query.ToLower()))
.Group(b => b.Lab.ToLower(),
// incoming bullshit hack
bg => new Tuple<string>(bg.Key))
.ToListAsync();
task.Wait();
// work ourselves out of aforementioned bullshit hack
return task.Result.Select(b => b.Item1).ToList();
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public IEnumerable<string> SelectBuildLabs()
{
var task = _buildCollection.DistinctAsync(b => b.Lab.ToLower(), b => !string.IsNullOrWhiteSpace(b.Lab));
var task = _buildCollection.Aggregate()
.Match(b => b.Lab != null)
.Match(b => b.Lab != "")
.Group(b => b.Lab.ToLower(),
// incoming bullshit hack
bg => new Tuple<string>(bg.Key))
.SortBy(b => b.Item1)
.ToListAsync();
task.Wait();
var outTask = task.Result.ToListAsync();
outTask.Wait();
return outTask.Result.OrderBy(b => b);
// work ourselves out of aforementioned bullshit hack
return task.Result.Select(b => b.Item1).ToList();
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public IEnumerable<string> SelectBuildLabs(byte major, byte minor)
{
var task = _buildCollection.DistinctAsync(b => b.Lab.ToLower(), b => !string.IsNullOrWhiteSpace(b.Lab) && b.MajorVersion == major && b.MinorVersion == minor);
var task = _buildCollection.Aggregate()
.Match(b => b.MajorVersion == major)
.Match(b => b.MinorVersion == minor)
.Match(b => b.Lab != null)
.Match(b => b.Lab != "")
.Group(b => b.Lab.ToLower(),
// incoming bullshit hack
bg => new Tuple<string>(bg.Key))
.SortBy(b => b.Item1)
.ToListAsync();
task.Wait();
var outTask = task.Result.ToListAsync();
outTask.Wait();
return outTask.Result.OrderBy(b => b);
// work ourselves out of aforementioned bullshit hack
return task.Result.Select(b => b.Item1).ToList();
}
[DataObjectMethod(DataObjectMethodType.Insert, true)]
@ -470,11 +523,21 @@ public enum LevelOfFlight
High = 3
}
public struct BuildVersion
public class BuildVersion
{
public byte Major { get; set; }
public byte Minor { get; set; }
public BuildVersion()
{
}
public BuildVersion(byte major, byte minor)
{
Major = major;
Minor = minor;
}
public override string ToString()
{
return $"{Major}.{Minor}";