mirror of
https://gitlab.com/buildfeed/BuildFeed.git
synced 2024-03-22 21:10:34 +08:00
Another round of automated time fixes
Curse Mongo driver assuming UTC.
This commit is contained in:
parent
38f58f9ba5
commit
5501453484
21
MongoTimeChecker/Build.cs
Normal file
21
MongoTimeChecker/Build.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RedisMongoMigration
|
||||
{
|
||||
public enum TypeOfSource
|
||||
{
|
||||
PublicRelease,
|
||||
InternalLeak,
|
||||
UpdateGDR,
|
||||
UpdateLDR,
|
||||
AppPackage,
|
||||
BuildTools,
|
||||
Documentation,
|
||||
Logging,
|
||||
PrivateLeak
|
||||
}
|
||||
}
|
137
MongoTimeChecker/Mongo/Build.cs
Normal file
137
MongoTimeChecker/Mongo/Build.cs
Normal file
|
@ -0,0 +1,137 @@
|
|||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace RedisMongoMigration.Mongo
|
||||
{
|
||||
public class BuildModel
|
||||
{
|
||||
[BsonId]
|
||||
public Guid Id { get; set; }
|
||||
public long? LegacyId { get; set; }
|
||||
public byte MajorVersion { get; set; }
|
||||
public byte MinorVersion { get; set; }
|
||||
public ushort Number { get; set; }
|
||||
public ushort? Revision { get; set; }
|
||||
public string Lab { get; set; }
|
||||
public DateTime? BuildTime { get; set; }
|
||||
|
||||
public DateTime Added { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
public TypeOfSource SourceType { get; set; }
|
||||
public string SourceDetails { get; set; }
|
||||
public DateTime? LeakDate { get; set; }
|
||||
public MongoLevelOfFlight FlightLevel { 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.AppendFormat("{0}.{1}.{2}", MajorVersion, MinorVersion, Number);
|
||||
|
||||
if (Revision.HasValue)
|
||||
{
|
||||
sb.AppendFormat(".{0}", Revision);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Lab))
|
||||
{
|
||||
sb.AppendFormat(".{0}", Lab);
|
||||
}
|
||||
|
||||
if (BuildTime.HasValue)
|
||||
{
|
||||
sb.AppendFormat(".{0:yyMMdd-HHmm}", BuildTime);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public string GenerateLabUrl() => (Lab ?? "").Replace('/', '-').ToLower();
|
||||
}
|
||||
|
||||
public class Build
|
||||
{
|
||||
private const string _buildCollectionName = "builds";
|
||||
|
||||
private MongoClient _dbClient;
|
||||
private IMongoCollection<BuildModel> _buildCollection;
|
||||
|
||||
public Build()
|
||||
{
|
||||
_dbClient = new MongoClient(new MongoClientSettings()
|
||||
{
|
||||
Server = new MongoServerAddress("localhost", 27017)
|
||||
});
|
||||
|
||||
_buildCollection = _dbClient.GetDatabase("BuildFeed").GetCollection<BuildModel>(_buildCollectionName);
|
||||
}
|
||||
|
||||
public List<BuildModel> Select()
|
||||
{
|
||||
var task = _buildCollection.Find(new BsonDocument()).ToListAsync();
|
||||
task.Wait();
|
||||
return task.Result;
|
||||
}
|
||||
|
||||
public BuildModel SelectByLegacyId(long id)
|
||||
{
|
||||
var task = _buildCollection.Find(b => b.LegacyId == id).SingleOrDefaultAsync();
|
||||
task.Wait();
|
||||
return task.Result;
|
||||
}
|
||||
|
||||
public void UpdateDateOfLegacy(long id, DateTime? leak)
|
||||
{
|
||||
var task = _buildCollection.UpdateOneAsync(f => f.LegacyId == id, Builders<BuildModel>.Update.Set(f => f.BuildTime, leak));
|
||||
task.Wait();
|
||||
}
|
||||
|
||||
public void Insert(BuildModel item)
|
||||
{
|
||||
item.Id = Guid.NewGuid();
|
||||
var task = _buildCollection.InsertOneAsync(item);
|
||||
task.Wait();
|
||||
}
|
||||
|
||||
public void InsertAll(IEnumerable<BuildModel> items)
|
||||
{
|
||||
var task = _buildCollection.InsertManyAsync(items);
|
||||
task.Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public enum MongoLevelOfFlight
|
||||
{
|
||||
None = 0,
|
||||
WIS = 1,
|
||||
WIF = 2,
|
||||
OSG = 3,
|
||||
MSIT = 4,
|
||||
Canary = 5
|
||||
}
|
||||
}
|
|
@ -33,7 +33,36 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MongoDB.Bson, Version=2.1.0.145, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDB.Bson.2.1.0\lib\net45\MongoDB.Bson.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="MongoDB.Driver, Version=2.1.0.145, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDB.Driver.2.1.0\lib\net45\MongoDB.Driver.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="MongoDB.Driver.Core, Version=2.1.0.145, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDB.Driver.Core.2.1.0\lib\net45\MongoDB.Driver.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NServiceKit.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NServiceKit.Common.1.0.31\lib\net35\NServiceKit.Common.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NServiceKit.Interfaces, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NServiceKit.Common.1.0.31\lib\net35\NServiceKit.Interfaces.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NServiceKit.Redis, Version=1.0.17.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NServiceKit.Redis.1.0.17\lib\net35\NServiceKit.Redis.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NServiceKit.Text, Version=1.0.10.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NServiceKit.Text.1.0.10\lib\net35\NServiceKit.Text.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
|
@ -43,11 +72,15 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Build.cs" />
|
||||
<Compile Include="Mongo\Build.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Redis\Build.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
@ -4,12 +4,35 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using MBuildModel = RedisMongoMigration.Mongo.BuildModel;
|
||||
using MBuild = RedisMongoMigration.Mongo.Build;
|
||||
using RBuild = RedisMongoMigration.Redis.Build;
|
||||
|
||||
namespace MongoTimeChecker
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var builds = RBuild.Select();
|
||||
|
||||
MBuild mBuildObj = new MBuild();
|
||||
foreach (var build in builds)
|
||||
{
|
||||
var mBuild = mBuildObj.SelectByLegacyId(build.Id);
|
||||
if(mBuild != null)
|
||||
{
|
||||
bool isSame = mBuild.BuildTime == build.BuildTime;
|
||||
if(!isSame)
|
||||
{
|
||||
Console.WriteLine($"{build.FullBuildString}: {build.BuildTime} != {mBuild.BuildTime}");
|
||||
DateTime dt = DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc);
|
||||
mBuildObj.UpdateDateOfLegacy(build.Id, dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
94
MongoTimeChecker/Redis/Build.cs
Normal file
94
MongoTimeChecker/Redis/Build.cs
Normal file
|
@ -0,0 +1,94 @@
|
|||
using NServiceKit.DataAnnotations;
|
||||
using NServiceKit.DesignPatterns.Model;
|
||||
using NServiceKit.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
|
||||
namespace RedisMongoMigration.Redis
|
||||
{
|
||||
[DataObject]
|
||||
public class Build : IHasId<long>
|
||||
{
|
||||
[Key]
|
||||
[AutoIncrement]
|
||||
[Index]
|
||||
public long Id { get; set; }
|
||||
public byte MajorVersion { get; set; }
|
||||
public byte MinorVersion { get; set; }
|
||||
public ushort Number { get; set; }
|
||||
public ushort? Revision { get; set; }
|
||||
public string Lab { get; set; }
|
||||
public DateTime? BuildTime { get; set; }
|
||||
|
||||
public DateTime Added { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
public TypeOfSource SourceType { get; set; }
|
||||
public string SourceDetails { get; set; }
|
||||
public DateTime? LeakDate { get; set; }
|
||||
public RedisLevelOfFlight FlightLevel { get; set; }
|
||||
|
||||
public bool IsLeaked
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (SourceType)
|
||||
{
|
||||
case TypeOfSource.PublicRelease:
|
||||
case TypeOfSource.InternalLeak:
|
||||
case TypeOfSource.UpdateGDR:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FullBuildString
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendFormat("{0}.{1}.{2}", MajorVersion, MinorVersion, Number);
|
||||
|
||||
if (Revision.HasValue)
|
||||
{
|
||||
sb.AppendFormat(".{0}", Revision);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Lab))
|
||||
{
|
||||
sb.AppendFormat(".{0}", Lab);
|
||||
}
|
||||
|
||||
if (BuildTime.HasValue)
|
||||
{
|
||||
sb.AppendFormat(".{0:yyMMdd-HHmm}", BuildTime);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public string GenerateLabUrl() => (Lab ?? "").Replace('/', '-').ToLower();
|
||||
|
||||
public static IEnumerable<Build> Select()
|
||||
{
|
||||
using (RedisClient rClient = new RedisClient("localhost", 6379, db: 1))
|
||||
{
|
||||
var client = rClient.As<Build>();
|
||||
return client.GetAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum RedisLevelOfFlight
|
||||
{
|
||||
None = 0,
|
||||
Low = 1,
|
||||
Medium = 2,
|
||||
High = 3
|
||||
}
|
||||
}
|
9
MongoTimeChecker/packages.config
Normal file
9
MongoTimeChecker/packages.config
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MongoDB.Bson" version="2.1.0" targetFramework="net46" />
|
||||
<package id="MongoDB.Driver" version="2.1.0" targetFramework="net46" />
|
||||
<package id="MongoDB.Driver.Core" version="2.1.0" targetFramework="net46" />
|
||||
<package id="NServiceKit.Common" version="1.0.31" targetFramework="net46" />
|
||||
<package id="NServiceKit.Redis" version="1.0.17" targetFramework="net46" />
|
||||
<package id="NServiceKit.Text" version="1.0.10" targetFramework="net46" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user