Skip to content

Commit

Permalink
Merge pull request #139 from spaceisfun/dontdisposenull
Browse files Browse the repository at this point in the history
Fixes Bug 32803715: [Watson Failure] caused by CLR_EXCEPTION_System.NullReferenceException_80004003_Microsoft.FactoryOrchestrator.Service.dll!Microsoft.FactoryOrchestrator.Service.FOService.Dispose

Fixes backwards check for DisableContainerSupport

Fixes #113 - ResetService is buggy

Fixes #135 - Support /etc/FactoryOrchestrator/appsettings.json

Fixes #111 - WDP doesn't work on Desktop

Related to #140 - Implements the workaround, but will keep the issue open until an official .NET fix is made
  • Loading branch information
spaceisfun authored Apr 28, 2021
2 parents 433fffa + 51c113e commit 6db51c2
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build/internal/FactoryOrchestratorServiceTemplate.wm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
description="Factory Orchestrator Service"
displayName="Factory Orchestrator Service"
errorControl="normal"
imagePath="%systemroot%\system32\manufacturing\FactoryOrchestrator\Microsoft.FactoryOrchestrator.Service.exe action:run"
imagePath="%systemroot%\system32\manufacturing\FactoryOrchestrator\Microsoft.FactoryOrchestrator.Service.exe -IsService"
name="Microsoft.FactoryOrchestrator.Service"
objectName="LocalSystem"
start="auto"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#### [Microsoft.FactoryOrchestrator.Client](./Microsoft-FactoryOrchestrator-Client.md 'Microsoft.FactoryOrchestrator.Client')
### [Microsoft.FactoryOrchestrator.Client](./Microsoft-FactoryOrchestrator-Client.md 'Microsoft.FactoryOrchestrator.Client').[FactoryOrchestratorClient](./Microsoft-FactoryOrchestrator-Client-FactoryOrchestratorClient.md 'Microsoft.FactoryOrchestrator.Client.FactoryOrchestratorClient')
## FactoryOrchestratorClient.GetWdpHttpPort() Method
Asynchronously Gets the Windows Device Portal HTTP port. Does not ensure WDP is running or supports HTTP.
```csharp
public System.Threading.Tasks.Task<int> GetWdpHttpPort();
```
#### Returns
[System.Threading.Tasks.Task&lt;](https://docs.microsoft.com/en-us/dotnet/api/System.Threading.Tasks.Task-1 'System.Threading.Tasks.Task')[System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32')[&gt;](https://docs.microsoft.com/en-us/dotnet/api/System.Threading.Tasks.Task-1 'System.Threading.Tasks.Task')
The HTTP port.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If true, are logs not deleted.

<a name='Microsoft-FactoryOrchestrator-Client-FactoryOrchestratorClient-ResetService(bool_bool)-factoryReset'></a>
`factoryReset` [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean')
If true, the service is restarted as if it is first boot.
If true, the service is restarted as if it is first boot. NOTE: Network communication is not disabled, connected clients may encounter issues and the 'EnableNetworkAccess' setting will be ignored!

#### Returns
[System.Threading.Tasks.Task](https://docs.microsoft.com/en-us/dotnet/api/System.Threading.Tasks.Task 'System.Threading.Tasks.Task')
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Inheritance [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.O
- [GetServiceVersionString()](./Microsoft-FactoryOrchestrator-Client-FactoryOrchestratorClient-GetServiceVersionString().md 'Microsoft.FactoryOrchestrator.Client.FactoryOrchestratorClient.GetServiceVersionString()')
- [GetTaskListGuids()](./Microsoft-FactoryOrchestrator-Client-FactoryOrchestratorClient-GetTaskListGuids().md 'Microsoft.FactoryOrchestrator.Client.FactoryOrchestratorClient.GetTaskListGuids()')
- [GetTaskListSummaries()](./Microsoft-FactoryOrchestrator-Client-FactoryOrchestratorClient-GetTaskListSummaries().md 'Microsoft.FactoryOrchestrator.Client.FactoryOrchestratorClient.GetTaskListSummaries()')
- [GetWdpHttpPort()](./Microsoft-FactoryOrchestrator-Client-FactoryOrchestratorClient-GetWdpHttpPort().md 'Microsoft.FactoryOrchestrator.Client.FactoryOrchestratorClient.GetWdpHttpPort()')
- [InstallApp(string, System.Collections.Generic.List&lt;string&gt;, string)](./Microsoft-FactoryOrchestrator-Client-FactoryOrchestratorClient-InstallApp(string_System-Collections-Generic-List-string-_string).md 'Microsoft.FactoryOrchestrator.Client.FactoryOrchestratorClient.InstallApp(string, System.Collections.Generic.List&lt;string&gt;, string)')
- [IsContainerRunning()](./Microsoft-FactoryOrchestrator-Client-FactoryOrchestratorClient-IsContainerRunning().md 'Microsoft.FactoryOrchestrator.Client.FactoryOrchestratorClient.IsContainerRunning()')
- [IsExecutingBootTasks()](./Microsoft-FactoryOrchestrator-Client-FactoryOrchestratorClient-IsExecutingBootTasks().md 'Microsoft.FactoryOrchestrator.Client.FactoryOrchestratorClient.IsExecutingBootTasks()')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#### [Microsoft.FactoryOrchestrator.Core](./Microsoft-FactoryOrchestrator-Core.md 'Microsoft.FactoryOrchestrator.Core')
### [Microsoft.FactoryOrchestrator.Core](./Microsoft-FactoryOrchestrator-Core.md 'Microsoft.FactoryOrchestrator.Core').[IFactoryOrchestratorService](./Microsoft-FactoryOrchestrator-Core-IFactoryOrchestratorService.md 'Microsoft.FactoryOrchestrator.Core.IFactoryOrchestratorService')
## IFactoryOrchestratorService.GetWdpHttpPort() Method
Gets the Windows Device Portal HTTP port. Does not ensure WDP is running or supports HTTP.
```csharp
int GetWdpHttpPort();
```
#### Returns
[System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32')
The HTTP port.
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ If true, are logs not deleted.

<a name='Microsoft-FactoryOrchestrator-Core-IFactoryOrchestratorService-ResetService(bool_bool)-factoryReset'></a>
`factoryReset` [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean')
If true, the service is restarted as if it is first boot.
If true, the service is restarted as if it is first boot. NOTE: Network communication is not disabled, connected clients may encounter issues and the 'EnableNetworkAccess' setting will be ignored!

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public interface IFactoryOrchestratorService
- [GetServiceVersionString()](./Microsoft-FactoryOrchestrator-Core-IFactoryOrchestratorService-GetServiceVersionString().md 'Microsoft.FactoryOrchestrator.Core.IFactoryOrchestratorService.GetServiceVersionString()')
- [GetTaskListGuids()](./Microsoft-FactoryOrchestrator-Core-IFactoryOrchestratorService-GetTaskListGuids().md 'Microsoft.FactoryOrchestrator.Core.IFactoryOrchestratorService.GetTaskListGuids()')
- [GetTaskListSummaries()](./Microsoft-FactoryOrchestrator-Core-IFactoryOrchestratorService-GetTaskListSummaries().md 'Microsoft.FactoryOrchestrator.Core.IFactoryOrchestratorService.GetTaskListSummaries()')
- [GetWdpHttpPort()](./Microsoft-FactoryOrchestrator-Core-IFactoryOrchestratorService-GetWdpHttpPort().md 'Microsoft.FactoryOrchestrator.Core.IFactoryOrchestratorService.GetWdpHttpPort()')
- [InstallApp(string, System.Collections.Generic.List&lt;string&gt;, string)](./Microsoft-FactoryOrchestrator-Core-IFactoryOrchestratorService-InstallApp(string_System-Collections-Generic-List-string-_string).md 'Microsoft.FactoryOrchestrator.Core.IFactoryOrchestratorService.InstallApp(string, System.Collections.Generic.List&lt;string&gt;, string)')
- [IsContainerRunning()](./Microsoft-FactoryOrchestrator-Core-IFactoryOrchestratorService-IsContainerRunning().md 'Microsoft.FactoryOrchestrator.Core.IFactoryOrchestratorService.IsContainerRunning()')
- [IsExecutingBootTasks()](./Microsoft-FactoryOrchestrator-Core-IFactoryOrchestratorService-IsExecutingBootTasks().md 'Microsoft.FactoryOrchestrator.Core.IFactoryOrchestratorService.IsExecutingBootTasks()')
Expand Down
5 changes: 3 additions & 2 deletions docs/docs/service-configuration.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Factory Orchestrator service configuration using appsettings.json
The Factory Orchestrator service has many configurable settings that impact its startup behavior, enabled features, and more. This configuration is easily modified using an [appsettings.json file](https://docs.microsoft.com/en-us/dotnet/core/extensions/configuration-providers#json-configuration-provider).

The appsettings.json file is checked for in two locations:
The appsettings.json file is checked for in the following locations:

- The directory where the service executable (Microsoft.FactoryOrchestrator.Service) is located
- The [service log file directory](#factory-orchestrator-service-log-file) (`%ProgramData%\FactoryOrchestrator\` or `/var/log/FactoryOrchestrator/`)
- The [service log file directory](#factory-orchestrator-service-log-file): `%ProgramData%\FactoryOrchestrator\` (Windows) or `/var/log/FactoryOrchestrator/`(Linux)
- (Linux only) The `/etc/FactoryOrchestrator/` directory

The following table describes each setting and its usage:

Expand Down
2 changes: 1 addition & 1 deletion install/InstallFactoryOrchestratorService.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ else
}
else
{
$null = New-Service -Name "Microsoft.FactoryOrchestrator" -BinaryPathName "$installdir\Microsoft.FactoryOrchestrator.Service.exe" -Description "Factory Orchestrator service version $Version$" -StartupType Manual
$null = New-Service -Name "Microsoft.FactoryOrchestrator" -BinaryPathName "$installdir\Microsoft.FactoryOrchestrator.Service.exe -IsService" -Description "Factory Orchestrator service version $Version$" -StartupType Manual
}

Write-Host "Factory Orchestrator service version $Version$ is installed to `"$installdir`" and configured as a Windows service!`n"
Expand Down
10 changes: 5 additions & 5 deletions src/App/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<value>Could not connect to {0}.

Check that the IP address, Server Name and Certificate Hash is correct and that the Factory Orchestrator Service is running on the target IP.</value>
<comment>Message displayed to the user if connection to the target machine cannot be established.</comment>
<comment>Message displayed to the user if connection to the target machine cannot be established.</comment>
</data>
<data name="BadIpTitle" xml:space="preserve">
<value>Unable to connect to target IP</value>
Expand Down Expand Up @@ -283,7 +283,7 @@ Check that the IP address, Server Name and Certificate Hash is correct and that

Manually exported FactoryOrchestratorXML files will not be deleted, but will need to be manually imported via "Load FactoryOrchestratorXML file".

If "Factory Reset" is chosen, the service is restarted as if it is first boot. First boot and every boot tasks will re-run. Initial TaskLists will be loaded. "Factory Reset" will temporarily interrupt communication with clients, including this app.</value>
If "Factory Reset" is chosen, the service is restarted as if it is first boot. First boot and every boot tasks will re-run. Initial TaskLists will be loaded. NOTE: Network communication is not disabled, connected clients may encounter issues and the 'EnableNetworkAccess' setting will be ignored!</value>
</data>
<data name="DeleteButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Delete</value>
Expand Down Expand Up @@ -720,7 +720,7 @@ On retry</value>
<value>Launch Windows Device Portal</value>
</data>
<data name="WDPFailedContent" xml:space="preserve">
<value>Make sure Windows Device Portal is running and try again.</value>
<value>Make sure Windows Device Portal is running and supports HTTP with no authentication, then try again.</value>
</data>
<data name="WDPFailedTitle" xml:space="preserve">
<value>Failed to launch Windows Device Portal</value>
Expand Down Expand Up @@ -770,10 +770,10 @@ On retry</value>
</data>
<data name="CertHash.Text" xml:space="preserve">
<value>Certificate Hash:</value>
<comment>Hash value of the Certificate of the target machine.</comment>
<comment>Hash value of the Certificate of the target machine.</comment>
</data>
<data name="ServerName.Text" xml:space="preserve">
<value>Server Identity:</value>
<comment>Distinguished Name of the target machine.</comment>
<comment>Distinguished Name of the target machine.</comment>
</data>
</root>
2 changes: 1 addition & 1 deletion src/App/WdpPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
if (await IsWindowsDevicePortalRunning())
{
string ipAddress = Client.IsLocalHost ? "localhost" : $"{Client.IpAddress.ToString()}";
string url = "http://" + ipAddress + ":80";
string url = "http://" + ipAddress + ":" + await Client.GetWdpHttpPort();
Uri myUri = new Uri(url);
wdp.Navigate(myUri);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ClientLibrary/FactoryOrchestratorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public async Task SendAndInstallApp(string appFilename, List<string> dependentPa

try
{
await WDPHelpers.InstallAppWithWDP(appFilename, dependentPackages, certificateFile, IpAddress.ToString());
await WDPHelpers.InstallAppWithWDP(appFilename, dependentPackages, certificateFile, IpAddress.ToString(), await GetWdpHttpPort());
}
catch (Exception ex)
{
Expand Down
19 changes: 12 additions & 7 deletions src/CoreLibrary/IPCInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Runtime.InteropServices;

using System.Runtime.InteropServices;

namespace Microsoft.FactoryOrchestrator.Core
{
/// <summary>
Expand Down Expand Up @@ -193,7 +193,7 @@ public interface IFactoryOrchestratorService
/// Stops all running Tasks and deletes all TaskLists.
/// </summary>
/// <param name="preserveLogs">If true, are logs not deleted.</param>
/// <param name="factoryReset">If true, the service is restarted as if it is first boot.</param>
/// <param name="factoryReset">If true, the service is restarted as if it is first boot. NOTE: Network communication is not disabled, connected clients may encounter issues and the 'EnableNetworkAccess' setting will be ignored! </param>
void ResetService(bool preserveLogs = false, bool factoryReset = false);
/// <summary>
/// Gets all Service events.
Expand Down Expand Up @@ -287,6 +287,11 @@ public interface IFactoryOrchestratorService
/// </summary>
/// <returns><c>true</c> if the service allows connections over the local network.</returns>
bool IsNetworkAccessEnabled();
/// <summary>
/// Gets the Windows Device Portal HTTP port. Does not ensure WDP is running or supports HTTP.
/// </summary>
/// <returns>The HTTP port.</returns>
int GetWdpHttpPort();

// TaskList APIs
/// <summary>
Expand Down Expand Up @@ -371,14 +376,14 @@ public interface IFactoryOrchestratorService
/// </summary>
/// <param name="guid">The Task GUID.</param>
/// <returns></returns>
TaskBase QueryTask(Guid guid);

TaskBase QueryTask(Guid guid);

/// <summary>
/// Gets the AUMIDs of all installed apps on the OS. Requires Windows Device Portal.
/// </summary>
/// <returns>The list of app AUMIDs.</returns>
List<string> GetInstalledApps();

List<string> GetInstalledApps();

/// <summary>
/// Gets all installed apps on the OS. Requires Windows Device Portal.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/CoreLibrary/Microsoft.FactoryOrchestrator.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<EmbeddedResource Include="FactoryOrchestratorXML.xsd">
<SubType>Designer</SubType>
</EmbeddedResource>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
Expand Down Expand Up @@ -63,7 +64,7 @@
</Target>
<Target Name="FixAndCopyMd" AfterTargets="Build">
<ItemGroup>
<FilesToMove Include="$(DefaultDocumentationFolder)/*.md"/>
<FilesToMove Include="$(DefaultDocumentationFolder)/*.md" />
</ItemGroup>
<Exec Command="$(PowerShellExeName) $(ProjectDir)../../build/FixupAPIMarkdown.ps1 -DefaultDocumentationFolder $(DefaultDocumentationFolder)" />
<Move SourceFiles="@(FilesToMove)" DestinationFolder="../../docs/docs/CoreLibrary" />
Expand Down
4 changes: 2 additions & 2 deletions src/CoreLibrary/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
<value>Error: Failed to launch AUMID: {0}</value>
</data>
<data name="WDPAppLaunchFailed2" xml:space="preserve">
<value>Error: Device Portal is required for app launch and may not be running on the system.</value>
<value>Error: Device Portal is required for app launch and may not be running on the system or may not support HTTP with no authentication.</value>
</data>
<data name="WDPAppLaunchFailed3" xml:space="preserve">
<value>Error: If it is running, the AUMID may be incorrect.</value>
Expand All @@ -373,7 +373,7 @@
<value>Windows Device Portal failed with HTTP error</value>
</data>
<data name="WDPNotRunningError" xml:space="preserve">
<value>Windows Device Portal must be running to call GetInstalledApps!</value>
<value>Windows Device Portal may not be running or may not support HTTP with no authentication!</value>
</data>
<data name="WindowsOnlyError" xml:space="preserve">
<value>{0} is only supported on Windows!</value>
Expand Down
Loading

0 comments on commit 6db51c2

Please sign in to comment.