예제 #1
0
        /// <summary>
        /// Gets a value indicating whether or not to count the hit.
        /// </summary>
        /// <param name="file">The name of the file.</param>
        /// <returns><c>true</c> if the hit must be counted, <c>false</c> otherwise.</returns>
        private bool CountHit(string file)
        {
            bool result = Request["NoHit"] != "1";

            if (!result)
            {
                return(false);
            }
            else
            {
                FileDownloadCountFilterMode mode = Settings.FileDownloadCountFilterMode;
                if (mode == FileDownloadCountFilterMode.CountAll)
                {
                    return(true);
                }
                else
                {
                    string[] allowedExtensions = Settings.FileDownloadCountFilter;
                    string   extension         = Path.GetExtension(file);
                    if (string.IsNullOrEmpty(extension))
                    {
                        return(false);
                    }
                    else
                    {
                        extension = extension.Trim('.').ToLowerInvariant();
                    }

                    bool found = false;
                    foreach (string ex in allowedExtensions)
                    {
                        if (ex == extension)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found && mode == FileDownloadCountFilterMode.CountSpecifiedExtensions)
                    {
                        return(true);
                    }
                    else if (!found && mode == FileDownloadCountFilterMode.ExcludeSpecifiedExtensions)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        ///     Gets a value indicating whether or not to count the hit.
        /// </summary>
        /// <param name="file">The name of the file.</param>
        /// <returns><c>true</c> if the hit must be counted, <c>false</c> otherwise.</returns>
        private bool CountHit(string file)
        {
            bool result = Request["NoHit"] != "1";

            if (!result)
            {
                return(false);
            }
            FileDownloadCountFilterMode mode = Settings.FileDownloadCountFilterMode;

            if (mode == FileDownloadCountFilterMode.CountAll)
            {
                return(true);
            }
            string[] allowedExtensions = Settings.FileDownloadCountFilter;
            string   extension         = Path.GetExtension(file);

            if (string.IsNullOrEmpty(extension))
            {
                return(false);
            }

            extension = extension.Trim('.').ToLowerInvariant( );

            bool found = allowedExtensions.Any(ex => ex == extension);

            if (found && mode == FileDownloadCountFilterMode.CountSpecifiedExtensions)
            {
                return(true);
            }
            if (!found && mode == FileDownloadCountFilterMode.ExcludeSpecifiedExtensions)
            {
                return(true);
            }
            return(false);
        }
예제 #3
0
 /// <summary>
 /// Sets the file download count filter mode for the given wiki.
 /// </summary>
 /// <param name="wiki">The wiki.</param>
 /// <param name="fileDonwloadCountFilterMode">The file donwload count filter mode.</param>
 public static void SetFileDownloadCountFilterMode(string wiki, FileDownloadCountFilterMode fileDonwloadCountFilterMode)
 {
     GetProvider(wiki).SetSetting("FileDownloadCountFilterMode", fileDonwloadCountFilterMode.ToString());
 }