Skip to content

Commit

Permalink
Distribution mode for Curupira.WindowsService and adjustments to the …
Browse files Browse the repository at this point in the history
…build scripts
  • Loading branch information
tiglate committed Oct 13, 2024
1 parent 018795c commit 8789ab3
Show file tree
Hide file tree
Showing 27 changed files with 566 additions and 191 deletions.
44 changes: 44 additions & 0 deletions Curupira.AppClient/AppConfigurationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using NLog;
using NLog.Config;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;

namespace Curupira.AppClient
{
[ExcludeFromCodeCoverage]
public static class AppConfigurationHelper
{
public static void ConfigureAppSettings(string configFileName)
{
// Override the default app.config location
var configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\conf", configFileName);
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configPath);
}

public static void ConfigureNLog()
{
// Load NLog configuration from the specified path
var nlogConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\conf\NLog.config");
LogManager.Configuration = new XmlLoggingConfiguration(nlogConfigPath);
}

public static Assembly ResolveAssemblyFromLibFolder(object sender, ResolveEventArgs args)
{
// Extract the assembly name
var assemblyName = new AssemblyName(args.Name).Name + ".dll";
var libPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\lib", assemblyName);

// Check if the DLL exists in the lib directory
if (File.Exists(libPath))
{
#pragma warning disable S3885
return Assembly.LoadFrom(libPath);
#pragma warning restore S3885
}

return null; // Return null if the assembly is not found
}
}
}
1 change: 1 addition & 0 deletions Curupira.AppClient/Curupira.AppClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppConfigurationHelper.cs" />
<Compile Include="AppRunner.cs" />
<Compile Include="Services\AutofacHelper.cs" />
<Compile Include="Services\ConsoleService.cs" />
Expand Down
49 changes: 4 additions & 45 deletions Curupira.AppClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

#if !DEBUG
using NLog.Config;
using NLog;
using System.IO;
using System.Reflection;
using System;
#endif

namespace Curupira.AppClient
{
[ExcludeFromCodeCoverage]
Expand All @@ -18,16 +10,16 @@ static class Program
static Program()
{
#if !DEBUG
AppDomain.CurrentDomain.AssemblyResolve += ResolveAssemblyFromLibFolder;
System.AppDomain.CurrentDomain.AssemblyResolve += AppConfigurationHelper.ResolveAssemblyFromLibFolder;
#endif
}

static async Task<int> Main(string[] args)
{
#if !DEBUG
// Load config files and set up assembly resolution only in release mode
ConfigureAppSettings();
ConfigureNLog();
AppConfigurationHelper.ConfigureAppSettings("Curupira.exe.config");
AppConfigurationHelper.ConfigureNLog();
#endif

using (var container = AutofacContainerBuilder.Configure())
Expand All @@ -38,38 +30,5 @@ static async Task<int> Main(string[] args)
}
}
}

#if !DEBUG
private static void ConfigureAppSettings()
{
// Override the default app.config location
string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\conf\Curupira.exe.config");
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configPath);
}

private static void ConfigureNLog()
{
// Load NLog configuration from the specified path
string nlogConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\conf\NLog.config");
LogManager.Configuration = new XmlLoggingConfiguration(nlogConfigPath);
}

private static Assembly ResolveAssemblyFromLibFolder(object sender, ResolveEventArgs args)
{
// Extract the assembly name
var assemblyName = new AssemblyName(args.Name).Name + ".dll";
var libPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\lib", assemblyName);

// Check if the DLL exists in the lib directory
if (File.Exists(libPath))
{
#pragma warning disable S3885
return Assembly.LoadFrom(libPath);
#pragma warning restore S3885
}

return null; // Return null if the assembly is not found
}
#endif
}
}
}
1 change: 0 additions & 1 deletion Curupira.WindowsService/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<appSettings>
<add key="UploadDirectory" value="C:\Temp" />
<add key="BaseAddress" value="http://localhost:9000/" />
<add key="ConfigDir" value="C:\Users\danie\source\repos\Curupira\Curupira.AppClient\Config" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
Expand Down
Binary file added Curupira.WindowsService/App.ico
Binary file not shown.
44 changes: 44 additions & 0 deletions Curupira.WindowsService/AppConfigurationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using NLog;
using NLog.Config;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;

