How to use the @bentley/imodeljs-frontend.AuthorizedFrontendRequestContext.create function in @bentley/imodeljs-frontend

To help you get started, we’ve selected a few @bentley/imodeljs-frontend 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 / test-apps / display-performance-test-app / src / frontend / DisplayPerformanceTestApp.ts View on Github external
alert("openSnapshot failed: " + err.toString());
      openLocalIModel = false;
    }
    const esvString = await DisplayPerfRpcInterface.getClient().readExternalSavedViews(testConfig.iModelFile!);
    if (undefined !== esvString && "" !== esvString) {
      activeViewState.externalSavedViews = JSON.parse(esvString) as any[];
    }
  }

  // Open an iModel from the iModelHub
  if (!openLocalIModel && testConfig.iModelHubProject !== undefined && !MobileRpcConfiguration.isMobileFrontend) {
    const signedIn: boolean = await signIn();
    if (!signedIn)
      return false;

    const requestContext = await AuthorizedFrontendRequestContext.create();
    requestContext.enter();

    activeViewState.projectConfig = { projectName: testConfig.iModelHubProject, iModelName: testConfig.iModelName!.replace(".ibim", "").replace(".bim", "") } as ConnectProjectConfiguration;
    activeViewState.project = await initializeIModelHub(activeViewState.projectConfig!.projectName);
    activeViewState.iModel = await IModelApi.getIModelByName(requestContext, activeViewState.project!.wsgId, activeViewState.projectConfig!.iModelName);
    if (activeViewState.iModel === undefined)
      throw new Error(`${activeViewState.projectConfig!.iModelName} - IModel not found in project ${activeViewState.project!.name}`);
    activeViewState.iModelConnection = await IModelApi.openIModel(activeViewState.project!.wsgId, activeViewState.iModel!.wsgId, undefined, OpenMode.Readonly);
  }

  // open the specified view
  if (undefined !== testConfig.viewStatePropsString)
    await loadViewString(activeViewState, testConfig.viewStatePropsString, testConfig.selectedElements, testConfig.overrideElements);
  else if (undefined !== testConfig.extViewName)
    await loadExternalView(activeViewState, testConfig.extViewName);
  else if (undefined !== testConfig.viewName)
github imodeljs / imodeljs / plugins / geo-photo / src / geoPhoto.ts View on Github external
private async saveSettings(): Promise {
    const view = IModelApp.viewManager.selectedView;
    if (!view || !view.iModel)
      return;

    // store settings to SettingsManager
    const geoPhotos: GeoPhotos = (view.iModel as any).geoPhotos;
    if (geoPhotos && geoPhotos.photoTree) {
      const newSettings: GeoPhotoFullSettings = new GeoPhotoFullSettings();
      const fullSettings = Object.assign(newSettings, this.settings);
      fullSettings.getPathList(geoPhotos.photoTree);
      const requestContext = await AuthorizedFrontendRequestContext.create();
      IModelApp.settings.saveUserSetting(requestContext, fullSettings, "GeoPhotoPlugin", "Settings", false, view.iModel.iModelToken.contextId, view.iModel.iModelToken.iModelId).catch((_err) => { });
    }
  }
