Make it compile

Any sane person would vomit reading the code in its current state.
This commit is contained in:
Thomas Hounsell 2015-09-08 23:59:52 +01:00
parent 8c8a30b6e6
commit 34141f60f1
11 changed files with 153 additions and 220 deletions

View File

@ -11,22 +11,22 @@ public class metaController : Controller
// GET: admin/meta
public ActionResult index()
{
var currentItems = from i in MetaItem.Select()
var currentItems = from i in new MetaItem().Select()
group i by i.Id.Type
into b
select b;
var pendingLabs = MetaItem.SelectUnusedLabs();
var pendingLabs = new MetaItem().SelectUnusedLabs();
return View(new MetaListing
{
CurrentItems = from i in MetaItem.Select()
CurrentItems = from i in new MetaItem().Select()
group i by i.Id.Type
into b
orderby b.Key.ToString()
select b,
NewItems = from i in (from l in MetaItem.SelectUnusedLabs()
select new MetaItem
NewItems = from i in (from l in new MetaItem().SelectUnusedLabs()
select new MetaItemModel
{
Id = new MetaItemKey
{
@ -34,8 +34,8 @@ orderby b.Key.ToString()
Value = l
}
})
.Concat(from v in MetaItem.SelectUnusedVersions()
select new MetaItem
.Concat(from v in new MetaItem().SelectUnusedVersions()
select new MetaItemModel
{
Id = new MetaItemKey
{
@ -43,8 +43,8 @@ orderby b.Key.ToString()
Value = v
}
})
.Concat(from y in MetaItem.SelectUnusedYears()
select new MetaItem
.Concat(from y in new MetaItem().SelectUnusedYears()
select new MetaItemModel
{
Id = new MetaItemKey
{
@ -61,7 +61,7 @@ select b
public ActionResult create(MetaType type, string value)
{
return View(new MetaItem
return View(new MetaItemModel
{
Id = new MetaItemKey
{
@ -72,11 +72,11 @@ public ActionResult create(MetaType type, string value)
}
[HttpPost]
public ActionResult create(MetaItem meta)
public ActionResult create(MetaItemModel meta)
{
if (ModelState.IsValid)
{
MetaItem.Insert(meta);
new MetaItem().Insert(meta);
return RedirectToAction("index");
}
@ -85,7 +85,7 @@ public ActionResult create(MetaItem meta)
public ActionResult edit(MetaType type, string value)
{
return View("create", MetaItem.SelectById(new MetaItemKey
return View("create", new MetaItem().SelectById(new MetaItemKey
{
Type = type,
Value = value
@ -93,11 +93,11 @@ public ActionResult edit(MetaType type, string value)
}
[HttpPost]
public ActionResult edit(MetaItem meta)
public ActionResult edit(MetaItemModel meta)
{
if (ModelState.IsValid)
{
MetaItem.Update(meta);
new MetaItem().Update(meta);
return RedirectToAction("index");
}

View File

@ -6,7 +6,7 @@ namespace BuildFeed.Areas.admin.Models.ViewModel
{
public class MetaListing
{
public IEnumerable<IGrouping<MetaType, MetaItem>> CurrentItems { get; set; }
public IEnumerable<IGrouping<MetaType, MetaItem>> NewItems { get; set; }
public IEnumerable<IGrouping<MetaType, MetaItemModel>> CurrentItems { get; set; }
public IEnumerable<IGrouping<MetaType, MetaItemModel>> NewItems { get; set; }
}
}

View File

@ -195,7 +195,6 @@
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Areas\admin\adminAreaRegistration.cs" />
<Compile Include="Areas\admin\Controllers\usersController.cs" />
<Compile Include="Code\LongIdGenerator.cs" />
<Compile Include="Code\MvcIntrinsics.cs" />
<Compile Include="Controllers\apiController.cs" />
<Compile Include="Controllers\frontController.cs" />

View File

@ -1,42 +0,0 @@
using System;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Bson.Serialization;
namespace BuildFeed.Code
{
public class LongIdGenerator : IIdGenerator
{
private const string _idCollectionName = "IDs";
private MongoClient _dbClient;
private IMongoCollection<long> _idCollection;
public LongIdGenerator()
{
_dbClient = new MongoClient(new MongoClientSettings()
{
Server = new MongoServerAddress(MongoConfig.Host, MongoConfig.Port)
});
_idCollection = _dbClient.GetDatabase(MongoConfig.Database).GetCollection<long>(_idCollectionName);
}
public object GenerateId(object container, object document)
{
var query = Query.EQ("_id", (container).Name);
return (_idCollection.FindOneAndUpdateAsync(new FindAndModifyArgs()
{
Query = query,
Update = CreateUpdateBuilder(),
VersionReturned = FindAndModifyDocumentVersion.Modified,
Upsert = true
}).AsInt64.ModifiedDocument["seq"]);
}
public bool IsEmpty(object id)
{
return ((long)id) == 0;
}
}
}

View File

@ -10,16 +10,17 @@ namespace BuildFeed.Controllers
{
public class apiController : ApiController
{
public IEnumerable<Build> GetBuilds()
public IEnumerable<BuildModel> GetBuilds()
{
return Build.SelectInBuildOrder();
return new Build().SelectInBuildOrder();
}
public IEnumerable<string> GetWin10Labs()
{
Build b = new Build();
List<string> labs = new List<string>();
labs.AddRange(Build.SelectBuildLabs(6, 4));
labs.AddRange(Build.SelectBuildLabs(10, 0));
labs.AddRange(b.SelectBuildLabs(6, 4));
labs.AddRange(b.SelectBuildLabs(10, 0));
return labs.GroupBy(l => l).Select(l => l.Key).Where(l => l.All(c => c != '(')).ToArray();
}
@ -33,7 +34,7 @@ public bool AddWin10Builds(NewBuild apiModel)
}
if (Membership.ValidateUser(apiModel.Username, apiModel.Password))
{
Build.InsertAll(apiModel.NewBuilds.Select(nb => new Build()
new Build().InsertAll(apiModel.NewBuilds.Select(nb => new BuildModel()
{
MajorVersion = nb.MajorVersion,
MinorVersion = nb.MinorVersion,
@ -74,7 +75,7 @@ orderby s.Text.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) asce
results.AddRange(sourceResults);
var versionResults = from v in Build.SelectBuildVersions()
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()
@ -88,7 +89,7 @@ orderby s.Text.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) asce
results.AddRange(versionResults);
var yearResults = from y in Build.SelectBuildYears()
var yearResults = from y in new Build().SelectBuildYears()
where y.ToString().Contains(query)
orderby y descending
select new SearchResult()
@ -102,7 +103,7 @@ orderby y descending
results.AddRange(yearResults);
var labResults = from l in Build.SelectBuildLabs()
var labResults = from l in new Build().SelectBuildLabs()
where l.ToLower().Contains(query.ToLower())
orderby l.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) ascending
select new SearchResult()
@ -116,7 +117,7 @@ orderby l.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) ascending
results.AddRange(labResults);
var buildResults = from b in Build.Select()
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

View File

@ -27,7 +27,7 @@ public class frontController : Controller
#endif
public ActionResult indexPage(int page)
{
var buildGroups = (from b in Build.Select()
var buildGroups = (from b in new Build().Select()
group b by new BuildGroup
{
Major = b.MajorVersion,
@ -64,7 +64,7 @@ bg.Key.Revision descending
#endif
public ActionResult viewGroup(byte major, byte minor, ushort number, ushort? revision = null)
{
var builds = (from b in Build.Select()
var builds = (from b in new Build().Select()
group b by new BuildGroup
{
Major = b.MajorVersion,
@ -88,9 +88,9 @@ into bg
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName")]
#endif
public ActionResult viewBuild(long id)
public ActionResult viewBuild(Guid id)
{
Build b = Build.SelectById(id);
BuildModel b = new Build().SelectById(id);
return View(b);
}
@ -99,9 +99,9 @@ public ActionResult viewBuild(long id)
[OutputCache(Duration = 600, VaryByParam = "none")]
[CustomContentType(ContentType = "image/png", Order = 2)]
#endif
public ActionResult twitterCard(long id)
public ActionResult twitterCard(Guid id)
{
Build b = Build.SelectById(id);
BuildModel b = new Build().SelectById(id);
using (Bitmap bm = new Bitmap(560, 300))
{
@ -142,14 +142,14 @@ public ActionResult twitterCard(long id)
#endif
public ActionResult viewLabPage(string lab, int page)
{
ViewBag.MetaItem = MetaItem.SelectById(new MetaItemKey
ViewBag.MetaItem = new MetaItem().SelectById(new MetaItemKey
{
Type = MetaType.Lab,
Value = lab
});
ViewBag.ItemId = lab;
var builds = Build.SelectInBuildOrder().Where(b => b.Lab != null && (b.Lab.ToLower() == lab.ToLower())).ToArray();
var builds = new Build().SelectInBuildOrder().Where(b => b.Lab != null && (b.Lab.ToLower() == lab.ToLower())).ToArray();
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Length) / Convert.ToDouble(PAGE_SIZE));
@ -174,14 +174,14 @@ public ActionResult viewLabPage(string lab, int page)
#endif
public ActionResult viewSourcePage(TypeOfSource source, int page)
{
ViewBag.MetaItem = MetaItem.SelectById(new MetaItemKey
ViewBag.MetaItem = new MetaItem().SelectById(new MetaItemKey
{
Type = MetaType.Source,
Value = source.ToString()
});
ViewBag.ItemId = DisplayHelpers.GetDisplayTextForEnum(source);
var builds = Build.SelectInBuildOrder().Where(b => b.SourceType == source).ToArray();
var builds = new Build().SelectInBuildOrder().Where(b => b.SourceType == source).ToArray();
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Length) / Convert.ToDouble(PAGE_SIZE));
@ -206,14 +206,14 @@ public ActionResult viewSourcePage(TypeOfSource source, int page)
#endif
public ActionResult viewYearPage(int year, int page)
{
ViewBag.MetaItem = MetaItem.SelectById(new MetaItemKey
ViewBag.MetaItem = new MetaItem().SelectById(new MetaItemKey
{
Type = MetaType.Year,
Value = year.ToString()
});
ViewBag.ItemId = year.ToString();
var builds = Build.SelectInBuildOrder().Where(b => b.BuildTime.HasValue && b.BuildTime.Value.Year == year).ToArray();
var builds = new Build().SelectInBuildOrder().Where(b => b.BuildTime.HasValue && b.BuildTime.Value.Year == year).ToArray();
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Length) / Convert.ToDouble(PAGE_SIZE));
@ -239,14 +239,14 @@ public ActionResult viewYearPage(int year, int page)
public ActionResult viewVersionPage(int major, int minor, int page)
{
string valueString = $"{major}.{minor}";
ViewBag.MetaItem = MetaItem.SelectById(new MetaItemKey
ViewBag.MetaItem = new MetaItem().SelectById(new MetaItemKey
{
Type = MetaType.Version,
Value = valueString
});
ViewBag.ItemId = valueString;
var builds = Build.SelectInBuildOrder().Where(b => b.MajorVersion == major && b.MinorVersion == minor).ToArray();
var builds = new Build().SelectInBuildOrder().Where(b => b.MajorVersion == major && b.MinorVersion == minor).ToArray();
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Length) / Convert.ToDouble(PAGE_SIZE));
@ -263,7 +263,7 @@ public ActionResult viewVersionPage(int major, int minor, int page)
public ActionResult addBuild() { return View("editBuild"); }
[Route("add/"), Authorize, HttpPost]
public ActionResult addBuild(Build build)
public ActionResult addBuild(BuildModel build)
{
if (ModelState.IsValid)
{
@ -271,7 +271,7 @@ public ActionResult addBuild(Build build)
{
build.Added = DateTime.Now;
build.Modified = DateTime.Now;
Build.Insert(build);
new Build().Insert(build);
}
catch
{
@ -286,20 +286,20 @@ public ActionResult addBuild(Build build)
}
[Route("edit/{id}/"), Authorize]
public ActionResult editBuild(long id)
public ActionResult editBuild(Guid id)
{
Build b = Build.SelectById(id);
BuildModel b = new Build().SelectById(id);
return View(b);
}
[Route("edit/{id}/"), Authorize, HttpPost]
public ActionResult editBuild(long id, Build build)
public ActionResult editBuild(long id, BuildModel build)
{
if (ModelState.IsValid)
{
try
{
Build.Update(build);
new Build().Update(build);
}
catch
{
@ -312,9 +312,9 @@ public ActionResult editBuild(long id, Build build)
}
[Route("delete/{id}/"), Authorize(Roles = "Administrators")]
public ActionResult deleteBuild(long id)
public ActionResult deleteBuild(Guid id)
{
Build.DeleteById(id);
new Build().DeleteById(id);
return RedirectToAction("index");
}
}

View File

@ -15,7 +15,7 @@ public class rssController : Controller
[Route("rss/compiled")]
public async Task<ActionResult> index()
{
var builds = Build.SelectInBuildOrder().Take(20);
var builds = new Build().SelectInBuildOrder().Take(20);
RssDocument rdoc = new RssDocument()
{
@ -48,7 +48,7 @@ public async Task<ActionResult> index()
[Route("rss/added")]
public async Task<ActionResult> added()
{
var builds = Build.Select().OrderByDescending(b => b.Added).Take(20);
var builds = new Build().Select().OrderByDescending(b => b.Added).Take(20);
RssDocument rdoc = new RssDocument()
{
@ -83,7 +83,7 @@ public async Task<ActionResult> added()
[Route("rss/leaked")]
public async Task<ActionResult> leaked()
{
var builds = Build.Select().Where(b => b.LeakDate.HasValue).OrderByDescending(b => b.LeakDate.Value).Take(20);
var builds = new Build().Select().Where(b => b.LeakDate.HasValue).OrderByDescending(b => b.LeakDate.Value).Take(20);
RssDocument rdoc = new RssDocument()
{
@ -118,7 +118,7 @@ public async Task<ActionResult> leaked()
[Route("rss/version")]
public async Task<ActionResult> version()
{
var builds = Build.SelectInVersionOrder()
var builds = new Build().SelectInVersionOrder()
.Take(20);
@ -154,7 +154,7 @@ public async Task<ActionResult> version()
[Route("rss/flight/{id}")]
public async Task<ActionResult> flight(LevelOfFlight id)
{
var builds = Build.SelectInBuildOrder()
var builds = new Build().SelectInBuildOrder()
.Where(b => b.FlightLevel == id)
.Take(20);
@ -191,7 +191,7 @@ public async Task<ActionResult> flight(LevelOfFlight id)
[Route("rss/lab/{lab}")]
public async Task<ActionResult> lab(string lab)
{
var builds = Build.SelectInBuildOrder()
var builds = new Build().SelectInBuildOrder()
.Where(b => b.Lab == lab)
.Take(20);

View File

@ -128,7 +128,7 @@ public ActionResult thanks_register()
[Route("rss")]
public ActionResult rss()
{
ViewBag.Labs = Build.SelectBuildLabs();
ViewBag.Labs = new Build().SelectBuildLabs();
return View();
}
@ -138,7 +138,7 @@ public ActionResult rss()
#endif
public ActionResult sitemap()
{
var builds = Build.SelectInVersionOrder().ToArray();
var builds = new Build().SelectInVersionOrder();
Dictionary<string, SitemapPagedAction[]> actions = new Dictionary<string, SitemapPagedAction[]>
{
{
@ -152,7 +152,7 @@ public ActionResult sitemap()
action = "index",
page = 1
}),
Pages = (builds.Length + (frontController.PAGE_SIZE - 1)) / frontController.PAGE_SIZE
Pages = (builds.Count() + (frontController.PAGE_SIZE - 1)) / frontController.PAGE_SIZE
}
}
},
@ -245,7 +245,7 @@ orderby bv.Key
SitemapData model = new SitemapData()
{
Builds = (from b in Build.Select()
Builds = (from b in new Build().Select()
group b by new BuildGroup()
{
Major = b.MajorVersion,
@ -292,7 +292,7 @@ public ActionResult xmlsitemap()
home.Add(new XElement(xn + "changefreq", "daily"));
xlist.Add(home);
foreach (var b in Build.Select())
foreach (var b in new Build().Select())
{
XElement url = new XElement(xn + "url");
url.Add(new XElement(xn + "loc", Request.Url.GetLeftPart(UriPartial.Authority) + Url.Action("viewBuild", "front", new { id = b.Id })));
@ -321,7 +321,7 @@ public ActionResult xmlsitemap()
#endif
public ActionResult stats()
{
var builds = Build.Select().ToArray();
var builds = new Build().Select().ToArray();
List<MonthCount> additions = new List<MonthCount>();
var rawAdditions = (from b in builds

View File

@ -18,7 +18,9 @@ namespace BuildFeed.Models
public class BuildModel
{
[Key, BsonId]
public long Id { get; set; }
public Guid Id { get; set; }
public long? LegacyId { get; set; }
[@Required]
[Display(ResourceType = typeof(Model), Name = "MajorVersion")]
@ -139,13 +141,21 @@ public IEnumerable<BuildModel> Select()
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public BuildModel SelectById(long id)
public BuildModel SelectById(Guid id)
{
var task = _buildCollection.Find(f => f.Id == id).SingleOrDefaultAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public BuildModel SelectByLegacyId(long id)
{
var task = _buildCollection.Find(f => f.LegacyId == id).SingleOrDefaultAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public IEnumerable<BuildModel> SelectInBuildOrder()
{
@ -219,47 +229,34 @@ public IEnumerable<string> SelectBuildLabs(byte major, byte minor)
[DataObjectMethod(DataObjectMethodType.Insert, true)]
public void Insert(BuildModel item)
{
item.Id =
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<Build>();
item.Id = client.GetNextSequence();
client.Store(item);
}
item.Id = Guid.NewGuid();
var task = _buildCollection.InsertOneAsync(item);
task.Wait();
}
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static void Update(Build item)
public void Update(BuildModel item)
{
Build old = SelectById(item.Id);
BuildModel old = SelectById(item.Id);
item.Added = old.Added;
item.Modified = DateTime.Now;
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<Build>();
client.Store(item);
}
var task = _buildCollection.ReplaceOneAsync(f => f.Id == item.Id, item);
task.Wait();
}
[DataObjectMethod(DataObjectMethodType.Insert, false)]
public static void InsertAll(IEnumerable<Build> items)
public void InsertAll(IEnumerable<BuildModel> items)
{
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<Build>();
client.StoreAll(items);
}
var task = _buildCollection.InsertManyAsync(items);
task.Wait();
}
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static void DeleteById(long id)
public void DeleteById(Guid id)
{
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<Build>();
client.DeleteById(id);
}
var task = _buildCollection.DeleteOneAsync(f => f.Id == id);
task.Wait();
}
}

View File

@ -1,6 +1,6 @@
using NServiceKit.DataAnnotations;
using NServiceKit.DesignPatterns.Model;
using NServiceKit.Redis;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -12,10 +12,10 @@
namespace BuildFeed.Models
{
[DataObject]
public class MetaItem : IHasId<MetaItemKey>
public class MetaItemModel
{
[Key]
[Index]
[BsonId]
[@Required]
public MetaItemKey Id { get; set; }
@ -25,136 +25,114 @@ public class MetaItem : IHasId<MetaItemKey>
[DisplayName("Meta Description")]
public string MetaDescription { get; set; }
}
public class MetaItem
{
private const string _metaCollectionName = "metaitem";
private MongoClient _dbClient;
private IMongoCollection<MetaItemModel> _metaCollection;
public MetaItem()
{
_dbClient = new MongoClient(new MongoClientSettings()
{
Server = new MongoServerAddress(MongoConfig.Host, MongoConfig.Port)
});
_metaCollection = _dbClient.GetDatabase(MongoConfig.Database).GetCollection<MetaItemModel>(_metaCollectionName);
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static IEnumerable<MetaItem> Select()
public IEnumerable<MetaItemModel> Select()
{
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<MetaItem>();
return client.GetAll();
}
var task = _metaCollection.Find(new BsonDocument()).ToListAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static IEnumerable<MetaItem> SelectByType(MetaType type)
public IEnumerable<MetaItemModel> SelectByType(MetaType type)
{
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<MetaItem>();
return from t in client.GetAll()
where t.Id.Type == type
select t;
}
var task = _metaCollection.Find(f => f.Id.Type == type).ToListAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static MetaItem SelectById(MetaItemKey id)
public MetaItemModel SelectById(MetaItemKey id)
{
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<MetaItem>();
return client.GetById(id);
}
var task = _metaCollection.Find(f => f.Id.Type == id.Type && f.Id.Value == id.Value).SingleOrDefaultAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static IEnumerable<string> SelectUnusedLabs()
public IEnumerable<string> SelectUnusedLabs()
{
var labs = new Build().SelectBuildLabs();
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<MetaItem>();
var labs = Build.SelectBuildLabs();
var usedLabs = from u in client.GetAll()
where u.Id.Type == MetaType.Lab
select u;
var usedLabs = _metaCollection.Find(f => f.Id.Type == MetaType.Lab).ToListAsync();
usedLabs.Wait();
return from l in labs
where usedLabs.All(ul => ul.Id.Value != l)
where usedLabs.Result.All(ul => ul.Id.Value != l)
select l;
}
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static IEnumerable<string> SelectUnusedVersions()
public IEnumerable<string> SelectUnusedVersions()
{
var versions = new Build().SelectBuildVersions();
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<MetaItem>();
var versions = Build.SelectBuildVersions();
var usedLabs = from u in client.GetAll()
where u.Id.Type == MetaType.Version
select u;
var usedVersions = _metaCollection.Find(f => f.Id.Type == MetaType.Version).ToListAsync();
usedVersions.Wait();
return from v in versions
where usedLabs.All(ul => ul.Id.Value != v.ToString())
where usedVersions.Result.All(ul => ul.Id.Value != v.ToString())
select v.ToString();
}
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static IEnumerable<string> SelectUnusedYears()
public IEnumerable<string> SelectUnusedYears()
{
var years = new Build().SelectBuildYears();
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<MetaItem>();
var years = Build.SelectBuildYears();
var usedYears = from u in client.GetAll()
where u.Id.Type == MetaType.Year
select u;
var usedYears = _metaCollection.Find(f => f.Id.Type == MetaType.Year).ToListAsync();
usedYears.Wait();
return from y in years
where usedYears.All(ul => ul.Id.Value != y.ToString())
where usedYears.Result.All(ul => ul.Id.Value != y.ToString())
select y.ToString();
}
}
[DataObjectMethod(DataObjectMethodType.Insert, true)]
public static void Insert(MetaItem item)
public void Insert(MetaItemModel item)
{
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<MetaItem>();
client.Store(item);
}
var task = _metaCollection.InsertOneAsync(item);
task.Wait();
}
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static void Update(MetaItem item)
public void Update(MetaItemModel item)
{
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<MetaItem>();
client.Store(item);
}
var task = _metaCollection.ReplaceOneAsync(f => f.Id.Type == item.Id.Type && f.Id.Value == item.Id.Value, item);
task.Wait();
}
[DataObjectMethod(DataObjectMethodType.Insert, false)]
public static void InsertAll(IEnumerable<MetaItem> items)
public void InsertAll(IEnumerable<MetaItemModel> items)
{
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<MetaItem>();
client.StoreAll(items);
}
var task = _metaCollection.InsertManyAsync(items);
task.Wait();
}
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static void DeleteById(long id)
public void DeleteById(MetaItemKey id)
{
using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database))
{
var client = rClient.As<MetaItem>();
client.DeleteById(id);
}
var task = _metaCollection.DeleteOneAsync(f => f.Id.Type == id.Type && f.Id.Value == id.Value);
task.Wait();
}
}

View File

@ -22,7 +22,7 @@ public class SitemapDataBuildGroup
public class SitemapDataBuild
{
public long Id { get; set; }
public Guid Id { get; set; }
public string Name { get; set; }
}