/// <summary> /// Processes the instance edit. /// </summary> /// <param name="runtime">The runtime.</param> /// <param name="result">The result.</param> /// <param name="view">The view.</param> /// <param name="editAction">The edit action.</param> /// <returns>ExecutionView.</returns> /// <exception cref="System.NotSupportedException">Error occured during edit: + lastError</exception> /// <exception cref="System.Collections.Generic.KeyNotFoundException">Specified edit hasn't been found</exception> private static ExecutionView processInstanceEdit(RuntimeAssembly runtime, AnalyzingResult result, ExecutionView view, EditAction editAction) { var editOwner = result.EntryContext.GetValue(editAction.Variable); string lastError = null; foreach (var edit in editOwner.Edits) { if (edit.Name != editAction.Name) { continue; } var editView = new EditView(view); var resultView = runtime.RunEdit(edit, editView); editView = (resultView as EditView); if (editView.HasError) { lastError = editView.Error; continue; } return(editView.CopyView()); } if (lastError != null) { throw new NotSupportedException("Error occured during edit: " + lastError); } throw new KeyNotFoundException("Specified edit hasn't been found"); }
/// <summary> /// Run analysis on given composition point. /// </summary> /// <param name="compositionPoint">Composition point to be analyzed.</param> private void runAnalysis(CompositionPoint compositionPoint) { _analysisError = null; try { var entryMethod = compositionPoint.EntryMethod; _loader.Settings.CodeBaseFullPath = getCodeBase(entryMethod); var entryArguments = getCompositionPointArguments(compositionPoint); _currentArguments = entryArguments; //run analysis on selected compsition with obtained arguments _currentResult = _machine.Run(_loader, entryMethod, entryArguments); _currentResult.OnViewCommit += (v) => { _vs.ForceFlushChanges(); }; handleRuntimeException(_currentResult.RuntimeException); } catch (Exception ex) { _currentArguments = null; _analysisError = _vs.LogErrorEntry(ex.Message, ex.ToString()); } }
/// <summary> /// Processes given remove edits. /// </summary> /// <param name="result">The result.</param> /// <param name="view">The view.</param> /// <param name="editAction">The edit action.</param> /// <returns>ExecutionView.</returns> /// <exception cref="System.NotSupportedException">Remove edit doesn't succeeded</exception> private static ExecutionView processRemoveEdit(AnalyzingResult result, ExecutionView view, EditAction editAction) { var inst = result.EntryContext.GetValue(editAction.Variable); var success = view.Remove(inst); if (!success) { throw new NotSupportedException("Remove edit doesn't succeeded"); } return(view); }
/// <summary> /// Initializes a new instance of the <see cref="DrawingPipeline"/> class. /// </summary> /// <param name="drawer">The general drawer.</param> /// <param name="runtime">Corresponding <see cref="RuntimeAssembly"/>.</param> /// <param name="result">The analysis result which instances will be drawn.</param> public DrawingPipeline(GeneralDrawer drawer, RuntimeAssembly runtime, AnalyzingResult result) { Runtime = runtime; _result = result; _drawer = drawer; var initialView = new EditView(_result.CreateExecutionView()); Context = new DiagramDefinition(initialView); foreach (var edit in runtime.GlobalEdits) { var drawingEdit = CreateEditDefinition(edit); Context.AddEdit(drawingEdit); } }
/// <summary> /// Processes given edits on results view. /// </summary> /// <param name="runtime">The runtime.</param> /// <param name="result">The result.</param> /// <param name="editActions">The edit actions.</param> /// <returns>ExecutionView.</returns> private static ExecutionView processEdits(RuntimeAssembly runtime, AnalyzingResult result, IEnumerable <EditAction> editActions) { var view = result.CreateExecutionView(); foreach (var editAction in editActions) { if (editAction.IsRemoveAction) { view = processRemoveEdit(result, view, editAction); } else { view = processInstanceEdit(runtime, result, view, editAction); } } view.Commit(); return(view); }
/// <summary> /// Create drawings from given result. /// </summary> /// <param name="result">The result.</param> /// <returns>DiagramDefinition.</returns> private DiagramDefinition createDrawings(AnalyzingResult result) { var pipeline = _loader.Settings.Runtime.CreateDrawingPipeline(generalDrawer, result); var entryInstance = _currentArguments == null || _currentArguments.Length == 0 ? null : _currentArguments[0]; foreach (var instance in result.CreatedInstances) { var isEntryInstance = instance == entryInstance; var hasDrawer = Runtime.GetDrawer(instance) != null; var hasComponentInfo = _loader.GetComponentInfo(instance.Info) != null; var addToQueue = hasDrawer || hasComponentInfo; if (addToQueue) { pipeline.AddToDrawQueue(instance); if (hasComponentInfo) { pipeline.ForceDisplay(instance); } } } var definition = pipeline.GetOutput(); foreach (var instance in pipeline.DisplayedInstances) { if (instance.IsDirty) { _vs.Log.Warning("Instance {0} is marked as dirty, therefore it's display can be incorrect", instance.ID); } } definition.AddEditsMenu("Add Component", componentCreationEdits); definition.AddCommand(new CommandDefinition("Reset workspace", () => _vs.SafeRunAction(_guiManager.ResetWorkspace, "Resetting workspace failed"))); definition.UseItemAvoidance = _guiManager.UseItemAvoidance; definition.UseJoinAvoidance = _guiManager.UseJoinAvoidance; definition.ShowJoinLines = _guiManager.ShowJoinLines; return(definition); }
/// <summary> /// Show composition based on analysis of given method. /// </summary> /// <param name="compositionPoint">Composition point to be analyzed.</param> private void showComposition(CompositionPoint compositionPoint) { _vs.SafeRunAction(() => { if (_currentResult != null) { //invalidate result, to free up resources UserInteraction.DisposeResources(); } if (compositionPoint == null) { _guiManager.Display(null, true); _currentResult = null; } else { var watch = Stopwatch.StartNew(); runAnalysis(compositionPoint); _vs.Log.Message("Executing composition point {0}ms", watch.ElapsedMilliseconds); if (_analysisError == null) { watch.Restart(); //analysis has been successful var drawing = createDrawings(_currentResult); _guiManager.Display(drawing); _vs.Log.Message("Drawing composition point {0}ms", watch.ElapsedMilliseconds); } else { _guiManager.DisplayEntry(_analysisError); } } }, "Refreshing composition point"); }
/// <summary> /// Initializes a new instance of the <see cref="ExecutionView"/> class. /// </summary> /// <param name="result">The result of analysis represented by current view.</param> internal ExecutionView(AnalyzingResult result) { _result = result; _instanceRemoveProvider = new InstanceRemoveProvider(result.EntryContext); }
/// <summary> /// Creates the drawing pipeline that is used for drawing processing. /// Pipeline is used therefore drawing of every instance consists of multiple steps. /// </summary> /// <param name="drawer">The drawer of general definitions that is used for every drawn instance.</param> /// <param name="result">The result of analysis which instances are drawn.</param> /// <returns>Created pipeline.</returns> public DrawingPipeline CreateDrawingPipeline(GeneralDrawer drawer, AnalyzingResult result) { return(new DrawingPipeline(drawer, this, result)); }