2015-01-05 01:31:27 +08:00
|
|
|
|
using NServiceKit.DataAnnotations;
|
2014-12-16 22:43:26 +08:00
|
|
|
|
using NServiceKit.DesignPatterns.Model;
|
2014-12-18 05:46:34 +08:00
|
|
|
|
using NServiceKit.Redis;
|
2015-01-30 05:44:54 +08:00
|
|
|
|
using System;
|
2014-12-16 22:43:26 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using Required = System.ComponentModel.DataAnnotations.RequiredAttribute;
|
|
|
|
|
|
|
|
|
|
namespace BuildFeed.Models
|
|
|
|
|
{
|
|
|
|
|
[DataObject]
|
2015-01-05 01:31:27 +08:00
|
|
|
|
public class MetaItem : IHasId<MetaItemKey>
|
2014-12-16 22:43:26 +08:00
|
|
|
|
{
|
|
|
|
|
[Key]
|
|
|
|
|
[Index]
|
|
|
|
|
[@Required]
|
2015-01-05 01:31:27 +08:00
|
|
|
|
public MetaItemKey Id { get; set; }
|
2014-12-16 22:43:26 +08:00
|
|
|
|
|
|
|
|
|
[DisplayName("Page Content")]
|
|
|
|
|
[AllowHtml]
|
|
|
|
|
public string PageContent { get; set; }
|
|
|
|
|
|
|
|
|
|
[DisplayName("Meta Description")]
|
|
|
|
|
public string MetaDescription { get; set; }
|
2014-12-18 05:46:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-05 06:14:43 +08:00
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select, false)]
|
2015-01-05 01:31:27 +08:00
|
|
|
|
public static IEnumerable<MetaItem> Select()
|
2014-12-18 05:46:34 +08:00
|
|
|
|
{
|
|
|
|
|
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
|
|
|
|
|
{
|
2015-01-05 01:31:27 +08:00
|
|
|
|
var client = rClient.As<MetaItem>();
|
2014-12-18 05:46:34 +08:00
|
|
|
|
return client.GetAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-05 06:14:43 +08:00
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select, true)]
|
|
|
|
|
public static IEnumerable<MetaItem> SelectByType(MetaType type)
|
|
|
|
|
{
|
|
|
|
|
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
|
|
|
|
|
{
|
|
|
|
|
var client = rClient.As<MetaItem>();
|
|
|
|
|
return from t in client.GetAll()
|
|
|
|
|
where t.Id.Type == type
|
|
|
|
|
select t;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 05:46:34 +08:00
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select, false)]
|
2015-01-05 01:31:27 +08:00
|
|
|
|
public static MetaItem SelectById(MetaItemKey id)
|
2014-12-18 05:46:34 +08:00
|
|
|
|
{
|
|
|
|
|
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
|
|
|
|
|
{
|
2015-01-05 01:31:27 +08:00
|
|
|
|
var client = rClient.As<MetaItem>();
|
2014-12-18 05:46:34 +08:00
|
|
|
|
return client.GetById(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select, false)]
|
|
|
|
|
public static IEnumerable<string> SelectUnusedLabs()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
|
|
|
|
|
{
|
2015-01-05 01:31:27 +08:00
|
|
|
|
var client = rClient.As<MetaItem>();
|
2014-12-18 05:46:34 +08:00
|
|
|
|
var labs = Build.SelectBuildLabs();
|
|
|
|
|
|
2015-01-05 01:31:27 +08:00
|
|
|
|
var usedLabs = from u in client.GetAll()
|
|
|
|
|
where u.Id.Type == MetaType.Lab
|
|
|
|
|
select u;
|
2014-12-18 05:46:34 +08:00
|
|
|
|
|
|
|
|
|
return from l in labs
|
2015-01-05 01:31:27 +08:00
|
|
|
|
where !usedLabs.Any(ul => ul.Id.Value as string == l)
|
2014-12-18 05:46:34 +08:00
|
|
|
|
select l;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-09 23:15:12 +08:00
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select, false)]
|
|
|
|
|
public static IEnumerable<string> SelectUnusedVersions()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.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;
|
|
|
|
|
|
|
|
|
|
return from v in versions
|
|
|
|
|
where !usedLabs.Any(ul => ul.Id.Value == v.ToString())
|
|
|
|
|
select v.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 06:15:03 +08:00
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select, false)]
|
|
|
|
|
public static IEnumerable<string> SelectUnusedYears()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.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;
|
|
|
|
|
|
|
|
|
|
return from y in years
|
|
|
|
|
where !usedYears.Any(ul => ul.Id.Value == y.ToString())
|
|
|
|
|
select y.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 05:46:34 +08:00
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Insert, true)]
|
2015-01-05 01:31:27 +08:00
|
|
|
|
public static void Insert(MetaItem item)
|
2014-12-18 05:46:34 +08:00
|
|
|
|
{
|
|
|
|
|
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
|
|
|
|
|
{
|
2015-01-05 01:31:27 +08:00
|
|
|
|
var client = rClient.As<MetaItem>();
|
2014-12-18 05:46:34 +08:00
|
|
|
|
client.Store(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Update, true)]
|
2015-01-05 01:31:27 +08:00
|
|
|
|
public static void Update(MetaItem item)
|
2014-12-18 05:46:34 +08:00
|
|
|
|
{
|
|
|
|
|
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
|
|
|
|
|
{
|
2015-01-05 01:31:27 +08:00
|
|
|
|
var client = rClient.As<MetaItem>();
|
2014-12-18 05:46:34 +08:00
|
|
|
|
client.Store(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Insert, false)]
|
2015-01-05 01:31:27 +08:00
|
|
|
|
public static void InsertAll(IEnumerable<MetaItem> items)
|
2014-12-18 05:46:34 +08:00
|
|
|
|
{
|
|
|
|
|
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
|
|
|
|
|
{
|
2015-01-05 01:31:27 +08:00
|
|
|
|
var client = rClient.As<MetaItem>();
|
2014-12-18 05:46:34 +08:00
|
|
|
|
client.StoreAll(items);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Delete, true)]
|
|
|
|
|
public static void DeleteById(long id)
|
|
|
|
|
{
|
|
|
|
|
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
|
|
|
|
|
{
|
2015-01-05 01:31:27 +08:00
|
|
|
|
var client = rClient.As<MetaItem>();
|
2014-12-18 05:46:34 +08:00
|
|
|
|
client.DeleteById(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-16 22:43:26 +08:00
|
|
|
|
}
|
2015-01-05 01:31:27 +08:00
|
|
|
|
|
|
|
|
|
public struct MetaItemKey
|
|
|
|
|
{
|
2015-01-30 05:44:54 +08:00
|
|
|
|
public string Value { get; set; }
|
2015-01-05 01:31:27 +08:00
|
|
|
|
public MetaType Type { get; set; }
|
2015-01-30 05:44:54 +08:00
|
|
|
|
|
|
|
|
|
public MetaItemKey(string id)
|
|
|
|
|
{
|
|
|
|
|
var items = id.Split(':');
|
|
|
|
|
Type = (MetaType)Enum.Parse(typeof(MetaType), items[0]);
|
|
|
|
|
Value = items[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return string.Format("{0}:{1}", Type, Value);
|
|
|
|
|
}
|
2015-01-05 01:31:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum MetaType
|
|
|
|
|
{
|
|
|
|
|
Lab,
|
|
|
|
|
Version,
|
2015-05-06 06:15:03 +08:00
|
|
|
|
Source,
|
|
|
|
|
Year
|
2015-01-05 01:31:27 +08:00
|
|
|
|
}
|
2014-12-16 22:43:26 +08:00
|
|
|
|
}
|