2016-01-12 05:16:29 +08:00
|
|
|
|
using System.Collections.Generic;
|
2015-11-10 00:43:05 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-08-20 05:10:55 +08:00
|
|
|
|
using BuildFeed.Model.View;
|
2016-01-11 06:23:13 +08:00
|
|
|
|
using MongoDB.Bson;
|
|
|
|
|
using MongoDB.Driver;
|
2015-11-10 00:43:05 +08:00
|
|
|
|
|
2016-08-20 05:10:55 +08:00
|
|
|
|
namespace BuildFeed.Model
|
2015-11-10 00:43:05 +08:00
|
|
|
|
{
|
2016-08-21 07:09:56 +08:00
|
|
|
|
public partial class BuildRepository
|
2015-11-10 00:43:05 +08:00
|
|
|
|
{
|
2016-01-11 06:23:13 +08:00
|
|
|
|
public async Task<FrontBuildGroup[]> SelectAllGroups(int limit = -1, int skip = 0)
|
2015-11-10 17:37:03 +08:00
|
|
|
|
{
|
2016-07-15 21:39:30 +08:00
|
|
|
|
IAggregateFluent<BsonDocument> query = _buildCollection.Aggregate().Group(new BsonDocument
|
|
|
|
|
{
|
2016-08-19 20:45:52 +08:00
|
|
|
|
new BsonElement("_id",
|
|
|
|
|
new BsonDocument
|
|
|
|
|
{
|
2016-08-21 07:09:56 +08:00
|
|
|
|
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)}")
|
2016-08-19 20:45:52 +08:00
|
|
|
|
}),
|
2016-08-21 07:09:56 +08:00
|
|
|
|
new BsonElement("date", new BsonDocument("$max", $"${nameof(Build.BuildTime)}")),
|
2016-07-15 21:39:30 +08:00
|
|
|
|
new BsonElement("count", new BsonDocument("$sum", 1))
|
|
|
|
|
}).Sort(new BsonDocument
|
|
|
|
|
{
|
|
|
|
|
new BsonElement($"_id.{nameof(BuildGroup.Major)}", -1),
|
|
|
|
|
new BsonElement($"_id.{nameof(BuildGroup.Minor)}", -1),
|
|
|
|
|
new BsonElement($"_id.{nameof(BuildGroup.Build)}", -1),
|
|
|
|
|
new BsonElement($"_id.{nameof(BuildGroup.Revision)}", -1)
|
|
|
|
|
}).Skip(skip);
|
2015-11-10 17:37:03 +08:00
|
|
|
|
|
2016-01-11 06:23:13 +08:00
|
|
|
|
if (limit > 0)
|
|
|
|
|
{
|
2016-01-12 05:16:29 +08:00
|
|
|
|
query = query.Limit(limit);
|
2016-01-11 06:23:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 21:39:30 +08:00
|
|
|
|
List<BsonDocument> grouping = await query.ToListAsync();
|
2016-01-11 06:23:13 +08:00
|
|
|
|
|
|
|
|
|
return (from g in grouping
|
|
|
|
|
select new FrontBuildGroup
|
2016-07-15 21:39:30 +08:00
|
|
|
|
{
|
|
|
|
|
Key = new BuildGroup
|
|
|
|
|
{
|
|
|
|
|
Major = (uint)g["_id"].AsBsonDocument[nameof(BuildGroup.Major)].AsInt32,
|
|
|
|
|
Minor = (uint)g["_id"].AsBsonDocument[nameof(BuildGroup.Minor)].AsInt32,
|
|
|
|
|
Build = (uint)g["_id"].AsBsonDocument[nameof(BuildGroup.Build)].AsInt32,
|
|
|
|
|
Revision = (uint?)g["_id"].AsBsonDocument[nameof(BuildGroup.Revision)].AsNullableInt32
|
|
|
|
|
},
|
|
|
|
|
LastBuild = g["date"].ToNullableUniversalTime(),
|
|
|
|
|
BuildCount = g["count"].AsInt32
|
|
|
|
|
}).ToArray();
|
2015-11-10 17:37:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 05:16:29 +08:00
|
|
|
|
public async Task<long> SelectAllGroupsCount()
|
2015-11-10 00:43:05 +08:00
|
|
|
|
{
|
2016-07-15 21:39:30 +08:00
|
|
|
|
List<BsonDocument> grouping = await _buildCollection.Aggregate().Group(new BsonDocument
|
|
|
|
|
{
|
2016-08-19 20:45:52 +08:00
|
|
|
|
new BsonElement("_id",
|
|
|
|
|
new BsonDocument
|
|
|
|
|
{
|
2016-08-21 07:09:56 +08:00
|
|
|
|
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)}")
|
2016-08-19 20:45:52 +08:00
|
|
|
|
})
|
2016-07-15 21:39:30 +08:00
|
|
|
|
}).ToListAsync();
|
2016-01-11 06:23:13 +08:00
|
|
|
|
return grouping.Count;
|
2015-11-10 00:43:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-21 07:09:56 +08:00
|
|
|
|
public async Task<List<Build>> SelectGroup(BuildGroup group, int limit = -1, int skip = 0)
|
2016-01-12 05:16:29 +08:00
|
|
|
|
{
|
2016-08-21 07:09:56 +08:00
|
|
|
|
IFindFluent<Build, Build> query = _buildCollection.Find(new BsonDocument
|
2016-07-15 21:39:30 +08:00
|
|
|
|
{
|
2016-08-21 07:09:56 +08:00
|
|
|
|
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)
|
2016-07-15 21:39:30 +08:00
|
|
|
|
}).Sort(new BsonDocument
|
|
|
|
|
{
|
2016-08-21 07:09:56 +08:00
|
|
|
|
new BsonElement(nameof(Build.BuildTime), 1)
|
2016-07-15 21:39:30 +08:00
|
|
|
|
}).Skip(skip);
|
2016-01-12 05:16:29 +08:00
|
|
|
|
|
|
|
|
|
if (limit > 0)
|
|
|
|
|
{
|
|
|
|
|
query = query.Limit(limit);
|
|
|
|
|
}
|
2015-11-10 00:43:05 +08:00
|
|
|
|
|
2016-01-12 05:16:29 +08:00
|
|
|
|
return await query.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-19 20:45:52 +08:00
|
|
|
|
public async Task<long> SelectGroupCount(BuildGroup group) => await _buildCollection.CountAsync(new BsonDocument
|
2016-01-12 05:16:29 +08:00
|
|
|
|
{
|
2016-08-21 07:09:56 +08:00
|
|
|
|
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)
|
2016-08-19 20:45:52 +08:00
|
|
|
|
});
|
2015-11-10 00:43:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|