Esempio n. 1
0
        /// <summary>
        /// Gets the resource type hierarchy.
        /// </summary>
        /// <param name="resourceTypeInfo">The resource type info.</param>
        /// <returns>List of resource type by heirarchy.</returns>
        internal List <string> GetResourceTypeHierarchy(ResourceType resourceTypeInfo)
        {
            List <string> resourceTypeList = new List <string>();

            if (null == resourceTypeInfo)
            {
                return(resourceTypeList);
            }

            if (CoreHelper.resourceTypeHierarchy.ContainsKey(resourceTypeInfo.Name))
            {
                return(CoreHelper.resourceTypeHierarchy[resourceTypeInfo.Name]);
            }

            ResourceType orginalResourceType = resourceTypeInfo;

            resourceTypeList.Add(resourceTypeInfo.Name);

            using (Core.ZentityContext context = CoreHelper.CreateZentityContext(entityConnectionString))
            {
                while (resourceTypeInfo.BaseType != null)
                {
                    ResourceType resourceType = null;
                    foreach (ResourceType resType in CoreHelper.GetResourceTypes(context))
                    {
                        if ((resourceTypeInfo.BaseType.FullName.EndsWith(resType.Name, StringComparison.Ordinal) &&
                             resourceTypeInfo.BaseType.FullName.StartsWith(resType.Parent.NameSpace, StringComparison.Ordinal)))
                        {
                            resourceType = resType;
                            break;
                        }
                    }

                    resourceTypeInfo = resourceType;
                    resourceTypeList.Add(resourceTypeInfo.Name);
                }
            }
            CoreHelper.resourceTypeHierarchy.Add(orginalResourceType.Name, resourceTypeList);
            return(resourceTypeList);
        }
        /// <summary>
        /// Gets all the resource types that inherit from ScholarlyWork, including ScholarlyWork.
        /// </summary>
        /// <returns>An array of strings containing the resource type names.</returns>
        string[] IAtomPubStoreReader.GetCollectionNames()
        {
            List <string> resourceTypes = new List <string>();

            using (ZentityContext zentityContext = CoreHelper.CreateZentityContext())
            {
                resourceTypes = new List <string>();

                // Get all resource types which are derived from ScholarlyWork as
                // only ScholarlyWork type supports authors list.
                foreach (ResourceType typeInfo in CoreHelper.GetResourceTypes(zentityContext))
                {
                    if (AtomPubHelper.IsValidCollectionType(typeInfo.Name))
                    {
                        resourceTypes.Add(typeInfo.Name);
                    }
                }
            }

            return(resourceTypes
                   .OrderBy(name => name)
                   .ToArray());
        }