コード例 #1
0
 /// <summary>
 /// Finds a resource by a search string. The string can be a partial resource name.
 /// <param name="searchString">The case insensitive string to use for the search</param>
 /// <param name="resource">The found resource (if any)</param>
 /// <param name="error">Describes the error that occured when locating the resource (if any)</param>
 /// <param name="kind">The resource kind to filter results against</param>
 /// </summary>
 public static bool TryFind(string searchString, out IResource resource, out Error error, ResourceKind kind = ResourceKind.All)
 {
     searchString = searchString.ToLower();
     error        = null;
     resource     = Admin.ResourceAlias.GetByAlias(searchString)?.IResource;
     if (resource != null)
     {
         return(true);
     }
     if (!RESTarConfig.ResourceFinder.TryGetValue(searchString, out resource))
     {
         error = new UnknownResource(searchString);
         return(false);
     }
     if (resource == null)
     {
         error = new AmbiguousResource(searchString);
         return(false);
     }
     if (!kind.HasFlag(resource.ResourceKind))
     {
         error = new WrongResourceKind(searchString, kind, resource.ResourceKind);
         return(false);
     }
     return(true);
 }
コード例 #2
0
        /// <summary>
        /// Finds a resource by a search string. The string can be a partial resource name. If no resource
        /// is found, throws an UnknownResource exception. If more than one resource is found, throws
        /// an AmbiguousResource exception.
        /// <param name="searchString">The case insensitive string to use for the search</param>
        /// <param name="kind">The resource kind to filter results against</param>
        /// </summary>
        public static IResource Find(string searchString, ResourceKind kind = ResourceKind.All)
        {
            if (searchString == null)
            {
                throw new UnknownResource("null");
            }
            var resource = Admin.ResourceAlias.GetByAlias(searchString)?.IResource;

            if (resource != null)
            {
                return(resource);
            }
            if (!RESTarConfig.ResourceFinder.TryGetValue(searchString, out resource))
            {
                throw new UnknownResource(searchString);
            }
            if (resource == null)
            {
                throw new AmbiguousResource(searchString);
            }
            if (!kind.HasFlag(resource.ResourceKind))
            {
                throw new WrongResourceKind(searchString, kind, resource.ResourceKind);
            }
            return(resource);
        }
コード例 #3
0
ファイル: ResourceCollection.cs プロジェクト: erikvk/RESTable
 /// <summary>
 /// Finds a resource by a search string. The string can be a partial resource name. If no resource
 /// is found, throws an UnknownResource exception. If more than one resource is found, throws
 /// an AmbiguousResource exception.
 /// <param name="searchString">The case insensitive string to use for the search</param>
 /// <param name="kind">The resource kind to filter results against</param>
 /// </summary>
 public IResource FindResource(string searchString, ResourceKind kind = ResourceKind.All)
 {
     if (searchString == null)
     {
         throw new UnknownResource("null");
     }
     if (!ResourceFinder.TryGetValue(searchString, out var resource))
     {
         throw new UnknownResource(searchString);
     }
     if (resource == null)
     {
         throw new AmbiguousResource(searchString);
     }
     if (!kind.HasFlag(resource.ResourceKind))
     {
         throw new WrongResourceKind(searchString, kind, resource.ResourceKind);
     }
     return(resource);
 }
コード例 #4
0
ファイル: ResourceCollection.cs プロジェクト: erikvk/RESTable
 /// <summary>
 /// Finds a resource by a search string. The string can be a partial resource name.
 /// <param name="searchString">The case insensitive string to use for the search</param>
 /// <param name="resource">The found resource (if any)</param>
 /// <param name="error">Describes the error that occured when locating the resource (if any)</param>
 /// <param name="kind">The resource kind to filter results against</param>
 /// </summary>
 public bool TryFindResource(string searchString, out IResource resource, out Error error, ResourceKind kind = ResourceKind.All)
 {
     searchString = searchString.ToLower();
     error        = null;
     if (!ResourceFinder.TryGetValue(searchString, out resource))
     {
         error = new UnknownResource(searchString);
         return(false);
     }
     if (resource == null)
     {
         error = new AmbiguousResource(searchString);
         return(false);
     }
     if (!kind.HasFlag(resource.ResourceKind))
     {
         error = new WrongResourceKind(searchString, kind, resource.ResourceKind);
         return(false);
     }
     return(true);
 }