Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mastersign committed Jul 4, 2016
2 parents f6fbcea + 9c24a27 commit c5f2f26
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 125 deletions.
48 changes: 27 additions & 21 deletions BenchManager/BenchDashboard/AppLauncherControl.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Mastersign.Bench.Dashboard.Properties;
using System.Threading.Tasks;

namespace Mastersign.Bench.Dashboard
{
Expand All @@ -25,29 +27,29 @@ public AppIndexFacade AppIndex
get { return appIndex; }
set
{
if (appIndex != null) ReleaseAppIndex();
appIndex = value;
if (appIndex != null) BindAppIndex();
}
}

private void ReleaseAppIndex()
private async void BindAppIndex()
{
listView.Items.Clear();
icons16.Images.Clear();
icons32.Images.Clear();
}

private void BindAppIndex()
{
foreach (var app in appIndex.ActiveApps)
{
if (app.Launcher != null)
{
LoadIcons(app);
listView.Items.Add(AppItem(app));
var icons = await LoadIcons(app);
icons16.Images.Add(app.ID, icons.Item1);
icons32.Images.Add(app.ID, icons.Item2);
}
}
listView.Items.Clear();
var items = from app in appIndex.ActiveApps
where app.Launcher != null
select AppItem(app);
listView.Items.AddRange(items.ToArray());
}

private ListViewItem AppItem(AppFacade app)
Expand All @@ -59,20 +61,24 @@ private ListViewItem AppItem(AppFacade app)
};
}

private void LoadIcons(AppFacade app)
private Task<Tuple<Icon, Icon>> LoadIcons(AppFacade app)
{
var path = app.LauncherIcon;
Icon icon;
try
{
icon = Icon.ExtractAssociatedIcon(path);
}
catch (Exception)
return Task.Run(() =>
{
icon = Resources.MissingApp;
}
icons16.Images.Add(app.ID, new Icon(icon, icons16.ImageSize));
icons32.Images.Add(app.ID, new Icon(icon, icons32.ImageSize));
var path = app.LauncherIcon;
Icon icon;
try
{
icon = Icon.ExtractAssociatedIcon(path);
}
catch (Exception)
{
icon = Resources.MissingApp;
}
return Tuple.Create(
new Icon(icon, icons16.ImageSize),
new Icon(icon, icons32.ImageSize));
});
}

private void listView_DoubleClick(object sender, EventArgs e)
Expand Down
25 changes: 20 additions & 5 deletions BenchManager/BenchDashboard/ConEmuExecutionHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class ConEmuExecutionHost : IProcessExecutionHost

private IProcessExecutionHost backupHost;

private bool reloadConfigBeforeNextExecution = false;

public ConEmuExecutionHost(Core core, ConEmuControl control, string conEmuExe)
{
this.core = core;
Expand All @@ -45,11 +47,12 @@ public ConEmuExecutionHost(Core core, ConEmuControl control, string conEmuExe)
backupHost = new DefaultExecutionHost();
config = LoadConfigFromResource();
StartPowerShellExecutionHost();
this.core.ConfigReloaded += (s, e) =>
{
StopPowerShellExecutionHost();
StartPowerShellExecutionHost();
};
this.core.ConfigReloaded += CoreConfigReloadedHandler;
}

private void CoreConfigReloadedHandler(object sender, EventArgs e)
{
reloadConfigBeforeNextExecution = true;
}

private XmlDocument LoadConfigFromResource()
Expand Down Expand Up @@ -185,6 +188,13 @@ private IEnumerable<string> SendCommand(string command, params string[] argument
}
}

private void ReloadConfiguration()
{
if (!IsPowerShellExecutionHostRunning) return;
SendCommand("reload").Any(l => l == "OK");
reloadConfigBeforeNextExecution = false;
}

