Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 3c96a78

Browse files
author
Christy Henriksson
authored
Update ArchivePackages to use ISqlConnectionFactory (#423)
1 parent 13adac7 commit 3c96a78

4 files changed

Lines changed: 56 additions & 134 deletions

File tree

src/ArchivePackages/App.config

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
55
</startup>
66
<runtime>
77
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
88
<dependentAssembly>
9-
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
10-
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
9+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
10+
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0"/>
1111
</dependentAssembly>
1212
<dependentAssembly>
13-
<assemblyIdentity name="Microsoft.Azure.KeyVault" publicKeyToken="31bf3856ad364e35" culture="neutral" />
14-
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
13+
<assemblyIdentity name="Microsoft.Azure.KeyVault" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
14+
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0"/>
1515
</dependentAssembly>
1616
<dependentAssembly>
17-
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform" publicKeyToken="31bf3856ad364e35" culture="neutral" />
18-
<bindingRedirect oldVersion="0.0.0.0-3.13.4.878" newVersion="3.13.4.878" />
17+
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
18+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
1919
</dependentAssembly>
2020
<dependentAssembly>
21-
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
22-
<bindingRedirect oldVersion="0.0.0.0-3.13.4.878" newVersion="3.13.4.878" />
21+
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
22+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
2323
</dependentAssembly>
2424
<dependentAssembly>
25-
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
26-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
25+
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
26+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
2727
</dependentAssembly>
2828
<dependentAssembly>
29-
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
30-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
31-
</dependentAssembly>
32-
<dependentAssembly>
33-
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
34-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
35-
</dependentAssembly>
36-
<dependentAssembly>
37-
<assemblyIdentity name="NuGet.Services.KeyVault" publicKeyToken="31bf3856ad364e35" culture="neutral" />
38-
<bindingRedirect oldVersion="0.0.0.0-2.2.3.0" newVersion="2.2.3.0" />
39-
</dependentAssembly>
40-
<dependentAssembly>
41-
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" />
42-
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
29+
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
30+
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0"/>
4331
</dependentAssembly>
4432
</assemblyBinding>
4533
</runtime>

src/ArchivePackages/ArchivePackages.Job.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.ComponentModel.Design;
7-
using System.Data.SqlClient;
87
using System.Diagnostics.Tracing;
98
using System.Linq;
109
using System.Threading.Tasks;
@@ -13,6 +12,8 @@
1312
using Microsoft.WindowsAzure.Storage.Blob;
1413
using Newtonsoft.Json.Linq;
1514
using NuGet.Jobs;
15+
using NuGet.Services.KeyVault;
16+
using NuGet.Services.Sql;
1617

1718
namespace ArchivePackages
1819
{
@@ -30,6 +31,7 @@ public class Job : JobBase
3031
/// Gets or sets an Azure Storage Uri referring to a container to use as the source for package blobs
3132
/// </summary>
3233
public CloudStorageAccount Source { get; set; }
34+
3335
public string SourceContainerName { get; set; }
3436

3537
/// <summary>
@@ -51,22 +53,22 @@ public class Job : JobBase
5153
/// Blob containing the cursor data. Cursor data comprises of cursorDateTime
5254
/// </summary>
5355
public string CursorBlobName { get; set; }
54-
55-
/// <summary>
56-
/// Gets or sets a connection string to the database containing package data.
57-
/// </summary>
58-
public SqlConnectionStringBuilder PackageDatabase { get; set; }
56+
57+
private ISqlConnectionFactory _packageDbConnectionFactory;
5958

6059
protected CloudBlobContainer SourceContainer { get; private set; }
60+
6161
protected CloudBlobContainer PrimaryDestinationContainer { get; private set; }
62+
6263
protected CloudBlobContainer SecondaryDestinationContainer { get; private set; }
6364

6465
public Job() : base(JobEventSource.Log) { }
6566

6667
public override void Init(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary)
6768
{
68-
PackageDatabase = new SqlConnectionStringBuilder(
69-
JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.PackageDatabase));
69+
var secretInjector = (ISecretInjector)serviceContainer.GetService(typeof(ISecretInjector));
70+
var packageDbConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.PackageDatabase);
71+
_packageDbConnectionFactory = new AzureSqlConnectionFactory(packageDbConnectionString, secretInjector);
7072

7173
Source = CloudStorageAccount.Parse(
7274
JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.Source));
@@ -90,9 +92,10 @@ public override void Init(IServiceContainer serviceContainer, IDictionary<string
9092

9193
public override async Task Run()
9294
{
93-
JobEventSourceLog.PreparingToArchive(Source.Credentials.AccountName, SourceContainer.Name, PrimaryDestination.Credentials.AccountName, PrimaryDestinationContainer.Name, PackageDatabase.DataSource, PackageDatabase.InitialCatalog);
95+
JobEventSourceLog.PreparingToArchive(Source.Credentials.AccountName, SourceContainer.Name, PrimaryDestination.Credentials.AccountName, PrimaryDestinationContainer.Name, _packageDbConnectionFactory.DataSource, _packageDbConnectionFactory.InitialCatalog);
9496
await Archive(PrimaryDestinationContainer);
9597

98+
// todo: consider reusing package query for primary and secondary archives
9699
if (SecondaryDestinationContainer != null)
97100
{
98101
JobEventSourceLog.PreparingToArchive2(SecondaryDestination.Credentials.AccountName, SecondaryDestinationContainer.Name);
@@ -121,9 +124,9 @@ private async Task Archive(CloudBlobContainer destinationContainer)
121124

122125
JobEventSourceLog.CursorData(cursorDateTime.ToString(DateTimeFormatSpecifier));
123126

124-
JobEventSourceLog.GatheringPackagesToArchiveFromDb(PackageDatabase.DataSource, PackageDatabase.InitialCatalog);
127+
JobEventSourceLog.GatheringPackagesToArchiveFromDb(_packageDbConnectionFactory.DataSource, _packageDbConnectionFactory.InitialCatalog);
125128
List<PackageRef> packages;
126-
using (var connection = await PackageDatabase.ConnectTo())
129+
using (var connection = await _packageDbConnectionFactory.CreateAsync())
127130
{
128131
packages = (await connection.QueryAsync<PackageRef>(@"
129132
SELECT pr.Id, p.NormalizedVersion AS Version, p.Hash, p.LastEdited, p.Published
@@ -132,7 +135,7 @@ FROM Packages p
132135
WHERE Published > @cursorDateTime OR LastEdited > @cursorDateTime", new { cursorDateTime = cursorDateTime }))
133136
.ToList();
134137
}
135-
JobEventSourceLog.GatheredPackagesToArchiveFromDb(packages.Count, PackageDatabase.DataSource, PackageDatabase.InitialCatalog);
138+
JobEventSourceLog.GatheredPackagesToArchiveFromDb(packages.Count, _packageDbConnectionFactory.DataSource, _packageDbConnectionFactory.InitialCatalog);
136139

137140
var archiveSet = packages
138141
.AsParallel()
Lines changed: 27 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -9,8 +9,9 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>ArchivePackages</RootNamespace>
1111
<AssemblyName>ArchivePackages</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1415
<TargetFrameworkProfile />
1516
<NuGetPackageImportStamp>
1617
</NuGetPackageImportStamp>
@@ -35,56 +36,11 @@
3536
<WarningLevel>4</WarningLevel>
3637
</PropertyGroup>
3738
<ItemGroup>
38-
<Reference Include="Dapper.StrongName, Version=1.50.2.0, Culture=neutral, PublicKeyToken=e3e8412083d25dd3, processorArchitecture=MSIL">
39-
<HintPath>..\..\packages\Dapper.StrongName.1.50.2\lib\net451\Dapper.StrongName.dll</HintPath>
40-
</Reference>
41-
<Reference Include="Microsoft.Azure.KeyVault.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
42-
<HintPath>..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
43-
</Reference>
44-
<Reference Include="Microsoft.Data.Edm, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
45-
<HintPath>..\..\packages\Microsoft.Data.Edm.5.7.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
46-
</Reference>
47-
<Reference Include="Microsoft.Data.OData, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48-
<HintPath>..\..\packages\Microsoft.Data.OData.5.7.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
49-
</Reference>
50-
<Reference Include="Microsoft.Data.Services.Client, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
51-
<HintPath>..\..\packages\Microsoft.Data.Services.Client.5.7.0\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
52-
</Reference>
53-
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
54-
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
55-
</Reference>
56-
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
57-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
58-
</Reference>
59-
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
60-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
61-
</Reference>
62-
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
63-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
64-
</Reference>
65-
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66-
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.2.1\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
67-
</Reference>
68-
<Reference Include="Microsoft.WindowsAzure.Storage, Version=7.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
69-
<HintPath>..\..\packages\WindowsAzure.Storage.7.1.2\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
70-
</Reference>
71-
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
72-
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
73-
</Reference>
7439
<Reference Include="System" />
7540
<Reference Include="System.Core" />
7641
<Reference Include="System.Net" />
7742
<Reference Include="System.Net.Http" />
78-
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
79-
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
80-
</Reference>
81-
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
82-
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
83-
</Reference>
8443
<Reference Include="System.Net.Http.WebRequest" />
85-
<Reference Include="System.Spatial, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
86-
<HintPath>..\..\packages\System.Spatial.5.7.0\lib\net40\System.Spatial.dll</HintPath>
87-
</Reference>
8844
<Reference Include="System.Xml.Linq" />
8945
<Reference Include="System.Data.DataSetExtensions" />
9046
<Reference Include="Microsoft.CSharp" />
@@ -98,9 +54,8 @@
9854
</ItemGroup>
9955
<ItemGroup>
10056
<None Include="App.config">
101-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
57+
<SubType>Designer</SubType>
10258
</None>
103-
<None Include="packages.config" />
10459
<None Include="Scripts\*" />
10560
<None Include="ArchivePackages.nuspec" />
10661
</ItemGroup>
@@ -110,23 +65,29 @@
11065
<Name>NuGet.Jobs.Common</Name>
11166
</ProjectReference>
11267
</ItemGroup>
68+
<ItemGroup>
69+
<PackageReference Include="Dapper.StrongName">
70+
<Version>1.50.2</Version>
71+
</PackageReference>
72+
<PackageReference Include="Microsoft.Data.Edm">
73+
<Version>5.7.0</Version>
74+
</PackageReference>
75+
<PackageReference Include="Microsoft.Data.OData">
76+
<Version>5.7.0</Version>
77+
</PackageReference>
78+
<PackageReference Include="Microsoft.Data.Services.Client">
79+
<Version>5.7.0</Version>
80+
</PackageReference>
81+
<PackageReference Include="Newtonsoft.Json">
82+
<Version>9.0.1</Version>
83+
</PackageReference>
84+
<PackageReference Include="NuGet.Services.Sql">
85+
<Version>2.25.0-master-30453</Version>
86+
</PackageReference>
87+
<PackageReference Include="WindowsAzure.Storage">
88+
<Version>7.1.2</Version>
89+
</PackageReference>
90+
</ItemGroup>
11391
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
11492
<Import Project="..\..\build\sign.targets" Condition="Exists('..\..\build\sign.targets')" />
115-
<PropertyGroup>
116-
<PostBuildEvent>move /y App.config ArchivePackages.exe.config</PostBuildEvent>
117-
</PropertyGroup>
118-
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
119-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
120-
<PropertyGroup>
121-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
122-
</PropertyGroup>
123-
<Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
124-
</Target>
125-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
126-
Other similar extension points exist, see Microsoft.Common.targets.
127-
<Target Name="BeforeBuild">
128-
</Target>
129-
<Target Name="AfterBuild">
130-
</Target>
131-
-->
13293
</Project>

src/ArchivePackages/packages.config

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)