iTwin / imodel-transformer

API for exporting an iModel's parts and also importing them into another iModel
MIT License
3 stars 2 forks source link

Add support for transforming file properties #183

Open nick4598 opened 4 months ago

nick4598 commented 4 months ago

I'm not sure who requested this, but I assume its low priority until we are requested to do it again. Just capturing this work in a work item.

3 years ago Mike B. opened a PR here that never merged: https://github.com/iTwin/itwinjs-core/pull/2986 Important functions from Mike B's PR

 protected override onExportFileProperty(props: FilePropertyProps): void {
    const hasNoSuchFileProp = this.targetDb.queryNextAvailableFileProperty(props) === 0;
    if (hasNoSuchFileProp) {
      // TODO: replace with new native call that is a single query
      const blob = this.sourceDb.queryFilePropertyBlob(props);
      const strval = this.sourceDb.queryFilePropertyString(props);
      this.targetDb.saveFileProperty(props, strval, blob);
    }
  }
/** Export all file properties from the source iModel. Used to export things such as file settings.
   * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
   * file properties are not merged, conflicts resolve to the target, only file properties that do not already exist in the target are inserted.
   * @note file properties with the same id but different sub-ids are considered conflicting
   */
  public async exportFileProperties(): Promise<void> {
    Logger.logTrace(loggerCategory, `exportFileProperties()`);
    for (const props of this.sourceDb.nativeDb.getAllFileProperties()) {
      await this.exportFileProperty(props);
    }
  }

  public async exportFileProperty(props: FilePropertyProps): Promise<void> {
    this.callHandlerOrThis("onExportFileProperty", props);
  }