public void Execute(Shape s, string context) { RationallyModel model = Globals.RationallyAddIn.Model; Log.Debug("Model found: " + (model != null)); AlternativesContainer alternativesContainer = (AlternativesContainer)Globals.RationallyAddIn.View.Children.First(ch => ch is AlternativesContainer); Log.Debug("Alternatives container found in view tree: " + (alternativesContainer != null)); Log.Debug("Alternatives count: " + model.Alternatives.Count); if (model.Alternatives.Count >= Constants.SupportedAmountOfAlternatives) //The view does not handling more than 3 alternatives well, by default. { AddAlternativeWithWarning alternativePopUp = new AddAlternativeWithWarning(model); if (alternativePopUp.ShowDialog() == DialogResult.OK) { alternativesContainer?.AddAlternative(alternativePopUp.alternativeName.Text, alternativePopUp.alternativeStatus.SelectedItem.ToString()); } alternativePopUp.Dispose(); } else { AddAlternative alternativePopUp = new AddAlternative(model); if (alternativePopUp.ShowDialog() == DialogResult.OK) { Log.Debug("About to enter AddAlternative method"); alternativesContainer?.AddAlternative(alternativePopUp.alternativeName.Text, alternativePopUp.alternativeStatus.SelectedItem.ToString()); } alternativePopUp.Dispose(); } }
private void Application_ShapeAddedEvent(Shape s) { Log.Debug("Shape added with name: " + s.Name); if (s.Document.Template.Contains(Information.TemplateName) && (s.CellExistsU[VisioFormulas.Cell_RationallyType, (short)VisExistsFlags.visExistsAnywhere] == Constants.CellExists) && !View.ExistsInTree(s)) { try { switch (s.CellsU[VisioFormulas.Cell_RationallyType].ResultStr[VisioFormulas.Value]) { case "alternativeAddStub": if (!Application.IsUndoingOrRedoing) { int scopeId = Application.BeginUndoScope(Messages.Scope_AddAlternative); s.Delete(); AlternativesContainer alternativesContainer = Globals.RationallyAddIn.View.Children.FirstOrDefault(ch => ch is AlternativesContainer) as AlternativesContainer; alternativesContainer?.AddAlternative("Title", default(AlternativeState).GetName()); Application.EndUndoScope(scopeId, true); } break; case "forceAddStub": if (!Application.IsUndoingOrRedoing) { int scopeId = Application.BeginUndoScope(Messages.Scope_AddForce); s.Delete(); MarkerEventHandlerRegistry.HandleEvent("forces.add", null, null); Application.EndUndoScope(scopeId, true); } break; case "relatedDocumentAddStub": if (!Application.IsUndoingOrRedoing) { int scopeId = Application.BeginUndoScope(Messages.Scope_AddFile); s.Delete(); MarkerEventHandlerRegistry.HandleEvent("relatedDocuments.addRelatedFile", null, null); Application.EndUndoScope(scopeId, true); } break; case "relatedUrlAddStub": if (!Application.IsUndoingOrRedoing) { int scopeId = Application.BeginUndoScope(Messages.Scope_AddUrl); s.Delete(); MarkerEventHandlerRegistry.HandleEvent("relatedDocuments.addRelatedUrl", null, null); Application.EndUndoScope(scopeId, true); } break; case "stakeholderAddStub": if (!Application.IsUndoingOrRedoing) { int scopeId = Application.BeginUndoScope(Messages.Scope_AddStakeholder); s.Delete(); StakeholdersContainer stakeholdersContainer = View.Children.FirstOrDefault(ch => ch is StakeholdersContainer) as StakeholdersContainer; stakeholdersContainer?.AddStakeholder("<<name>>", "<<role>>"); Application.EndUndoScope(scopeId, true); } break; case "planningItemStub": if (!Application.IsUndoingOrRedoing) { int scopeId = Application.BeginUndoScope(Messages.Scope_AddPlanningItem); s.Delete(); PlanningContainer planningContainer = View.Children.FirstOrDefault(ch => ch is PlanningContainer) as PlanningContainer; planningContainer?.AddPlanningItem(); Application.EndUndoScope(scopeId, true); } break; default: View.AddToTree(s, true); break; } } catch (Exception ex) { Log.Error(ex, ex); #if DEBUG throw; #endif } } }