How to use the @bentley/imodeljs-backend.IModelHost.startup function in @bentley/imodeljs-backend

To help you get started, we’ve selected a few @bentley/imodeljs-backend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / integration-tests / rpc / src / backend / CommonBackendSetup.ts View on Github external
* 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;
});
github imodeljs / imodeljs / test-apps / display-performance-test-app / src / backend / backend.ts View on Github external
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);
}
github imodeljs / imodeljs / test-apps / display-test-app / src / backend / backend.ts View on Github external
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/")));
}
github imodeljs / imodeljs / presentation / testing / src / Helpers.ts View on Github external
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 });
github imodeljs / imodeljs / example-code / app / src / backend / RobotWorldEngine.ts View on Github external
public static initialize(_requestContext: ClientRequestContext) {
    const config = new IModelHostConfiguration();
    if (Platform.isNodeJs)
      config.appAssetsDir = path.join(__dirname, "assets");
    else
      config.appAssetsDir = KnownLocations.packageAssetsDir;
    IModelHost.startup(config);

    // Can't to this, as our logging config uses Bunyan/Seq, and we don't really want to do that here.
    // initializeLogging();

    RpcManager.registerImpl(RobotWorldWriteRpcInterface, RobotWorldWriteRpcImpl); // register impls that we don't want in the doc example
    this.registerImpls();
    const interfaces = this.chooseInterfacesToExpose();
    if (this._features.check("robot.imodel.readwrite"))  // choose add'l interfaces that we don't want in the doc example
      interfaces.push(IModelWriteRpcInterface);
    TestRpcManager.initialize(interfaces);

    // __PUBLISH_EXTRACT_START__ Schema.registerSchema
    // Register the TypeScript schema classes that I intend to use.
    RobotWorld.registerSchema();
    // __PUBLISH_EXTRACT_END__
github imodeljs / imodeljs / test-apps / imodel-from-reality-model / src / Main.ts View on Github external
/** Use [yargs](https://www.npmjs.com/package/yargs) to validate and extract command line options. */
const argv: yargs.Arguments<{}> = yargs
  .usage("Usage: $0 --input [RealityModelURL] --output [iModelFileName]")
  .describe("input", "Reality Model URL")
  .string("input")
  .alias("input", "i")
  .describe("output", "Output iModel file name")
  .string("output")
  .alias("output", "o")
  .string("name")
  .describe("name", "Name (displayed in GUI and tool tip)")
  .demandOption(["input", "output"])
  .argv;

IModelHost.startup();
Logger.initializeToConsole();

const creator = new RealityModelContextIModelCreator(argv.output as string, argv.input as string, argv.name as string);
creator.create().then(() => {
  process.stdout.write("IModel: " + argv.output + " Created for Reality Model: " + argv.input);
}).catch(() => {
  process.stdout.write("Error occurred creating IModel\n");
});

IModelHost.shutdown();
github imodeljs / imodeljs / test-apps / imodel-from-geojson / src / Main.ts View on Github external
.describe("map", "Background Map (none, aerial, streets, hybrid)")
  .choices("map", ["none", "aerial", "streets", "hybrid"])
  .describe("mapBias", "Background Map ground bias")
  .number("mapBias")
  .describe("classifiedName", "Add classified reality model name")
  .string("classifiedName")
  .describe("classifiedURL", "Add classified reality model URL")
  .string("classifiedURL")
  .describe("classifiedOutside", "Classifier Outside (on, off, dimmed, hilite, color)")
  .choices("classifiedOutside", ["on", "off", "dimmed", "hilite", "color"])
  .describe("classifiedInside", "Classifier Outside (on, off, dimmed, hilite, color)")
  .choices("classifiedInside", ["on", "off", "dimmed", "hilite", "color"])
  .demandOption(["input", "output"])
  .argv;

IModelHost.startup();
Logger.initializeToConsole();

const geoJson = new GeoJson(argv.input as string);
const importer = new GeoJsonImporter(argv.output as string, geoJson, argv.append as boolean, argv.model_name as string, argv.label as string, argv.point_radius as number, argv.color as boolean,
  argv.map as string, argv.mapBias as number,
  argv.classifiedURL as string, argv.classifiedName as string, argv.classifiedOutside as string, argv.classifiedInside as string);
importer.import().then(() => {
  process.stdout.write("IModel: " + argv.output + " Created for GeoJson: " + argv.input + "\n");
  IModelHost.shutdown();
}).catch(() => {
  process.stdout.write("Error occurred\n");
});
github imodeljs / imodeljs / test-apps / analysis-importer / src / Main.ts View on Github external
/*---------------------------------------------------------------------------------------------
* 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 { Logger } from "@bentley/bentleyjs-core";
import { IModelHost } from "@bentley/imodeljs-backend";
import { AnalysisImporter } from "./AnalysisImporter";
import * as path from "path";
import * as fs from "fs";

IModelHost.startup();
Logger.initializeToConsole();

const outputDir = path.join(__dirname, "output");
const dbName = path.join(outputDir, "AnalysisExample.bim");
fs.mkdir(outputDir, ((_err) => { }));
fs.unlink(dbName, ((_err) => { }));

const importer = new AnalysisImporter(dbName);
importer.import();

IModelHost.shutdown();
github imodeljs / imodeljs / test-apps / agent-test-app / src / changeSetUtility / ChangesetGenerationHarness.ts View on Github external
private _initializeIModelHost(): void {
        const configuration = new IModelHostConfiguration();
        IModelHost.startup(configuration);
    }
    /** Clean up the test output directory to prepare for fresh output */