Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Changed outproc demo #327

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/outproc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
net48.yaml
contract.yaml
contract.yaml
.venv
35 changes: 17 additions & 18 deletions examples/outproc/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "clr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}\\server\\dotnet6\\bin\\Debug\\net6.0-windows\\dotnet6.exe",
"args": ["/Embedding"],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": ".\\server\\bin\\Debug\\net8.0\\server.dll",
"args": [
"/regserver"
],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
5 changes: 0 additions & 5 deletions examples/outproc/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
Expand All @@ -9,9 +7,7 @@
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
Expand All @@ -21,5 +17,4 @@
"problemMatcher": "$msCompile"
}
]

}
53 changes: 53 additions & 0 deletions examples/outproc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# COM OutProc Server Demo

## Introduction

This is a simple demo of an out-of-process COM server. The server is implemented in C# and the client is implemented in Python.
The `OutProcServer` class shows how to register a .NET type for use by COM clients as a local server.
The local server is implemented as a console application that listens for incoming connections from COM clients.
The new instance of the .NET type is registered as `MultipleUse`, which means that a client uses the same process to call methods on the .NET type.

## Pre-requisites

- .NET >= 8.0 SDK
- Python => 3.9

## Build the .NET server

```powershell
dotnet publish
```

## Register the .NET server

Open a new PowerShell window **as an Administrator** and run the following command:

```powershell
.\server\bin\Release\net8.0\publish\server.exe /regserver
```

Now the server is registered and ready to be used by COM clients.

## Run the python client

Open a new PowerShell window as a regular user and run the following commands:

```powershell
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r .\client\requirements.txt
```

Now you can run the client:

```cmd
python .\client\client.py
```

## Unregister the .NET server

Open a new PowerShell window **as an Administrator** and run the following command:

```powershell
.\server\bin\Release\net8.0\publish\server.exe /unregserver
```
18 changes: 0 additions & 18 deletions examples/outproc/client/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions examples/outproc/client/app-dotnet6.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import win32com.client

application = win32com.client.Dispatch("Greeter.Net48")
application = win32com.client.Dispatch("Greeter.Application")

