Skip to content

Commit

Permalink
Feat(general) Reduce number of files in the platform specific builds
Browse files Browse the repository at this point in the history
  • Loading branch information
rnwood authored Mar 2, 2024
1 parent 765d9bc commit d67ffd4
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 23 deletions.
4 changes: 3 additions & 1 deletion Rnwood.Smtp4dev/ClientApp/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ module.exports = {
publicPath: './',
configureWebpack: {
devtool: 'source-map'
}
},
productionSourceMap: false

}
19 changes: 17 additions & 2 deletions Rnwood.Smtp4dev/Controllers/ServerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using MailKit.Security;
using Microsoft.Extensions.Hosting;
using Rnwood.Smtp4dev.Service;
using System.Text.Json.Serialization;

namespace Rnwood.Smtp4dev.Controllers
{
Expand Down Expand Up @@ -86,8 +87,9 @@ public ActionResult UpdateServer(ApiModel.Server serverUpdate)
newRelaySettings.AutomaticEmails = serverUpdate.RelayOptions.AutomaticEmails;

System.IO.File.WriteAllText(hostingEnvironmentHelper.GetEditableSettingsFilePath(),
JsonSerializer.Serialize(new { ServerOptions = newSettings, RelayOptions = newRelaySettings },
new JsonSerializerOptions { WriteIndented = true }));
JsonSerializer.Serialize(new SettingsFile{ ServerOptions = newSettings, RelayOptions = newRelaySettings },
SettingsFileSerializationContext.Default.SettingsFile)
);

if (!serverUpdate.IsRunning && this.server.IsRunning)
{
Expand All @@ -111,4 +113,17 @@ public ActionResult UpdateServer(ApiModel.Server serverUpdate)
return Ok();
}
}

internal class SettingsFile
{
public ServerOptions ServerOptions { get; set; }
public RelayOptions RelayOptions { get; set; }
}


[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(SettingsFile))]
internal partial class SettingsFileSerializationContext : JsonSerializerContext {

}
}
21 changes: 18 additions & 3 deletions Rnwood.Smtp4dev/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using CommandLiners;
Expand All @@ -28,6 +29,7 @@ namespace Rnwood.Smtp4dev
public class Program
{
public static bool IsService { get; private set; }

private static ILogger _log;

public static async Task Main(string[] args)
Expand Down Expand Up @@ -168,14 +170,13 @@ private static IHost BuildWebHost(string[] args, CommandLineOptions cmdLineOptio

if (cmdLineOptions.DebugSettings)
{
JsonSerializerOptions jsonSettings = new JsonSerializerOptions { WriteIndented = true };
Console.WriteLine(JsonSerializer.Serialize(new
Console.WriteLine(JsonSerializer.Serialize(new SettingsDebugInfo
{
CmdLineArgs = Environment.GetCommandLineArgs(),
CmdLineOptions = cmdLineOptions,
ServerOptions = config.GetSection("ServerOptions").Get<ServerOptions>(),
RelayOption = config.GetSection("RelayOptions").Get<RelayOptions>()
}, jsonSettings));
}, SettingsDebugInfoSerializationContext.Default.SettingsDebugInfo));
}

});
Expand Down Expand Up @@ -245,4 +246,18 @@ public static void SetupStaticLogger(IEnumerable<string> args)

}
}

internal class SettingsDebugInfo
{
public string[] CmdLineArgs { get; set; }
public CommandLineOptions CmdLineOptions { get; set; }
public ServerOptions ServerOptions { get; set; }
public RelayOptions RelayOption { get; set; }
}

