R
Rechtfertigung
Guest
I have three classes, the FileManagerClass contains two events which are EventHandler<FileTransferEventArgs> FileMove;, and EventHandler<FileTransferEventArgs> FileMoveError;. I then have a custom EventArgs class named FileTransferEventArg that inherits from the base EventArgs class. I then have a third class called FolderDirectoryModel that then listens for the events to be raised and responds to it with either a OnFileMove(object sender, FileTransferEventArg arg) or OnFileMoveError(object sender, FileTransferEventArg arg). My problem is that I would like to use the properties inside my FileTransferEventArgs class to display the file name that was moved and if it was successful or not detailing a reason that will be inside the message property. However when I get every thing wired up im not able to view the data that is passed along. I am not sure if i am improperly using the events or I am trying to do something that is not possible.
class FileTransferManager
{
public event EventHandler<FileTransferEventArgs> FileMove;
public event EventHandler<FileTransferEventArgs> FileMoveError;
}
public class FileTransferEventArgs : EventArgs
{
string FileName { get; set; }
string Message { get; set; }
internal FileTransferEventArgs(FileModel file, string message)
{
this.FileName = file.FileName;
this.Message = message;
}
}
public class FolderDirectoryModel
{
void TransferFile(FileModel toBeTransfered, string destinationPath)
{
if (!File.Exists(toBeTransfered.FilePath))
{
File.Move(toBeTransfered.FilePath, destinationPath);
FileTransferEvents.FileTransferManager TransferAgent = new FileTransferEvents.FileTransferManager();
TransferAgent.FileMove += new EventHandler<FileTransferEventArgs>(OnFileMove);
}
else
{
FileTransferEvents.FileTransferManager TransferAgent = new FileTransferEvents.FileTransferManager();
TransferAgent.FileMoveError += new EventHandler<FileTransferEventArgs>(OnFileMoveError;
}
}
//Handler Methods
private void OnFileMoveError(object sender, FileTransferEventArgs args)
{
//what i want to happen
MessageBox.Show($"File {args.FileName} has not been moved succefully to {args.FilePath} because of....");
}
private void OnFileMove(object sender, FileTransferEventArgs e)
{
//what i want to happen
MessageBox.Show($"File {args.FileName} has been moved successfully to {args.FilePath}
}
}
Recht
Continue reading...
class FileTransferManager
{
public event EventHandler<FileTransferEventArgs> FileMove;
public event EventHandler<FileTransferEventArgs> FileMoveError;
}
public class FileTransferEventArgs : EventArgs
{
string FileName { get; set; }
string Message { get; set; }
internal FileTransferEventArgs(FileModel file, string message)
{
this.FileName = file.FileName;
this.Message = message;
}
}
public class FolderDirectoryModel
{
void TransferFile(FileModel toBeTransfered, string destinationPath)
{
if (!File.Exists(toBeTransfered.FilePath))
{
File.Move(toBeTransfered.FilePath, destinationPath);
FileTransferEvents.FileTransferManager TransferAgent = new FileTransferEvents.FileTransferManager();
TransferAgent.FileMove += new EventHandler<FileTransferEventArgs>(OnFileMove);
}
else
{
FileTransferEvents.FileTransferManager TransferAgent = new FileTransferEvents.FileTransferManager();
TransferAgent.FileMoveError += new EventHandler<FileTransferEventArgs>(OnFileMoveError;
}
}
//Handler Methods
private void OnFileMoveError(object sender, FileTransferEventArgs args)
{
//what i want to happen
MessageBox.Show($"File {args.FileName} has not been moved succefully to {args.FilePath} because of....");
}
private void OnFileMove(object sender, FileTransferEventArgs e)
{
//what i want to happen
MessageBox.Show($"File {args.FileName} has been moved successfully to {args.FilePath}
}
}
Recht
Continue reading...