/// <summary> /// Deletes a <see cref="BinaryRelationship" /> for the selected pair of thing /// </summary> /// <param name="direction">The direction of the relationship to delete</param> /// <returns>The task</returns> private Task DeleteRelationship(RelationshipDirectionKind direction) { if (!(this.SelectedCell is MatrixCellViewModel vm)) { return(Task.FromResult(0)); } var iterationClone = this.iteration.Clone(false); var context = TransactionContextResolver.ResolveContext(iterationClone); var transaction = new ThingTransaction(context, iterationClone); foreach (var binaryRelationship in vm.Relationships) { var clone = binaryRelationship.Clone(false); if (vm.RelationshipDirection != RelationshipDirectionKind.BiDirectional || direction == RelationshipDirectionKind.BiDirectional) { // delete every relationship transaction.Delete(clone); } else if (direction == RelationshipDirectionKind.RowThingToColumnThing && vm.SourceY.Iid == binaryRelationship.Source.Iid) { transaction.Delete(clone); } else if (direction == RelationshipDirectionKind.ColumnThingToRowThing && vm.SourceX.Iid == binaryRelationship.Source.Iid) { transaction.Delete(clone); } } return(this.session.Write(transaction.FinalizeTransaction())); }
/// <summary> /// Removes the first found <see cref="Parameter"/> from the first found <see cref="ElementDefinition"/> /// </summary> private void RemoveParameter() { if (this.session.OpenIterations.Count == 0) { Console.WriteLine("At first an iteration should be opened"); return; } var iteration = this.session.OpenIterations.Keys.First(); if (iteration != null) { var elementDefinition = iteration.Element[0]; var elementDefinitionClone = elementDefinition.Clone(false); var parameterClone = elementDefinition.Parameter[0].Clone(false); var transaction = new ThingTransaction( TransactionContextResolver.ResolveContext(elementDefinitionClone), elementDefinitionClone); transaction.Delete(parameterClone, elementDefinitionClone); this.session.Write(transaction.FinalizeTransaction()).GetAwaiter().GetResult(); this.PrintCacheCount(); this.PrintCommands(); } }
/// <summary> /// Execute the <see cref="DeleteCommand"/> /// </summary> /// <param name="thing"> /// The thing to delete. /// </param> protected virtual async void ExecuteDeleteCommand(Thing thing) { if (thing == null) { return; } var confirmation = new ConfirmationDialogViewModel(thing); var dialogResult = this.dialogNavigationService.NavigateModal(confirmation); if (dialogResult == null || !dialogResult.Result.HasValue || !dialogResult.Result.Value) { return; } this.IsBusy = true; var context = TransactionContextResolver.ResolveContext(this.Thing); var transaction = new ThingTransaction(context); transaction.Delete(thing.Clone(false)); try { await this.Session.Write(transaction.FinalizeTransaction()); } catch (Exception ex) { logger.Error("An error was produced when deleting the {0}: {1}", thing.ClassKind, ex.Message); this.Feedback = ex.Message; } finally { this.IsBusy = false; } }
/// <summary> /// Remove one or more parameter from the specified <see cref="ElementDefinition" /> /// </summary> public void Remove() { if (!this.commandArguments.SelectedParameters.Any()) { Console.WriteLine("Action remove-parameters: No --parameters given."); return; } var aggregateRdl = this.sessionService.Iteration.RequiredRdls.ToList(); var selectedParameterTypes = new List <ParameterType>(); foreach (var selectedParameter in this.commandArguments.SelectedParameters) { var parameterType = aggregateRdl.SelectMany(pt => pt.ParameterType).SingleOrDefault(pt => pt.ShortName == selectedParameter); if (parameterType == null) { Console.WriteLine($"Action remove-parameters: parameter type with short name \"{selectedParameter}\" not found."); } else { selectedParameterTypes.Add(parameterType); } } if (!selectedParameterTypes.Any()) { return; } DomainOfExpertise owner = null; if (!string.IsNullOrEmpty(this.commandArguments.DomainOfExpertise)) { owner = this.sessionService.SiteDirectory.Domain.FirstOrDefault(domainOfExpertise => domainOfExpertise.ShortName == this.commandArguments.DomainOfExpertise); if (owner == null) { Console.WriteLine($"Action remove-parameters: domain-of-expertise with short name \"{this.commandArguments.DomainOfExpertise}\" not found."); return; } } foreach (var elementDefinition in this.sessionService.Iteration.Element.OrderBy(x => x.ShortName)) { if (!this.filterService.IsFilteredIn(elementDefinition)) { continue; } var elementDefinitionClone = elementDefinition.Clone(true); this.sessionService.Transactions.Add(new ThingTransaction(TransactionContextResolver.ResolveContext(elementDefinitionClone), elementDefinitionClone)); foreach (var parameterType in selectedParameterTypes) { // Remove parameter if it exists and if owner is given, owned by given domain var parameter = elementDefinition.Parameter.FirstOrDefault(p => p.ParameterType == parameterType); if (parameter != null && (owner == null || parameter.Owner == owner)) { var parameterClone = parameter.Clone(true); var transaction = new ThingTransaction(TransactionContextResolver.ResolveContext(parameterClone), parameterClone); transaction.Delete(parameter, elementDefinitionClone); this.sessionService.Transactions.Add(transaction); Console.WriteLine($"In {elementDefinition.ShortName} removed Parameter {parameterType.ShortName}"); } } } }