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

Commit 99c1e85

Browse files
author
Christy Henriksson
authored
Update SupportRequests.Notifications to use ISqlConnectionFactory (#422)
1 parent e017a93 commit 99c1e85

11 files changed

Lines changed: 66 additions & 163 deletions

src/NuGet.SupportRequests.Notifications/Images.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGet.SupportRequests.Notifications/Job.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace NuGet.SupportRequests.Notifications
1212
internal class Job
1313
: JobBase
1414
{
15+
private IServiceContainer _serviceContainer;
1516
private IDictionary<string, string> _jobArgsDictionary;
1617

1718
public override void Init(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary)
@@ -21,12 +22,13 @@ public override void Init(IServiceContainer serviceContainer, IDictionary<string
2122
throw new NotSupportedException("The required argument -Task is missing.");
2223
}
2324

25+
_serviceContainer = serviceContainer ?? throw new ArgumentNullException(nameof(serviceContainer));
2426
_jobArgsDictionary = jobArgsDictionary;
2527
}
2628

2729
public override async Task Run()
2830
{
29-
var scheduledTask = ScheduledTaskFactory.Create(_jobArgsDictionary, LoggerFactory);
31+
var scheduledTask = ScheduledTaskFactory.Create(_serviceContainer, _jobArgsDictionary, LoggerFactory);
3032

3133
await scheduledTask.RunAsync();
3234
}
Lines changed: 16 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="14.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,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>NuGet.SupportRequests.Notifications</RootNamespace>
1111
<AssemblyName>NuGet.SupportRequests.Notifications</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1515
<TargetFrameworkProfile />
@@ -37,71 +37,6 @@
3737
<StartupObject>NuGet.SupportRequests.Notifications.Program</StartupObject>
3838
</PropertyGroup>
3939
<ItemGroup>
40-
<Reference Include="Hyak.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
41-
<HintPath>..\..\packages\Hyak.Common.1.0.2\lib\net45\Hyak.Common.dll</HintPath>
42-
<Private>True</Private>
43-
</Reference>
44-
<Reference Include="Microsoft.Azure.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
45-
<HintPath>..\..\packages\Microsoft.Azure.Common.2.0.4\lib\net45\Microsoft.Azure.Common.dll</HintPath>
46-
<Private>True</Private>
47-
</Reference>
48-
<Reference Include="Microsoft.Azure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
49-
<HintPath>..\..\packages\Microsoft.Azure.Common.2.0.4\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
50-
</Reference>
51-
<Reference Include="Microsoft.Azure.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
52-
<HintPath>..\..\packages\Microsoft.Azure.KeyVault.1.0.0\lib\net45\Microsoft.Azure.KeyVault.dll</HintPath>
53-
</Reference>
54-
<Reference Include="Microsoft.Extensions.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
55-
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Configuration.dll</HintPath>
56-
</Reference>
57-
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
58-
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
59-
</Reference>
60-
<Reference Include="Microsoft.Extensions.Configuration.FileExtensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
61-
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.FileExtensions.1.0.0\lib\net451\Microsoft.Extensions.Configuration.FileExtensions.dll</HintPath>
62-
</Reference>
63-
<Reference Include="Microsoft.Extensions.Configuration.Json, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
64-
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.Json.1.0.0\lib\net451\Microsoft.Extensions.Configuration.Json.dll</HintPath>
65-
</Reference>
66-
<Reference Include="Microsoft.Extensions.FileProviders.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
67-
<HintPath>..\..\packages\Microsoft.Extensions.FileProviders.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.FileProviders.Abstractions.dll</HintPath>
68-
</Reference>
69-
<Reference Include="Microsoft.Extensions.FileProviders.Physical, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
70-
<HintPath>..\..\packages\Microsoft.Extensions.FileProviders.Physical.1.0.0\lib\net451\Microsoft.Extensions.FileProviders.Physical.dll</HintPath>
71-
</Reference>
72-
<Reference Include="Microsoft.Extensions.FileSystemGlobbing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
73-
<HintPath>..\..\packages\Microsoft.Extensions.FileSystemGlobbing.1.0.0\lib\net451\Microsoft.Extensions.FileSystemGlobbing.dll</HintPath>
74-
</Reference>
75-
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
76-
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
77-
</Reference>
78-
<Reference Include="Microsoft.Extensions.Primitives, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
79-
<HintPath>..\..\packages\Microsoft.Extensions.Primitives.1.0.0\lib\netstandard1.0\Microsoft.Extensions.Primitives.dll</HintPath>
80-
</Reference>
81-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.13.5.907, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
82-
<HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.5\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
83-
</Reference>
84-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.13.5.907, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
85-
<HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.5\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll</HintPath>
86-
</Reference>
87-
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
88-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
89-
</Reference>
90-
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
91-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
92-
</Reference>
93-
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
94-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
95-
</Reference>
96-
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
97-
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
98-
</Reference>
99-
<Reference Include="NuGet.Services.Configuration, Version=2.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
100-
<HintPath>..\..\packages\NuGet.Services.Configuration.2.2.3\lib\net452\NuGet.Services.Configuration.dll</HintPath>
101-
</Reference>
102-
<Reference Include="NuGet.Services.KeyVault, Version=2.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
103-
<HintPath>..\..\packages\NuGet.Services.KeyVault.2.2.3\lib\net45\NuGet.Services.KeyVault.dll</HintPath>
104-
</Reference>
10540
<Reference Include="System" />
10641
<Reference Include="System.ComponentModel.Composition" />
10742
<Reference Include="System.ComponentModel.DataAnnotations" />
@@ -110,12 +45,6 @@
11045
<Reference Include="System.Data" />
11146
<Reference Include="System.Net" />
11247
<Reference Include="System.Net.Http" />
113-
<Reference Include="System.Net.Http.Extensions, Version=2.2.22.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
114-
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.22\lib\net45\System.Net.Http.Extensions.dll</HintPath>
115-
</Reference>
116-
<Reference Include="System.Net.Http.Primitives, Version=4.2.22.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
117-
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.22\lib\net45\System.Net.Http.Primitives.dll</HintPath>
118-
</Reference>
11948
<Reference Include="System.Net.Http.WebRequest" />
12049
</ItemGroup>
12150
<ItemGroup>
@@ -168,24 +97,23 @@
16897
<None Include="app.config">
16998
<SubType>Designer</SubType>
17099
</None>
171-
<None Include="packages.config">
172-
<SubType>Designer</SubType>
173-
</None>
174100
<None Include="Scripts\*" />
175101
<None Include="NuGet.SupportRequests.Notifications.nuspec" />
176102
</ItemGroup>
103+
<ItemGroup>
104+
<PackageReference Include="Microsoft.Extensions.Logging">
105+
<Version>1.0.0</Version>
106+
</PackageReference>
107+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions">
108+
<Version>1.0.0</Version>
109+
</PackageReference>
110+
<PackageReference Include="Newtonsoft.Json">
111+
<Version>9.0.1</Version>
112+
</PackageReference>
113+
<PackageReference Include="NuGet.Services.Sql">
114+
<Version>2.25.0-master-30453</Version>
115+
</PackageReference>
116+
</ItemGroup>
177117
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
178118
<Import Project="..\..\build\sign.targets" Condition="Exists('..\..\build\sign.targets')" />
179-
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
180-
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
181-
<Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
182-
<Error Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
183-
</Target>
184-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
185-
Other similar extension points exist, see Microsoft.Common.targets.
186-
<Target Name="BeforeBuild">
187-
</Target>
188-
<Target Name="AfterBuild">
189-
</Target>
190-
-->
191119
</Project>

src/NuGet.SupportRequests.Notifications/ScheduledTaskFactory.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.ComponentModel.Design;
67
using Microsoft.Extensions.Logging;
78

89
namespace NuGet.SupportRequests.Notifications
@@ -11,7 +12,7 @@ internal class ScheduledTaskFactory
1112
{
1213
private const string _tasksNamespace = "NuGet.SupportRequests.Notifications.Tasks";
1314

14-
public static IScheduledTask Create(IDictionary<string, string> jobArgsDictionary, ILoggerFactory loggerFactory)
15+
public static IScheduledTask Create(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary, ILoggerFactory loggerFactory)
1516
{
1617
if (jobArgsDictionary == null)
1718
{
@@ -24,13 +25,14 @@ public static IScheduledTask Create(IDictionary<string, string> jobArgsDictionar
2425
}
2526

2627
var scheduledTaskName = jobArgsDictionary[JobArgumentNames.ScheduledTask];
27-
var scheduledTask = GetTaskOfType(scheduledTaskName, jobArgsDictionary, loggerFactory);
28+
var scheduledTask = GetTaskOfType(scheduledTaskName, serviceContainer, jobArgsDictionary, loggerFactory);
2829

2930
return scheduledTask;
3031
}
3132

3233
private static IScheduledTask GetTaskOfType(
3334
string taskName,
35+
IServiceContainer serviceContainer,
3436
IDictionary<string, string> jobArgsDictionary,
3537
ILoggerFactory loggerFactory)
3638
{
@@ -49,7 +51,7 @@ private static IScheduledTask GetTaskOfType(
4951
IScheduledTask scheduledTask;
5052
if (scheduledTaskType != null && typeof(IScheduledTask).IsAssignableFrom(scheduledTaskType))
5153
{
52-
var args = new object[] { jobArgsDictionary, loggerFactory };
54+
var args = new object[] { serviceContainer, jobArgsDictionary, loggerFactory };
5355
scheduledTask = (IScheduledTask)Activator.CreateInstance(scheduledTaskType, args);
5456
}
5557
else

src/NuGet.SupportRequests.Notifications/SqlQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ internal static string GetUnresolvedIssues(string onCallPagerDutyUserName = null
3131
"SELECT COUNT(I.[Key]) FROM [dbo].[Issues] AS I (NOLOCK) INNER JOIN [dbo].[History] AS H (NOLOCK) ON I.[Key] = H.[IssueId] WHERE I.[IssueStatusId] = 3 AND H.[IssueStatusId] = 3 AND H.[EntryDate] BETWEEN @startDate AND @endDate";
3232

3333
internal const string GetAverageTimeToResolutionInPeriod =
34-
"SELECT CAST(AVG(CAST(T.[ResolutionTime] AS FLOAT)) AS DATETIME) AS \'AvgResolutionTime\' FROM (SELECT MAX(H.[EntryDate]) - I.[CreatedDate] AS \'ResolutionTime\' FROM [dbo].[Issues] AS I (NOLOCK) INNER JOIN[dbo].[History] AS H (NOLOCK) ON I.[Key] = H.[IssueId]WHERE I.[IssueStatusId] = 3 AND H.[IssueStatusId] = 3 AND I.[CreatedDate] BETWEEN @startDate AND @endDate GROUP BY I.[Key], I.[CreatedDate]) AS T";
34+
"SELECT ISNULL(CAST(AVG(CAST(T.[ResolutionTime] AS FLOAT)) AS DATETIME), GETDATE()) AS \'AvgResolutionTime\' FROM (SELECT MAX(H.[EntryDate]) - I.[CreatedDate] AS \'ResolutionTime\' FROM [dbo].[Issues] AS I (NOLOCK) INNER JOIN[dbo].[History] AS H (NOLOCK) ON I.[Key] = H.[IssueId]WHERE I.[IssueStatusId] = 3 AND H.[IssueStatusId] = 3 AND I.[CreatedDate] BETWEEN @startDate AND @endDate GROUP BY I.[Key], I.[CreatedDate]) AS T";
3535
}
3636
}

src/NuGet.SupportRequests.Notifications/SupportRequestRepository.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Threading.Tasks;
1010
using Microsoft.Extensions.Logging;
11+
using NuGet.Services.Sql;
1112
using NuGet.SupportRequests.Notifications.Models;
1213

1314
namespace NuGet.SupportRequests.Notifications
@@ -19,29 +20,29 @@ internal class SupportRequestRepository
1920
private const string _parameterNamePagerDutyUsername = "pagerDutyUserName";
2021
private readonly DateTime _defaultSqlDateTime = new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc);
2122
private readonly ILogger _logger;
22-
private readonly SqlConnectionStringBuilder _sourceDatabase;
23+
private readonly ISqlConnectionFactory _supportDbConnectionFactory;
2324

2425
public SupportRequestRepository(
2526
ILoggerFactory loggerFactory,
26-
SqlConnectionStringBuilder sourceDatabase)
27+
ISqlConnectionFactory supportDbConnectionFactory)
2728
{
2829
if (loggerFactory == null)
2930
{
3031
throw new ArgumentNullException(nameof(loggerFactory));
3132
}
3233

33-
if (sourceDatabase == null)
34+
if (supportDbConnectionFactory == null)
3435
{
35-
throw new ArgumentNullException(nameof(sourceDatabase));
36+
throw new ArgumentNullException(nameof(supportDbConnectionFactory));
3637
}
3738

3839
_logger = loggerFactory.CreateLogger<SupportRequestRepository>();
39-
_sourceDatabase = sourceDatabase;
40+
_supportDbConnectionFactory = supportDbConnectionFactory;
4041
}
4142

4243
internal async Task<SqlConnection> OpenConnectionAsync()
4344
{
44-
var connection = await _sourceDatabase.ConnectTo();
45+
var connection = await _supportDbConnectionFactory.CreateAsync();
4546
connection.InfoMessage += OnSqlConnectionInfoMessage;
4647

4748
return connection;

src/NuGet.SupportRequests.Notifications/Tasks/OnCallDailyNotificationTask.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.ComponentModel.Design;
67
using System.Linq;
78
using System.Text;
89
using System.Threading.Tasks;
@@ -22,9 +23,10 @@ internal class OnCallDailyNotificationTask
2223
private readonly PagerDutyClient _pagerDutyClient;
2324

2425
public OnCallDailyNotificationTask(
26+
IServiceContainer serviceContainer,
2527
IDictionary<string, string> jobArgsDictionary,
2628
ILoggerFactory loggerFactory)
27-
: base(jobArgsDictionary, loggerFactory)
29+
: base(serviceContainer, jobArgsDictionary, loggerFactory)
2830
{
2931
var pagerDutyConfiguration = new PagerDutyConfiguration(
3032
jobArgsDictionary[_argumentNamePagerDutyAccountName],

0 commit comments

Comments
 (0)