How to use cleanupContext method in root

Best JavaScript code snippet using root

onedrive-cleanup-manager.service.ts

Source:onedrive-cleanup-manager.service.ts Github

copy

Full Screen

1import {inject, injectable, service} from '@loopback/core';2import {WinstonLogger} from '@loopback/logging';3import {repository} from '@loopback/repository';4import {HttpErrors} from '@loopback/rest';5import {Client} from '@microsoft/microsoft-graph-client';6import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';7import {ConfigurationBindings, ErrorBindings, LoggerBindings} from '../../key';8import {9 ClientTenant,10 MsGraphPageResponse,11 OnedriveBackboneTenant,12} from '../../models';13import {14 ClientTenantRepository,15 OnedriveContentRepository,16 StorageNodeRepository,17} from '../../repositories';18import {ObjectUtils} from '../../utils';19import {AppCustomConfig} from '../../utils/configuration-utils';20import {ErrorService} from '../error.service';21import {MsGraphTokenService} from './msgraph-token.service';22import {OnedriveBackboneManager} from './onedrive-backbone-manager.service';23import {OnedriveContentManager} from './onedrive-content-manager.service';24export interface CleanupContext {25 preview?: boolean;26 deletedFolders?: number;27 deletedFiles?: number;28 reclaimedSpace?: number;29}30@injectable()31export class OnedriveCleanupManager {32 ENABLED = false;33 constructor(34 @inject(LoggerBindings.ONEDRIVE_LOGGER) private logger: WinstonLogger,35 @inject(ConfigurationBindings.ROOT_CONFIG)36 private configuration: AppCustomConfig,37 @inject(ErrorBindings.ERROR_SERVICE) private errorService: ErrorService,38 @repository(OnedriveContentRepository)39 private contentRepository: OnedriveContentRepository,40 @repository(StorageNodeRepository)41 private storageNodeRepository: StorageNodeRepository,42 @repository(ClientTenantRepository)43 private clientTenantRepository: ClientTenantRepository,44 @service(OnedriveBackboneManager)45 private onedriveBackboneManager: OnedriveBackboneManager,46 @service(OnedriveContentManager)47 private onedriveContentManager: OnedriveContentManager,48 @service(MsGraphTokenService)49 private msGraphTokenService: MsGraphTokenService,50 ) {}51 public async cleanupAll(52 options?: Partial<CleanupContext>,53 ): Promise<CleanupContext> {54 if (!this.ENABLED) {55 throw new HttpErrors.Forbidden('Not allowed');56 }57 const ctx: CleanupContext = {58 preview: true,59 deletedFolders: 0,60 deletedFiles: 0,61 reclaimedSpace: 0,62 ...options,63 };64 const tenants = await this.clientTenantRepository.find({65 where: {66 backboneType: 'ONEDRIVE',67 },68 });69 for (const tenant of tenants) {70 await this.cleanupTenant(tenant, ctx);71 }72 return ctx;73 }74 private async cleanupTenant(75 tenant: ClientTenant,76 ctx: CleanupContext,77 ): Promise<void> {78 this.logger.info('cleaning up tenant ' + tenant.name);79 if (tenant.backboneType !== 'ONEDRIVE') {80 throw new Error(81 'Tenant ' + tenant.id + ' does not belong to this backbone',82 );83 }84 const {client, backbone} = await this.getOnedriveClient(tenant);85 const storagePath = await this.onedriveContentManager.computeStoragePath(86 tenant,87 );88 const rootPath = OnedriveContentManager.buildOnedrivePath(89 storagePath.driveId,90 storagePath.path,91 );92 await this.cleanupFolder(backbone, tenant, client, rootPath, 0, ctx);93 }94 private async cleanupFolder(95 backbone: OnedriveBackboneTenant,96 tenant: ClientTenant,97 client: Client,98 rootPath: string,99 level: number,100 ctx: CleanupContext,101 ) {102 this.logger.info('cleaning up folder ' + rootPath);103 const reqUrl = rootPath + ':/children';104 this.logger.info('listing ' + reqUrl);105 const listingResponse = await client.api(reqUrl).get();106 let listing = new MsGraphPageResponse<MicrosoftGraph.DriveItem>(107 listingResponse,108 );109 if (level > 0) {110 await this.checkIfFolderIsEmpty(111 backbone,112 tenant,113 client,114 rootPath,115 listing,116 ctx,117 );118 }119 let someRemoved = false;120 while (listing?.value?.length) {121 const files = listing.value.filter(i => !!i.file);122 const folders = listing.value.filter(i => !!i.folder);123 const fileChunks = ObjectUtils.chunkify(files, 100);124 for (const fileChunk of fileChunks) {125 const remoteIdsOnDb = await this.contentRepository.find({126 where: {127 onedriveId: {128 inq: fileChunk.map(i => i.id!),129 },130 },131 });132 const missingFiles = fileChunk.filter(133 c => !remoteIdsOnDb.find(c2 => c2.onedriveId === c.id),134 );135 for (const missingFile of missingFiles) {136 await this.processRemoteFileMissingOnDB(137 backbone,138 tenant,139 client,140 rootPath,141 missingFile,142 ctx,143 );144 someRemoved = true;145 }146 }147 for (const item of folders) {148 const itemPath = rootPath + '/' + item.name;149 await this.cleanupFolder(150 backbone,151 tenant,152 client,153 itemPath,154 level + 1,155 ctx,156 );157 }158 if (listing.nextLink) {159 this.logger.info('fetching next page');160 listing = new MsGraphPageResponse<MicrosoftGraph.DriveItem>(161 await client.api(listing.nextLink).get(),162 );163 } else {164 break;165 }166 }167 if (someRemoved) {168 await this.checkIfFolderIsEmpty(169 backbone,170 tenant,171 client,172 rootPath,173 undefined,174 ctx,175 );176 }177 }178 private async checkIfFolderIsEmpty(179 backbone: OnedriveBackboneTenant,180 tenant: ClientTenant,181 client: Client,182 rootPath: string,183 listing: MsGraphPageResponse<MicrosoftGraph.DriveItem> | undefined,184 ctx: CleanupContext,185 ): Promise<void> {186 if (!listing) {187 const reqUrl = rootPath + ':/children';188 this.logger.info('listing ' + reqUrl);189 const listingResponse = await client.api(reqUrl).get();190 listing = new MsGraphPageResponse<MicrosoftGraph.DriveItem>(191 listingResponse,192 );193 }194 if (!listing.count && !listing?.value?.length) {195 // EMPTY FOLDER196 this.logger.warn('*** FOUND EMPTY FOLDER: ' + rootPath);197 const itemResponse = (await client198 .api(rootPath)199 .get()) as MicrosoftGraph.DriveItem;200 if (!ctx.preview) {201 this.logger.debug('deleting empty folder ' + rootPath);202 await this.onedriveContentManager.deleteItem(203 client,204 backbone.driveId,205 ObjectUtils.require(itemResponse, 'id'),206 );207 this.logger.debug('deleted empty folder ' + rootPath);208 }209 ctx.deletedFolders!++;210 ctx.reclaimedSpace! += itemResponse.size ?? 0;211 }212 }213 private async processRemoteFileMissingOnDB(214 backbone: OnedriveBackboneTenant,215 tenant: ClientTenant,216 client: Client,217 rootPath: string,218 item: MicrosoftGraph.DriveItem,219 ctx: CleanupContext,220 ): Promise<void> {221 const itemPath = rootPath + '/' + item.name;222 this.logger.warn(223 '*** START OF MISSING REMOTE FILE PROCESSING: ' + itemPath,224 );225 // DELETE FILE226 if (!ctx.preview) {227 await this.onedriveContentManager.deleteItem(228 client,229 backbone.driveId,230 ObjectUtils.require(item, 'id'),231 );232 }233 ctx.deletedFiles!++;234 ctx.reclaimedSpace! += item.size ?? 0;235 this.logger.warn('*** END OF MISSING REMOTE FILE PROCESSING');236 }237 private async getOnedriveClient(tenant: ClientTenant): Promise<{238 client: Client;239 backbone: OnedriveBackboneTenant;240 }> {241 const backBone = (await this.onedriveBackboneManager.findById(242 tenant.backboneId,243 ))!;244 const onedriveClient: Client =245 this.msGraphTokenService.buildClientForUserId(backBone.ownerPrincipalId);246 return {247 client: onedriveClient,248 backbone: backBone,249 };250 }...

