Skip to content

Commit 5a78adc

Browse files
committed
add new sample
1 parent 075b197 commit 5a78adc

File tree

5 files changed

+241
-0
lines changed

5 files changed

+241
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PartialDownloadPlugin", "PartialDownloadPlugin\PartialDownloadPlugin.csproj", "{E25E8B31-5845-45A0-B4AE-88A45FD9FF88}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E25E8B31-5845-45A0-B4AE-88A45FD9FF88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E25E8B31-5845-45A0-B4AE-88A45FD9FF88}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E25E8B31-5845-45A0-B4AE-88A45FD9FF88}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E25E8B31-5845-45A0-B4AE-88A45FD9FF88}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{E25E8B31-5845-45A0-B4AE-88A45FD9FF88}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>TRIM.ServiceAPI.Samples</RootNamespace>
11+
<AssemblyName>PartialDownloadPlugin</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="ServiceStack">
35+
<HintPath>..\..\lib\ServiceStack.dll</HintPath>
36+
</Reference>
37+
<Reference Include="ServiceStack.Client">
38+
<HintPath>..\..\lib\ServiceStack.Client.dll</HintPath>
39+
</Reference>
40+
<Reference Include="ServiceStack.Interfaces">
41+
<HintPath>..\..\lib\ServiceStack.Interfaces.dll</HintPath>
42+
</Reference>
43+
<Reference Include="ServiceStack.Text">
44+
<HintPath>..\..\lib\ServiceStack.Text.dll</HintPath>
45+
</Reference>
46+
<Reference Include="System" />
47+
<Reference Include="System.Core" />
48+
<Reference Include="System.Xml.Linq" />
49+
<Reference Include="System.Data.DataSetExtensions" />
50+
<Reference Include="Microsoft.CSharp" />
51+
<Reference Include="System.Data" />
52+
<Reference Include="System.Net.Http" />
53+
<Reference Include="System.Xml" />
54+
<Reference Include="TRIM.SDK">
55+
<HintPath>..\..\lib\TRIM.SDK.dll</HintPath>
56+
</Reference>
57+
<Reference Include="TRIMServiceAPICommon">
58+
<HintPath>..\..\lib\TRIMServiceAPICommon.dll</HintPath>
59+
</Reference>
60+
<Reference Include="TRIMServiceAPIModel">
61+
<HintPath>..\..\lib\TRIMServiceAPIModel.dll</HintPath>
62+
</Reference>
63+
</ItemGroup>
64+
<ItemGroup>
65+
<Compile Include="PartialDownloadService.cs" />
66+
<Compile Include="Properties\AssemblyInfo.cs" />
67+
</ItemGroup>
68+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
69+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
70+
Other similar extension points exist, see Microsoft.Common.targets.
71+
<Target Name="BeforeBuild">
72+
</Target>
73+
<Target Name="AfterBuild">
74+
</Target>
75+
-->
76+
</Project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+

2+
using HP.HPTRIM.Service;
3+
using ServiceStack;
4+
using System.IO;
5+
using System.Net;
6+
7+
namespace HP.HPTRIM.ServiceAPI.Samples
8+
{
9+
[Route("/PartialDownload/{Number}", "GET")]
10+
public class PartialDownload
11+
{
12+
public string Number { get; set; }
13+
}
14+
15+
16+
17+
18+
public class PartialDownloadService : TrimServiceBase
19+
{
20+
// this inherits from the base ServiceAPI service class so participates in all the authenticate and Database access.
21+
// This means we do not need to construct a database we just use the Database instance on the base class.
22+
23+
private string GetMimeType(TRIM.SDK.Record record)
24+
{
25+
string mimeType = (!string.IsNullOrEmpty(record.MimeType)) ? record.MimeType : (!string.IsNullOrEmpty(record.Extension) ? MimeTypes.GetMimeType(record.Extension) : "application/octet-stream");
26+
27+
return mimeType.ToLower();
28+
}
29+
30+
public object Get(PartialDownload request)
31+
{
32+
if (!string.IsNullOrWhiteSpace(request.Number))
33+
{
34+
TRIM.SDK.Record record = Database.FindTrimObjectByName(TRIM.SDK.BaseObjectTypes.Record, request.Number) as TRIM.SDK.Record;
35+
if (record != null && record.IsElectronic)
36+
{
37+
if (!record.IsDocumentInClientCache)
38+
{
39+
record.LoadDocumentIntoClientCache();
40+
}
41+
42+
return new HttpResult(new FileInfo(record.GetDocumentPathInClientCache(TRIM.SDK.Events.DocExtracted)), GetMimeType(record));
43+
// replace / with _ so that windows will not get confused by the path seperator in a file name
44+
// string fileLocation = trimObject.MakeReference(string.Format("c:\\temp\\{0}.tr5", request.Name.Replace('/', '_')));
45+
// return new HttpResult(new TempDownloadableFile(fileLocation), true);
46+
}
47+
}
48+
49+
throw new HttpError(HttpStatusCode.NotFound, "404", "File not found");
50+
}
51+
}
52+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("MakeReferencePlugin")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Micro Focus")]
12+
[assembly: AssemblyProduct("Content Manager")]
13+
[assembly: AssemblyCopyright("© Copyright 1994-2018 Micro Focus or one of its affiliates")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("e25e8b31-5845-45a0-b4ae-88a45fd9ff88")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Partial Download ServiceAPI Plugin
2+
This sample adds a new service to the ServiceAPI to support re-sumable file downloads.
3+
4+
## Background
5+
In CM versions up to 10.1 partial downloads are not supported by the standard file dowbload URL (e.g. Record/[Uri]/document/file), this sample adds a new service which does support this.
6+
7+
Partial downloads are implemented using Content-Range header.
8+
9+
## Setup
10+
To use this sample:
11+
- Copy these files from your ServiceAPI bin folder to the Samples\ServiceAPI\CSharp\lib folder
12+
- TRIM.SDK.dll
13+
- TRIMServiceAPICommon.dll
14+
- TRIMServiceAPIModel.dll
15+
- ServiceStack.Client.dll
16+
- ServiceStack.dll
17+
- ServiceStack.Interfaces.dll
18+
- ServiceStack.Text.dll
19+
- build the PartialDownloadPlugin project
20+
- copy PartialDownloadPlugin.dll to your ServiceAPI bin folder
21+
- add the XML below to the hptrim.config file in your ServiceAPI folder
22+
23+
## NOTE for HPE CM 9.x users
24+
This sample has been built against HPE CM 10.1 but will work against 9.x if you use the 9.x version of the Content Manager DLLs, which are""
25+
- HP.HPTRIM.SDK.dll
26+
- HP.HPTRIM.Service.dll
27+
- HP.HPTRIM.ServiceModel.dll
28+
29+
30+
## Plugin Configuration
31+
The following XML must be copied as a child of the hptrim element of hptrim.config
32+
33+
```
34+
<pluginAssemblies>
35+
<add name="PartialDownloadPlugin" />
36+
</pluginAssemblies>
37+
```
38+
39+
### Example
40+
41+
![Example Config](plugin_config.PNG)
42+
43+
44+
## Usage
45+
Once the plugin is installed you should be able to download a TR5 file using a URL similar to this:
46+
47+
### Record TR5
48+
```
49+
http://localhost/HPRMServiceAPI/MakeReference?TrimType=Record&Name=D16/1
50+
```
51+
52+
### Location TR5
53+
```
54+
http://localhost/HPRMServiceAPI/MakeReference?TrimType=Location&Name=David
55+
```

0 commit comments

Comments
 (0)