예제 #1
0
        /// <summary>
        /// Create copy of target site according to the specified parameters.
        /// </summary>
        /// <param name="uri">The target site uri.</param>
        /// <param name="storageFactory">A <see cref="IStorageFactory"/>.<</param>
        /// <param name="depthCopy">The link analysis depth. Default 0 - only current page.</param>
        /// <param name="linkRestriction">The restriction on switching to other domains. Default - no limit.</param>
        /// <param name="allowedResources">The restriction on the "expansion" of downloadable resources, e.g. what resources should be downloaded.
        /// Examle: 'js, png'. Default - not download resources.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        /// <exception cref="ArgumentException">
        /// The <paramref name="linkRestriction"/> is not supported.
        /// The <paramref name="uri"/> is not valid absolute uri.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="uri"/> is null.
        /// The <paramref name="allowedResources"/> is null.
        /// The <paramref name="storageFactory"/> is null.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// The <paramref name="depthCopy"/> is less than zero.
        /// </exception>
        public async Task GetSiteCopy(string uri, IStorageFactory storageFactory, int depthCopy = 0, PathLinkRestriction linkRestriction = PathLinkRestriction.NoLimit, string allowedResources = "")
        {
            if (string.IsNullOrEmpty(uri))
            {
                throw new ArgumentNullException($"The {nameof(uri)} can not be null or empty.");
            }

            if (depthCopy < 0)
            {
                throw new ArgumentOutOfRangeException($"The {nameof(depthCopy)} can not be negative.");
            }

            if (allowedResources == null)
            {
                throw new ArgumentNullException($"The {nameof(allowedResources)} can not be null.");
            }

            if (storageFactory == null)
            {
                throw new ArgumentNullException($"The {nameof(storageFactory)} can not be null.");
            }

            if (!LinkRestrictionCollection.Restrictions.TryGetValue(linkRestriction, out linkRestrictor))
            {
                throw new ArgumentException($"The {linkRestriction} is not supported.");
            }

            var createdUri = TryCreateAbsoluteUri(uri);

            if (!createdUri.isValidAbsoluteUri)
            {
                throw new ArgumentException($"The value of {nameof(uri)} is not valid absolute uri.");
            }

            dataStorage = storageFactory.GetDataStorage();

            await GetSiteCopyCoreLogic(createdUri.uri, depthCopy, allowedResources).ConfigureAwait(false);
        }