Skip to content

Commit 3e02fc7

Browse files
committed
Merge remote-tracking branch 'origin/feature-sqlrepository'
2 parents 89f939f + 1fc03e8 commit 3e02fc7

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using BizTalkComponents.Utilities.LookupUtility.Repository;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Diagnostics;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace BizTalkComponents.Utilities.LookupUtility.Application
10+
{
11+
public class SqlApplicationService : IApplicationService
12+
{
13+
private LookupUtilityService svc;
14+
15+
public SqlApplicationService()
16+
{
17+
svc = new LookupUtilityService(new SqlLookupRepository());
18+
}
19+
20+
public string GetValue(string list, string key, bool throwIfNotExists = false, bool allowDefaults = false)
21+
{
22+
string value;
23+
24+
try
25+
{
26+
value = svc.GetValue(list, key, throwIfNotExists, allowDefaults);
27+
}
28+
catch (Exception ex)
29+
{
30+
Trace.WriteLine(string.Format("An exception was thrown in LookupUtility {0}", ex.ToString()));
31+
throw ex;
32+
}
33+
34+
return value;
35+
}
36+
37+
public string GetValue(string list, string key, string defaultValue)
38+
{
39+
string value;
40+
41+
try
42+
{
43+
value = svc.GetValue(list, key, defaultValue);
44+
}
45+
catch (Exception ex)
46+
{
47+
Trace.WriteLine(string.Format("An exception was thrown in LookupUtility {0}", ex.ToString()));
48+
throw ex;
49+
}
50+
51+
return value;
52+
}
53+
}
54+
}

Src/LookupUtility/BizTalkComponents.Utilities.LookupUtility.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@
5656
<ItemGroup>
5757
<Compile Include="Application\IApplicationService.cs" />
5858
<Compile Include="Application\SharePointApplicationService.cs" />
59+
<Compile Include="Application\SqlApplicationService.cs" />
5960
<Compile Include="Repository\ILookupRepository.cs" />
6061
<Compile Include="Repository\LookupRepositoryMock.cs" />
6162
<Compile Include="LookupUtilityService.cs" />
6263
<Compile Include="Properties\AssemblyInfo.cs" />
6364
<Compile Include="Repository\SharepointLookupRepository.cs" />
65+
<Compile Include="Repository\SqlLookupRepository.cs" />
6466
</ItemGroup>
6567
<ItemGroup>
6668
<None Include="BizTalkComponents.Utilities.LookupUtility.nuspec" />

Src/LookupUtility/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
3636
[assembly: AssemblyFileVersion("1.0.0.0")]
37-
[assembly: AssemblyInformationalVersion("1.0.6.0")]
37+
[assembly: AssemblyInformationalVersion("1.1.0-beta2")]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data.SqlClient;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace BizTalkComponents.Utilities.LookupUtility.Repository
10+
{
11+
public class SqlLookupRepository : ILookupRepository
12+
{
13+
public Dictionary<string, string> LoadList(string list)
14+
{
15+
string query = string.Format("SELECT Key, Value FROM {0}", list);
16+
17+
var connectionString = ConfigurationManager.ConnectionStrings["SqlLookupRepository"].ConnectionString;
18+
var dictionary = new Dictionary<string, string>();
19+
20+
using (var con = new SqlConnection())
21+
{
22+
con.Open();
23+
using (var cmd = new SqlCommand(query, con))
24+
{
25+
var reader = cmd.ExecuteReader();
26+
27+
while(reader.Read())
28+
{
29+
dictionary.Add(reader.GetString(0), reader.GetString(1));
30+
}
31+
32+
reader.Close();
33+
}
34+
}
35+
36+
return dictionary;
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)