-
Notifications
You must be signed in to change notification settings - Fork 208
/
RpcImpl.ts
56 lines (47 loc) · 2.85 KB
/
RpcImpl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
import { ClientRequestContext, ClientRequestContextProps } from "@bentley/bentleyjs-core";
import { RpcInterface, RpcManager, IModelTokenProps, IModelToken } from "@bentley/imodeljs-common";
import { AuthorizedClientRequestContext, AuthorizedClientRequestContextProps } from "@bentley/imodeljs-clients";
import { IModelDb, ChangeSummaryExtractOptions, ChangeSummaryManager, BriefcaseManager, IModelJsFs, IModelHost } from "@bentley/imodeljs-backend";
import { TestRpcInterface } from "../common/RpcInterfaces";
export class TestRpcImpl extends RpcInterface implements TestRpcInterface {
public static register() {
RpcManager.registerImpl(TestRpcInterface, TestRpcImpl);
}
public async restartIModelHost(): Promise<void> {
IModelHost.shutdown();
IModelHost.startup();
}
public async extractChangeSummaries(tokenProps: IModelTokenProps, options: any): Promise<void> {
const requestContext = ClientRequestContext.current as AuthorizedClientRequestContext;
const iModelToken = IModelToken.fromJSON(tokenProps);
await ChangeSummaryManager.extractChangeSummaries(requestContext, IModelDb.find(iModelToken), options as ChangeSummaryExtractOptions);
}
public async deleteChangeCache(tokenProps: IModelTokenProps): Promise<void> {
const iModelToken = IModelToken.fromJSON(tokenProps);
if (!iModelToken.iModelId)
throw new Error("iModelToken is invalid. Must not be a standalone iModel");
const changesPath: string = BriefcaseManager.getChangeCachePathName(iModelToken.iModelId);
if (IModelJsFs.existsSync(changesPath))
IModelJsFs.unlinkSync(changesPath);
}
public async executeTest(tokenProps: IModelTokenProps, testName: string, params: any): Promise<any> {
const iModelToken = IModelToken.fromJSON(tokenProps);
return JSON.parse(IModelDb.find(iModelToken).nativeDb.executeTest(testName, JSON.stringify(params)));
}
public async reportRequestContext(): Promise<ClientRequestContextProps> {
if (ClientRequestContext.current instanceof AuthorizedClientRequestContext)
throw new Error("Did not expect AuthorizedClientRequestContext");
return ClientRequestContext.current.toJSON();
}
public async reportAuthorizedRequestContext(): Promise<AuthorizedClientRequestContextProps> {
if (!(ClientRequestContext.current instanceof AuthorizedClientRequestContext))
throw new Error("Expected AuthorizedClientRequestContext");
const context = ClientRequestContext.current as AuthorizedClientRequestContext;
return context.toJSON();
}
}
TestRpcImpl.register();