Skip to content

Commit a7c8a80

Browse files
committed
Refactoring.
1 parent 07d8f55 commit a7c8a80

File tree

12 files changed

+40
-33
lines changed

12 files changed

+40
-33
lines changed

src/SIM.Instances/InstanceHelper.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,38 @@
22
{
33
using System;
44
using System.IO;
5+
using System.Linq;
56
using System.Net;
7+
using System.Text.RegularExpressions;
68
using Sitecore.Diagnostics.Base;
9+
using Sitecore.Diagnostics.Base.Annotations;
710

811
public static class InstanceHelper
912
{
13+
[NotNull]
14+
private static readonly Regex LogGroupRegex = new Regex(@"(.+)(\.\d\d\d\d\d\d\d\d)(\.\d\d\d\d\d\d)?\.txt", RegexOptions.Compiled);
15+
1016
#region Public methods
1117

18+
public static string[] GetLogGroups(string[] files)
19+
{
20+
var groups = files
21+
.Where(x => !string.IsNullOrEmpty(x))
22+
.Select(x => new
23+
{
24+
FilePath = x,
25+
Position = x.LastIndexOf('\\')
26+
})
27+
.Select(x => x.Position < 0 ? x.FilePath : x.FilePath.Substring(x.Position + 1))
28+
.Select(x => LogGroupRegex.Match(x))
29+
.Where(x => x.Success)
30+
.Select(x => x.Groups[1].Value)
31+
.Distinct()
32+
.ToArray();
33+
34+
return groups;
35+
}
36+
1237
public static bool IsInstanceResponsive(Instance instance, string reason = null)
1338
{
1439
try

src/SIM.Tests/Tool/Base/InstanceHelperExTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System.Linq;
44
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
using SIM.Instances;
56
using SIM.Tool.Base;
67

78
[TestClass]
@@ -24,7 +25,7 @@ public void GetLogGroupsTest()
2425
"WebDAV.log.20140905.135957.txt",
2526
"WebDAV.log.20140905.txt"
2627
};
27-
var results = InstanceHelperEx.GetLogGroups(files).OrderBy(x => x).Select(x => x.ToLower()).ToArray();
28+
var results = InstanceHelper.GetLogGroups(files).OrderBy(x => x).Select(x => x.ToLower()).ToArray();
2829
var expected = new[]
2930
{
3031
"crawling.log", "log", "search.log", "webdav.log"

src/SIM.Tool.Base/EnvironmentHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
using System.Data.SqlClient;
66
using System.Linq;
77
using System.ServiceProcess;
8-
using SIM.Adapters.SqlServer;
9-
using SIM.Tool.Base.Profiles;
108
using Sitecore.Diagnostics.Base;
119
using Sitecore.Diagnostics.Base.Annotations;
1210
using Sitecore.Diagnostics.Logging;
11+
using SIM.Adapters.SqlServer;
12+
using SIM.Tool.Base.Profiles;
1313

1414
public class EnvironmentHelper
1515
{
@@ -47,7 +47,7 @@ public static bool CheckSqlServer()
4747
{
4848
using (new ProfileSection("Check SQL Server"))
4949
{
50-
Profile profile = ProfileManager.Profile;
50+
var profile = ProfileManager.Profile;
5151
Assert.IsNotNull(profile, "Profile is unavailable");
5252

5353
var ds = new SqlConnectionStringBuilder(profile.ConnectionString).DataSource;

src/SIM.Tool.Base/InstanceHelperEx.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ namespace SIM.Tool.Base
1313

1414
public static class InstanceHelperEx
1515
{
16-
#region Fields
17-
18-
[NotNull]
19-
private static readonly Regex LogGroupRegex = new Regex(@"(.+)(\.\d\d\d\d\d\d\d\d)(\.\d\d\d\d\d\d)?\.txt", RegexOptions.Compiled);
20-
21-
#endregion
22-
2316
#region Public methods
2417

2518
public static void BrowseInstance([NotNull] Instance instance, [NotNull] Window owner, [NotNull] string virtualPath, bool isFrontEnd, [CanBeNull] string browser = null, [CanBeNull] string[] parameters = null)
@@ -41,24 +34,6 @@ public static void BrowseInstance([NotNull] Instance instance, [NotNull] Window
4134
}
4235
}
4336

44-
public static string[] GetLogGroups(string[] files)
45-
{
46-
var groups = files
47-
.Where(x => !string.IsNullOrEmpty(x))
48-
.Select(x => new
49-
{
50-
FilePath = x,
51-
Position = x.LastIndexOf('\\')
52-
})
53-
.Select(x => x.Position < 0 ? x.FilePath : x.FilePath.Substring(x.Position + 1))
54-
.Select(x => LogGroupRegex.Match(x))
55-
.Where(x => x.Success)
56-
.Select(x => x.Groups[1].Value)
57-
.Distinct()
58-
.ToArray();
59-
return groups;
60-
}
61-
6237
public static void OpenCurrentLogFile([NotNull] Instance instance, [NotNull] Window owner, [CanBeNull] string logFileType = null)
6338
{
6439
Assert.ArgumentNotNull(instance, "instance");
@@ -260,7 +235,7 @@ private static string GetLogFileTypes(Window owner, string logsFolderPath)
260235
const string Pattern = "*" + Suffix;
261236
var files = FileSystem.FileSystem.Local.Directory.GetFiles(logsFolderPath, Pattern);
262237

263-
var groups = GetLogGroups(files);
238+
var groups = InstanceHelper.GetLogGroups(files);
264239

265240
if (groups.Any())
266241
{

src/SIM.Tool.Base/SIM.Tool.Base.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@
100100
<Reference Include="WindowsBase" />
101101
</ItemGroup>
102102
<ItemGroup>
103-
<Compile Include="AuthenticationHelper.cs" />
103+
<Compile Include="EnvironmentHelper.cs" />
104104
<Compile Include="WinAppSettings.cs" />
105+
<Compile Include="AuthenticationHelper.cs" />
105106
<Compile Include="Converters\IsNotNullOrEmptyAndDirectoryExists.cs" />
106107
<Compile Include="Converters\Product.cs" />
107-
<Compile Include="EnvironmentHelper.cs" />
108108
<Compile Include="InstanceHelperEx.cs" />
109109
<Compile Include="LicenseUpdater.cs" />
110110
<Compile Include="Plugins\IMainWindowButton.cs" />

src/SIM.Tool.Windows/MainWindowComponents/DatabaseManagerButton.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using SIM.Tool.Base.Plugins;
77
using SIM.Tool.Windows.Dialogs;
88
using Sitecore.Diagnostics.Base.Annotations;
9+
using SIM.Core;
910

1011
[UsedImplicitly]
1112
public class DatabaseManagerButton : IMainWindowButton

src/SIM.Tool.Windows/MainWindowComponents/InstallInstanceButton.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using SIM.Tool.Wizards;
1212
using Sitecore.Diagnostics.Base;
1313
using Sitecore.Diagnostics.Base.Annotations;
14+
using SIM.Core;
1415

1516
[UsedImplicitly]
1617
public class InstallInstanceButton : IMainWindowButton

src/SIM.Tool.Windows/MainWindowComponents/OpenToolboxButton.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using SIM.Tool.Base;
1010
using SIM.Tool.Base.Plugins;
1111
using Sitecore.Diagnostics.Base.Annotations;
12+
using SIM.Core;
1213

1314
[UsedImplicitly]
1415
public class OpenToolboxButton : IMainWindowButton

src/SIM.Tool.Windows/MainWindowComponents/OpenVisualStudioButton.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using SIM.Tool.Base.Plugins;
1212
using Sitecore.Diagnostics.Base;
1313
using Sitecore.Diagnostics.Base.Annotations;
14+
using SIM.Core;
1415

1516
[UsedImplicitly]
1617
public class OpenVisualStudioButton : IMainWindowButton

src/SIM.Tool.Windows/UserControls/Install/Modules/ConfigurationPackages.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using SIM.Tool.Base.Wizards;
1616
using Sitecore.Diagnostics.Base;
1717
using Sitecore.Diagnostics.Base.Annotations;
18+
using SIM.Core;
1819

1920
public partial class ConfigurationPackages : IWizardStep, ICustomButton, IFlowControl
2021
{

0 commit comments

Comments
 (0)