Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private doAutoPush() {
// Nothing to push?
if (!this.iModel.txns.hasLocalChanges) {
this.cancel();
this.scheduleNextPush();
return;
}
if (this.iModel === undefined) {
Logger.logInfo(loggerCategory, "AutoPush - No iModel! Cancelling...");
this.cancel();
return;
}
// If the previous push is still in progress ...
if (this._state === AutoPushState.Pushing) {
assert(this._pendingTimeout !== undefined);
Logger.logInfo(loggerCategory, "AutoPush - Attempt to auto-push while push is in progress. Re-scheduling.");
if (this._autoSchedule)
this.scheduleNextPush(); // wait a while before trying another one.
else
this.cancel(); // don't push
return;
}
// If the backend is busy, then put off the push for a little while, and wait for a lull.
public async get(requestContext: AuthorizedClientRequestContext, contextId: string, query: IModelQuery = new IModelQuery()): Promise {
requestContext.enter();
Logger.logInfo(loggerCategory, `Started querying iModels in context`, () => ({ contextId }));
ArgumentCheck.defined("requestContext", requestContext);
ArgumentCheck.defined("contextId", contextId); // contextId is a GUID for iModelHub and a JSON representation of an IModelBankAccessContext for iModelBank.
const imodels = await this._handler.getInstances(requestContext, HubIModel, this.getRelativeUrl(contextId, query.getId()), query.getQueryOptions());
requestContext.enter();
Logger.logInfo(loggerCategory, `Finished querying iModels in context`, () => ({ contextId, count: imodels.length }));
return imodels;
}
Logger.logInfo(loggerCategory, "Started deleting iModel", () => ({ iModelId, contextId }));
ArgumentCheck.defined("requestContext", requestContext);
ArgumentCheck.validGuid("contextId", contextId);
ArgumentCheck.validGuid("iModelId", iModelId);
if (this._handler.getCustomRequestOptions().isSet) {
// to add custom request options, request with body is needed.
const imodel = new HubIModel();
imodel.id = iModelId;
imodel.changeState = "deleted";
await this._handler.deleteInstance(requestContext, this.getRelativeUrl(contextId, iModelId), imodel);
} else {
await this._handler.delete(requestContext, this.getRelativeUrl(contextId, iModelId));
}
requestContext.enter();
Logger.logInfo(loggerCategory, "Finished deleting iModel", () => ({ iModelId, contextId }));
}
} finally {
changesFile.dispose();
// Reattach change cache if it was attached before the extraction
if (isChangeCacheAttached)
ChangeSummaryManager.attachChangeCache(iModel);
perfLogger = new PerfLogger("ChangeSummaryManager.extractChangeSummaries>Move iModel to original changeset");
if (iModel.briefcase.currentChangeSetId !== endChangeSetId)
await iModel.reinstateChanges(requestContext, IModelVersion.asOfChangeSet(endChangeSetId));
requestContext.enter();
perfLogger.dispose();
Logger.logTrace(loggerCategory, "Moved iModel to initial changeset (the end changeset).", () => ({ iModelId: ctx.iModelId, startChangeSetId, endChangeSetId }));
totalPerf.dispose();
Logger.logInfo(loggerCategory, "Finished Change Summary extraction.", () => ({ iModelId: ctx.iModelId, startChangeSetId, endChangeSetId }));
}
}
function processGlobalEvent(event: IModelHubGlobalEvent): void {
Logger.logInfo("example", `Global Event of the type ${typeof event} received.`);
}
// __PUBLISH_EXTRACT_END__
public async delete(requestContext: AuthorizedClientRequestContext, contextId: string, iModelId: GuidString): Promise {
requestContext.enter();
Logger.logInfo(loggerCategory, "Started deleting iModel", () => ({ iModelId, contextId }));
ArgumentCheck.defined("requestContext", requestContext);
ArgumentCheck.validGuid("contextId", contextId);
ArgumentCheck.validGuid("iModelId", iModelId);
if (this._handler.getCustomRequestOptions().isSet) {
// to add custom request options, request with body is needed.
const imodel = new HubIModel();
imodel.id = iModelId;
imodel.changeState = "deleted";
await this._handler.deleteInstance(requestContext, this.getRelativeUrl(contextId, iModelId), imodel);
} else {
await this._handler.delete(requestContext, this.getRelativeUrl(contextId, iModelId));
}
requestContext.enter();
Logger.logInfo(loggerCategory, "Finished deleting iModel", () => ({ iModelId, contextId }));
}
public async download(requestContext: AuthorizedClientRequestContext, changeSets: ChangeSet[], path: string, progressCallback?: (progress: ProgressInfo) => void): Promise {
requestContext.enter();
Logger.logInfo(loggerCategory, `Downloading ${changeSets.length} changesets`);
ArgumentCheck.nonEmptyArray("changeSets", changeSets);
ArgumentCheck.defined("path", path);
if (typeof window !== "undefined")
return Promise.reject(IModelHubClientError.browser());
if (!this._fileHandler)
return Promise.reject(IModelHubClientError.fileHandler());
changeSets.forEach((changeSet) => {
if (!changeSet.downloadUrl)
throw IModelHubClientError.missingDownloadUrl("changeSets");
});
let totalSize = 0;
let downloadedSize = 0;
public info(message?: any, ...optionalParams: any[]): void {
Logger.logInfo(loggerCategory, message, () => optionalParams);
}
azcopy.on("azinit", (args: InitEventArgs) => {
requestContext.enter();
Logger.logInfo(loggerCategory, `AzCopy started JobId: ${args.JobID} and log file located at ${args.LogFileLocation}`);
});
public async uploadSeedFile(requestContext: AuthorizedClientRequestContext, iModelId: GuidString, seedPath: string, seedFileDescription?: string, progressCallback?: (progress: ProgressInfo) => void): Promise {
requestContext.enter();
Logger.logInfo(loggerCategory, "Started uploading seed file", () => ({ iModelId, seedPath }));
const seedFile = new SeedFile();
seedFile.fileName = this._fileHandler!.basename(seedPath);
seedFile.fileSize = this._fileHandler!.getFileSize(seedPath).toString();
if (seedFileDescription)
seedFile.fileDescription = seedFileDescription;
const createdSeedFile: SeedFile = await this._handler.postInstance(requestContext, SeedFile, this.getRelativeUrl(iModelId), seedFile);
requestContext.enter();
await this._fileHandler!.uploadFile(requestContext, createdSeedFile.uploadUrl!, seedPath, progressCallback);
requestContext.enter();
createdSeedFile.uploadUrl = undefined;
createdSeedFile.downloadUrl = undefined;
createdSeedFile.isUploaded = true;
const confirmSeedFile: SeedFile = await this._handler.postInstance(requestContext, SeedFile, this.getRelativeUrl(iModelId, createdSeedFile.id), createdSeedFile);