/// <summary> /// Update <see cref="Thing"/> in the associated <see cref="IDal"/> /// </summary> /// <remarks> /// A Write Operation can be cancelled which will result in the Session will no longer waiting for the result. /// The operations are already dispatched to the E-TM-10-25 data source and will continue to run and complete there. /// </remarks> /// <param name="thing"> /// The instance of <see cref="Thing"/> that is to be updated /// </param> /// <param name="isRefresh">is True if the RevisionNumber is taken into account in the update</param> /// <returns> /// a <see cref="Task"/> that can be used with await /// </returns> private async Task Update(Thing thing, bool isRefresh = true) { var revisionNumber = isRefresh ? thing.RevisionNumber : 0; var queryAttribute = new DalQueryAttributes { RevisionNumber = revisionNumber }; // Create the token source var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenKey = Guid.NewGuid(); this.cancellationTokenSourceDictionary.TryAdd(cancellationTokenKey, cancellationTokenSource); IEnumerable <CDP4Common.DTO.Thing> dtoThings; try { dtoThings = await this.Dal.Read(thing.ToDto(), cancellationTokenSource.Token, queryAttribute); } catch (OperationCanceledException) { logger.Info("Session.Update {0} {1} cancelled", thing.ClassKind, thing.Iid); return; } finally { this.cancellationTokenSourceDictionary.TryRemove(cancellationTokenKey, out cancellationTokenSource); } var enumerable = dtoThings as IList <CDP4Common.DTO.Thing> ?? dtoThings.ToList(); await this.AfterReadOrWriteOrUpdate(enumerable); }
public async Task IntegrationTest() { this.dal = new WspDal(); var returned = await this.dal.Open(this.credentials, this.cancelationTokenSource.Token); var assembler = new Assembler(this.credentials.Uri); await assembler.Synchronize(returned); var attributes = new DalQueryAttributes { RevisionNumber = 0 }; var topcontainers = assembler.Cache.Select(x => x.Value).Where(x => x.Value is CDP4Common.CommonData.TopContainer).ToList(); foreach (var container in topcontainers) { returned = await this.dal.Read(container.Value.ToDto(), this.cancelationTokenSource.Token, attributes); await assembler.Synchronize(returned); } }