I'm building one software integration with one old WPF application. This WPF application have an event handler for drop event:
public void Window_Drop(object sender, DragEventArgs e)
{
// Spaghetti code
}
The Window_Drop event take the dropped file, elaborate it and send the result to a web services.
My goal is use the current logic dropping a file inside a specific folder.
I wrote this code:
Watcher class
public class Watcher
{
public delegate void ActionDelegate(string fileName, string fullPath);
private ActionDelegate Action;
private readonly FileSystemWatcher _watcher;
public Watcher(string path)
{
_watcher = new FileSystemWatcher();
_watcher.Path = path;
_watcher.Created += _watcher_Created;
_watcher.EnableRaisingEvents = true;
}
public void SubscribeOnCreate(ActionDelegate action)
{
Action = action;
}
private void _watcher_Created(object sender, FileSystemEventArgs e)
{
Console.WriteLine("Creato " + e.Name);
Action(e.Name, e.FullPath, string.Empty);
}
}
}
App.cs
public partial class App : Application, ISingleInstanceApp
{
private Watcher _watcher;
public App()
{
_watcher = new Watcher(@"C:\Users\Administrator\Desktop\Monitoraggio");
_watcher.SubscribeOnCreate(LoadFile);
}
private void LoadFile(string fileName, string fullPath)
{
var droppedFile = new DragEventArgs(); // How can I build one DragEventArgs object with dropped file?
var currentWindow = MainWindow.AppWindow; // this is a static reference of current MainWindow
a.Window_Drop(this, droppedFile);
}
}
How can I build one vali DragEventArgs manually?
Every suggestion is welcome, Thanks