public void GetArtifactsReturnsNull()
        {
            MockServiceProvider    mockServiceProvider = new MockServiceProvider();
            IArtifactLinkContainer links = ModelCollector.GetArtifacts(mockServiceProvider);

            Assert.IsNull(links);
        }
Example #2
0
        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);
				}
			}
		}
 /// <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);
         }
     }
 }
Example #5
0
        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();
        }
Example #6
0
        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);
        }
Example #7
0
 /// <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);
 }
Example #8
0
 public void OnMenuChangeGenerateCode(object sender, EventArgs e)
 {
     try
     {
         if (IsValidModel())
         {
             IArtifactLinkContainer links = ModelCollector.GetArtifacts(this.ServiceProvider);
             GenerateArtifacts(links);
         }
     }
     catch (Exception error)
     {
         Logger.Write(error);
     }
 }
Example #9
0
        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);
            }
        }
Example #10
0
        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);
        }
Example #11
0
        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;
                }
            }
        }
Example #12
0
        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);
        }
Example #13
0
        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);
        }
Example #14
0
 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);
         }
     }
 }
Example #15
0
        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);
            }
        }
Example #16
0
 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();
             }
         }
     }
 }
Example #17
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);
        }
Example #18
0
 /// <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;
 }
Example #19
0
 /// <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;
 }
Example #20
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;
 }
Example #21
0
        /// <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));
        }
Example #22
0
 /// <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);
 }