namespace Curupira.WindowsService
{
[ExcludeFromCodeCoverage]
public static class AppConfigurationHelper
{
public static void ConfigureAppSettings(string configFileName)
{
// Override the default app.config location
var configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\conf", configFileName);
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configPath);
}

public static void ConfigureNLog()
{
// Load NLog configuration from the specified path
var nlogConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\conf\NLog.config");
LogManager.Configuration = new XmlLoggingConfiguration(nlogConfigPath);
}

public static Assembly ResolveAssemblyFromLibFolder(object sender, ResolveEventArgs args)
{
// Extract the assembly name
var assemblyName = new AssemblyName(args.Name).Name + ".dll";
var libPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\lib", assemblyName);

// Check if the DLL exists in the lib directory
if (File.Exists(libPath))
{
#pragma warning disable S3885
return Assembly.LoadFrom(libPath);
#pragma warning restore S3885
}

return null; // Return null if the assembly is not found
}
}
}
24 changes: 24 additions & 0 deletions Curupira.WindowsService/Config/backup-plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<plugin xmlns="http://ampliar.dev.br/projects/curupira/plugin/backup-plugin"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ampliar.dev.br/projects/curupira/plugin/backup-plugin backup-plugin.xsd">
<settings destination="c:\temp" limit="3" />
<backups>
<backup id="ruby" root="C:\Ruby">
<remove>bin</remove>
<remove>etc</remove>
<remove>include\</remove>
<remove>lib\</remove>
<remove>msys64</remove>
<remove>packages\*</remove>
<remove>**\*.html</remove>
<remove>LICENSE.txt</remove>
</backup>
<backup id="dell" root="C:\Dell\Drivers\HFVP5\EULA" destination="P:\temp">
</backup>
<backup id="xampp" root="C:\xampp\cgi-bin">
<remove>*.pl</remove>
</backup>
<backup id="tomcat" root="C:\tomcat" />
</backups>
</plugin>
39 changes: 39 additions & 0 deletions Curupira.WindowsService/Config/backup-plugin.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://ampliar.dev.br/projects/curupira/plugin/backup-plugin"
xmlns="http://ampliar.dev.br/projects/curupira/plugin/backup-plugin"
elementFormDefault="qualified">

<xs:element name="plugin">
<xs:complexType>
<xs:sequence>
<xs:element name="settings">
<xs:complexType>
<xs:attribute name="destination" type="xs:string" use="optional" />
<xs:attribute name="limit" type="xs:positiveInteger" use="optional" />
</xs:complexType>
</xs:element>
<xs:element name="backups">
<xs:complexType>
<xs:sequence>
<xs:element name="backup" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="remove" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required" />
<xs:attribute name="root" type="xs:string" use="required" />
<xs:attribute name="destination" type="xs:string" use="optional" />
</xs:complexType>
<xs:unique name="uniqueBackupId">
<xs:selector xpath="." />
<xs:field xpath="@id" />
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
11 changes: 11 additions & 0 deletions Curupira.WindowsService/Config/folders-creator-plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<plugin xmlns="http://ampliar.dev.br/projects/curupira/plugin/folders-creator-plugin"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ampliar.dev.br/projects/curupira/plugin/folders-creator-plugin folders-creator-plugin.xsd">
<directories>
<add>C:\temp\myapp\bin</add>
<add>C:\temp\myapp\backup\logs</add>
<add>C:\temp\myapp\other</add>
<add>\\192.168.1.1\daniel\folder\newfolder</add>
</directories>
</plugin>
20 changes: 20 additions & 0 deletions Curupira.WindowsService/Config/folders-creator-plugin.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://ampliar.dev.br/projects/curupira/plugin/folders-creator-plugin"
xmlns="http://ampliar.dev.br/projects/curupira/plugin/folders-creator-plugin"
elementFormDefault="qualified">