private void StopPowerShellExecutionHost()
{
if (!IsPowerShellExecutionHostRunning) return;
Expand Down Expand Up @@ -228,6 +238,10 @@ public ProcessExecutionResult RunProcess(BenchEnvironment env,
{
return backupHost.RunProcess(env, cwd, executable, arguments, monitoring);
}
if (reloadConfigBeforeNextExecution)
{
ReloadConfiguration();
}
var collectOutput = (monitoring & ProcessMonitoring.Output) == ProcessMonitoring.Output;
var response = SendCommand("exec", cwd, executable, arguments);
var exitCode = 999999;
Expand Down Expand Up @@ -287,6 +301,7 @@ public void Dispose()
{
if (IsDisposed) return;
IsDisposed = true;
core.ConfigReloaded -= CoreConfigReloadedHandler;
StopPowerShellExecutionHost();
backupHost.Dispose();
backupHost = null;
Expand Down
81 changes: 41 additions & 40 deletions BenchManager/BenchDashboard/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Windows.Forms;
using Mastersign.Bench.Dashboard.Properties;
using TsudaKageyu;
using System.Threading.Tasks;

namespace Mastersign.Bench.Dashboard
{
Expand Down Expand Up @@ -75,7 +76,7 @@ private void InitializeAppLauncherList()
appLauncherList.AppIndex = core.Config.Apps;
}

private void InitializeDocsMenu()
private async void InitializeDocsMenu()
{
var ctxm = new ContextMenuStrip();

Expand All @@ -94,7 +95,7 @@ private void InitializeDocsMenu()
var docs = app.Docs;
if (string.IsNullOrEmpty(websiteUrl) && (docs == null || docs.Count == 0)) continue;
var item = new ToolStripMenuItem(label);
item.Image = ExtractLauncherIcon(app);
item.Image = await ExtractLauncherIcon(app);
if (!string.IsNullOrEmpty(websiteUrl))
{
if (item.Image == null)
Expand All @@ -119,20 +120,23 @@ private void InitializeDocsMenu()
docsMenu = ctxm;
}

private Image ExtractLauncherIcon(AppFacade app)
private Task<Image> ExtractLauncherIcon(AppFacade app)
{
var path = app.LauncherIcon;
if (string.IsNullOrEmpty(app.Launcher) || string.IsNullOrEmpty(path)) return null;
Icon icon;
try
return Task.Run<Image>(() =>
{
icon = Icon.ExtractAssociatedIcon(path);
}
catch (Exception)
{
return null;
}
return new Icon(icon, new Size(16, 16)).ToBitmap();
var path = app.LauncherIcon;
if (string.IsNullOrEmpty(app.Launcher) || string.IsNullOrEmpty(path)) return null;
Icon icon;
try
{
icon = Icon.ExtractAssociatedIcon(path);
}
catch (Exception)
{
return null;
}
return new Icon(icon, new Size(16, 16)).ToBitmap();
});
}

private void InitializeStatusStrip()
Expand All @@ -141,38 +145,35 @@ private void InitializeStatusStrip()
tsslAppCount.Text = core.Config.Apps.ActiveApps.Length.ToString();
}

private void InitializeTopPanel()
private async void InitializeTopPanel()
{
UpdateShellButtons();
new Thread(() =>
{
var cmdImg = ExtractIcon(core.CmdPath, "CMD");
var psImg = ExtractIcon(core.PowerShellPath, "PowerShell");
var imageResDllPath = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\System32\imageres.dll");
var bashImg = ExtractIcon(imageResDllPath, "Bash", 95);
BeginInvoke((ThreadStart)(() =>
{
btnShellCmd.Image = cmdImg ?? Resources.missing_app_16;
btnShellPowerShell.Image = psImg ?? Resources.missing_app_16;
btnShellBash.Image = bashImg ?? Resources.missing_app_16;
}));
}).Start();
var cmdImg = await ExtractIcon(core.CmdPath, "CMD");
var psImg = await ExtractIcon(core.PowerShellPath, "PowerShell");
var imageResDllPath = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\System32\imageres.dll");
var bashImg = await ExtractIcon(imageResDllPath, "Bash", 95);
btnShellCmd.Image = cmdImg ?? Resources.missing_app_16;
btnShellPowerShell.Image = psImg ?? Resources.missing_app_16;
btnShellBash.Image = bashImg ?? Resources.missing_app_16;
}

private static Bitmap ExtractIcon(string path, string name, int index = 0)
private static Task<Bitmap> ExtractIcon(string path, string name, int index = 0)
{
if (!File.Exists(path)) return null;
try
return Task.Run(() =>
{
var extractor = new IconExtractor(path);
var icon = extractor.GetIcon(index);
return new Icon(icon, new Size(16, 16)).ToBitmap();
}
catch (Exception e)
{
Debug.WriteLine("Failed to load icon for " + name + ": " + e);
return null;
}
if (!File.Exists(path)) return null;
try
{
var extractor = new IconExtractor(path);
var icon = extractor.GetIcon(index);
return new Icon(icon, new Size(16, 16)).ToBitmap();
}
catch (Exception e)
{
Debug.WriteLine("Failed to load icon for " + name + ": " + e);
return null;
}
});
}

private void UpdateShellButtons()
Expand Down
4 changes: 2 additions & 2 deletions BenchManager/BenchDashboard/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.11.3.0")]
[assembly: AssemblyFileVersion("0.11.3.0")]
[assembly: AssemblyVersion("0.11.4.0")]
[assembly: AssemblyFileVersion("0.11.4.0")]
4 changes: 2 additions & 2 deletions BenchManager/BenchLib/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.11.3.0")]
[assembly: AssemblyFileVersion("0.11.3.0")]
[assembly: AssemblyVersion("0.11.4.0")]
[assembly: AssemblyFileVersion("0.11.4.0")]
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ Add a link to the GitHub diff like
[Dev Changes](https://github.com/mastersign/bench/compare/master...dev),
[App Changes](https://github.com/mastersign/bench/compare/master...apps)

## [0.11.4] - 2016-07-04
[Full Changelog](https://github.com/mastersign/bench/compare/v0.11.3...v0.11.4)

### Changed
- Update: Node.js from 4.4.6 to 6.2.2

### Fixed
- UI performance when activating/deactivating apps

## [0.11.3] - 2016-07-02
[Full Changelog](https://github.com/mastersign/bench/compare/v0.11.2...v0.11.3)

Expand Down
17 changes: 14 additions & 3 deletions auto/lib/PsExecHost.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ $scriptsDir = [IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definition)
$rootDir = Resolve-Path "$scriptsDir\..\.."
. "$scriptsDir\bench.lib.ps1"
. "$scriptsLib\reg.lib.ps1"
$Script:benchEnv = New-Object Mastersign.Bench.BenchEnvironment ($Script:cfg)

$Script:BenchEnv = New-Object Mastersign.Bench.BenchEnvironment ($global:BenchConfig)

function _WaitForClient([IO.Pipes.NamedPipeServerStream]$pipe)
{
Expand Down Expand Up @@ -85,8 +86,8 @@ function _HandleExecutionRequest([IO.TextReader]$reader, [IO.TextWriter]$writer)
Write-Warning "Bench: Could not read execution arguments from named pipe."
return
}
$Script:benchEnv.Load()

$Script:BenchEnv.Load()
pushd $cwd
$exitCode = 0
$transcriptPath = [IO.Path]::Combine((Get-ConfigValue TempDir), $token)
Expand Down Expand Up @@ -121,6 +122,15 @@ function _HandleExecutionRequest([IO.TextReader]$reader, [IO.TextWriter]$writer)
$writer.WriteLine("TRANSCRIPT $Token $transcriptPath")
}

function _ReloadBenchConfig([IO.TextReader]$reader, [IO.TextWriter]$writer)
{
Write-Host "Reloading Bench configuration..."
$rootDir = $global:BenchConfig.BenchRootDir
$global:BenchConfig = New-Object Mastersign.Bench.BenchConfiguration ($rootDir)
$Script:BenchEnv = New-Object Mastersign.Bench.BenchEnvironment ($global:BenchConfig)
$writer.WriteLine("OK")
}

$server = New-Object System.IO.Pipes.NamedPipeServerStream($Token, [IO.Pipes.PipeDirection]::InOut)

$closed = $false
Expand All @@ -133,6 +143,7 @@ while (!$closed)
switch ($cmd)
{
"exec" { _HandleExecutionRequest $reader $writer | Out-Default }
"reload" { _ReloadBenchConfig $reader $writer | Out-Default }
"close" { $closed = $true }
}
$writer.Flush()
Expand Down
2 changes: 1 addition & 1 deletion auto/lib/Run-CustomScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ param (
[array]$scriptArgs
)

if (!$Script:cfg)
if (!$global:BenchConfig)
{
$scriptsLib = [IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definition)
. "$scriptsLib\bench.lib.ps1"
Expand Down
2 changes: 1 addition & 1 deletion auto/lib/Setup-Bench.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ param (
$myDir = [IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definition)
. "$myDir\bench.lib.ps1"

$manager = New-Object Mastersign.Bench.DefaultBenchManager ($Script:cfg)
$manager = New-Object Mastersign.Bench.DefaultBenchManager ($global:BenchConfig)
$manager.Verbose = $WithInfo

$success = $False
Expand Down
Loading

0 comments on commit c5f2f26

Please sign in to comment.