github imodeljs / imodeljs / ui / framework / src / ui-framework / clientservices / DefaultProjectServices.ts View on Github external
public async getProjects(projectScope: ProjectScope, top: number, skip: number, filter?: string): Promise {
    const requestContext = await AuthorizedFrontendRequestContext.create();

    const queryOptions: ConnectRequestQueryOptions = {
      $select: "*", // TODO: Get Name,Number,AssetType to work
      $top: top,
      $skip: skip,
      $filter: filter,
    };

    let projectList: Project[];
    try {
      if (projectScope === ProjectScope.Invited) {
        projectList = await this._connectClient.getInvitedProjects(requestContext, queryOptions);
      } else {
        if (projectScope === ProjectScope.Favorites) {
          queryOptions.isFavorite = true;
        } else if (projectScope === ProjectScope.MostRecentlyUsed) {
github imodeljs / imodeljs / plugins / geo-photo / src / geoPhoto.ts View on Github external
public async showGeoPhotoMarkers(iModel: IModelConnection): Promise {
    if (!iModel.isGeoLocated) {
      const errMsg: string = this.i18n.translate("geoPhoto:messages.notGeolocated");
      const errDetails: NotifyMessageDetails = new NotifyMessageDetails(OutputMessagePriority.Warning, errMsg, undefined, OutputMessageType.Sticky);
      IModelApp.notifications.outputMessage(errDetails);
      return;
    }

    if (this.uiProvider)
      this.uiProvider.showGeoPhotoDialog();

    let geoPhotos: GeoPhotos = (iModel as any).geoPhotos;
    let photoTree: PhotoTree | undefined;
    if (undefined === geoPhotos) {
      const requestContext = await AuthorizedFrontendRequestContext.create();
      const settingsPromise = IModelApp.settings.getUserSetting(requestContext, "GeoPhotoPlugin", "Settings", false, iModel.iModelToken.contextId, iModel.iModelToken.iModelId);

      /* ------------- Not needed now that we have the dialog box to show progress
      let message: string = this.i18n.translate("geoPhoto:messages.GatheringPhotos");
      let msgDetails: NotifyMessageDetails = new NotifyMessageDetails(OutputMessagePriority.Info, message);
      IModelApp.notifications.outputMessage(msgDetails);
      ------------------------------------------------------------------------------- */

      const treeHandler = new ProjectShareHandler(requestContext, this.i18n, iModel, this.uiProvider);
      geoPhotos = new GeoPhotos(this, treeHandler!, iModel, this.uiProvider);
      photoTree = await geoPhotos.readTreeContents();

      const settingsResult = await settingsPromise;
      if (SettingsStatus.Success === settingsResult.status) {
        // process the returned settings.
        const settings: any = settingsResult.setting;
github imodeljs / imodeljs / ui / framework / src / ui-framework / clientservices / DefaultIModelServices.ts View on Github external
public async getThumbnail(contextId: string, iModelId: GuidString): Promise {
    const requestContext = await AuthorizedFrontendRequestContext.create();
    try {
      const pngImage = await this._hubClient.thumbnails.download(requestContext, iModelId, { contextId: contextId!, size: "Small" });
      return pngImage;
    } catch (err) {
      // No image available
    }
    return undefined;
  }
github imodeljs / imodeljs / test-apps / display-test-app / src / frontend / ConnectEnv.ts View on Github external
export async function initializeIModelHub(state: SimpleViewState): Promise {
  _connectClient = new ConnectClient();

  showStatus("opening Project", state.projectConfig!.projectName);

  const requestContext = await AuthorizedFrontendRequestContext.create();
  state.project = await getProjectByName(requestContext, state.projectConfig!.projectName);
}
github imodeljs / simple-viewer-app / src / frontend / components / App.tsx View on Github external
private async getIModelInfo(): Promise<{ projectId: string, imodelId: string }> {
    const projectName = Config.App.get("imjs_test_project");
    const imodelName = Config.App.get("imjs_test_imodel");

    const requestContext: AuthorizedFrontendRequestContext = await AuthorizedFrontendRequestContext.create();

    const connectClient = new ConnectClient();
    let project: Project;
    try {
      project = await connectClient.getProject(requestContext, { $filter: `Name+eq+'${projectName}'` });
    } catch (e) {
      throw new Error(`Project with name "${projectName}" does not exist`);
    }

    const imodelQuery = new IModelQuery();
    imodelQuery.byName(imodelName);
    const imodels = await IModelApp.iModelClient.iModels.get(requestContext, project.wsgId, imodelQuery);
    if (imodels.length === 0)
      throw new Error(`iModel with name "${imodelName}" does not exist in project "${projectName}"`);
    return { projectId: project.wsgId, imodelId: imodels[0].wsgId };
  }
github imodeljs / imodeljs / ui / framework / src / ui-framework / clientservices / DefaultIModelServices.ts View on Github external
public async getUsers(iModelId: GuidString): Promise {
    const requestContext = await AuthorizedFrontendRequestContext.create();
    const userInfos: IModelUserInfo[] = [];
    try {
      const users: HubUserInfo[] = await this._hubClient.users.get(requestContext, iModelId, new UserInfoQuery().select("*"));
      for (const userInfo of users) {
        userInfos.push(this.createUserInfo(userInfo));
      }
    } catch (e) {
      alert(JSON.stringify(e));
      return Promise.reject(e);
    }
    return userInfos;
  }
github imodeljs / imodeljs / ui / framework / src / ui-framework / clientservices / DefaultIModelServices.ts View on Github external
public async getUser(iModelId: GuidString, userId: string): Promise {
    const requestContext = await AuthorizedFrontendRequestContext.create();
    const userInfos: IModelUserInfo[] = [];
    try {
      const users: HubUserInfo[] = await this._hubClient.users.get(requestContext, iModelId, new UserInfoQuery().byId(userId));
      for (const userInfo of users) {
        userInfos.push(this.createUserInfo(userInfo));
      }
    } catch (e) {
      alert(JSON.stringify(e));
      return Promise.reject(e);
    }
    return userInfos;
  }