/// <summary>
        /// Creates an instance
        /// </summary>
        /// <param name="artifactLinkType"></param>
        /// <param name="modelElement"></param>
        /// <param name="mappingTable"></param>
        /// <returns></returns>
        public static ArtifactLink CreateInstance(Type artifactLinkType, ModelElement modelElement, string mappingTable,
                                                  ICustomAttributeProvider attributeProvider)
        {
            Guard.ArgumentNotNull(artifactLinkType, "artifactLinkType");
            Guard.ArgumentNotNull(modelElement, "modelElement");
            Guard.ArgumentNotNull(attributeProvider, "attributeProvider");

            Tuple <Type, Guid, string> key = new Tuple <Type, Guid, string>(artifactLinkType, modelElement.Id, mappingTable);

            return(GlobalCache.AddOrGetExisting <ArtifactLink>(key.ToString(), k =>
            {
                ArtifactLink link = CreateLink(artifactLinkType, modelElement);
                if (!String.IsNullOrEmpty(mappingTable))
                {
                    try
                    {
                        link.Container = GetContainer(mappingTable, attributeProvider);
                        link.Path = GetProjectPath(mappingTable, link.Container);
                        link.Project = GetProject(modelElement, link.Container);
                    }
                    catch (Exception e)
                    {
                        Logger.Write(e);
                    }
                }
                return link;
            }));
        }
        private static ArtifactLink CreateLink(Type artifactLinkType, ModelElement modelElement)
        {
            ArtifactLink link = (ArtifactLink)Activator.CreateInstance(artifactLinkType);

            link.ModelElement = modelElement;
            link.ItemName     = GetName(modelElement);
            return(link);
        }
Esempio n. 3
0
        public static string DefaultNamespace(ModelElement element)
        {
            ArtifactLink link = GetFirstArtifactLink(element);

            if (link != null &&
                !string.IsNullOrEmpty(link.Namespace))
            {
                return(string.Format(CultureInfo.InvariantCulture, "urn:{0}", link.Namespace.ToLowerInvariant()));
            }
            return(string.Empty);
        }
        /// <summary>
        /// Creates the instance.
        /// </summary>
        /// <param name="linkType">Type of the link.</param>
        /// <param name="modelElement">The model element.</param>
        /// <param name="projectUniqueName">Name of the project unique.</param>
        /// <param name="itemPath">The item path.</param>
        /// <returns></returns>
        public static ArtifactLink CreateInstance(Type linkType, ModelElement modelElement, string projectUniqueName, string itemPath)
        {
            Guard.ArgumentNotNull(linkType, "linkType");
            Guard.ArgumentNotNull(modelElement, "modelElement");
            Guard.ArgumentNotNullOrEmptyString(projectUniqueName, "projectUniqueName");
            Guard.ArgumentNotNull(itemPath, "itemPath");

            Tuple <Type, Guid, string> key = new Tuple <Type, Guid, string>(linkType, modelElement.Id, projectUniqueName);

            return(GlobalCache.AddOrGetExisting <ArtifactLink>(key.ToString(), k =>
            {
                ArtifactLink link = CreateLink(linkType, modelElement);
                try
                {
                    link.Path = itemPath;
                    SetLinkContainerProperties(modelElement, projectUniqueName, link);
                }
                catch (Exception e)
                {
                    Logger.Write(e);
                }
                return link;
            }));
        }
        private static void SetLinkContainerProperties(ModelElement element, string projectUniqueName, ArtifactLink link)
        {
            IVsSolution vsSolution = GetService <IVsSolution, SVsSolution>(element);

            using (HierarchyNode hNode = new HierarchyNode(vsSolution, projectUniqueName))
            {
                link.Project   = GetProjectFromHierarchyNode(hNode);
                link.Container = hNode.ProjectGuid;
            }
        }