public static void FillFromAttributes(this INamespaceRegistry nsReg, IEnumerable<Assembly> assemblies)
        {
            var namespaces = XamlNamespace.DefinedInAssemblies(assemblies);

            foreach (var xamlNamespace in namespaces)
            {
                nsReg.AddNamespace(xamlNamespace);
            }            
        }
 public static ConventionBuilder AddPartsNamespace( this ConventionBuilder builder )
 {
     Arg.NotNull( builder, nameof( builder ) );
     Contract.Ensures( Contract.Result<ConventionBuilder>() != null );
     return builder.AddNamespace( "Parts" );
 }
Exemplo n.º 3
0
        /// <summary>
        /// Get the accessable entity-set URL.
        /// </summary>
        /// <param name="entityTypeShortName">The entity-type short name.</param>
        /// <returns>Returns the path nodes as a queue.</returns>
        private static Queue<string> GetAccessEntitySetPathNodes(this string entityTypeShortName)
        {
            if (string.IsNullOrEmpty(entityTypeShortName))
            {
                throw new ArgumentNullException(string.Format(ParamNullErrorMsgPattern, "entityTypeShortName"));
            }

            var queue = new Queue<string>();
            string entitySetUrl = entityTypeShortName.MapEntityTypeShortNameToEntitySetURL();
            if (!string.IsNullOrEmpty(entitySetUrl))
            {
                queue.Enqueue(entitySetUrl);

                return queue;
            }

            var svcStatus = ServiceStatus.GetInstance();
            XElement metadata = XElement.Parse(svcStatus.MetadataDocument);
            string entityTypeFullName = entityTypeShortName.AddNamespace(AppliesToType.EntityType);
            if (string.IsNullOrEmpty(entityTypeFullName))
            {
                return queue;
            }

            string etShortName = string.Empty;
            string xPath = string.Format("//*[local-name()='NavigationProperty' and contains(@Type, '{0}') and starts-with(@Type, 'Collection')]", entityTypeFullName);
            var navigElem = metadata.XPathSelectElement(xPath, ODataNamespaceManager.Instance);
            if (null != navigElem && null != navigElem.Attribute("Name"))
            {
                queue.Enqueue(navigElem.GetAttributeValue("Name"));
                var parentElem = navigElem.Parent;
                if (null == parentElem || null == parentElem.Attribute("Name"))
                {
                    return queue;
                }

                etShortName = parentElem.GetAttributeValue("Name");
            }
            else
            {
                xPath = string.Format("//*[local-name()='EntityType' and @BaseType='{0}']", entityTypeFullName);
                var baseTypeElem = metadata.XPathSelectElement(xPath, ODataNamespaceManager.Instance);
                if (null == baseTypeElem || null == baseTypeElem.Attribute("Name"))
                {
                    return queue;
                }

                etShortName = baseTypeElem.GetAttributeValue("Name");
            }

            if (!string.IsNullOrEmpty(etShortName))
            {
                var temp = MappingHelper.GetAccessEntitySetPathNodes(etShortName);
                while (temp.Any())
                {
                    queue.Enqueue(temp.Dequeue());
                }
            }

            return queue;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Map entity-type short name to entity-set URL.
        /// </summary>
        /// <param name="entityTypeShortName">An entity-type short name.</param>
        /// <returns>Returns the related entity-set URL.</returns>
        public static string MapEntityTypeShortNameToEntitySetURL(this string entityTypeShortName)
        {
            if (string.IsNullOrEmpty(entityTypeShortName))
            {
                throw new ArgumentNullException(string.Format(ParamNullErrorMsgPattern, "entityTypeShortName"));
            }

            if (!IsSpecifiedEntityTypeShortNameExist(entityTypeShortName))
            {
                throw new ArgumentException(string.Format(ParamNotFoundErrorMsgPattern, "entity-type", "short name", "entityTypeShortName"));
            }

            string entityTypeFullName = entityTypeShortName.AddNamespace(AppliesToType.EntityType, ServiceStatus.GetInstance().MetadataDocument);

            if (!string.IsNullOrEmpty(entityTypeFullName))
            {
                string entitySetName = entityTypeFullName.MapEntityTypeFullNameToEntitySetName();

                if (!string.IsNullOrEmpty(entitySetName))
                {
                    return entitySetName.MapEntitySetNameToEntitySetURL();
                }
            }

            return string.Empty;
        }
        /// <summary>
        /// Registers the namespace against the namespace manager if it doesn't exist
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="xmlNamespace"></param>
        /// <param name="xmlPrefix"></param>
        /// <returns>Empty string if no namespace, existing prefix if already defined, namespacePrefix otherwise</returns>
        public static void RegisterNamespace(this XmlNamespaceManager manager, string xmlPrefix, string xmlNamespace)
        {
            if (string.IsNullOrEmpty(xmlNamespace))
            {
                return;
            }

            var pf2 = manager.LookupNamespace(xmlNamespace);
            if (string.IsNullOrEmpty(pf2))
            {
                manager.AddNamespace(xmlPrefix, xmlNamespace);
            }
        }
Exemplo n.º 6
0
 internal static void AddNamespace(this XmlNamespaceManager nsm, string prefix, string namespaceURI, XmlElement addToNode)
 {
     nsm.AddNamespace(prefix, namespaceURI);
     if (string.IsNullOrEmpty(addToNode.GetAttribute("xmlns:" + prefix)))
     {
         addToNode.SetAttribute("xmlns:" + prefix, namespaceURI);
     }
 }