Exemplo n.º 1
0
        /// <summary>
        /// Gets the library group from the specified <paramref name="libraryId" />.
        /// </summary>
        /// <param name="libraryId">The unique library identifier.</param>
        /// <param name="cancellationToken">A token that allows the search to be cancelled.</param>
        /// <returns>
        /// An instance of <see cref="T:Microsoft.Web.LibraryManager.Contracts.ILibraryGroup" /> or <code>null</code>.
        /// </returns>
        public async Task <ILibrary> GetLibraryAsync(string libraryId, CancellationToken cancellationToken)
        {
            ILibrary library;

            if (libraryId.Contains("://"))
            {
                library = new FileSystemLibrary
                {
                    Name       = libraryId,
                    ProviderId = _provider.Id,
                    Files      = await GetFilesAsync(libraryId).ConfigureAwait(false)
                };

                return(library);
            }

            string path = Path.Combine(_provider.HostInteraction.WorkingDirectory, libraryId);

            if (!_underTest && !File.Exists(path) && !Directory.Exists(path))
            {
                return(null);
            }

            library = new FileSystemLibrary
            {
                Name       = libraryId,
                ProviderId = _provider.Id,
                Files      = await GetFilesAsync(path).ConfigureAwait(false)
            };

            return(library);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the library group from the specified <paramref name="libraryId" />.
        /// </summary>
        /// <param name="libraryId">The unique library identifier.</param>
        /// <param name="cancellationToken">A token that allows the search to be cancelled.</param>
        /// <returns>
        /// An instance of <see cref="T:Microsoft.Web.LibraryManager.Contracts.ILibraryGroup" /> or <code>null</code>.
        /// </returns>
        public async Task <ILibrary> GetLibraryAsync(string libraryId, CancellationToken cancellationToken)
        {
            ILibrary library;

            try
            {
                if (string.IsNullOrEmpty(libraryId) || libraryId.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
                {
                    throw new InvalidLibraryException(libraryId, _provider.Id);
                }

                if (libraryId.Contains("://"))
                {
                    library = new FileSystemLibrary
                    {
                        Name       = libraryId,
                        ProviderId = _provider.Id,
                        Files      = await GetFilesAsync(libraryId).ConfigureAwait(false)
                    };

                    return(library);
                }

                string path = Path.Combine(_provider.HostInteraction.WorkingDirectory, libraryId);

                if (!_underTest && !File.Exists(path) && !Directory.Exists(path))
                {
                    throw new InvalidLibraryException(libraryId, _provider.Id);
                }

                library = new FileSystemLibrary
                {
                    Name       = libraryId,
                    ProviderId = _provider.Id,
                    Files      = await GetFilesAsync(path).ConfigureAwait(false)
                };
            }
            catch (Exception)
            {
                throw new InvalidLibraryException(libraryId, _provider.Id);
            }

            return(library);
        }