本文整理汇总了C#中FileAction类的典型用法代码示例。如果您正苦于以下问题:C# FileAction类的具体用法?C# FileAction怎么用?C# FileAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileAction类属于命名空间,在下文中一共展示了FileAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleAction
public void HandleAction(string input, FileAction action)
{
switch (action)
{
case FileAction.NewFolder:
{
Directory.CreateDirectory(comboDrive.Text + txtAddress.Text + input);
ProcessDirectories(new DirectoryInfo(comboDrive.Text + txtAddress.Text));
break;
}
case FileAction.NewFile:
{
File.Create(comboDrive.Text + txtAddress.Text + input);
ProcessDirectories(new DirectoryInfo(comboDrive.Text + txtAddress.Text));
break;
}
case FileAction.Delete:
{
if (input.ToLower() == listDir.SelectedItems[0].Text.ToLower())
{
if (Directory.Exists(comboDrive.Text + txtAddress.Text + listDir.SelectedItems[0].Text))
Directory.Delete(comboDrive.Text + txtAddress.Text + listDir.SelectedItems[0].Text);
else if (File.Exists(comboDrive.Text + txtAddress.Text + listDir.SelectedItems[0].Text))
File.Delete(comboDrive.Text + txtAddress.Text + listDir.SelectedItems[0].Text);
}
else
MessageBox.Show("Error: File/Directory does not exsist.");
ProcessDirectories(new DirectoryInfo(comboDrive.Text + txtAddress.Text));
break;
}
}
}
示例2: OnFileAction
/// <summary>
/// Gets called after a file action was perforem for example after a rename or copy.
/// </summary>
/// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
/// <param name="action">File action type.</param>
/// <param name="file1">File object 1 for example from in a copy operation.</param>
/// <param name="file2">File object 2 for example to in a copy operation. Might be null in for example a delete.</param>
/// <returns>true/false if the execution of the event chain should continue execution.</returns>
public override bool OnFileAction(ManagerEngine man, FileAction action, IFile file1, IFile file2)
{
if (action != FileAction.Add)
return true;
HttpResponse response = HttpContext.Current.Response;
HttpRequest request = HttpContext.Current.Request;
HttpCookie cookie;
ArrayList chunks;
if ((cookie = request.Cookies["upl"]) == null)
cookie = new HttpCookie("upl");
cookie.Expires = DateTime.Now.AddDays(30);
if (cookie.Value != null) {
chunks = new ArrayList(cookie.Value.Split(new char[]{','}));
if (chunks.IndexOf(man.EncryptPath(file1.AbsolutePath)) == -1)
chunks.Add(man.EncryptPath(file1.AbsolutePath));
cookie.Value = this.Implode(chunks, ",");
} else
cookie.Value = man.EncryptPath(file1.AbsolutePath);
response.Cookies.Remove("upl");
response.Cookies.Add(cookie);
return true;
}
示例3: ApplyTo
public void ApplyTo(string startDir, IEnumerable<string> filters, FileAction action)
{
var enumerable = filters as IList<string> ?? filters.ToList();
foreach (var filter in enumerable)
{
var files = EnumerateFiles(startDir, filter);
if (files == null)
return;
foreach (var file in files)
{
action(file);
}
} try
{
foreach (var directory in Directory.GetDirectories(startDir))
{
ApplyTo(directory, enumerable, action);
}
}
catch (Exception)
{
return;
}
}
示例4: OnFileChange
private void OnFileChange(FileAction action, string fileName, long ticks)
{
DateTime minValue;
if (ticks == 0L)
{
minValue = DateTime.MinValue;
}
else
{
minValue = DateTimeUtil.FromFileTimeToUtc(ticks);
}
if (action == FileAction.Dispose)
{
if (this._rootCallback.IsAllocated)
{
this._rootCallback.Free();
}
}
else if (this._ndirMonCompletionHandle.Handle != IntPtr.Zero)
{
using (new ApplicationImpersonationContext())
{
this._dirMon.OnFileChange(action, fileName, minValue);
}
}
}
示例5: SaveOperationAsyncResult
internal SaveOperationAsyncResult(StorageDevice device, string container, string file, FileAction action, FileMode mode)
{
this.storageDevice = device;
this.containerName = container;
this.fileName = file;
this.fileAction = action;
this.fileMode = mode;
}
示例6: saveBtn_Click
private void saveBtn_Click(object sender, RoutedEventArgs e)
{
var type = (FileAction.ActionType)Enum.Parse(typeof(FileAction.ActionType), operationCmb.Text);
var action = new FileAction(type, new FileAction.ActionData() { FileName = fileNameCmb.Text, TargetVar = valueCmb.Text });
var entity = new StepEntity(action);
entity.Comment = string.Format("File Action {0}", operationCmb.Text);
Singleton.Instance<SaveData>().AddStepEntity(entity);
}
示例7: frmInput
public frmInput(frmMain frmObject, string title, string msg, FileAction action)
{
InitializeComponent();
_obj = frmObject;
this.Text = title;
lblInfo.Text = msg;
_action = action;
this.Show();
this.Focus();
}
示例8: ExcludedAction
private static bool ExcludedAction(FileAction fileAction)
{
switch (fileAction)
{
case FileAction.Delete:
case FileAction.DeleteFrom:
case FileAction.DeleteInto:
case FileAction.MoveDelete:
case FileAction.Purge:
return true;
default:
return false;
}
}
示例9: OnBeforeFileAction
/// <summary>
///
/// </summary>
/// <param name="man"></param>
/// <param name="action"></param>
/// <param name="file1"></param>
/// <param name="file2"></param>
/// <returns></returns>
public override bool OnBeforeFileAction(ManagerEngine man, FileAction action, IFile file1, IFile file2)
{
ManagerConfig config;
if (action == FileAction.Delete) {
config = file1.Config;
if (config.GetBool("filesystem.delete_format_images", false)) {
ImageUtils.DeleteFormatImages(file1.AbsolutePath, config.Get("upload.format"));
ImageUtils.DeleteFormatImages(file1.AbsolutePath, config.Get("edit.format"));
}
}
return true;
}
示例10: SaveAsync
/// <summary>
/// Saves a file asynchronously.
/// </summary>
/// <param name="containerName">The name of the container in which to save the file.</param>
/// <param name="fileName">The file to save.</param>
/// <param name="saveAction">The save action to perform.</param>
/// <param name="userState">A state object used to identify the async operation.</param>
public void SaveAsync(string containerName, string fileName, FileAction saveAction, object userState)
{
// increment our pending operations count
PendingOperationsIncrement();
// get a FileOperationState and fill it in
FileOperationState state = GetFileOperationState();
state.Container = containerName;
state.File = fileName;
state.Action = saveAction;
state.UserState = userState;
// queue up the work item
ThreadPool.QueueUserWorkItem(DoSaveAsync, state);
}
示例11: Load
/// <summary>
/// Loads a file.
/// </summary>
/// <param name="containerName">Used to match the ISaveDevice interface; ignored by the implementation.</param>
/// <param name="fileName">The file to load.</param>
/// <param name="loadAction">The load action to perform.</param>
/// <returns>True if the load completed without error, false otherwise.</returns>
public bool Load(string containerName, string fileName, FileAction loadAction)
{
if (!Directory.Exists(RootDirectory))
Directory.CreateDirectory(RootDirectory);
string path = Path.Combine(RootDirectory, fileName);
try
{
using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
loadAction(stream);
return true;
}
catch
{
return false;
}
}
示例12: Save
/// <summary>
/// Saves a file.
/// </summary>
/// <param name="containerName">Used to match the ISaveDevice interface; ignored by the implementation.</param>
/// <param name="fileName">The file to save.</param>
/// <param name="saveAction">The save action to perform.</param>
/// <returns>True if the save completed without errors, false otherwise.</returns>
public bool Save(string containerName, string fileName, FileAction saveAction)
{
if (!Directory.Exists(RootDirectory))
Directory.CreateDirectory(RootDirectory);
string path = Path.Combine(RootDirectory, fileName);
try
{
using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write))
saveAction(stream);
return true;
}
catch
{
return false;
}
}
示例13: Load
/// <summary>
/// Loads a file.
/// </summary>
/// <param name="containerName">The name of the container from which to load the file.</param>
/// <param name="fileName">The file to load.</param>
/// <param name="loadAction">The load action to perform.</param>
public void Load(String containerName, string fileName, FileAction loadAction)
{
VerifyIsReady();
// lock on the storage device so that only one storage operation can occur at a time
lock (storageDevice)
{
// open a container
using (StorageContainer currentContainer = OpenContainer(containerName))
{
// attempt the load
using (var stream = currentContainer.OpenFile(fileName, FileMode.Open))
{
loadAction(stream);
}
}
}
}
示例14: Save
/// <summary>
/// Saves a file.
/// </summary>
/// <param name="containerName">The name of the container in which to save the file.</param>
/// <param name="fileName">The file to save.</param>
/// <param name="saveAction">The save action to perform.</param>
public void Save(string containerName, string fileName, FileAction saveAction)
{
VerifyIsReady();
// lock on the storage device so that only one storage operation can occur at a time
lock (storageDevice)
{
// open a container
using (StorageContainer currentContainer = OpenContainer(containerName))
{
// attempt the save
using (var stream = currentContainer.CreateFile(fileName))
{
saveAction(stream);
}
}
}
}
示例15: ChooseFile
/// <summary>
/// Asks the user to choose a file through an OpenFileDialog
/// </summary>
/// <param name="action">The action we want to do with the file</param>
/// <returns>The file name chosen by the user</returns>
public string ChooseFile(FileAction action)
{
FileDialog fileDialog;
switch (action)
{
case FileAction.Save:
fileDialog = new SaveFileDialog();
break;
case FileAction.Open:
fileDialog = new OpenFileDialog();
break;
default:
throw new ArgumentException("The argument should be a valid FileAction enum value.", "action");
}
fileDialog.ShowDialog();
return fileDialog.FileName;
}