Full Screen

Full Screen

AbstractRenderingService.ts

Source:AbstractRenderingService.ts Github

copy

Full Screen

1import { Bind } from "dreamstate";2import { AbstractCanvasGraphicsRenderObject } from "../graphics_objects";3import { ICanvasGraphicsSizingContext } from "../types";4export abstract class AbstractRenderingService {5 protected renderWithAnimationFrame: boolean = true;6 protected renderingFps: number = 60;7 protected sizingContext: ICanvasGraphicsSizingContext = { height: 720, width: 1280 };8 protected renderingEnabled: boolean = true;9 protected interactionEnabled: boolean = true;10 protected cleanupContext: boolean = true;11 protected rendererObjects: Array<AbstractCanvasGraphicsRenderObject<any>> = [];12 protected internalWebGLRenderer: HTMLCanvasElement = document.createElement("canvas");13 protected internalRendererContext: CanvasRenderingContext2D = this.internalWebGLRenderer.getContext("2d") as CanvasRenderingContext2D;14 public constructor(sizing?: ICanvasGraphicsSizingContext) {15 this.setSizing(sizing || this.sizingContext);16 }17 // *** Get stream. ***18 // todo: Other options.19 public getMediaStream(frameRate: number): MediaStream {20 // @ts-ignore because is still experimental:21 return this.internalWebGLRenderer.captureStream(frameRate);22 }23 public setFPS(fps: number): void {24 this.renderingFps = fps;25 }26 // Context.27 public getRendererContext(): CanvasRenderingContext2D {28 return this.internalWebGLRenderer.getContext("2d") as CanvasRenderingContext2D;29 }30 // Renderer objects.31 public setRenderObjects(rendererObjects: Array<AbstractCanvasGraphicsRenderObject<any>>): void {32 this.rendererObjects = rendererObjects;33 this.rendererObjects.forEach((object: AbstractCanvasGraphicsRenderObject<any>) => object.setSizing(this.sizingContext));34 }35 public getRenderObjects(): Array<AbstractCanvasGraphicsRenderObject<any>> {36 return this.rendererObjects;37 }38 // Interaction enabled.39 public isContextCleanupEnabled(): boolean {40 return this.cleanupContext;41 }42 public enableContextCleanup(): void {43 this.cleanupContext = true;44 }45 public disableContextCleanup(): void {46 this.cleanupContext = false;47 }48 // Interaction enabled.49 public isInteractionEnabled(): boolean {50 return this.interactionEnabled;51 }52 public enableInteraction(): void {53 this.interactionEnabled = true;54 }55 public disableInteraction(): void {56 this.interactionEnabled = false;57 }58 // Rendering enabled.59 public isRenderingEnabled(): boolean {60 return this.renderingEnabled;61 }62 public enableRendering(): void {63 this.renderingEnabled = true;64 }65 public disableRendering(): void {66 this.renderingEnabled = false;67 }68 // Sizing context.69 public setSizing(sizingContext: ICanvasGraphicsSizingContext): void {70 this.sizingContext = sizingContext;71 this.internalWebGLRenderer.width = sizingContext.width;72 this.internalWebGLRenderer.height = sizingContext.height;73 this.rendererObjects.forEach((object: AbstractCanvasGraphicsRenderObject<any>): void => object.setSizing(sizingContext));74 }75 public getSizing(): ICanvasGraphicsSizingContext {76 return this.sizingContext;77 }78 /* Rendering: */79 @Bind()80 public render(): void {81 if (this.renderWithAnimationFrame) {82 this.renderAnimationFrame();83 } else {84 this.renderRaw();85 }86 }87 public clear(): void {88 this.internalRendererContext.clearRect(0, 0, this.sizingContext.width, this.sizingContext.height);89 }90 protected abstract renderItems(): void;91 /* Rendering implementation. */92 @Bind()93 private renderRaw(): void {94 if (this.cleanupContext) {95 this.clear();96 }97 if (this.renderingEnabled) {98 this.renderItems();99 window.setTimeout(this.renderRaw, 1000 / this.renderingFps);100 }101 }102 @Bind()103 private renderAnimationFrame(): void {104 if (this.cleanupContext) {105 this.clear();106 }107 if (this.renderingEnabled) {108 this.renderItems();109 window.setTimeout(window.requestAnimationFrame.bind(window, this.renderAnimationFrame), 1000 / this.renderingFps);110 }111 }...

Full Screen

Full Screen

related_1.js

Source:related_1.js Github

copy

Full Screen

1var searchData=2[3 ['cleanupcontext_1354',['cleanUpContext',['../struct_catch_1_1_i_mutable_context.html#ac07cdb7d744cc8f09672d924324b55fd',1,'Catch::IMutableContext']]]...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var rootElement = document.getElementById("root");2rootElement.cleanupContext();3var childElement = document.getElementById("child");4childElement.cleanupContext();5var rootElement = document.getElementById("root");6rootElement.cleanupContext();7var childElement = document.getElementById("child");8childElement.cleanupContext();9var rootElement = document.getElementById("root");10rootElement.cleanupContext();11var childElement = document.getElementById("child");12childElement.cleanupContext();13var rootElement = document.getElementById("root");14rootElement.cleanupContext();15var childElement = document.getElementById("child");16childElement.cleanupContext();17var rootElement = document.getElementById("root");18rootElement.cleanupContext();19var childElement = document.getElementById("child");20childElement.cleanupContext();21var rootElement = document.getElementById("root");22rootElement.cleanupContext();23var childElement = document.getElementById("child");24childElement.cleanupContext();25var rootElement = document.getElementById("root");26rootElement.cleanupContext();27var childElement = document.getElementById("child");28childElement.cleanupContext();29var rootElement = document.getElementById("root");30rootElement.cleanupContext();31var childElement = document.getElementById("child");32childElement.cleanupContext();33var rootElement = document.getElementById("root");34rootElement.cleanupContext();35var childElement = document.getElementById("child");36childElement.cleanupContext();

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('Root').getInstance();2root.cleanupContext();3var root = require('Root').getInstance();4root.cleanupContext(function() {5});6var root = require('Root').getInstance();7root.cleanupContext(function() {8}, context);9var root = require('Root').getInstance();10root.cleanupContext(context);11var root = require('Root').getInstance();12root.cleanupContext(context, function() {13});14var root = require('Root').getInstance();15root.cleanupContext(context, function() {16}, context);17var root = require('Root').getInstance();18root.cleanupContext(context, context, function() {19});20var root = require('Root').getInstance();21root.cleanupContext(context, context, function() {22}, context);23var root = require('Root').getInstance();24root.cleanupContext(context, context, context, function() {25});26var root = require('Root').getInstance();27root.cleanupContext(context, context, context, function() {28}, context);29var root = require('Root').getInstance();30root.cleanupContext(context, context, context, context, function() {31});32var root = require('Root').getInstance();33root.cleanupContext(context, context, context, context, function() {34}, context);35var root = require('Root').getInstance();36root.cleanupContext(context, context, context, context, context, function() {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful