How to use the @bentley/imodeljs-backend.IModelDb.onOpened 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 / example-code / app / src / backend / RobotWorldEngine.ts View on Github external
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__

    // __PUBLISH_EXTRACT_START__ Schema.importSchema
    // Make sure the RobotWorld schema is in the iModel.
    IModelDb.onOpened.addListener((requestContext: AuthorizedClientRequestContext, iModel: IModelDb) => {
      RobotWorld.importSchema(requestContext, iModel); // tslint:disable-line:no-floating-promises
    });
    // __PUBLISH_EXTRACT_END__
  }
github imodeljs / imodeljs / example-code / snippets / src / backend / ExampleOpenIModel.ts View on Github external
function configureIModel() {
  // __PUBLISH_EXTRACT_START__ IModelDb.onOpen
  IModelDb.onOpen.addListener((_requestContext: AuthorizedClientRequestContext, _contextId: string, _iModelId: string, openParams: OpenParams, _version: IModelVersion) => {
    // A read-only service might want to reject all requests to open an iModel for writing. It can do this in the onOpen event.
    if (openParams.openMode !== OpenMode.Readonly)
      throw new IModelError(IModelStatus.BadRequest, "Navigator is readonly");
  });
  // __PUBLISH_EXTRACT_END__

  // __PUBLISH_EXTRACT_START__ IModelDb.onOpened
  IModelDb.onOpened.addListener((_requestContext: AuthorizedClientRequestContext, iModel: IModelDb) => {
    if (iModel.openParams.openMode !== OpenMode.ReadWrite)
      return;

    // Setting a concurrency control policy is an example of something you might do in an onOpened event handler.
    iModel.concurrencyControl.setPolicy(new ConcurrencyControl.OptimisticPolicy());
  });
  // __PUBLISH_EXTRACT_END__
}
github imodeljs / imodeljs / presentation / backend / src / PresentationManager.ts View on Github external
this._nativePlatform = props.addon;
    } else {
      const nativePlatformImpl = createDefaultNativePlatform({
        id: this._props.id || "",
        localeDirectories: createLocaleDirectoryList(props),
        taskAllocationsMap: createTaskAllocationsMap(props),
        mode: (undefined !== this._props.mode) ? this._props.mode : PresentationManagerMode.ReadWrite,
      });
      this._nativePlatform = new nativePlatformImpl();
    }
    this.setupRulesetDirectories(props);
    if (props)
      this.activeLocale = props.activeLocale;
    this._rulesets = new RulesetManagerImpl(this.getNativePlatform);
    if (this._props.enableSchemasPreload)
      this._disposeIModelOpenedListener = IModelDb.onOpened.addListener(this.onIModelOpened);
  }