Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private static openBriefcase(requestContext: AuthorizedClientRequestContext, contextId: GuidString, iModelId: GuidString, changeSetId: GuidString, pathname: string, openParams: OpenParams, briefcaseId: number): BriefcaseEntry | undefined {
const nativeDb = new IModelHost.platform.DgnDb();
const res = nativeDb.openIModel(pathname, openParams.openMode);
if (DbResult.BE_SQLITE_OK !== res)
throw new IModelError(res, `Cannot open briefcase at ${pathname}`, Logger.logError, loggerCategory, () => ({ iModelId, pathname, openParams }));
const briefcase = new BriefcaseEntry(contextId, iModelId, changeSetId, pathname, openParams, briefcaseId);
briefcase.setNativeDb(nativeDb); // Note: Sets briefcaseId, currentChangeSetId in BriefcaseEntry by reading the values from nativeDb
assert(briefcase.isOpen);
// Validate the briefcase
let isValidBriefcase: boolean = true;
if (briefcase.currentChangeSetId !== briefcase.targetChangeSetId) {
if (openParams.syncMode === SyncMode.FixedVersion) {
Logger.logError(loggerCategory, "Briefcase found is invalid (is not of required version). Deleting it to allow retries", () => briefcase.getDebugInfo());
isValidBriefcase = false;
} else {
if (nativeDb.hasUnsavedChanges() || nativeDb.hasSavedChanges())
Logger.logWarning(loggerCategory, "Briefcase found with local changes, but is not of required version. Ignoring required version", () => briefcase.getDebugInfo());
else
isValidBriefcase = false; // Invalidate the briefcase to refetch it
}
}
if (briefcase.briefcaseId !== briefcaseId) {
Logger.logError(loggerCategory, "Briefcase found is invalid (does not have the expected briefcase id). Deleting it to allow retries", () => ({ expectedBriefcaseId: briefcaseId, ...briefcase.getDebugInfo() }));
public async getModelProps(tokenProps: IModelTokenProps, modelIdsList: Id64String[]): Promise {
const iModelToken = IModelToken.fromJSON(tokenProps);
const modelIds = new Set(modelIdsList);
const iModelDb: IModelDb = IModelDb.find(iModelToken);
const modelJsonArray: ModelProps[] = [];
for (const id of modelIds) {
try {
// TODO: Change iModelDbModels.getModelJson to return a ModelProps object, rather than a string.
const modelProps: any = JSON.parse(iModelDb.models.getModelJson(JSON.stringify({ id })));
assert("modeledElement" in modelProps, "iModelDb.models.getModelJson must return a ModelProps object");
modelJsonArray.push(modelProps);
} catch (error) {
if (modelIds.size === 1)
throw error; // if they're asking for more than one model, don't throw on error.
}
}
return modelJsonArray;
}
public addTriangle(triangle: Triangle): void {
// Prefer to avoid adding vertices originating from degenerate triangles before we get here...
assert(!triangle.isDegenerate);
const onInsert = (_vk: TriangleKey) => this.mesh.addTriangle(triangle);
this.triangleSet.insertKey(triangle, onInsert);
}
}
function addClippingPlanes(prog: ProgramBuilder, maxClipPlanes: number) {
assert(maxClipPlanes > 0);
const frag = prog.frag;
const vert = prog.vert;
addEyeSpace(prog);
prog.addUniform("u_numClips", VariableType.Int, (program) => {
program.addGraphicUniform("u_numClips", (uniform, params) => {
const doClipping = true; // set to false to visualize pre-shader culling of geometry...
const numClips = (doClipping && params.target.hasClipVolume) ? params.target.clips.count : 0;
assert(numClips > 0 || !doClipping);
uniform.setUniform1i(numClips);
});
});
addModelViewMatrix(vert);
if (System.instance.capabilities.supportsTextureFloat) {
case ECObjectsStatus.InvalidEnumValue: return this._appendMessage("ECObjectsStatus.InvalidEnumValue");
case ECObjectsStatus.InvalidModifier: return this._appendMessage("ECObjectsStatus.InvalidModifier");
case ECObjectsStatus.InvalidMultiplicity: return this._appendMessage("ECObjectsStatus.InvalidMultiplicity");
case ECObjectsStatus.InvalidPrimitiveType: return this._appendMessage("ECObjectsStatus.InvalidPrimitiveType");
case ECObjectsStatus.InvalidSchemaItemType: return this._appendMessage("ECObjectsStatus.InvalidSchemaItemType");
case ECObjectsStatus.InvalidStrength: return this._appendMessage("ECObjectsStatus.InvalidStrength");
case ECObjectsStatus.InvalidStrengthDirection: return this._appendMessage("ECObjectsStatus.InvalidStrengthDirection");
case ECObjectsStatus.InvalidRelationshipEnd: return this._appendMessage("ECObjectsStatus.InvalidRelationshipEnd");
case ECObjectsStatus.InvalidType: return this._appendMessage("ECObjectsStatus.InvalidType");
case ECObjectsStatus.MissingSchemaUrl: return this._appendMessage("ECObjectsStatus.MissingSchemaUrl");
case ECObjectsStatus.UnableToLocateSchema: return this._appendMessage("ECObjectsStatus.UnableToLocateSchema");
case ECObjectsStatus.ClassNotFound: return this._appendMessage("ECObjectsStatus.ClassNotFound");
case ECObjectsStatus.SchemaContextUndefined: return this._appendMessage("ECObjectsStatus.SchemaContextUndefined");
case ECObjectsStatus.DifferentSchemaContexts: return this._appendMessage("ECObjectsStatus.DifferentSchemaContexts");
default:
assert(false);
/* istanbul ignore next */
return this._appendMessage("Error " + this.errorNumber.toString());
}
}
public onInitialized(): void {
this._techniques = Techniques.create(this.context);
const noiseDim = 4;
const noiseArr = new Uint8Array([152, 235, 94, 173, 219, 215, 115, 176, 73, 205, 43, 201, 10, 81, 205, 198]);
this._noiseTexture = TextureHandle.createForData(noiseDim, noiseDim, noiseArr, false, GL.Texture.WrapMode.Repeat, GL.Texture.Format.Luminance);
assert(undefined !== this._noiseTexture, "System.noiseTexture not created.");
this._lineCodeTexture = TextureHandle.createForData(LineCode.size, LineCode.count, new Uint8Array(LineCode.lineCodeData), false, GL.Texture.WrapMode.Repeat, GL.Texture.Format.Luminance);
assert(undefined !== this._lineCodeTexture, "System.lineCodeTexture not created.");
}
}
const fbo = this._top.fbo;
this._stack.pop();
assert(fbo.isBound);
fbo.unbind();
assert(!fbo.isBound);
if (this.isEmpty) {
System.instance.context.bindFramebuffer(GL.FrameBuffer.TARGET, null);
} else {
const top = this._top;
assert(top.fbo.isSuspended);
top.fbo.bind(top.withAttachments);
assert(top.fbo.isBound);
}
}
private static roundUpToNearestMultipleOf(value: number, factor: number): number {
const maxPlanes = Math.ceil(value / factor) * factor;
assert(maxPlanes >= value);
return maxPlanes;
}
public bind(bindAttachments: boolean = false): boolean {
assert(undefined !== this._fbo);
assert(!this.isBound);
if (undefined === this._fbo)
return false;
const gl: WebGLRenderingContext = System.instance.context;
gl.bindFramebuffer(GL.FrameBuffer.TARGET, this._fbo);
if (bindAttachments) {
System.instance.setDrawBuffers(this._colorAttachments);
this._bindState = FrameBufferBindState.BoundWithAttachments;
} else {
this._bindState = FrameBufferBindState.Bound;
}
return true;