[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(SettingsDebugInfo))]
internal partial class SettingsDebugInfoSerializationContext : JsonSerializerContext {

}
}
2 changes: 1 addition & 1 deletion Rnwood.Smtp4dev/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"Rnwood.Smtp4dev": {
"commandName": "Project",
"commandLineArgs": "--imapport=0 --urls=http://localhost:5000;http://localhost:5001",
"commandLineArgs": "--imapport=0 --db=c:/temp/smtp4dev.db",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
2 changes: 2 additions & 0 deletions Rnwood.Smtp4dev/Rnwood.Smtp4dev.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<RollForward>Major</RollForward>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<IsPackable>true</IsPackable>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
</PropertyGroup>
<PropertyGroup Condition="'$(PackAsTool)'=='true'">
<StaticWebAssetsEnabled>false</StaticWebAssetsEnabled>
Expand Down
25 changes: 18 additions & 7 deletions Rnwood.Smtp4dev/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Rnwood.Smtp4dev.Data;
using Rnwood.Smtp4dev.Service;
using Serilog;
using System.Linq;

namespace Rnwood.Smtp4dev
{
Expand Down Expand Up @@ -49,14 +50,17 @@ public void ConfigureServices(IServiceCollection services)
}
else
{
if (serverOptions.RecreateDb && File.Exists(serverOptions.Database))


var dbLocation = Path.GetFullPath(serverOptions.Database);
if (serverOptions.RecreateDb && File.Exists(dbLocation))
{
Log.Logger.Information("Deleting Sqlite database.");
File.Delete(serverOptions.Database);
File.Delete(dbLocation);
}

Log.Logger.Information("Using Sqlite database at {dbLocation}" ,Path.GetFullPath(serverOptions.Database));
opt.UseSqlite($"Data Source='{serverOptions.Database}'");
Log.Logger.Information("Using Sqlite database at {dbLocation}" , dbLocation);
opt.UseSqlite($"Data Source='{dbLocation}'");
}
}, ServiceLifetime.Scoped, ServiceLifetime.Singleton);

Expand Down Expand Up @@ -130,13 +134,20 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
}
});

using (IServiceScope scope = subdir.ApplicationServices.CreateScope())
using (var scope = subdir.ApplicationServices.CreateScope())
{
using (Smtp4devDbContext context = scope.ServiceProvider.GetService<Smtp4devDbContext>())
using (var context = scope.ServiceProvider.GetService<Smtp4devDbContext>())
{
if (!context.Database.IsInMemory())
{
context.Database.Migrate();

var pendingMigrations = context.Database.GetPendingMigrations();
if (pendingMigrations.Any())
{
Log.Logger.Information("Updating DB schema with migrations: {migrations}", string.Join(", ", pendingMigrations));
context.Database.Migrate();
}

}
}
}
Expand Down
16 changes: 8 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,32 @@ stages:
runTests: ${{ false }}
win-x64:
platformName: win-x64
buildArgs: "-r win-x64 --self-contained"
buildArgs: "-r win-x64 --self-contained -p:PublishSingleFile=true"
vmImage: "windows-2022"
runTests: ${{ true }}
linux-x64:
platformName: linux-x64
buildArgs: "-r linux-x64 --self-contained"
buildArgs: "-r linux-x64 --self-contained -p:PublishSingleFile=true"
vmImage: "ubuntu-22.04"
runTests: ${{ true }}
# osx-x64:
# platformName: osx-x64
# buildArgs: "-r osx-x64 --self-contained"
# buildArgs: "-r osx-x64 --self-contained -p:PublishSingleFile=true"
# vmImage: "macOS-11"
# runTests: ${{ true }}
linux-musl-x64:
platformName: linux-musl-x64
buildArgs: "-r linux-musl-x64 --self-contained"
buildArgs: "-r linux-musl-x64 --self-contained -p:PublishSingleFile=true"
vmImage: ubuntu-22.04
runTests: ${{ false }}
win-arm64:
platformName: win-arm64
buildArgs: "-r win-arm64 --self-contained"
buildArgs: "-r win-arm64 --self-contained -p:PublishSingleFile=true"
vmImage: windows-2022
runTests: ${{ false }}
linux-arm:
platformName: linux-arm
buildArgs: "-r linux-arm --self-contained"
buildArgs: "-r linux-arm --self-contained -p:PublishSingleFile=true"
vmImage: ubuntu-22.04
runTests: ${{ false }}
steps:
Expand Down Expand Up @@ -176,7 +176,7 @@ stages:
command: publish
projects: "Rnwood.Smtp4dev.Desktop/Rnwood.Smtp4dev.Desktop.csproj"
publishWebProjects: false
arguments: '-c Release -r win-x64 -p:version=$(tag) --self-contained -p:PublishSingleFile=true -p:PublishReadyToRun=true -o "$(Build.ArtifactStagingDirectory)/win-x64-desktop"'
arguments: '-c Release -r win-x64 -p:version=$(tag) --self-contained -p:PublishSingleFile=true -p:PublishReadyToRun=true -p:PublishSingleFile=true -o "$(Build.ArtifactStagingDirectory)/win-x64-desktop"'
- powershell: move-item $(Build.ArtifactStagingDirectory)/win-x64-desktop/Rnwood.Smtp4dev.Desktop.zip $(Build.ArtifactStagingDirectory)/win-x64-desktop/Rnwood.Smtp4dev.Desktop-win-x64-$(tag).zip
displayName: Rename artifact
- publish: $(Build.ArtifactStagingDirectory)/win-x64-desktop
Expand All @@ -188,7 +188,7 @@ stages:
# command: publish
# projects: 'Rnwood.Smtp4dev.Desktop/Rnwood.Smtp4dev.Desktop.csproj'
# publishWebProjects: false
# arguments: '-c Release -r linux-x64 -p:version=$(tag) --self-contained -p:PublishSingleFile=true -p:PublishReadyToRun=true -o "$(Build.ArtifactStagingDirectory)/linux-x64-desktop"'
# arguments: '-c Release -r linux-x64 -p:version=$(tag) --self-contained -p:PublishSingleFile=true -p:PublishReadyToRun=true -p:PublishSingleFile=true -o "$(Build.ArtifactStagingDirectory)/linux-x64-desktop"'
# - powershell: move-item $(Build.ArtifactStagingDirectory)/linux-x64-desktop/Rnwood.Smtp4dev.Desktop.zip $(Build.ArtifactStagingDirectory)/linux-x64-desktop/Rnwood.Smtp4dev.Desktop-linux-x64-$(tag).zip
# displayName: Rename artifact
# - publish: $(Build.ArtifactStagingDirectory)/linux-x64-desktop
Expand Down
2 changes: 1 addition & 1 deletion sendtestemail.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ param($count=1)

