Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into BundleSize
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonGvili committed Nov 3, 2018
2 parents 17c0501 + c58830d commit f2731df
Show file tree
Hide file tree
Showing 41 changed files with 6,686 additions and 3,883 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -190,7 +190,7 @@ ClientBin/
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
# *.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -92,7 +92,7 @@ When building your dashboard in debug mode, make sure to use the port 10001. The

## Resources

- [Documentation](https://www.gitbook.com/book/adamdriscoll/powershell-universal-dashboard)
- [Documentation](https://docs.universaldashboard.io)
- [Licensing](https://ironmansoftware.com/universal-dashboard)
- [Live Preview](https://poshud.com/)
- [YouTube Videos](https://www.youtube.com/playlist?list=PL-0mHH7DlSiSZ4ozleNTUSXNkF6dlySVz)
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
@@ -1,4 +1,4 @@
version: 2.0.0.{build}
version: 2.1.0.{build}

image: Visual Studio 2017

Expand Down
65 changes: 57 additions & 8 deletions src/UniversalDashboard.Server/DashboardManager.cs
Expand Up @@ -3,6 +3,7 @@
using System.Management.Automation;
using System.Reflection;
using System.Linq;
using System.Diagnostics;

namespace UniversalDashboard
{
Expand All @@ -15,16 +16,31 @@ public void Start()
var assemblyBasePath = Path.GetDirectoryName(typeof(Program).GetTypeInfo().Assembly.Location);
var dashboardScript = Path.Combine(assemblyBasePath, "..", "dashboard.ps1");

using(var powerShell = PowerShell.Create())
{
var modulePath = Path.Combine(assemblyBasePath, "..\\UniversalDashboard.Community.psd1");
Log($"Starting Universal Dashboard service. {Environment.NewLine} Dashboard Script: {dashboardScript} {Environment.NewLine} Assembly Base Path: {dashboardScript}", false);

powerShell.AddStatement().AddScript("Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process");
powerShell.AddStatement().AddScript($"Import-Module '{modulePath}'");
powerShell.AddStatement().AddScript($". '{dashboardScript}'");
try
{
using(var powerShell = PowerShell.Create())
{
var modulePath = Path.Combine(assemblyBasePath, "..\\UniversalDashboard.Community.psd1");

_server = powerShell.Invoke().FirstOrDefault()?.BaseObject as Server;
}
powerShell.AddStatement().AddScript("Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process");
powerShell.AddStatement().AddScript($"Import-Module '{modulePath}'");
powerShell.AddStatement().AddScript($". '{dashboardScript}'");

_server = powerShell.Invoke().FirstOrDefault()?.BaseObject as Server;

if (powerShell.HadErrors) {
foreach(var error in powerShell.Streams.Error) {
Log($"Error starting dashboard: {Environment.NewLine} {error.ToString()} {Environment.NewLine} {error.ScriptStackTrace}", true);
}
}
}
}
catch (Exception ex)
{
Log($"Error starting dashboard: {Environment.NewLine} {ex.ToString()}", true);
}

if (_server == null || !_server.Running)
{
Expand All @@ -35,5 +51,38 @@ public void Start()
public void Stop() {
_server.Stop();
}

private void CreateEventSource() {
#if NET472
try
{
if (!EventLog.SourceExists("Universal Dashboard"))
{
EventLog.CreateEventSource("Universal Dashboard", "Application");
}
}
catch (Exception ex)
{
Console.WriteLine("Failed to create event source: " + ex.Message);
}
#endif
}

private void Log(string message, bool error)
{
#if NET472
try
{
EventLog eventLog = new EventLog();
eventLog.Source = "Universal Dashboard";
eventLog.WriteEntry(message, error ? EventLogEntryType.Error : EventLogEntryType.Information);
}
catch
{

}
#endif
Console.WriteLine(message);
}
}
}
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Binary file not shown.
184 changes: 29 additions & 155 deletions src/UniversalDashboard.UITest/Integration/Card.Tests.ps1
@@ -1,4 +1,4 @@
param([Switch]$Release)
param([Switch]$Release)

Import-Module "$PSScriptRoot\..\TestFramework.psm1" -Force
$ModulePath = Get-ModulePath -Release:$Release
Expand All @@ -21,58 +21,28 @@ Describe "Card" {
New-UDCard -Title "Test" -Text "My text" -Id "Card" -Links @(
New-UDLink -Text "My Link" -Url "http://www.google.com"
)
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"

It "should have title text" {
$Element = Find-SeElement -Id "Card" -Driver $Driver
$Element.Text.Split("`r`n")[0] | should be "Test"
}

It "should have link" {
Find-SeElement -LinkText "MY LINK" -Driver $Driver | Should not be $null
}
New-UDCard -Title "ÆØÅ" -Text "Test" -Id "nordic"

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}


Context "No text card" {
$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDCard -Title "Test" -Id "Card" -Endpoint {
New-UDCard -Title "Test" -Id "EndpointCard" -Endpoint {
New-UDElement -Tag "div" -Content { "Endpoint Content" }
}
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
New-UDCard -Title "Test" -Id "NoTextCard"

Start-Sleep 2
New-UDCard -Title "Test" -Text "My text`r`nNew Line" -Id "MultiLineCard"

It "should have body text" {
$Element = Find-SeElement -Id "Card" -Driver $Driver
($Element.Text).Contains("Endpoint Content") | should be $true
}
New-UDCard -Title "Test" -Text "Small Text" -Id "Card-Small-Text" -TextSize Small

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}

Context "No text card" {
$tempDir = [System.IO.Path]::GetTempPath()
$tempFile = Join-Path $tempDir "output.txt"
New-UDCard -Title "Test" -Text "Medium Text" -Id "Card-Medium-Text" -TextSize Medium

if ((Test-path $tempFile)) {
Remove-Item $tempFile -Force
}
New-UDCard -Title "Test" -Text "Large Text" -Id "Card-Large-Text" -TextSize Large

$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDCard -Title "Test" -Id "Card"
New-UDCard -Title "Test" -Content {
New-UDElement -Tag "span" -Attributes @{id = "spanTest"} -Content {
"This is some custom content"
}
}
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
Expand All @@ -81,79 +51,39 @@ Describe "Card" {

It "should have title text" {
$Element = Find-SeElement -Id "Card" -Driver $Driver
$Element.Text | should be "Test"
$Element.Text.Split("`r`n")[0] | should be "Test"
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}

Context "Multi-line Card" {
$tempDir = [System.IO.Path]::GetTempPath()
$tempFile = Join-Path $tempDir "output.txt"
It "should have link" {
Find-SeElement -LinkText "MY LINK" -Driver $Driver | Should not be $null
}

if ((Test-path $tempFile)) {
Remove-Item $tempFile -Force
It "should show nordic chars correctly" {
$Element = Find-SeElement -Id "nordic" -Driver $Driver
$Element.Text.Split("`r`n")[0] | should be "ÆØÅ"
}

$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDCard -Title "Test" -Text "My text`r`nNew Line" -Id "Card"
It "should load content from endpoint" {
$Element = Find-SeElement -Id "EndpointCard" -Driver $Driver
($Element.Text).Contains("Endpoint Content") | should be $true
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
It "should have title text" {
$Element = Find-SeElement -Id "NoTextCard" -Driver $Driver
$Element.Text | should be "Test"
}

It "should support new line in card" {
$Element = Find-SeElement -Id "Card" -Driver $Driver
$Element = Find-SeElement -Id "MultiLineCard" -Driver $Driver
$Br = Find-SeElement -Tag "br" -Element $Element
$Br | should not be $null
}
Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}

Context "Card With Small Text" {
$tempDir = [System.IO.Path]::GetTempPath()
$tempFile = Join-Path $tempDir "output.txt"

if ((Test-path $tempFile)) {
Remove-Item $tempFile -Force
}

$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDCard -Title "Test" -Text "Small Text" -Id "Card-Small-Text" -TextSize Small
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"

$Element = Find-SeElement -Id "Card-Small-Text" -Driver $Driver
It "should have text of Small Text" {
$Element = Find-SeElement -Id "Card-Small-Text" -Driver $Driver
($Element.Text -split "`r`n")[1] | should be 'Small Text'
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}

Context "Card With Medium Text" {
$tempDir = [System.IO.Path]::GetTempPath()
$tempFile = Join-Path $tempDir "output.txt"

if ((Test-path $tempFile)) {
Remove-Item $tempFile -Force
}

$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDCard -Title "Test" -Text "Medium Text" -Id "Card-Medium-Text" -TextSize Medium
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"

$Element = Find-SeElement -Id "Card-Medium-Text" -Driver $Driver
$CardContent = Find-SeElement -Element $Element -TagName 'h5'

Expand All @@ -164,26 +94,6 @@ Describe "Card" {
It "should have text of Medium Text" {
$CardContent.Text | should be 'Medium Text'
}
Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}

Context "Card With Large Text" {
$tempDir = [System.IO.Path]::GetTempPath()
$tempFile = Join-Path $tempDir "output.txt"

if ((Test-path $tempFile)) {
Remove-Item $tempFile -Force
}

$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDCard -Title "Test" -Text "Large Text" -Id "Card-Large-Text" -TextSize Large
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"


$Element = Find-SeElement -Id "Card-Large-Text" -Driver $Driver
$CardContent = Find-SeElement -Element $Element -TagName 'h3'
Expand All @@ -196,41 +106,6 @@ Describe "Card" {
$CardContent.Text | should be 'Large Text'
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}


Context "Custom Card" {
$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDCard -Title "Test" -Text "My text`r`nNew Line" -Id "Card" -TextAlignment Center -TextSize Medium -Watermark user
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"

It "should support new line in card" {

}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}

Context "Card with content" {
$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDCard -Title "Test" -Content {
New-UDElement -Tag "span" -Attributes @{id = "spanTest"} -Content {
"This is some custom content"
}
}
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"

It "should have custom content" {
$Element = Find-SeElement -Id "spanTest" -Driver $Driver
$Element.Text | should be "This is some custom content"
Expand All @@ -239,5 +114,4 @@ Describe "Card" {
Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}

}

0 comments on commit f2731df

Please sign in to comment.