Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
import { IModelHost } from "@bentley/imodeljs-backend";
import { RpcConfiguration, IModelReadRpcInterface } from "@bentley/imodeljs-common";
import { Logger, LogLevel } from "@bentley/bentleyjs-core";
import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig";
import { Config } from "@bentley/imodeljs-clients";
import { registerBackendCallback } from "@bentley/certa/lib/utils/CallbackUtils";
import { BackendTestCallbacks } from "../common/SideChannels";
import { TestRpcImpl2, resetOp8Initializer } from "./TestRpcImpl";
IModelJsConfig.init(true, true, Config.App);
RpcConfiguration.developmentMode = true;
// Start the backend
IModelHost.startup();
registerBackendCallback(BackendTestCallbacks.registerTestRpcImpl2Class, () => {
TestRpcImpl2.register();
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.replaceTestRpcImpl2Instance, () => {
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.unregisterTestRpcImpl2Class, () => {
TestRpcImpl2.unregister();
return true;
});
export function createFilePath(filePath: string) {
// ###TODO: Make this function platform independent
const files = filePath.split(/\/|\\/); // /\.[^/.]+$/ // /\/[^\/]+$/
let curFile = "";
for (const file of files) {
if (file === "") break;
curFile += file + "\\";
if (!IModelJsFs.existsSync(curFile)) IModelJsFs.mkdirSync(curFile);
}
}
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
import { Logger, LogLevel } from "@bentley/bentleyjs-core";
import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig";
import { IModelHost, IModelHostConfiguration } from "@bentley/imodeljs-backend";
import { Config } from "@bentley/imodeljs-clients";
import { IModelJsExpressServer } from "@bentley/express-server";
import { BentleyCloudRpcManager, ElectronRpcConfiguration, ElectronRpcManager, RpcConfiguration } from "@bentley/imodeljs-common";
import { rpcInterfaces } from "../common/RpcInterfaces";
import "./RpcImpl";
IModelJsConfig.init(true, true, Config.App);
RpcConfiguration.developmentMode = true;
// Start the backend
const hostConfig = new IModelHostConfiguration();
hostConfig.concurrentQuery.concurrent = 2;
hostConfig.concurrentQuery.pollInterval = 5;
IModelHost.startup(hostConfig);
Logger.initializeToConsole();
Logger.setLevel("imodeljs-backend.IModelReadRpcImpl", LogLevel.Error); // Change to trace to debug
Logger.setLevel("imodeljs-backend.IModelDb", LogLevel.Error); // Change to trace to debug
Logger.setLevel("Performance", LogLevel.Error); // Change to Info to capture
async function init() {
if (ElectronRpcConfiguration.isElectron) {
ElectronRpcManager.initializeImpl({}, rpcInterfaces);
} else {
const rpcConfig = BentleyCloudRpcManager.initializeImpl({ info: { title: "integration-test", version: "v1.0" } }, rpcInterfaces);
// create a basic express web server
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
import { Logger, LogLevel } from "@bentley/bentleyjs-core";
import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig";
import { IModelHost, IModelHostConfiguration } from "@bentley/imodeljs-backend";
import { Config } from "@bentley/imodeljs-clients";
import { BentleyCloudRpcManager, ElectronRpcConfiguration, ElectronRpcManager, RpcConfiguration } from "@bentley/imodeljs-common";
import { IModelJsExpressServer } from "@bentley/express-server";
import { rpcInterfaces } from "../common/RpcInterfaces";
import "./RpcImpl";
IModelJsConfig.init(true, true, Config.App);
RpcConfiguration.developmentMode = true;
// Start the backend
const hostConfig = new IModelHostConfiguration();
IModelHost.startup(hostConfig);
Logger.initializeToConsole();
Logger.setLevel("imodeljs-backend.IModelReadRpcImpl", LogLevel.Error); // Change to trace to debug
Logger.setLevel("imodeljs-backend.IModelDb", LogLevel.Error); // Change to trace to debug
Logger.setLevel("Performance", LogLevel.Error); // Change to Info to capture
async function init() {
if (ElectronRpcConfiguration.isElectron) {
ElectronRpcManager.initializeImpl({}, rpcInterfaces);
} else {
const rpcConfig = BentleyCloudRpcManager.initializeImpl({ info: { title: "perf-tests", version: "v1.0" } }, rpcInterfaces);
// create a basic express web server
const port = Number(process.env.CERTA_PORT || 3011) + 2000;
const server = new IModelJsExpressServer(rpcConfig.protocol);
public async finishTest() {
IModelHost.shutdown();
// Electron only
if (app !== undefined) app.exit();
// Browser only
if (DisplayPerfRpcInterface.webServer) DisplayPerfRpcInterface.webServer.close();
if (DisplayPerfRpcInterface.backendServer) DisplayPerfRpcInterface.backendServer.close();
if (DisplayPerfRpcInterface.chrome) await DisplayPerfRpcInterface.chrome.kill();
}
export function initializeBackend() {
setupStandaloneConfiguration();
const hostConfig = new IModelHostConfiguration();
if (!MobileRpcConfiguration.isMobileBackend) {
// tslint:disable-next-line:no-var-requires
const configPathname = path.normalize(path.join(__dirname, "../webresources", "configuration.json"));
const svtConfig: SVTConfiguration = require(configPathname);
if (svtConfig.customOrchestratorUri)
hostConfig.imodelClient = new IModelBankClient(svtConfig.customOrchestratorUri, new UrlFileHandler());
}
IModelHost.startup(hostConfig);
}
let logLevel = LogLevel.None;
if (MobileRpcConfiguration.isMobileBackend) {
// Does not seem SVTConfiguraiton is used anymore.
} else {
if (svtConfig.customOrchestratorUri)
hostConfig.imodelClient = new IModelBankClient(svtConfig.customOrchestratorUri, new UrlFileHandler());
if (svtConfig.useFakeCloudStorageTileCache)
hostConfig.tileCacheCredentials = { service: "external", account: "", accessKey: "" };
const logLevelEnv = process.env.SVT_LOG_LEVEL as string;
if (undefined !== logLevelEnv)
logLevel = Logger.parseLogLevel(logLevelEnv);
}
IModelHost.startup(hostConfig);
// Set up logging (by default, no logging is enabled)
Logger.initializeToConsole();
Logger.setLevelDefault(logLevel);
Logger.setLevel("SVT", LogLevel.Trace);
if (svtConfig.useFakeCloudStorageTileCache)
IModelHost.tileCacheService = new FakeTileCacheService(path.normalize(path.join(__dirname, "../webresources", "tiles/")));
}
export const initialize = (backendProps?: PresentationBackendProps, frontendProps?: PresentationFrontendProps, frontendApp: { startup: (opts?: IModelAppOptions) => void } = NoRenderApp) => {
if (isInitialized)
return;
// make sure backend gets assigned an id which puts its resources into a unique directory
backendProps = backendProps || {};
if (!backendProps.id)
backendProps.id = `test-${Guid.createValue()}`;
// init backend
IModelHost.startup();
PresentationBackend.initialize(backendProps);
// set up rpc interfaces
initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);
if (!isFrontendAppInitialized) {
// init frontend
frontendApp.startup();
setCustomFavoritePropertiesManager();
isFrontendAppInitialized = true;
}
const defaultFrontendProps: PresentationFrontendProps = {
activeLocale: IModelApp.i18n.languageList()[0],
};
PresentationFrontend.initialize({ ...defaultFrontendProps, ...frontendProps });
const pathname: string = path.join(this._localIModelDbPath, this._iModelName + ".bim");
if (fs.existsSync(pathname))
fs.unlinkSync(pathname);
this._iModelDb = IModelDb.createStandalone(pathname, { rootSubject: { name: this._iModelName } });
const definitionModelId: Id64String = IModel.dictionaryId;
this._physicalModelId = PhysicalModel.insert(this._iModelDb, IModel.rootSubjectId, "TestModel");
this._codeSpecId = this._iModelDb.codeSpecs.insert("TestCodeSpec", CodeScopeSpec.Type.Model);
this._categoryId = SpatialCategory.insert(this._iModelDb, definitionModelId, "TestCategory", { color: new ColorDef("blanchedAlmond") });
// Insert a ViewDefinition for the PhysicalModel
const viewName = "Physical View";
const modelSelectorId: Id64String = ModelSelector.insert(this._iModelDb, definitionModelId, viewName, [this._physicalModelId]);
const categorySelectorId: Id64String = CategorySelector.insert(this._iModelDb, definitionModelId, viewName, [this._categoryId]);
const displayStyleId: Id64String = DisplayStyle3d.insert(this._iModelDb, definitionModelId, viewName);
const viewRange = new Range3d(0, 0, 0, 50, 50, 50);
OrthographicViewDefinition.insert(this._iModelDb, definitionModelId, viewName, modelSelectorId, categorySelectorId, displayStyleId, viewRange);
this._iModelDb.updateProjectExtents(new Range3d(-1000, -1000, -1000, 1000, 1000, 1000));
this._iModelDb.saveChanges("Setup new iModel");
this._iModelDb.closeStandalone();
this._iModelDb = undefined;
return pathname;
}
private _initializeLogger(): void {
iModel.views.iterateViews({ from: "BisCore.SpatialViewDefinition" }, (view: ViewDefinition) => {
if (!view.isSpatialView())
return true;
// Create a new display style.
const vf = new ViewFlags();
vf.renderMode = RenderMode.SmoothShade;
vf.cameraLights = true;
const bgColor = new ColorDef("rgb(127, 127, 127)");
const displayStyleId = DisplayStyle3d.insert(iModel, view.model, "Schedule View Style", { viewFlags: vf, backgroundColor: bgColor, scheduleScript: script });
iModel.views.setDefaultViewId(SpatialViewDefinition.insertWithCamera(iModel, view.model, "Schedule View", view.modelSelectorId, view.categorySelectorId, displayStyleId, iModel.projectExtents, StandardViewIndex.Iso));
return true;
});
return true;