forked from petrsvihlik/WopiHost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
petrsvihlik#192 create WopiValidator sample and move all to sample/
- Loading branch information
Leon Segal
committed
Mar 6, 2025
1 parent
c792420
commit c7f7e4b
Showing
205 changed files
with
90,175 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#  WopiHost Samples | ||
|
||
Introduction | ||
========== | ||
This folder includes samples for hosting the WopiHost and the Host pages. | ||
|
||
wopi-docs | ||
--- | ||
|
||
Sample documents used by our Host pages - referenced by the FileSystemProvider as configured in the samples. | ||
|
||
WopiHost and WopiHost.Web | ||
--- | ||
|
||
Two companion samples - the WopiHost is the actual Wopi Server host and the WopiHost.Web provides a sample Host page to actually view/edit the sample documents in the Wopi client (as configured in WopiHost.Web/Wopi:ClientUrl). | ||
|
||
#### Configuration: WopiHost | ||
|
||
[WopiHost\appSettings.json](https://github.com/petrsvihlik/WopiHost/blob/master/sample/WopiHost/appsettings.json) | ||
|
||
| Parameter | Sample value | Description | | ||
| :--- | :--- | :--- | | ||
|`Wopi:StorageProviderAssemblyName`| [`"WopiHost.FileSystemProvider"`](https://github.com/petrsvihlik/WopiHost/tree/master/WopiHost.FileSystemProvider) | Name of assembly containing implementation of the `IWopiStorageProvider` and `IWopiSecurityHandler` interfaces | | ||
|`Wopi:StorageProvider:RootPath` | [`".\\wopi-docs"`](https://github.com/petrsvihlik/WopiHost/tree/master/sample/wopi-docs) | Provider-specific setting used by `WopiHost.FileSystemProvider` (which is an implementation of `IWopiStorageProvider` working with System.IO) | | ||
|`Wopi:LockProviderAssemblyName`| [`"WopiHost.LockProvider"`](https://github.com/petrsvihlik/WopiHost/tree/master/WopiHost.MemoryLockProvider) | Name of assembly containing implementation of the `IWopiLockProvider` interface | | ||
|`Wopi:UseCobalt`| `false`| Whether or not to use [MS-FSSHTTP](https://learn.microsoft.com/openspecs/sharepoint_protocols/ms-fsshttp/) for file synchronization. More details at [Cobalt](#cobalt)| | ||
|
||
#### Configuration: WopiHost.Web | ||
[WopiHost.Web\appSettings.json](https://github.com/petrsvihlik/WopiHost/blob/master/sample/WopiHost.Web/appsettings.json) | ||
|
||
| Parameter | Sample value | Description | | ||
| :--- | :--- | :--- | | ||
| `Wopi:HostUrl` | `"http://wopihost:52788"` | URL pointing to a WopiHost instance (above). It's used by the URL generator. | | ||
| `Wopi:ClientUrl` | ` "http://owaserver"` | Base URL of your WOPI client - typically, [Office Online Server](#compatible-wopi-clients) - used by the discovery module to load WOPI client URL templates | | ||
| `Wopi:StorageProvider:RootPath` | [`".\\wopi-docs"`](https://github.com/petrsvihlik/WopiHost/tree/master/sample/wopi-docs) | Provider-specific setting used by `WopiHost.FileSystemProvider` (which is an implementation of `IWopiStorageProvider` working with System.IO) | | ||
| `Wopi:Discovery:NetZone` | `"InternalHttp"` | Determines the target zone configuration of your [OOS Deployment](https://learn.microsoft.com/officeonlineserver/deploy-office-online-server). Values correspond with the [`NetZoneEnum`](https://github.com/petrsvihlik/WopiHost/blob/master/WopiHost.Discovery/NetZoneEnum.cs). | | ||
|
||
|
||
Additionally, you can use the [secret storage](https://learn.microsoft.com/aspnet/core/security/app-secrets?view=aspnetcore-2.2&tabs=windows) to configure both of the apps. | ||
|
||
WopiHost.Validator | ||
--- | ||
|
||
Single hosting for both the Wopi Server and the Host page server by a single .NET HTTP server. | ||
This has been preconfigured to handle custom Wopi Events and is used to validate the Wopi Server implementation using the WOPI-Validator. | ||
|
||
#### Configuration: WopiHost.Validator | ||
|
||
This is a combination of the WopiHost and WopiHost.Web configurations, with the additional `Wopi:UserId` (default: Anonymous) setting to specify the hard-coded token to be used by the WOPI-Validator. | ||
|
||
#### Running the WOPI-Validator | ||
|
||
After cloning and building the [WOPI-Validator repository](https://github.com/Microsoft/wopi-validator-core) use the following command to run the `Office Online` suite of validations: | ||
|
||
``` | ||
dotnet run --project src\WopiValidator\WopiValidator.csproj --framework net8.0 -s -e OfficeOnline -w http://localhost:28752/wopi/files/Llx0ZXN0LndvcGl0ZXN0 -t Anonymous -l 0 | ||
``` | ||
|
||
|
||
Running the samples | ||
--- | ||
Once you've successfully built the app you can: | ||
|
||
- run it directly from the Visual Studio using [IIS Express or self-hosted](/img/debug.png?raw=true). | ||
- make sure you run both `WopiHost` and `WopiHost.Web`. You can set them both as [startup projects](/img/multiple_projects.png?raw=true) | ||
- run it from the `cmd` | ||
- navigate to the WopiHost folder and run `dotnet run` | ||
- run it in IIS (tested in IIS 8.5) | ||
- TODO |
68 changes: 68 additions & 0 deletions
68
sample/WopiHost.Validator/Infrastructure/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Microsoft.Extensions.Options; | ||
using Serilog; | ||
using Serilog.Events; | ||
using WopiHost.Abstractions; | ||
using WopiHost.Core.Extensions; | ||
using WopiHost.Core.Models; | ||
using WopiHost.Discovery; | ||
using WopiHost.FileSystemProvider; | ||
using WopiHost.Validator.Models; | ||
|
||
namespace WopiHost.Validator.Infrastructure; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddWopiLogging(this IServiceCollection services) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console() | ||
.WriteTo.Debug() | ||
.CreateLogger(); | ||
|
||
services.AddSerilog(Log.Logger); | ||
services.AddLogging(loggingBuilder => | ||
{ | ||
loggingBuilder.AddConsole(); | ||
loggingBuilder.AddDebug(); | ||
}); | ||
return services; | ||
} | ||
public static IServiceCollection AddWopiServer(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
// ------ add Wopi Server .Core services | ||
|
||
// Configuration | ||
services.Configure<WopiHostOptions>(configuration.GetSection(WopiConfigurationSections.WOPI_ROOT)); | ||
// Add file provider | ||
services.AddSingleton<IWopiStorageProvider, WopiFileSystemProvider>(); | ||
// Add lock provider | ||
services.AddSingleton<IWopiLockProvider, MemoryLockProvider.MemoryLockProvider>(); | ||
services.AddSingleton<IWopiSecurityHandler, WopiSecurityHandler>(); | ||
// Add WOPI | ||
services.AddWopi(o => | ||
{ | ||
o.OnCheckFileInfo = WopiEvents.OnGetWopiCheckFileInfo; | ||
}); | ||
return services; | ||
} | ||
|
||
public static IServiceCollection AddWopiHostPages(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
// ------- add Wopi Host services | ||
services.Configure<DiscoveryOptions>(configuration.GetSection(WopiConfigurationSections.DISCOVERY_OPTIONS)); | ||
services.Configure<WopiOptions>(configuration.GetSection(WopiConfigurationSections.WOPI_ROOT)); | ||
|
||
services.AddHttpClient<IDiscoveryFileProvider, HttpDiscoveryFileProvider>((sp, client) => | ||
{ | ||
var wopiOptions = sp.GetRequiredService<IOptions<WopiOptions>>(); | ||
client.BaseAddress = wopiOptions.Value.ClientUrl; | ||
}); | ||
|
||
services.AddSingleton<IDiscoverer, WopiDiscoverer>(); | ||
return services; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using WopiHost.Abstractions; | ||
using WopiHost.Core.Models; | ||
|
||
namespace WopiHost.Validator.Infrastructure; | ||
|
||
public static class WopiEvents | ||
{ | ||
/// <summary> | ||
/// Custom handling of CheckFileInfo results for WOPI-Validator | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <returns></returns> | ||
public static Task<WopiCheckFileInfo> OnGetWopiCheckFileInfo(WopiCheckFileInfoContext context) | ||
{ | ||
var wopiCheckFileInfo = context.CheckFileInfo; | ||
wopiCheckFileInfo.AllowAdditionalMicrosoftServices = true; | ||
wopiCheckFileInfo.AllowErrorReportPrompt = true; | ||
|
||
// ##183 required for WOPI-Validator | ||
if (wopiCheckFileInfo.BaseFileName == "test.wopitest") | ||
{ | ||
wopiCheckFileInfo.CloseUrl = new("https://example.com/close"); | ||
wopiCheckFileInfo.DownloadUrl = new("https://example.com/download"); | ||
wopiCheckFileInfo.FileSharingUrl = new("https://example.com/share"); | ||
wopiCheckFileInfo.FileUrl = new("https://example.com/file"); | ||
wopiCheckFileInfo.FileVersionUrl = new("https://example.com/version"); | ||
wopiCheckFileInfo.HostEditUrl = new("https://example.com/edit"); | ||
wopiCheckFileInfo.HostEmbeddedViewUrl = new("https://example.com/embedded"); | ||
wopiCheckFileInfo.HostEmbeddedEditUrl = new("https://example.com/embeddededit"); | ||
wopiCheckFileInfo.HostRestUrl = new("https://example.com/rest"); | ||
wopiCheckFileInfo.HostViewUrl = new("https://example.com/view"); | ||
wopiCheckFileInfo.SignInUrl = new("https://example.com/signin"); | ||
wopiCheckFileInfo.SignoutUrl = new("https://example.com/signout"); | ||
|
||
wopiCheckFileInfo.ClientUrl = new("https://example.com/client"); | ||
wopiCheckFileInfo.FileEmbedCommandUrl = new("https://example.com/embed"); | ||
|
||
// https://learn.microsoft.com/microsoft-365/cloud-storage-partner-program/rest/files/checkfileinfo/checkfileinfo-other#breadcrumb-properties | ||
wopiCheckFileInfo.BreadcrumbBrandName = "WopiHost"; | ||
wopiCheckFileInfo.BreadcrumbBrandUrl = new("https://example.com"); | ||
wopiCheckFileInfo.BreadcrumbDocName = "test"; | ||
wopiCheckFileInfo.BreadcrumbFolderName = "root"; | ||
wopiCheckFileInfo.BreadcrumbFolderUrl = new("https://example.com/folder"); | ||
} | ||
return Task.FromResult(wopiCheckFileInfo); | ||
} | ||
} |
Oops, something went wrong.