Skip to content

Commit

Permalink
Merge pull request #8 from CollaboraOnline/masterForDotNet
Browse files Browse the repository at this point in the history
dotNet SDK Example
  • Loading branch information
pedropintosilva committed Sep 5, 2022
2 parents 1d9a2ba + 4c0afed commit 5e4217c
Show file tree
Hide file tree
Showing 12 changed files with 673 additions and 0 deletions.
454 changes: 454 additions & 0 deletions webapp/dotNET/.gitignore

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions webapp/dotNET/WebApplication1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32630.192
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{2BEC5984-3403-4E6F-97B6-47A2B38B8E3B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2BEC5984-3403-4E6F-97B6-47A2B38B8E3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BEC5984-3403-4E6F-97B6-47A2B38B8E3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BEC5984-3403-4E6F-97B6-47A2B38B8E3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BEC5984-3403-4E6F-97B6-47A2B38B8E3B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {25293B49-E761-48D1-BEE3-C1C6D5B19C23}
EndGlobalSection
EndGlobal
60 changes: 60 additions & 0 deletions webapp/dotNET/WebApplication1/Controllers/FileControllers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;

namespace WebApplication1.Controllers
{
[ApiController]
[Route("[controller]")]
public class FileControllers : Controller
{
[HttpGet("/wopi/files/{fileId}")]
// This endpoint gets the information of the file, which id value is being used in the endpoint and returns it
// to the host machiene that is running the webpage from the collabora server. It responds to a GET request at
// http://<HOSTNAME>/wopi/files/<fileId>. The minimum amount of information needed to be returned is Name and
// Size of the file.
public ActionResult<FileInfoTemplate> CheckFileInfo()
{
return new FileInfoTemplate
{
BaseFileName = "test.txt",
Size = 11,
UserId = 1,
UserCanWrite = true
};
}

[HttpGet("/wopi/files/{fileId}/contents")]
// This endpoint gets the contents of the file, as this a SDK example the content loaded onto the file origionally
// is hardcoded into the system. This is what makes sure when a new page of the SDK is opened it always opens with
// the text 'Hello World'. It is called when the GET request is called at http://<HOSTNAME>/wopi/files/<fileId>/contents
public IActionResult GetFile()
{
var fileContent = "Hello World";
return base.Content(fileContent);
}

[HttpPost("/wopi/files/{fileId}/contents")]
// This endpoint allows for the files to save to the collabora space. This SDK example outputs in the console, or something
// {need to find this}, the body text put bellow then returns the status code 200; meaning it was a success but only if the
// body has something in, from being edited. Else it returns a failure code of 404.
public IActionResult PutFile()
{
using (StreamReader stream = new StreamReader(HttpContext.Request.Body))
{
string body = stream.ReadToEndAsync().ToString();
body = "param=somevalue&param2=someothervalue";

if (body != null)
{
System.Diagnostics.Debug.WriteLine(body);
return StatusCode(200);
}
else
{
return StatusCode(404);
}
}
}

}
}
15 changes: 15 additions & 0 deletions webapp/dotNET/WebApplication1/FileInfoTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This is a basic class as to the infomation needed to be held about a document. It is used in the GET request
// http://<HOSTNAME>/wopi/files/<fileId> endpoint.
namespace WebApplication1
{
public class FileInfoTemplate
{
public string BaseFileName { get; set; }

public int Size { get; set; }

public int UserId { get; set; }

public bool UserCanWrite { get; set; }
}
}
16 changes: 16 additions & 0 deletions webapp/dotNET/WebApplication1/Pages/Index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- This Html file is to load Collabora in an Iframe format so it doesn't change the webpage you are at. Must be open with a server system or
won't load correctly, error of 'Localhost refused to connect'-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<form action="http://localhost:9980/browser/b00961f06/cool.html?WOPISrc=http://172.22.240.1:5123/wopi/files/1" target="my-iframe" enctype="multipart/form-data" method="post">
<input name="access_token" value="test" type="hidden" />
<input type="submit" value="Load Collabora Online" />
</form>
<iframe name="my-iframe" height="1000" width="1000">
</iframe>
</body>
</html>
10 changes: 10 additions & 0 deletions webapp/dotNET/WebApplication1/Pages/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- This HTML file loads a button that then links you onto the collabora space. It doesn't use an Iframe. Must be open with a server system or
won't load correctly, error of 'Localhost refused to connect'-->
<html>
<body>
<form action="http://localhost:9980/browser/b00961f06/cool.html?WOPISrc=http://172.22.240.1:5123/wopi/files/1" enctype="multipart/form-data" method="post">
<input name="access_token" value="test" type="hidden" />
<input type="submit" value="Load Collabora Online" />
</form>
</body>
</html>
25 changes: 25 additions & 0 deletions webapp/dotNET/WebApplication1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers().AddJsonOptions(opition=>opition.JsonSerializerOptions.PropertyNamingPolicy=null);
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();


app.Run();

31 changes: 31 additions & 0 deletions webapp/dotNET/WebApplication1/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:27487"
//"sslPort": 44340
}
},
"profiles": {
"WebApplication1": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "Swagger",
"applicationUrl": "https://0.0.0.0:7123;http://0.0.0.0:5123",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "Swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
13 changes: 13 additions & 0 deletions webapp/dotNET/WebApplication1/WebApplication1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions webapp/dotNET/WebApplication1/WebApplication1.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
</Project>
8 changes: 8 additions & 0 deletions webapp/dotNET/WebApplication1/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions webapp/dotNET/WebApplication1/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

0 comments on commit 5e4217c

Please sign in to comment.