Beispiel #1
0
 private void OnFileRemoving(FileCancelEventArgs e)
 {
     if (FileRemoving != null)
     {
         FileRemoving(this, e);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Removes a file, raising the appropriate events. This method may show message boxes.
        /// </summary>
        public void RemoveFile(string fileName, bool isDirectory)
        {
            var eargs = new FileCancelEventArgs(fileName, isDirectory);

            OnFileRemoving(eargs);
            if (eargs.Cancel)
            {
                return;
            }
            if (!eargs.OperationAlreadyDone)
            {
                if (isDirectory)
                {
                    try
                    {
                        if (Directory.Exists(fileName))
                        {
                            if (Altaxo.Current.GetRequiredService <IFileService>().DeleteToRecycleBin)
                            {
                                NativeMethods.DeleteToRecycleBin(fileName);
                            }
                            else
                            {
                                Directory.Delete(fileName, true);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MessageService.ShowHandledException(e, "Can't remove directory " + fileName);
                    }
                }
                else
                {
                    try
                    {
                        if (File.Exists(fileName))
                        {
                            if (Altaxo.Current.GetRequiredService <IFileService>().DeleteToRecycleBin)
                            {
                                NativeMethods.DeleteToRecycleBin(fileName);
                            }
                            else
                            {
                                File.Delete(fileName);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MessageService.ShowHandledException(e, "Can't remove file " + fileName);
                    }
                }
            }
            OnFileRemoved(new FileEventArgs(fileName, isDirectory));
        }
Beispiel #3
0
        /// <summary>
        /// Fires the event handlers for a file being created.
        /// </summary>
        /// <param name="fileName">The name of the file being created. This should be a fully qualified path.</param>
        /// <param name="isDirectory">Set to true if this is a directory</param>
        /// <returns>True if the operation can proceed, false if an event handler cancelled the operation.</returns>
        public bool FireFileReplacing(string fileName, bool isDirectory)
        {
            var e = new FileCancelEventArgs(fileName, isDirectory);

            if (FileReplacing != null)
            {
                FileReplacing(this, e);
            }
            return(!e.Cancel);
        }