Skip to content

Commit

Permalink
Update EmbedIO Server
Browse files Browse the repository at this point in the history
  • Loading branch information
dk307 committed Jan 1, 2019
1 parent 3fd9f72 commit 88fbbaa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 41 deletions.
8 changes: 3 additions & 5 deletions HSPI_ChromecastSpeak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="EmbedIO">
<Version>1.16.1</Version>
<Version>2.1.1</Version>
</PackageReference>
<PackageReference Include="Fody">
<Version>3.3.5</Version>
Expand Down Expand Up @@ -274,7 +274,6 @@
<Using xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Namespace="System.Xml.Linq" />
</Task>
</UsingTask>

<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release' ">
<ItemGroup>
<InputAssemblies Include="$(OutputPath)\HSPI_ChromecastSpeak.exe" />
Expand All @@ -290,11 +289,10 @@
<InputAssemblies Include="$(OutputPath)\System.Collections.Immutable.dll" />
</ItemGroup>
<!-- <CreateItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)'=='.dll'"> -->
<!-- <Output ItemName="AssembliesToMerge" TaskParameter="Include" /> -->
<!-- <Output ItemName="AssembliesToMerge" TaskParameter="Include" /> -->
<!-- </CreateItem> -->
<Message Importance="high" Text="Executing ILMerge in $(ProjectDir)..." />
<Exec WorkingDirectory="$(ProjectDir)"
Command="&quot;$(ILMergeConsolePath)&quot; /ndebug /target:winexe /out:@(MainAssembly) /internalize /targetplatform:v4 @(InputAssemblies->'&quot;%(FullPath)&quot;', ' ')" />
<Exec WorkingDirectory="$(ProjectDir)" Command="&quot;$(ILMergeConsolePath)&quot; /ndebug /target:winexe /out:@(MainAssembly) /internalize /targetplatform:v4 @(InputAssemblies->'&quot;%(FullPath)&quot;', ' ')" />
<!-- <Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" /> -->
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Chromecast Device Settings

Firewall
------------
Open the firewall based on Settings. Windows 10 powershell script is included.
Open the firewall based on port settings. Windows 10 powershell script is included.
![Firewall](/asserts/firewall.PNG "Firewall")

Build State
Expand Down
26 changes: 9 additions & 17 deletions Web/InMemoryFileSystemModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ public InMemoryFileSystemModule(Dictionary<string, string> headers = null)
AddHandler(ModuleMap.AnyPath, HttpVerbs.Get, (context, ct) => HandleGet(context, ct));
}

/// <summary>
/// Gets the collection holding the MIME types.
/// </summary>
/// <value>
/// The MIME types.
/// </value>
public static IReadOnlyDictionary<string, string> MimeTypes
=> new ReadOnlyDictionary<string, string>(Unosquare.Labs.EmbedIO.Constants.MimeTypes.DefaultMimeTypes);

/// <summary>
/// Gets the name of this module.
/// </summary>
Expand Down Expand Up @@ -109,14 +100,14 @@ private static bool CalculateRange(string partialHeader, long fileSize, out int
return false;
}

private static string GetUrlPath(HttpListenerContext context)
private static string GetUrlPath(IHttpContext context)
{
var urlPath = context.RequestPathCaseSensitive().Replace('/', Path.DirectorySeparatorChar);
urlPath = urlPath.TrimStart(Path.DirectorySeparatorChar);
return urlPath;
}