<xs:element name="plugin">
<xs:complexType>
<xs:sequence>
<xs:element name="directories">
<xs:complexType>
<xs:sequence>
<xs:element name="add" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
25 changes: 25 additions & 0 deletions Curupira.WindowsService/Config/installer-plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<plugin xmlns="http://ampliar.dev.br/projects/curupira/plugin/installer-plugin"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ampliar.dev.br/projects/curupira/plugin/installer-plugin installer-plugin.xsd">
<components>
<component id="ruby" type="zip">
<param name="SourceFile" value="C:\temp\ruby.zip" />
<param name="TargetDir" value="P:\Ruby" />
<remove>include\ruby-3.2.0\ruby.h</remove>
<remove>include\ruby-3.2.0\ruby\io\*</remove>
</component>
<component id="InstallAppTest" type="msi" action="install">
<param name="SourceFile" value="C:\temp\AppTeste.msi" />
<param name="Params" value="/qn" />
</component>
<component id="Install.bat" type="bat">
<param name="SourceFile" value="C:\temp\Install.bat" />
<param name="Params" value="C:\temp\myapp" />
</component>
<component id="Installer.exe" type="exe">
<param name="SourceFile" value="C:\temp\Installer.exe" />
<param name="Params" value="C:\temp\myapp2" />
</component>
</components>
</plugin>
68 changes: 68 additions & 0 deletions Curupira.WindowsService/Config/installer-plugin.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://ampliar.dev.br/projects/curupira/plugin/installer-plugin"
xmlns="http://ampliar.dev.br/projects/curupira/plugin/installer-plugin"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<!-- Root element definition -->
<xs:element name="plugin">
<xs:complexType>
<xs:sequence>
<xs:element name="components">
<xs:complexType>
<xs:sequence>
<!-- One or more components allowed -->
<xs:element name="component" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<!-- One or more params allowed -->
<xs:element name="param" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="remove" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<!-- Attributes for component -->
<xs:attribute name="id" type="xs:string" use="required"/>
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="zip"/>
<xs:enumeration value="msi"/>
<xs:enumeration value="bat"/>
<xs:enumeration value="exe"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<!-- Conditional action attribute for type="msi" -->
<xs:attribute name="action" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="install"/>
<xs:enumeration value="uninstall"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<!-- Action attribute required only for type="msi" -->
<xs:unique name="uniqueParamName">
<xs:selector xpath="param"/>
<xs:field xpath="@name"/>
</xs:unique>
<!-- Unique id constraint for component -->
<xs:unique name="uniqueComponentId">
<xs:selector xpath="component"/>
<xs:field xpath="@id"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>
20 changes: 20 additions & 0 deletions Curupira.WindowsService/Config/service-manager-plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<plugin xmlns="http://ampliar.dev.br/projects/curupira/plugin/service-manager-plugin"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ampliar.dev.br/projects/curupira/plugin/service-manager-plugin service-manager-plugin.xsd">
<bundles>
<bundle id="stop_all">
<service name="WSearch" action="Stop" />
<service name="wuauserv" action="Stop" />
</bundle>
<bundle id="start_all">
<service name="WSearch" action="Start" />
<service name="wuauserv" action="Start" />
</bundle>
<bundle id="status_test" logFile="c:\temp\{0:yyyy-MM-dd}-services.txt">
<service name="VSSERV" action="Status" />
<service name="W32Time" action="Status" />
<service name="WaaSMedicSvc" action="Status" />
</bundle>
</bundles>
</plugin>
Loading

0 comments on commit 8789ab3

Please sign in to comment.