Updated version and finally got web server running
This commit is contained in:
5
RadioDJViewer/Main.Designer.cs
generated
5
RadioDJViewer/Main.Designer.cs
generated
@@ -86,9 +86,12 @@
|
||||
//
|
||||
// toolStripStatusLabel2
|
||||
//
|
||||
this.toolStripStatusLabel2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripStatusLabel2.Image")));
|
||||
this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
|
||||
this.toolStripStatusLabel2.Size = new System.Drawing.Size(16, 20);
|
||||
// Use BackColor only to indicate status. Text is a single space so the label renders as a square.
|
||||
this.toolStripStatusLabel2.Text = " ";
|
||||
this.toolStripStatusLabel2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
|
||||
this.toolStripStatusLabel2.BackColor = System.Drawing.Color.Red;
|
||||
//
|
||||
// toolStripStatusLabel4
|
||||
//
|
||||
|
||||
@@ -517,6 +517,49 @@ namespace RadioDJViewer
|
||||
File.WriteAllText(Path.Combine(outputFolderPath, "album.txt"), marqueeTextAlbum);
|
||||
}
|
||||
|
||||
// Update in-memory cache for widget server
|
||||
try
|
||||
{
|
||||
WidgetServer.CachedArtist = marqueeTextArtist ?? string.Empty;
|
||||
WidgetServer.CachedTitle = marqueeTextTitle ?? string.Empty;
|
||||
byte[] imgBytes = null;
|
||||
// Prefer album art from main images folder
|
||||
if (!string.IsNullOrEmpty(albumArt) && !string.IsNullOrEmpty(mainImagesFolderPath))
|
||||
{
|
||||
var imagePath = Path.Combine(mainImagesFolderPath, albumArt);
|
||||
if (File.Exists(imagePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var img = System.Drawing.Image.FromFile(imagePath))
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
||||
imgBytes = ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { imgBytes = null; }
|
||||
}
|
||||
}
|
||||
// Fallback to embedded resource image
|
||||
if (imgBytes == null)
|
||||
{
|
||||
var fallback = Properties.Resources.fallback;
|
||||
if (fallback != null)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
fallback.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
||||
imgBytes = ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
WidgetServer.CachedImageBytes = imgBytes;
|
||||
}
|
||||
catch { }
|
||||
|
||||
// Handle album art image
|
||||
if (!string.IsNullOrWhiteSpace(albumArt))
|
||||
{
|
||||
|
||||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("1.8.0")]
|
||||
[assembly: AssemblyFileVersion("1.8.0")]
|
||||
[assembly: AssemblyVersion("1.9.0")]
|
||||
[assembly: AssemblyFileVersion("1.9.0")]
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
@@ -25,7 +26,6 @@
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -18,6 +18,11 @@ namespace RadioDJViewer
|
||||
/// </summary>
|
||||
public class WidgetServer
|
||||
{
|
||||
// In-memory cache for fast serving
|
||||
public static string CachedArtist = "";
|
||||
public static string CachedTitle = "";
|
||||
public static byte[] CachedImageBytes = null;
|
||||
|
||||
private readonly int port;
|
||||
private readonly Func<string> getArtist;
|
||||
private readonly Func<string> getTitle;
|
||||
@@ -105,13 +110,28 @@ namespace RadioDJViewer
|
||||
if (path == "/" || path.Equals("/index.html", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var html = htmlTemplate ?? "";
|
||||
html = html.Replace("{{ARTIST}}", WebUtility.HtmlEncode(getArtist()))
|
||||
.Replace("{{TITLE}}", WebUtility.HtmlEncode(getTitle()));
|
||||
// Replace placeholders with in-memory cache values
|
||||
html = html.Replace("{{ARTIST}}", WebUtility.HtmlEncode(CachedArtist ?? string.Empty))
|
||||
.Replace("{{TITLE}}", WebUtility.HtmlEncode(CachedTitle ?? string.Empty));
|
||||
var buf = Encoding.UTF8.GetBytes(html);
|
||||
resp.ContentType = "text/html; charset=utf-8";
|
||||
resp.ContentLength64 = buf.Length;
|
||||
resp.OutputStream.Write(buf, 0, buf.Length);
|
||||
}
|
||||
else if (path.Equals("/artist.txt", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var buf = Encoding.UTF8.GetBytes(CachedArtist ?? string.Empty);
|
||||
resp.ContentType = "text/plain; charset=utf-8";
|
||||
resp.ContentLength64 = buf.Length;
|
||||
resp.OutputStream.Write(buf, 0, buf.Length);
|
||||
}
|
||||
else if (path.Equals("/title.txt", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var buf = Encoding.UTF8.GetBytes(CachedTitle ?? string.Empty);
|
||||
resp.ContentType = "text/plain; charset=utf-8";
|
||||
resp.ContentLength64 = buf.Length;
|
||||
resp.OutputStream.Write(buf, 0, buf.Length);
|
||||
}
|
||||
else if (path.Equals("/style.css", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var buf = Encoding.UTF8.GetBytes(cssText ?? "");
|
||||
@@ -126,17 +146,15 @@ namespace RadioDJViewer
|
||||
resp.ContentLength64 = buf.Length;
|
||||
resp.OutputStream.Write(buf, 0, buf.Length);
|
||||
}
|
||||
else if (path.Equals("/albumart", StringComparison.OrdinalIgnoreCase))
|
||||
else if (path.Equals("/Album-Art.png", StringComparison.OrdinalIgnoreCase) || path.Equals("/album-art.png", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var imagePath = getAlbumArtPath();
|
||||
if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath))
|
||||
if (CachedImageBytes != null && CachedImageBytes.Length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] imgBytes = File.ReadAllBytes(imagePath);
|
||||
resp.ContentType = GetMimeTypeFromPath(imagePath);
|
||||
resp.ContentLength64 = imgBytes.Length;
|
||||
resp.OutputStream.Write(imgBytes, 0, imgBytes.Length);
|
||||
resp.ContentType = "image/png";
|
||||
resp.ContentLength64 = CachedImageBytes.Length;
|
||||
resp.OutputStream.Write(CachedImageBytes, 0, CachedImageBytes.Length);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user