Date / Time fixes

Mongo treated Unspecified as if they were Local, helpfully "correcting"
them all to UTC.
This commit is contained in:
Thomas Hounsell 2015-10-14 14:06:23 +01:00
parent fe46a78847
commit a8b9ac9d53
9 changed files with 295 additions and 7 deletions

View File

@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RedisMongoMigration", "Redi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuildFeedApp-Full", "BuildFeedApp-Full\BuildFeedApp-Full.csproj", "{5370D7B3-CF04-47D4-B7D3-402B35ABF8E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoTimeFix", "MongoTimeFix\MongoTimeFix.csproj", "{B7EC3C45-E5CE-4AD5-B303-65D865F12454}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -135,6 +137,22 @@ Global
{5370D7B3-CF04-47D4-B7D3-402B35ABF8E8}.Release|x86.ActiveCfg = Release|x86
{5370D7B3-CF04-47D4-B7D3-402B35ABF8E8}.Release|x86.Build.0 = Release|x86
{5370D7B3-CF04-47D4-B7D3-402B35ABF8E8}.Release|x86.Deploy.0 = Release|x86
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Debug|ARM.ActiveCfg = Debug|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Debug|ARM.Build.0 = Debug|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Debug|x64.ActiveCfg = Debug|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Debug|x64.Build.0 = Debug|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Debug|x86.ActiveCfg = Debug|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Debug|x86.Build.0 = Debug|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Release|Any CPU.Build.0 = Release|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Release|ARM.ActiveCfg = Release|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Release|ARM.Build.0 = Release|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Release|x64.ActiveCfg = Release|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Release|x64.Build.0 = Release|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Release|x86.ActiveCfg = Release|Any CPU
{B7EC3C45-E5CE-4AD5-B303-65D865F12454}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -263,8 +263,16 @@ public async Task<ActionResult> addBuild(BuildModel build)
{
try
{
build.Added = DateTime.Now;
build.Modified = DateTime.Now;
build.Added = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
build.Modified = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
if (build.BuildTime.HasValue)
{
build.BuildTime = DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc);
}
if (build.LeakDate.HasValue)
{
build.LeakDate = DateTime.SpecifyKind(build.LeakDate.Value, DateTimeKind.Utc);
}
await bModel.Insert(build);
}
catch
@ -293,6 +301,14 @@ public async Task<ActionResult> editBuild(Guid id, BuildModel build)
{
try
{
if (build.BuildTime.HasValue)
{
build.BuildTime = DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc);
}
if (build.LeakDate.HasValue)
{
build.LeakDate = DateTime.SpecifyKind(build.LeakDate.Value, DateTimeKind.Utc);
}
await bModel.Update(build);
}
catch

View File

@ -497,7 +497,7 @@ public async Task Update(BuildModel item)
{
BuildModel old = await SelectById(item.Id);
item.Added = old.Added;
item.Modified = DateTime.Now;
item.Modified = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
item.LabUrl = item.GenerateLabUrl();
await _buildCollection.ReplaceOneAsync(f => f.Id == item.Id, item);

6
MongoTimeFix/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B7EC3C45-E5CE-4AD5-B303-65D865F12454}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MongoTimeFix</RootNamespace>
<AssemblyName>MongoTimeFix</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MongoDB.Bson, Version=2.0.1.27, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.0.1\lib\net45\MongoDB.Bson.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MongoDB.Driver, Version=2.0.1.27, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.0.1\lib\net45\MongoDB.Driver.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.0.1.27, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.0.1\lib\net45\MongoDB.Driver.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.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.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

133
MongoTimeFix/Program.cs Normal file
View File

@ -0,0 +1,133 @@
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MongoTimeFix
{
class Program
{
static void Main(string[] args)
{
const string _buildCollectionName = "builds";
MongoClient _dbClient = new MongoClient(new MongoClientSettings()
{
Server = new MongoServerAddress("localhost", 27017)
});
IMongoCollection<BuildModel> _buildCollection = _dbClient.GetDatabase("BuildFeed").GetCollection<BuildModel>(_buildCollectionName);
var task = _buildCollection.Find(new BsonDocument()).ToListAsync();
task.Wait();
foreach(var b in task.Result)
{
if (b.BuildTime.HasValue)
{
b.BuildTime = DateTime.SpecifyKind(b.BuildTime.Value.AddHours(1), DateTimeKind.Utc);
}
if (b.LeakDate.HasValue)
{
b.LeakDate = DateTime.SpecifyKind(b.LeakDate.Value.AddHours(1), DateTimeKind.Utc);
}
_buildCollection.ReplaceOneAsync(f => f.Id == b.Id, b);
}
}
}
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 LevelOfFlight 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 enum LevelOfFlight
{
None = 0,
WIS = 1,
WIF = 2,
OSG = 3,
MSIT = 4,
Canary = 5
}
public enum TypeOfSource
{
PublicRelease,
InternalLeak,
UpdateGDR,
UpdateLDR,
AppPackage,
BuildTools,
Documentation,
Logging,
PrivateLeak
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MongoTimeFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MongoTimeFix")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b7ec3c45-e5ce-4ad5-b303-65d865f12454")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MongoDB.Bson" version="2.0.1" targetFramework="net452" />
<package id="MongoDB.Driver" version="2.0.1" targetFramework="net452" />
<package id="MongoDB.Driver.Core" version="2.0.1" targetFramework="net452" />
</packages>

View File

@ -36,13 +36,13 @@ static void Main(string[] args)
Number = b.Number,
Revision = b.Revision,
Lab = b.Lab,
BuildTime = b.BuildTime,
BuildTime = b.BuildTime.HasValue ? DateTime.SpecifyKind(b.BuildTime.Value, DateTimeKind.Utc) as DateTime? : null as DateTime?,
Added = b.Added,
Modified = b.Modified,
Added = DateTime.SpecifyKind(b.Added, DateTimeKind.Utc),
Modified = DateTime.SpecifyKind(b.Modified, DateTimeKind.Utc),
SourceType = b.SourceType,
SourceDetails = b.SourceDetails,
LeakDate = b.LeakDate,
LeakDate = b.LeakDate.HasValue ? DateTime.SpecifyKind(b.LeakDate.Value, DateTimeKind.Utc) as DateTime? : null as DateTime?,
FlightLevel = ExchangeFlights(b.FlightLevel),
LabUrl = b.GenerateLabUrl()