Skip to content

Commit

Permalink
Merge pull request #612 from Sitecore/feature/610-Analyze_log_files_a…
Browse files Browse the repository at this point in the history
…nd_Open_log_file_commands_in_context_menu_do_not_work_for_Sitecore_members

Feature/610 analyze log files and open log file commands in context menu do not work for sitecore members
  • Loading branch information
AndreyFilchenkov authored Sep 17, 2021
2 parents a214c1b + 59e0ecd commit a923b10
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 13 deletions.
24 changes: 21 additions & 3 deletions src/SIM.Instances/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,17 @@ protected virtual string GetDataFolderPath()
}
catch (Exception ex)
{
var rootData = Path.Combine(Path.GetDirectoryName(WebRootPath), "Data");
if (FileSystem.FileSystem.Local.Directory.Exists(rootData))
string rootData = Path.Combine(Path.GetDirectoryName(WebRootPath), "Data");
if (this.IsValidDataFolderPath(rootData, ex))
{
Log.Error(ex, $"Cannot get data folder of {WebRootPath}");
return rootData;
}

// InvalidOperationException occurs when the RuntimeSettingsAccessor.GetWebConfigResult method fails due to missing <sitecore> node (e.g. in xConnect, Identity Server, etc.)
// In this case, the log file folder can be resolved manually
rootData = FileSystem.FileSystem.Local.Directory.MapPath("App_data", WebRootPath);
if (this.IsValidDataFolderPath(rootData, ex))
{
return rootData;
}

Expand All @@ -662,6 +668,18 @@ protected virtual string GetDataFolderPath()
}
}

private bool IsValidDataFolderPath(string rootData, Exception ex)
{
if (FileSystem.FileSystem.Local.Directory.Exists(rootData))
{
Log.Error(ex, $"Cannot get data folder of {WebRootPath}");

return true;
}

return false;
}