private static async Task WriteToOutputMemoryStream(HttpListenerContext context, long byteLength, byte[] buffer,
private static async Task WriteToOutputMemoryStream(IHttpContext context, long byteLength, byte[] buffer,
int lowerByteIndex, CancellationToken ct)
{
checked
Expand All @@ -133,7 +124,7 @@ private static async Task WriteToOutputMemoryStream(HttpListenerContext context,
}
}

private async Task<bool> HandleGet(HttpListenerContext context, CancellationToken ct, bool sendBuffer = true)
private async Task<bool> HandleGet(IHttpContext context, CancellationToken ct, bool sendBuffer = true)
{
Trace.WriteLine($"Request Type {context.RequestVerb()} from {context.Request.RemoteEndPoint} for {context.Request.Url}");

Expand Down Expand Up @@ -237,7 +228,7 @@ private async Task<bool> HandleGet(HttpListenerContext context, CancellationToke
return true;
}

private async Task<bool> SendFileList(HttpListenerContext context, CancellationToken ct)
private async Task<bool> SendFileList(IHttpContext context, CancellationToken ct)
{
StringBuilder stb = new StringBuilder();

Expand All @@ -264,12 +255,13 @@ private async Task<bool> SendFileList(HttpListenerContext context, CancellationT
return await context.HtmlResponseAsync(stb.ToString(), cancellationToken: ct).ConfigureAwait(false);
}

private void SetHeaders(HttpListenerContext context, string localPath, string utcFileDateString)
private void SetHeaders(IHttpContext context, string localPath, string utcFileDateString)
{
var fileExtension = Path.GetExtension(localPath);

if (MimeTypes.ContainsKey(fileExtension))
context.Response.ContentType = MimeTypes[fileExtension];
var mimeTypes = MimeTypes.DefaultMimeTypes.Value;
if (mimeTypes.ContainsKey(fileExtension))
context.Response.ContentType = mimeTypes[fileExtension];

context.Response.AddHeader(Headers.CacheControl,
DefaultHeaders.ContainsKey(Headers.CacheControl)
Expand All @@ -290,7 +282,7 @@ private void SetHeaders(HttpListenerContext context, string localPath, string ut
context.Response.AddHeader(Headers.AcceptRanges, "bytes");
}

private void SetStatusCode304(HttpListenerContext context)
private void SetStatusCode304(IHttpContext context)
{
context.Response.AddHeader(Headers.CacheControl,
DefaultHeaders.ContainsKey(Headers.CacheControl)
Expand Down
21 changes: 3 additions & 18 deletions scripts/Win10Firewall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $currentPrincipal = New-Object Security.Principal.WindowsPrincipal( [Security.Pr
if ( -not $currentPrincipal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator ))
{
write-host "Error Script only works as administrator".
// return
return
}

$builder = New-Object System.UriBuilder
Expand All @@ -25,22 +25,7 @@ $builder.Port = $port
$builder.Scheme = 'http'
$serviceUrl = $builder.ToString()

$serviceUser = [String]::Join("\", $env:userdomain, $env:username)

if( -not (netsh http show urlacl url=$serviceUrl | Where-Object { $_ -match [regex]::Escape($serviceUrl) }) )
{
if ($operation -eq 'add') {
Write-Verbose -Message ('Granting {0} permission to listen on {1}' -f $serviceUser, $serviceUrl) -Verbose
netsh http add urlacl url=$serviceUrl user=$serviceUser| Write-Verbose -Verbose
}
} else {
if ($operation -eq 'remove') {
Write-Verbose -Message ('Removing listen on {0}' -f $serviceUrl) -Verbose
netsh http delete urlacl url=$serviceUrl | Write-Verbose -Verbose
}
}

$ruleName = 'Homeseer Chromecast Speak'
$ruleName = 'HSPI Chromecast Speak Plugin'
$exitingRules = @()

$potentialRules = @(Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue)
Expand All @@ -56,7 +41,7 @@ foreach($rule in $potentialRules) {
if ($operation -eq 'add') {
if ($exitingRules.Length -eq 0) {
Write-Verbose -Message ('Adding Firewall rule for {0}' -f $serviceUrl) -Verbose
New-NetFirewallRule -DisplayName 'Homeseer Chromecast Speak' -LocalAddress $ipAddress -LocalPort $port -Protocol TCP -Program "System" | Write-Verbose -Verbose
New-NetFirewallRule -DisplayName $ruleName -LocalAddress $ipAddress -LocalPort $port -Protocol TCP | Write-Verbose -Verbose
}
}

Expand Down

0 comments on commit 88fbbaa

Please sign in to comment.