Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlenPelin committed Feb 18, 2016
1 parent 07d8f55 commit a7c8a80
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 33 deletions.
25 changes: 25 additions & 0 deletions src/SIM.Instances/InstanceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@
{
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using Sitecore.Diagnostics.Base;
using Sitecore.Diagnostics.Base.Annotations;

public static class InstanceHelper
{
[NotNull]
private static readonly Regex LogGroupRegex = new Regex(@"(.+)(\.\d\d\d\d\d\d\d\d)(\.\d\d\d\d\d\d)?\.txt", RegexOptions.Compiled);

#region Public methods

public static string[] GetLogGroups(string[] files)
{
var groups = files
.Where(x => !string.IsNullOrEmpty(x))
.Select(x => new
{
FilePath = x,
Position = x.LastIndexOf('\\')
})
.Select(x => x.Position < 0 ? x.FilePath : x.FilePath.Substring(x.Position + 1))
.Select(x => LogGroupRegex.Match(x))
.Where(x => x.Success)
.Select(x => x.Groups[1].Value)
.Distinct()
.ToArray();

return groups;
}

public static bool IsInstanceResponsive(Instance instance, string reason = null)
{
try
Expand Down
3 changes: 2 additions & 1 deletion src/SIM.Tests/Tool/Base/InstanceHelperExTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SIM.Instances;
using SIM.Tool.Base;

[TestClass]
Expand All @@ -24,7 +25,7 @@ public void GetLogGroupsTest()
"WebDAV.log.20140905.135957.txt",
"WebDAV.log.20140905.txt"
};
var results = InstanceHelperEx.GetLogGroups(files).OrderBy(x => x).Select(x => x.ToLower()).ToArray();
var results = InstanceHelper.GetLogGroups(files).OrderBy(x => x).Select(x => x.ToLower()).ToArray();
var expected = new[]
{
"crawling.log", "log", "search.log", "webdav.log"
Expand Down
6 changes: 3 additions & 3 deletions src/SIM.Tool.Base/EnvironmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System.Data.SqlClient;
using System.Linq;
using System.ServiceProcess;
using SIM.Adapters.SqlServer;
using SIM.Tool.Base.Profiles;
using Sitecore.Diagnostics.Base;
using Sitecore.Diagnostics.Base.Annotations;
using Sitecore.Diagnostics.Logging;
using SIM.Adapters.SqlServer;
using SIM.Tool.Base.Profiles;

public class EnvironmentHelper
{
Expand Down Expand Up @@ -47,7 +47,7 @@ public static bool CheckSqlServer()
{
using (new ProfileSection("Check SQL Server"))
{
Profile profile = ProfileManager.Profile;
var profile = ProfileManager.Profile;
Assert.IsNotNull(profile, "Profile is unavailable");

var ds = new SqlConnectionStringBuilder(profile.ConnectionString).DataSource;
Expand Down
27 changes: 1 addition & 26 deletions src/SIM.Tool.Base/InstanceHelperEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ namespace SIM.Tool.Base

public static class InstanceHelperEx
{
#region Fields

[NotNull]
private static readonly Regex LogGroupRegex = new Regex(@"(.+)(\.\d\d\d\d\d\d\d\d)(\.\d\d\d\d\d\d)?\.txt", RegexOptions.Compiled);

#endregion

#region Public methods

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

public static string[] GetLogGroups(string[] files)
{
var groups = files
.Where(x => !string.IsNullOrEmpty(x))
.Select(x => new
{
FilePath = x,
Position = x.LastIndexOf('\\')
})
.Select(x => x.Position < 0 ? x.FilePath : x.FilePath.Substring(x.Position + 1))
.Select(x => LogGroupRegex.Match(x))
.Where(x => x.Success)
.Select(x => x.Groups[1].Value)
.Distinct()
.ToArray();
return groups;
}

public static void OpenCurrentLogFile([NotNull] Instance instance, [NotNull] Window owner, [CanBeNull] string logFileType = null)
{
Assert.ArgumentNotNull(instance, "instance");
Expand Down Expand Up @@ -260,7 +235,7 @@ private static string GetLogFileTypes(Window owner, string logsFolderPath)
const string Pattern = "*" + Suffix;
var files = FileSystem.FileSystem.Local.Directory.GetFiles(logsFolderPath, Pattern);

var groups = GetLogGroups(files);
var groups = InstanceHelper.GetLogGroups(files);

if (groups.Any())
{
Expand Down
4 changes: 2 additions & 2 deletions src/SIM.Tool.Base/SIM.Tool.Base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="AuthenticationHelper.cs" />
<Compile Include="EnvironmentHelper.cs" />
<Compile Include="WinAppSettings.cs" />
<Compile Include="AuthenticationHelper.cs" />
<Compile Include="Converters\IsNotNullOrEmptyAndDirectoryExists.cs" />
<Compile Include="Converters\Product.cs" />
<Compile Include="EnvironmentHelper.cs" />
<Compile Include="InstanceHelperEx.cs" />
<Compile Include="LicenseUpdater.cs" />
<Compile Include="Plugins\IMainWindowButton.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SIM.Tool.Base.Plugins;
using SIM.Tool.Windows.Dialogs;
using Sitecore.Diagnostics.Base.Annotations;
using SIM.Core;

[UsedImplicitly]
public class DatabaseManagerButton : IMainWindowButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SIM.Tool.Wizards;
using Sitecore.Diagnostics.Base;
using Sitecore.Diagnostics.Base.Annotations;
using SIM.Core;

[UsedImplicitly]
public class InstallInstanceButton : IMainWindowButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using SIM.Tool.Base;
using SIM.Tool.Base.Plugins;
using Sitecore.Diagnostics.Base.Annotations;
using SIM.Core;

[UsedImplicitly]
public class OpenToolboxButton : IMainWindowButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SIM.Tool.Base.Plugins;
using Sitecore.Diagnostics.Base;
using Sitecore.Diagnostics.Base.Annotations;
using SIM.Core;

[UsedImplicitly]
public class OpenVisualStudioButton : IMainWindowButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using SIM.Tool.Base.Wizards;
using Sitecore.Diagnostics.Base;
using Sitecore.Diagnostics.Base.Annotations;
using SIM.Core;

public partial class ConfigurationPackages : IWizardStep, ICustomButton, IFlowControl
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using SIM.Tool.Base.Wizards;
using Sitecore.Diagnostics.Base;
using Sitecore.Diagnostics.Base.Annotations;
using SIM.Core;

public partial class FilePackages : IWizardStep, ICustomButton, IFlowControl
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sitecore Instance Manager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Global
{CCA7B157-A743-4A5A-A03B-B6B27CB2BE1C} = {9285A641-C759-471D-A4FE-9C92C529128C}
{8F514FFE-EE16-49B0-96F6-503DA3CCF332} = {27597389-98A2-4AF7-8629-DC761E20EEDC}
{12CD4F43-229C-4A9F-A2B0-8E1FF16EC6B2} = {AD1198CF-70E6-415E-BF0E-995E95FF7179}
{EF380B2A-1171-4A9F-96D0-176ABA6CAD74} = {AD1198CF-70E6-415E-BF0E-995E95FF7179}
{EF380B2A-1171-4A9F-96D0-176ABA6CAD74} = {12CD4F43-229C-4A9F-A2B0-8E1FF16EC6B2}
{E67BF633-2709-4106-A984-DE811CE8C689} = {12CD4F43-229C-4A9F-A2B0-8E1FF16EC6B2}
{221FB0E1-56C0-499C-82F3-BA4060D6ED0C} = {12CD4F43-229C-4A9F-A2B0-8E1FF16EC6B2}
{F0F64BA4-1ED6-4062-B014-D5D67FBB45B1} = {AD1198CF-70E6-415E-BF0E-995E95FF7179}
Expand Down

0 comments on commit a7c8a80

Please sign in to comment.