protected virtual bool GetIsHidden()
{
try
Expand Down
22 changes: 22 additions & 0 deletions src/SIM.Tool.Windows/LogFileFolder/LogFileFolderFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using SIM.Instances;

namespace SIM.Tool.Windows.LogFileFolder
{
public static class LogFileFolderFactory
{
public static LogFileFolderResolver GetResolver(Instance instance)
{
if (instance.Type == Instance.InstanceType.SitecoreMember)
{
return new SitecoreMembersLogFileFolderResolver(instance);
}

return new SitecoreDefaultLogFileFolderResolver(instance);
}

public static LogFileFolderResolver GetDefaultResolver(Instance instance)
{
return new SitecoreDefaultLogFileFolderResolver(instance);
}
}
}
7 changes: 7 additions & 0 deletions src/SIM.Tool.Windows/LogFileFolder/LogFileFolderResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SIM.Tool.Windows.LogFileFolder
{
public abstract class LogFileFolderResolver
{
public abstract string GetLogFolder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.IO;
using SIM.Extensions;
using SIM.Instances;

namespace SIM.Tool.Windows.LogFileFolder
{
public class SitecoreDefaultLogFileFolderResolver : LogFileFolderResolver
{
private readonly Instance _instance;

public SitecoreDefaultLogFileFolderResolver(Instance instance)
{
this._instance = instance;
}

public override string GetLogFolder()
{
var dataFolderPath = _instance.DataFolderPath;

FileSystem.FileSystem.Local.Directory.AssertExists(dataFolderPath, "The data folder ({0}) of the {1} instance doesn't exist".FormatWith(dataFolderPath, _instance.Name));

return Path.Combine(dataFolderPath, "logs");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using SIM.Instances;

namespace SIM.Tool.Windows.LogFileFolder
{
public class SitecoreMembersLogFileFolderResolver : LogFileFolderResolver
{
private readonly Instance _instance;

public SitecoreMembersLogFileFolderResolver(Instance instance)
{
this._instance = instance;
}

public override string GetLogFolder()
{
// Sitecore members like Identity Server contain the logs folder inside the root folder
string logsPath = FileSystem.FileSystem.Local.Directory.MapPath("logs", _instance.WebRootPath);
if (FileSystem.FileSystem.Local.Directory.Exists(logsPath))
{
return logsPath;
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using JetBrains.Annotations;
using SIM.Extensions;
using SIM.Instances;
using SIM.Tool.Base;
using SIM.Tool.Windows.LogFileFolder;

namespace SIM.Tool.Windows.MainWindowComponents.Buttons
{
Expand Down Expand Up @@ -39,11 +41,16 @@ public override void OnClick(Window mainWindow, Instance instance)
{
if (instance != null)
{
var dataFolderPath = instance.DataFolderPath;
FileSystem.FileSystem.Local.Directory.AssertExists(dataFolderPath, "The data folder ({0}) of the {1} instance doesn't exist".FormatWith(dataFolderPath, instance.Name));
string logs = LogFileFolderFactory.GetResolver(instance).GetLogFolder() ?? LogFileFolderFactory.GetDefaultResolver(instance).GetLogFolder();

var logs = Path.Combine(dataFolderPath, "logs");
RunApp(mainWindow, logs);
if (string.IsNullOrEmpty(logs))
{
WindowHelper.ShowMessage($"Unable to find the logs folder under '{instance.WebRootPath}'.", MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
{
RunApp(mainWindow, logs);
}

return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/SIM.Tool.Windows/SIM.Tool.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
<DependentUpon>RestoreDatabaseDialog.xaml</DependentUpon>
</Compile>
<Compile Include="GroupDefinition.cs" />
<Compile Include="LogFileFolder\SitecoreMembersLogFileFolderResolver.cs" />
<Compile Include="MainWindowComponents\Buttons\AboutButton.cs" />
<Compile Include="MainWindowComponents\Buttons\AbstractInstanceButton.cs" />
<Compile Include="MainWindowComponents\Buttons\AppStateButton.cs" />
Expand Down Expand Up @@ -221,7 +222,10 @@
<Compile Include="MainWindowComponents\Buttons\SettingsButton.cs" />
<Compile Include="MainWindowComponents\Buttons\UpdateLicenseButton.cs" />
<Compile Include="MainWindowComponents\Buttons\InstallContainerButton.cs" />
<Compile Include="LogFileFolder\LogFileFolderResolver.cs" />
<Compile Include="LogFileFolder\LogFileFolderFactory.cs" />
<Compile Include="MainWindowComponents\MainWindowButtonFactory.cs" />
<Compile Include="LogFileFolder\SitecoreDefaultLogFileFolderResolver.cs" />
<Compile Include="MainWindowData.cs" />
<Compile Include="Pipelines\Download8\Download8Args.cs" />
<Compile Include="Pipelines\Download8\DownloadProcessor.cs" />
Expand Down
7 changes: 1 addition & 6 deletions src/SIM.Tool/ButtonsConfiguration/ButtonsConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
"UpdateLicenseButton",
/*Multiple Deletion*/
"MultipleDeletionButton",
/*Log Analyzer*/
"OpenLogsButton",
/*SSPG*/
"OpenSSPGButton",
/*Config Builder*/
Expand Down Expand Up @@ -58,7 +56,7 @@
"AppStateButton",
/*Current Log file*/
"OpenCurrentLogButton",
/*Entire Log files*/
/*Log Analyzer, Entire Log files*/
"OpenLogsButton",
/*Visual Studio*/
"OpenVisualStudioButton",
Expand Down Expand Up @@ -108,7 +106,6 @@
"DatabaseManagerButton",
"UpdateLicenseButton",
"MultipleDeletionButton",
"OpenLogsButton",
"OpenSSPGButton",
"ConfigBuilderButton",
"InstallSolrButton",
Expand Down Expand Up @@ -144,7 +141,6 @@
"DatabaseManagerButton",
"UpdateLicenseButton",
"MultipleDeletionButton",
"OpenLogsButton",
"OpenSSPGButton",
"ConfigBuilderButton",
"InstallSolrButton",
Expand All @@ -153,7 +149,6 @@
"CreateSupportHotfixButton",
"OpenFileButton",
"ConfigBuilderButton",
"OpenCurrentLogButton",
"OpenLogsButton",
"OpenVisualStudioButton",
"ControlAppPoolButton",
Expand Down

0 comments on commit a923b10

Please sign in to comment.