public void GetArtifactsReturnsNull() { MockServiceProvider mockServiceProvider = new MockServiceProvider(); IArtifactLinkContainer links = ModelCollector.GetArtifacts(mockServiceProvider); Assert.IsNull(links); }
private void OnElementDeleted(object sender, ElementDeletedEventArgs e) { IArtifactLinkContainer artifactContainer = ModelCollector.GetArtifacts(e.ModelElement); if (artifactContainer != null && artifactContainer.ArtifactLinks != null) { ICodeGenerationService codeGenerationService = GetService <ICodeGenerationService>(); codeGenerationService.ValidateDeleteFromCollection(artifactContainer.ArtifactLinks); } }
/// <summary> /// Collects the specified links. /// </summary> /// <param name="links">The links.</param> public void Collect(IArtifactLinkContainer links) { if (links != null && links.ArtifactLinks != null) { foreach (IArtifactLink link in links.ArtifactLinks) { // This "Add()" will only add if not present (returns true if added) artifacts.Add(link); } } }
private void GenerateAllArtifacts() { HashSet <ModelElement> elementList = new HashSet <ModelElement>(); FullDepthElementWalker elementWalker = new FullDepthElementWalker( new ModelElementVisitor(elementList), new EmbeddingReferenceVisitorFilter(), false); elementWalker.DoTraverse(DomainModelHelper.GetModelElement(this.FocusedSelection)); IArtifactLinkContainer links = ModelCollector.GetArtifacts(elementList); GenerateArtifacts(links); elementList.Clear(); }
public static IArtifactLinkContainer GetArtifacts(ICollection <ModelElement> elements) { ArtifactLinkCollector collector = new ArtifactLinkCollector(); foreach (ModelElement element in elements) { if (typeof(IExtensibleObject).IsAssignableFrom(element.GetType())) { IArtifactLinkContainer links = GetArtifacts(element); collector.Collect(links); } } return(collector); }
/// <summary> /// Returns true if it finds roles in an ArtifactLink /// </summary> /// <param name="container"></param> /// <returns></returns> public static bool HasRoles(IArtifactLinkContainer container) { if (container != null) { foreach (IArtifactLink link in container.ArtifactLinks) { if (link.Container != Guid.Empty) { return(true); } } } return(false); }
public void OnMenuChangeGenerateCode(object sender, EventArgs e) { try { if (IsValidModel()) { IArtifactLinkContainer links = ModelCollector.GetArtifacts(this.ServiceProvider); GenerateArtifacts(links); } } catch (Exception error) { Logger.Write(error); } }
protected override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults) { base.DoValidate(objectToValidate, currentTarget, key, validationResults); IArtifactLinkContainer container = objectToValidate as IArtifactLinkContainer; if (validationResults.IsValid && ModelCollector.HasValidArtifacts(container) && !ModelCollector.HasRoles(container)) { this.LogValidationResult(validationResults, ValidatorUtility.ShowFormattedMessage(Resources.ExtenderObjectValidatorMessage, currentTarget), currentTarget, key); } }
public static IArtifactLinkContainer GetArtifacts(ModelElement modelElement) { IArtifactLinkContainer links = null; if (modelElement is IArtifactLinkContainer) { links = (IArtifactLinkContainer)modelElement; } else if (modelElement is IExtensibleObject) { IExtensibleObject extendedObject = (IExtensibleObject)modelElement; links = extendedObject.ObjectExtender as IArtifactLinkContainer; } return(links); }
public void OnMenuChangeViewGeneratedCode(object sender, EventArgs e) { IArtifactLinkContainer container = ModelCollector.GetArtifacts(DomainModelHelper.GetSelectedElement(this.ServiceProvider)); foreach (IArtifactLink link in container.ArtifactLinks) { string fullPath = GetFullPath(link); if (File.Exists(fullPath)) { EnvDTE.DTE dte = (EnvDTE.DTE) this.ServiceProvider.GetService(typeof(EnvDTE.DTE)); if (dte != null) { dte.ItemOperations.OpenFile(fullPath, EnvDTE.Constants.vsViewKindCode); } return; } } }
private bool IsValidSelectedContainer() { IArtifactLinkContainer container = ModelCollector.GetArtifacts(DomainModelHelper.GetSelectedElement(this.ServiceProvider)); bool isValid = (container != null && container.ArtifactLinks.Count > 0); if (isValid) { foreach (IArtifactLink link in container.ArtifactLinks) { if (!File.Exists(GetFullPath(link))) { isValid = false; break; } } } return(isValid); }
private static IArtifactLinkContainer GetArtifacts(IServiceProvider serviceProvider, bool firstValid) { ShapeElement selectedShape = DomainModelHelper.GetSelectedShape(serviceProvider); if (selectedShape != null && selectedShape.ModelElement != null) { if (selectedShape is Diagram) { if (firstValid) { foreach (ModelElement element in selectedShape.ModelElement.Store.ElementDirectory.AllElements) { if (typeof(IExtensibleObject).IsAssignableFrom(element.GetType())) { IArtifactLinkContainer links = GetArtifacts(element); // trim walk on first valid links return(FilterValidLinks(selectedShape.ModelElement.Store, links)); } } return(null); } return(GetArtifacts(selectedShape.ModelElement.Store)); } else { IArtifactLinkContainer links = GetArtifacts(selectedShape.ModelElement); return(firstValid ? FilterValidLinks(serviceProvider, links) : links); } } ModelElement selectedElement = DomainModelHelper.GetSelectedElement(serviceProvider); if (selectedElement != null) { IArtifactLinkContainer links = GetArtifacts(selectedElement); return(firstValid ? FilterValidLinks(serviceProvider, links) : links); } return(null); }
private void OnElementChanged(object sender, ElementPropertyChangedEventArgs e) { if (e.DomainProperty.DisplayName.Equals("Name", StringComparison.OrdinalIgnoreCase)) { try { string oldName = e.OldValue.ToString(); string newName = e.NewValue.ToString(); IArtifactLinkContainer artifactContainer = ModelCollector.GetArtifacts(e.ModelElement); if (artifactContainer != null && artifactContainer.ArtifactLinks != null) { ICodeGenerationService codeGenerationService = GetService <ICodeGenerationService>(); codeGenerationService.ValidateRenameFromCollection(artifactContainer.ArtifactLinks, newName, oldName); } } catch (Exception ex) { Logger.Write(ex); } } }
protected override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults) { //TODO: Fix this call if not working if (objectToValidate != null) { // Ignore objects than have already been validated. // if (IsValidated(objectToValidate)) { return; } Type targetType = objectToValidate.GetType(); using (FileConfigurationSource configurationSource = new FileConfigurationSource(TargetConfigurationFile)) { Validator v = ValidationFactory.CreateValidator(targetType, "Common", configurationSource); v.Validate(objectToValidate, validationResults); v = ValidationFactory.CreateValidator(targetType, targetRuleset, configurationSource); v.Validate(objectToValidate, validationResults); } Debug.WriteLine(String.Format(CultureInfo.CurrentUICulture, "{0} {1}", objectToValidate.ToString(), validationResults.IsValid ? "Succeeded" : "Failed")); } //base.DoValidate(objectToValidate, currentTarget, key, validationResults); IArtifactLinkContainer container = objectToValidate as IArtifactLinkContainer; if (validationResults.IsValid && ModelCollector.HasValidArtifacts(container) && !ModelCollector.HasRoles(container)) { this.LogValidationResult(validationResults, ValidatorUtility.ShowFormattedMessage(Resources.ExtenderObjectValidatorMessage, currentTarget), currentTarget, key); } }
private void GenerateArtifacts(IArtifactLinkContainer links) { if (links != null) { if (links != null && links.ArtifactLinks != null) { VSStatusBar status = new VSStatusBar(this.ServiceProvider); try { ICodeGenerationService codeGenerationService = this.ServiceProvider.GetService(typeof(ICodeGenerationService)) as ICodeGenerationService; int generatedObjects = codeGenerationService.GenerateArtifacts(links.ArtifactLinks, l => { status.ShowMessage(l.ItemPath); }); Logger.Write( string.Format(CultureInfo.CurrentCulture, Properties.Resources.GeneratedObjects, generatedObjects), System.Diagnostics.TraceEventType.Information); } finally { status.Clear(); } } } }
private static IArtifactLinkContainer FilterValidLinks(IServiceProvider serviceProvider, IArtifactLinkContainer links) { ICodeGenerationService codeGenerationService = serviceProvider.GetService(typeof(ICodeGenerationService)) as ICodeGenerationService; if (codeGenerationService == null || links == null || !codeGenerationService.AreValid(links.ArtifactLinks)) { return(null); } return(links); }
/// <summary> /// Returns true if it finds roles in an ArtifactLink /// </summary> /// <param name="container"></param> /// <returns></returns> public static bool HasRoles(IArtifactLinkContainer container) { if (container != null) { foreach (IArtifactLink link in container.ArtifactLinks) { if (link.Container != Guid.Empty) { return true; } } } return false; }
/// <summary> /// Returns true if if finds any ArtifactLink /// </summary> /// <param name="container"></param> /// <returns></returns> public static bool HasValidArtifacts(IArtifactLinkContainer container) { return container != null && container.ArtifactLinks != null && container.ArtifactLinks.Count > 0; }
private static IArtifactLinkContainer FilterValidLinks(IServiceProvider serviceProvider, IArtifactLinkContainer links) { ICodeGenerationService codeGenerationService = serviceProvider.GetService(typeof(ICodeGenerationService)) as ICodeGenerationService; if (codeGenerationService == null || links == null || !codeGenerationService.AreValid(links.ArtifactLinks)) { return null; } return links; }
/// <summary> /// Will walk until it finds the first valid artifact link with roles /// </summary> /// <param name="serviceProvider"></param> /// <returns></returns> public static bool HasValidArtifactsAndRoles(IServiceProvider serviceProvider) { IArtifactLinkContainer container = ModelCollector.GetArtifacts(serviceProvider, true); return(HasValidArtifacts(container) && HasRoles(container)); }
/// <summary> /// Returns true if if finds any ArtifactLink /// </summary> /// <param name="container"></param> /// <returns></returns> public static bool HasValidArtifacts(IArtifactLinkContainer container) { return(container != null && container.ArtifactLinks != null && container.ArtifactLinks.Count > 0); }