public static List <DespatchBasePlugin> LoadPlugins(string pluginPath, BaseForm logger, EventHandler resultCallBack) { //1. Get all assemblies in the folder foreach (var filePath in Directory.GetFiles(pluginPath, "*.dll")) { if (!pluginsCache.ContainsKey(filePath) && Path.GetFileName(filePath).ToUpper() != Path.GetFileName(Assembly.GetAssembly(typeof(DespatchBasePlugin)).CodeBase).ToUpper()) { var type = Assembly.LoadFrom(filePath).GetTypes() .FirstOrDefault(t => t.IsClass && t.IsSubclassOf(typeof(DespatchBasePlugin))); if (type != null) { DespatchBasePlugin obj = Activator.CreateInstance(type, new object[] { logger }) as DespatchBasePlugin; obj.OnResultReceived += resultCallBack; pluginsCache.Add(filePath, obj); } } } return(pluginsCache.Values.ToList()); }
void currentPlugin_OnResultReceived(object sender, EventArgs e) { UpdateTextBox(FeedbackTextBox, currentPlugin.Result); if (string.IsNullOrEmpty(currentPlugin.TrackingNumber)) { WriteLog("No tracking number received. Assuming success.", Color.Green); CurrentProcessStatusLabel.Text = "No tracking number received."; } else if (!UpdateTrackingNumber()) { WriteLog("Failed to update tracking number.", Color.Red); CurrentProcessStatusLabel.Text = "Failed to update tracking number."; return; } if (!String.IsNullOrEmpty(Settings.ArchivePath)) FileOperations.ArchiveFile(currentFile, Settings.ArchivePath); else FileOperations.DeleteFile(currentFile); PreviewTextbox.Clear(); FeedbackTextBox.Clear(); CheckButton.Enabled = true; currentPlugin = null; }
private void skipButton_Click(object sender, EventArgs e) { StopAsyncTasks(); //Archive File. if (!String.IsNullOrEmpty(Settings.ArchivePath) && !String.IsNullOrEmpty(currentFile)) FileOperations.ArchiveFile(currentFile, Settings.ArchivePath); else FileOperations.DeleteFile(currentFile); PreviewTextbox.Clear(); FeedbackTextBox.Clear(); CheckButton.Enabled = true; currentPlugin = null; }
private bool ProcessData() { CheckButton.Enabled = false; CurrentProcessStatusLabel.Text = "Checking download for despatch file"; currentFile = FileOperations.GetFirstFileInFolder(Settings.DownloadPath, "*.pvx"); if (!string.IsNullOrEmpty(currentFile)) { WriteLog(string.Format("Reading file {0}", currentFile), Color.Black); //read file var content = FileOperations.ReadFile(currentFile); //Find the right plugin to process. currentPlugin = DespatchPluginFactory.GetPlugin(content); if (currentPlugin == null) { return false; } PreviewTextbox.Text = ""; WriteLog(string.Format("Waiting to be processed by {0}", currentPlugin.PluginName), Color.Black); UpdateTextBox(PreviewTextbox, currentPlugin.GetPreview()); CurrentProcessStatusLabel.Text = "Previewing despatch file for " + currentPlugin.SalesOrderNumber; return true; } PreviewTextbox.Text = ""; CheckButton.Enabled = true; //WriteLog("No file found.", Color.Black); CurrentProcessStatusLabel.Text = "No file found."; if (!AutoCheck.Checked) CheckButton.Enabled = true; return false; }