1..$count | %{
write-host $_
Send-MailMessage -verbose -Attachments ./smtp4dev.sln -To foo2@bar.com -From from@from.com -Subject "Message $_" -SmtpServer localhost -BodyAsHtml -Body "<h1>Hey</h1>This is a message!<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae interdum arcu. Donec vel odio sed mauris luctus aliquet. Suspendisse vel magna ipsum. Praesent mollis nisi sed sapien blandit, non ultrices magna ultricies. Duis blandit tempor rutrum. Integer egestas eleifend lorem, eget volutpat tellus. Maecenas mauris dui, tincidunt vitae lacus laoreet, laoreet porta lectus. Mauris a urna justo. Phasellus porta vestibulum lorem in ultricies. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed convallis at neque in consectetur. Duis sed ipsum nec risus tempor dictum et id libero. Praesent imperdiet lacinia ullamcorper. Duis ante magna, accumsan in est in, tincidunt porta felis. Suspendisse venenatis nisi eget tellus mollis semper. Phasellus tristique elit nec ultricies tincidunt.
Send-MailMessage -verbose -Attachments ./smtp4dev.sln -To to@bar.com -Cc cc@bar.com -bcc bcc@bar.com -From from@from.com -Subject "Message $_" -SmtpServer localhost -BodyAsHtml -Body "<h1>Hey</h1>This is a message!<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae interdum arcu. Donec vel odio sed mauris luctus aliquet. Suspendisse vel magna ipsum. Praesent mollis nisi sed sapien blandit, non ultrices magna ultricies. Duis blandit tempor rutrum. Integer egestas eleifend lorem, eget volutpat tellus. Maecenas mauris dui, tincidunt vitae lacus laoreet, laoreet porta lectus. Mauris a urna justo. Phasellus porta vestibulum lorem in ultricies. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed convallis at neque in consectetur. Duis sed ipsum nec risus tempor dictum et id libero. Praesent imperdiet lacinia ullamcorper. Duis ante magna, accumsan in est in, tincidunt porta felis. Suspendisse venenatis nisi eget tellus mollis semper. Phasellus tristique elit nec ultricies tincidunt.

<p>Sed pellentesque sit amet nibh eget pellentesque. Etiam mi lectus, elementum vitae sapien id, placerat ornare nunc. Integer sagittis, est id viverra venenatis, sapien velit pulvinar felis, in fringilla urna lorem a libero. Fusce diam magna, laoreet elementum ullamcorper non, fringilla scelerisque dolor. Aenean venenatis arcu vel orci imperdiet, eu semper sapien egestas. Pellentesque condimentum elit in congue vulputate. Phasellus sed lacus feugiat, egestas justo et, sodales lorem. Morbi fringilla bibendum ligula vel imperdiet. Sed non cursus urna, eu consectetur urna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus dui leo, pretium eu commodo eget, sagittis vitae odio. Aenean non arcu imperdiet, malesuada massa at, porta turpis. Proin iaculis ullamcorper imperdiet. Donec lacus lacus, varius eu mauris et, eleifend convallis nisi. In ut nunc tellus. Aliquam convallis congue metus at imperdiet.

Expand Down

0 comments on commit d67ffd4

Please sign in to comment.