207
208
protected setStatus(status: SyncStatus): void {
210
>
this._status = status;
211
>
this._onDidChangStatus.fire(status);
212
>
}
213
>
}
214
215
async sync(refOrUserData: string | IUserData | null, preview: boolean = false, userDataSyncConfiguration: IUserDataSyncConfiguration = this.getUserDataSyncConfiguration(), headers: IHeaders = {}): Promise<IUserDataSyncResourcePreview | null> {
217
>
this.syncHeaders = { ...headers };
218
>
219
>
if (this.status === SyncStatus.HasConflicts) {
220
this.logService.info(`${this.syncResourceLogLabel}: Skipped synchronizing ${this.resource.toLowerCase()} as there are conflicts.`);
221
return this.syncPreviewPromise;
222
}
224
>
if (this.status === SyncStatus.Syncing) {
225
this.logService.info(`${this.syncResourceLogLabel}: Skipped synchronizing ${this.resource.toLowerCase()} as it is running already.`);
226
return this.syncPreviewPromise;
227
}
229
>
this.logService.trace(`${this.syncResourceLogLabel}: Started synchronizing ${this.resource.toLowerCase()}...`);
230
>
this.setStatus(SyncStatus.Syncing);
231
>
232
>
let status: SyncStatus = SyncStatus.Idle;
233
>
try {
234
>
const lastSyncUserData = await this.getLastSyncUserData();
235
>
const remoteUserData = await this.getLatestRemoteUserData(refOrUserData, lastSyncUserData);
236
>
status = await this.performSync(remoteUserData, lastSyncUserData, preview ? SyncStrategy.Preview : SyncStrategy.Merge, userDataSyncConfiguration);
237
if (status === SyncStatus.HasConflicts) {
238
this.logService.info(`${this.syncResourceLogLabel}: Detected conflicts while synchronizing ${this.resource.toLowerCase()}.`);