Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Piedone committed Apr 3, 2020
2 parents fc4cbbd + 3ed8ddd commit 1d10f99
Show file tree
Hide file tree
Showing 18 changed files with 273 additions and 58 deletions.
23 changes: 11 additions & 12 deletions .hgignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
syntax: glob
desktop.ini
*.suo
*.sln.cache
*.orig
*.user
*Thumbs.db
bin/
obj/
packages/
App_Data/
.vs/*
desktop.ini
*.suo
*.sln.cache
*.orig
*.user
*Thumbs.db
bin/
obj/
packages/
App_Data/
.vs/
9 changes: 0 additions & 9 deletions .hgtags

This file was deleted.

5 changes: 3 additions & 2 deletions Lombiq.Vsix.Orchard.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
# Visual Studio Version 16
VisualStudioVersion = 16.0.29905.134
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lombiq.Vsix.Orchard", "Lombiq.Vsix.Orchard\Lombiq.Vsix.Orchard.csproj", "{EF02401B-9EB3-4E06-8C34-8411700E4B58}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C8659693-2378-4A5D-B136-4983D0CDD7EE}"
ProjectSection(SolutionItems) = preProject
NuGet.config = NuGet.config
Readme.md = Readme.md
EndProjectSection
EndProject
Expand Down
23 changes: 20 additions & 3 deletions Lombiq.Vsix.Orchard/Commands/OpenErrorLogCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ internal sealed class OpenErrorLogCommand : IDisposable
private readonly DTE _dte;
private readonly Lazy<ILogWatcherSettings> _lazyLogWatcherSettings;
private readonly IEnumerable<ILogFileWatcher> _logWatchers;
private readonly IBlinkStickManager _blinkStickManager;
private OleMenuCommand _openErrorLogCommand;
private CommandBar _orchardLogWatcherToolbar;
private bool _hasSeenErrorLogUpdate;
private bool _errorIndicatorStateChanged;
private ILogFileStatus _latestUpdatedLogFileStatus;


Expand All @@ -39,6 +41,7 @@ private OpenErrorLogCommand(Package package)
_lazyLogWatcherSettings = new Lazy<ILogWatcherSettings>(
_serviceProvider.GetService<ILogWatcherSettingsAccessor>().GetSettings);
_logWatchers = _serviceProvider.GetServices<ILogFileWatcher>();
_blinkStickManager = _serviceProvider.GetService<IBlinkStickManager>();

Initialize();
}
Expand All @@ -50,9 +53,11 @@ public static void Initialize(Package package)
{
Instance = Instance ?? new OpenErrorLogCommand(package);
}

public void Dispose()
{
_blinkStickManager.Dispose();

foreach (var watcher in _logWatchers)
{
watcher.LogUpdated -= LogFileUpdatedCallback;
Expand All @@ -66,6 +71,7 @@ public void Dispose()
private void Initialize()
{
_hasSeenErrorLogUpdate = true;
_errorIndicatorStateChanged = true;

foreach (var watcher in _logWatchers)
{
Expand Down Expand Up @@ -135,22 +141,33 @@ private void LogWatcherSettingsUpdatedCallback(object sender, LogWatcherSettings

private void UpdateOpenErrorLogCommandAccessibilityAndText(ILogFileStatus logFileStatus = null)
{
var logWatcherSettings = _lazyLogWatcherSettings.Value;

if (!_dte.Solution.IsOpen)
{
_openErrorLogCommand.Enabled = false;
_openErrorLogCommand.Text = "Solution is not open";
_openErrorLogCommand.Text = "Solution is initializing";
}
else if (_lazyLogWatcherSettings.Value.LogWatcherEnabled &&
else if (logWatcherSettings.LogWatcherEnabled &&
((logFileStatus?.HasContent ?? false) ||
!_hasSeenErrorLogUpdate))
{
_openErrorLogCommand.Enabled = true;
_openErrorLogCommand.Text = "Open Orchard error log";

if (_errorIndicatorStateChanged)
{
if (logWatcherSettings.BlinkBlinkStick) _blinkStickManager.Blink(logWatcherSettings.BlinkStickColor);
else _blinkStickManager.TurnOn(logWatcherSettings.BlinkStickColor);
_errorIndicatorStateChanged = false;
}
}
else
{
_openErrorLogCommand.Enabled = false;
_openErrorLogCommand.Text = "Orchard error log doesn't exist or hasn't been updated";
_blinkStickManager.TurnOff();
_errorIndicatorStateChanged = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Lombiq.Vsix.Orchard/Constants/ExtensionVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
internal static class ExtensionVersion
{
public const string Current = "1.4.2";
public const string Current = "1.5.0";
}
}
17 changes: 17 additions & 0 deletions Lombiq.Vsix.Orchard/Lombiq.Vsix.Orchard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,23 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="BlinkStickDotNet, Version=2.0.16.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\BlinkStickDotNet.2.0.16\lib\net40\BlinkStickDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
<HintPath>..\packages\EnvDTE.8.0.2\lib\net10\EnvDTE.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="HidSharp, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HidSharp.1.5\lib\net35\HidSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="LibUsbDotNet, Version=2.2.8.104, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LibUsbDotNet.2.2.8\lib\LibUsbDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.CommandBars, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
Expand Down Expand Up @@ -251,12 +263,15 @@
<Compile Include="Services\DependencyInjector\DependencyInjector.cs" />
<Compile Include="Services\DependencyInjector\DefaultFieldNameFromDependencyGenerator.cs" />
<Compile Include="Services\DependencyInjector\IDependencyNameProvider.cs" />
<Compile Include="Services\LogWatcher\BlinkStickManager.cs" />
<Compile Include="Services\LogWatcher\IBlinkStickManager.cs" />
<Compile Include="Services\LogWatcher\LogFileWatcherBase.cs" />
<Compile Include="Services\LogWatcher\OrchardCoreLogFileWatcher.cs" />
<Compile Include="Services\LogWatcher\OrchardErrorLogFileWatcher.cs" />
<Compile Include="Services\DependencyInjector\IFieldNameFromDependencyGenerator.cs" />
<Compile Include="Services\LogWatcher\ILogWatcherSettingsAccessor.cs" />
<Compile Include="Services\LogWatcher\ILogFileWatcher.cs" />
<Compile Include="Services\LogWatcher\WildcardLogFileWatcher.cs" />
<Compile Include="VSPackage.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -328,7 +343,9 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.27\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.27\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets'))" />
<Error Condition="!Exists('..\packages\StrongNamer.0.2.5\build\StrongNamer.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\StrongNamer.0.2.5\build\StrongNamer.targets'))" />
</Target>
<Import Project="..\packages\StrongNamer.0.2.5\build\StrongNamer.targets" Condition="Exists('..\packages\StrongNamer.0.2.5\build\StrongNamer.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<Parent guid= "LombiqOrchardVisualStudioExtensionCommandSetGuid" id="LogWatcherToolbarGroup" />
<Icon guid="OrchardLogWatcherImagesGuid" id="OrchardErrorSmallBitmapId" />
<Strings>
<ButtonText>Solution is not open</ButtonText>
<ButtonText>Solution is initializing</ButtonText>
</Strings>
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ namespace Lombiq.Vsix.Orchard
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration(
// Such values can supposedly come from resx files (see: https://docs.microsoft.com/en-us/visualstudio/extensibility/creating-an-extension-with-a-vspackage?view=vs-2019)
// Such values can supposedly come from resx files (see:
// https://docs.microsoft.com/en-us/visualstudio/extensibility/creating-an-extension-with-a-vspackage?view=vs-2019)
// but that code doesn't work.
"Lombiq Orchard Visual Studio Extension",
"Lombiq Orchard Visual Studio Extension",
"Visual Studio extension with many features frequently used by Lombiq developers. Contains Orchard-related as well as generic goodies.",
ExtensionVersion.Current,
IconResourceID = 400)]
Expand Down Expand Up @@ -69,7 +70,9 @@ private void RegisterServices()
serviceContainer.AddService<ILogWatcherSettingsAccessor>(this);
serviceContainer.AddServices<ILogFileWatcher>(
new OrchardErrorLogFileWatcher(this),
new OrchardCoreLogFileWatcher(this));
new OrchardCoreLogFileWatcher(this),
new WildcardLogFileWatcher(this));
serviceContainer.AddService<IBlinkStickManager>(new BlinkStickManager());
}


Expand Down
17 changes: 17 additions & 0 deletions Lombiq.Vsix.Orchard/Models/ILogWatcherSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ public interface ILogWatcherSettings
/// </summary>
bool LogWatcherEnabled { get; }

/// <summary>
/// Log file name search pattern (as offered by Directory.EnumerateFiles()) to look for files in the
/// directories provided by <see cref="GetLogFileFolderPaths"/>.
/// </summary>
string LogFileNameSearchPattern { get; }

/// <summary>
/// The color, as a hex value or noun, to use with an attached BlinkStick USB LED stick if present.
/// </summary>
string BlinkStickColor { get; }

/// <summary>
/// Indicates whether an attached BlinkStick USB LED stick, if present, will blink (<c>true</c>) or light up
/// continuously (<c>false</c>) when a new error log entry is detected.
/// </summary>
bool BlinkBlinkStick { get; }

/// <summary>
/// Returns the relative paths of the folders where the log files can be located.
/// </summary>
Expand Down
52 changes: 34 additions & 18 deletions Lombiq.Vsix.Orchard/Options/LogWatcherOptionsPage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Lombiq.Vsix.Orchard.Constants;
using Lombiq.Vsix.Orchard.Helpers;
using Lombiq.Vsix.Orchard.Models;
using Lombiq.Vsix.Orchard.Services.LogWatcher;
using Microsoft.VisualStudio.Shell;
using System;
using System.Collections.Generic;
Expand All @@ -13,29 +14,34 @@ namespace Lombiq.Vsix.Orchard.Options
[Guid(PackageGuids.LogWatcherOptionsPageGuidString)]
public class LogWatcherOptionsPage : DialogPage, ILogWatcherSettings
{
private const bool DefaultLogWatcherEnabled = true;
private const string DefaultLogFileFolderPath = @"Orchard.Web/App_Data/Logs|src/OrchardCore.Cms.Web/App_Data/logs|*.Web/App_Data/logs|src/*.Web/App_Data/logs";


public event EventHandler<LogWatcherSettingsUpdatedEventArgs> SettingsUpdated;

[DisplayName("Enabled")]
[Category("General Log Watcher Options")]
[Description("Enable/disable Log Watcher feature. With this option turned off the Log Watcher won't check if the log file has any new entry.")]
public bool LogWatcherEnabled { get; set; }
public bool LogWatcherEnabled { get; set; } = true;

[DisplayName("Log file folder path")]
[DisplayName("Log file folder paths")]
[Category("General Log Watcher Options")]
[Description("List of relative paths where the log files are located. Values must be relative to the solution file that is currently opened. Wildcards can be used. Use the '|' character to separate values. Example: App_Data/logs|*.Web/App_Data/logs.")]
public string LogFileFolderPathsSerialized { get; set; }
public string LogFileFolderPathsSerialized { get; set; } =
@"Orchard.Web/App_Data/Logs|src/OrchardCore.Cms.Web/App_Data/logs|*.Web/App_Data/logs|src/*.Web/App_Data/logs";

[DisplayName("Log file name search pattern")]
[Category("General Log Watcher Options")]
[Description("If your app doesn't the standard Orchard log file naming conventions of orchard-log-YYYY-MM-DD.log and orchard-error-YYYY-MM-DD.log then you can specify a single search pattern (as offered by Directory.EnumerateFiles(), something like \"*.log\") to look for files in the directories configured above. If multiple files are found then the most recently written one will be used. Note that with a large number of matching files this will be slow so empty the log directory often.")]
public string LogFileNameSearchPattern { get; set; } = string.Empty;

[DisplayName("Color for the BlinkStick LED stick")]
[Category("Log Watcher BlinkStick Options")]
[Description("Set the color for the BlinkStick USB LED stick here. Use either a hex value or one of the names listed here: https://github.com/arvydas/BlinkStickDotNet/blob/master/BlinkStickDotNet/RgbColor.cs#L30.")]
public string BlinkStickColor { get; set; } = "red";

[DisplayName("Blink BlinkStick LED stick")]
[Category("Log Watcher BlinkStick Options")]
[Description("You can use your BlinkStick USB LED stick (see the Readme) so it lights up when a new log entry is detected. Enable/disable whether to make it blink when a new long entry is detected. When disabled the BlinkStick will light up continuously.")]
public bool BlinkBlinkStick { get; set; } = false;

public LogWatcherOptionsPage()
{
LogWatcherEnabled = DefaultLogWatcherEnabled;
LogFileFolderPathsSerialized = DefaultLogFileFolderPath;
}


public IEnumerable<string> GetLogFileFolderPaths() =>
LogFileFolderPathsSerialized?
Expand All @@ -48,17 +54,27 @@ protected override void OnDeactivate(CancelEventArgs e)
base.OnDeactivate(e);

// Check if the log file folder path is empty only if the feature is enabled. Don't allow invalid paths at all.
if (LogWatcherEnabled && string.IsNullOrEmpty(LogFileFolderPathsSerialized))
{
DialogHelpers.Warning("Log file folder path is required if the feature is enabled.", "Log Watcher settings");

e.Cancel = true;
if (LogWatcherEnabled)
{
if (string.IsNullOrEmpty(LogFileFolderPathsSerialized))
{
DialogHelpers.Warning("Log file folder path is required if the feature is enabled.", "Log Watcher settings");
e.Cancel = true;
}

if (!BlinkStickManager.IsValidColor(BlinkStickColor))
{
DialogHelpers.Warning(
"The given BlinkStick color is invalid. Please use a valid hex value or one of the names listed here: https://github.com/arvydas/BlinkStickDotNet/blob/master/BlinkStickDotNet/RgbColor.cs#L30.",
"Log Watcher settings");
e.Cancel = true;
}
}

if (GetLogFileFolderPaths().Any(path => !Uri.IsWellFormedUriString(path, UriKind.Relative)))
{
DialogHelpers.Warning("The given log file folder path is invalid.", "Log Watcher settings");

e.Cancel = true;
}
}
Expand Down
Loading

0 comments on commit 1d10f99

Please sign in to comment.