Example #1
0
        /// <summary>
        /// Checks if the server contains a file containing <paramref
        /// name="name"/> in the name, and returns a value indicating whether to
        /// continue the upload or not.
        /// </summary>
        /// <param name="name">
        /// The name to check for in files on the server. This is typically the
        /// name of the original file being uploaded. If this is <c>null</c> or
        /// the empty string, this function will always return <c>true</c>.
        /// </param>
        /// <param name="target">The name of the file to upload.</param>
        /// <returns>
        /// <c>true</c> if the upload should continue (as <paramref
        /// name="target"/>), <c>false</c> otherwise.
        /// </returns>
        public virtual bool CheckDuplicates(string name, ref string target)
        {
            if (string.IsNullOrEmpty(name)) return true;

            var directory = Path.GetDirectoryName(target).Replace('\\', '/');
            var duplicate = FindDuplicate(name, directory);

            if (duplicate != null)
            {
                var e = new DuplicateFileEventArgs(this, target, duplicate);

                OnDuplicateFileFound(e);
                switch (e.Action)
                {
                    case DuplicateFileAction.Replace:
                        target = duplicate;
                        return true;

                    case DuplicateFileAction.Abort:
                        return false;

                    case DuplicateFileAction.Ignore:
                    default:
                        return true;
                }
            }

            return true;
        }
Example #2
0
        /// <summary>
        /// Checks if the server contains a file containing <paramref
        /// name="name"/> in the name, and returns a value indicating whether to
        /// continue the upload or not.
        /// </summary>
        /// <param name="name">
        /// The name to check for in files on the server. This is typically the
        /// name of the original file being uploaded. If this is <c>null</c> or
        /// the empty string, this function will always return <c>true</c>.
        /// </param>
        /// <param name="target">The name of the file to upload.</param>
        /// <returns>
        /// <c>true</c> if the upload should continue (as <paramref
        /// name="target"/>), <c>false</c> otherwise.
        /// </returns>
        public virtual bool CheckDuplicates(string name, ref string target)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(true);
            }

            var directory = Path.GetDirectoryName(target).Replace('\\', '/');
            var duplicate = FindDuplicate(name, directory);

            if (duplicate != null)
            {
                var e = new DuplicateFileEventArgs(this, target, duplicate);

                OnDuplicateFileFound(e);
                switch (e.Action)
                {
                case DuplicateFileAction.Replace:
                    target = duplicate;
                    return(true);

                case DuplicateFileAction.Abort:
                    return(false);

                case DuplicateFileAction.Ignore:
                default:
                    return(true);
                }
            }

            return(true);
        }
Example #3
0
        /// <summary>
        /// Raises the <see cref="DuplicateFileFound"/> event.
        /// </summary>
        /// <param name="e">
        /// A <see cref="DuplicateFileEventArgs"/> object that contains the
        /// event data.
        /// </param>
        protected virtual void OnDuplicateFileFound(DuplicateFileEventArgs e)
        {
            var duplicateFileFound = DuplicateFileFound;

            if (duplicateFileFound != null)
            {
                duplicateFileFound(this, e);
            }
        }
Example #4
0
 /// <summary>
 /// Raises the <see cref="DuplicateFileFound"/> event.
 /// </summary>
 /// <param name="e">
 /// A <see cref="DuplicateFileEventArgs"/> object that contains the
 /// event data.
 /// </param>
 protected virtual void OnDuplicateFileFound(DuplicateFileEventArgs e)
 {
     var duplicateFileFound = DuplicateFileFound;
     if (duplicateFileFound != null)
     {
         duplicateFileFound(this, e);
     }
 }
Example #5
0
 /// <summary>
 /// Raises the <see cref="DuplicateFileFound"/> event.
 /// </summary>
 protected virtual void OnDuplicateFileFound(DuplicateFileEventArgs arg)
 {
     var handler = DuplicateFileFound;
     if (handler != null)
         handler(this, arg);
 }