print(application.SayHello("from Python"))
69 changes: 6 additions & 63 deletions examples/outproc/outproc.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dscom", "..\..\src\dscom\dscom.csproj", "{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "net48", "server\net48\net48.csproj", "{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet6", "server\dotnet6\dotnet6.csproj", "{50B7354F-F7D1-4567-B42E-95C50364E3E1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "contract", "server\common\contract.csproj", "{2862429B-3A43-415F-B94E-773B04A438C3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "server", "server\server.csproj", "{3A975E74-3A27-44D1-8285-88D1419B45A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Debug|x64.ActiveCfg = Debug|Any CPU
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Debug|x64.Build.0 = Debug|Any CPU
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Debug|x86.ActiveCfg = Debug|x86
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Debug|x86.Build.0 = Debug|x86
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Release|Any CPU.Build.0 = Release|Any CPU
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Release|x64.ActiveCfg = Release|Any CPU
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Release|x64.Build.0 = Release|Any CPU
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Release|x86.ActiveCfg = Release|x86
{1F853F7D-2D46-4B70-A2E9-0755EB01E7E6}.Release|x86.Build.0 = Release|x86
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Debug|Any CPU.ActiveCfg = Debug|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Debug|Any CPU.Build.0 = Debug|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Debug|x64.ActiveCfg = Debug|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Debug|x64.Build.0 = Debug|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Debug|x86.ActiveCfg = Debug|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Debug|x86.Build.0 = Debug|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Release|Any CPU.ActiveCfg = Release|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Release|Any CPU.Build.0 = Release|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Release|x64.ActiveCfg = Release|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Release|x64.Build.0 = Release|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Release|x86.ActiveCfg = Release|x64
{8F0F3DA5-4CCB-4A12-B031-7309460ADB29}.Release|x86.Build.0 = Release|x64
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Debug|x64.ActiveCfg = Debug|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Debug|x64.Build.0 = Debug|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Debug|x86.ActiveCfg = Debug|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Debug|x86.Build.0 = Debug|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Release|Any CPU.Build.0 = Release|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Release|x64.ActiveCfg = Release|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Release|x64.Build.0 = Release|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Release|x86.ActiveCfg = Release|Any CPU
{50B7354F-F7D1-4567-B42E-95C50364E3E1}.Release|x86.Build.0 = Release|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Debug|x64.ActiveCfg = Debug|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Debug|x64.Build.0 = Debug|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Debug|x86.ActiveCfg = Debug|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Debug|x86.Build.0 = Debug|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Release|Any CPU.Build.0 = Release|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Release|x64.ActiveCfg = Release|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Release|x64.Build.0 = Release|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Release|x86.ActiveCfg = Release|Any CPU
{2862429B-3A43-415F-B94E-773B04A438C3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3A25F7FE-6881-4408-AC73-0BC79971FEC1}
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3A975E74-3A27-44D1-8285-88D1419B45A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A975E74-3A27-44D1-8285-88D1419B45A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A975E74-3A27-44D1-8285-88D1419B45A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A975E74-3A27-44D1-8285-88D1419B45A9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
73 changes: 4 additions & 69 deletions examples/outproc/scripts/msbuild-acceptance-test.cmd
Original file line number Diff line number Diff line change
@@ -1,85 +1,20 @@
@ECHO on
@ECHO off

SET root=%~dp0\..\..\..\

PUSHD %root%

dotnet build-server shutdown

dotnet pack -p:Configuration=Release

IF NOT EXIST %root%\_packages MKDIR _packages

XCOPY /Y /I /C /F .\src\dscom\bin\x64\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom.build\bin\x64\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom\bin\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom.build\bin\Release\*.nupkg _packages\

dotnet build-server shutdown

dotnet nuget locals global-packages --clear

POPD

PUSHD %~dp0\..

dotnet build-server shutdown

dotnet msbuild -nodeReuse:False -t:Clean -p:Configuration=Release -p:PerformAcceptanceTest=Runtime -p:SkipResolvePackageAssets=true

dotnet build-server shutdown

dotnet msbuild -nodeReuse:False -t:Restore -p:Configuration=Release -p:PerformAcceptanceTest=Runtime

dotnet build-server shutdown

dotnet add server\common\contract.csproj package --prerelease -s %root%\_packages dSPACE.Runtime.InteropServices.BuildTasks

dotnet msbuild -nodeReuse:False -t:Restore -p:Configuration=Release -p:PerformAcceptanceTest=Runtime

dotnet build-server shutdown

dotnet msbuild -nodeReuse:False -t:Build -p:Configuration=Release -p:PerformAcceptanceTest=Runtime -bl
SET ERRUNTIME=%ERRORLEVEL%

dotnet build-server shutdown

dotnet msbuild -nodeReuse:False -t:Clean -p:Configuration=Release -p:PerformAcceptanceTest=NetStandard -p:SkipResolvePackageAssets=true

dotnet build-server shutdown

dotnet msbuild -nodeReuse:False -t:Restore -p:Configuration=Release -p:PerformAcceptanceTest=NetStandard

dotnet build-server shutdown

dotnet msbuild -nodeReuse:False -t:Build -p:Configuration=Release -p:PerformAcceptanceTest=NetStandard -bl

SET ERSTANDARD=%ERRORLEVEL%

dotnet build-server shutdown

dotnet remove server\common\contract.csproj package dSPACE.Runtime.InteropServices.BuildTasks

dotnet build-server shutdown
dotnet build

POPD

SetLocal EnableDelayedExpansion

SET EXITCODE=0

IF NOT "%ERRUNTIME%" == "0" (
SET EXITCODE=1
ECHO "::warning::Runtime specific acceptance test failed."
)

IF NOT "%ERSTANDARD%" == "0" (
IF NOT "%ERRORLEVEL%" == "0" (
SET EXITCODE=1
ECHO "::warning::.NET Standard 2.0 specific acceptance test failed."
)

IF "%EXITCODE%" == "0" (
ECHO "Acceptance test completed successfully."
ECHO "acceptance test failed."
)

EXIT /B %EXITCODE%
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Server.Common;
[ComVisible(true)]
[ComDefaultInterface(typeof(IGreeter))]
[ClassInterface(ClassInterfaceType.None)]
[Guid("A9BD4ABF-1518-4F3C-B017-6BC45F983FF0")]
[Guid("A9BD4ABF-1518-4F3C-B017-6BC45F983FF1")]
public class Greeter : IGreeter
{
private readonly Guid _instanceGuid;
Expand All @@ -18,12 +18,12 @@ public string GetInstanceId()
public Greeter()
{
_instanceGuid = Guid.NewGuid();
System.Console.WriteLine($"Greeter object created. PID: {System.Diagnostics.Process.GetCurrentProcess().Id} ID:{_instanceGuid}");
Console.WriteLine($"Greeter object created. PID: {System.Diagnostics.Process.GetCurrentProcess().Id} ID:{_instanceGuid}");
}

public string SayHello(string name)
{
var text = $"Hello {name}. This is the {System.Environment.Version.ToString()} OutProc server! PID: {System.Diagnostics.Process.GetCurrentProcess().Id}";
var text = $"Hello {name}. This is the {Environment.Version} OutProc server! PID: {System.Diagnostics.Process.GetCurrentProcess().Id}";
Console.WriteLine(text);
return text;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Runtime.InteropServices;

namespace Server.Common;
Expand Down
Loading