public Worker(ref App x, ref IPlugin plg, ref PluginContext ctx, ref ManualResetEvent rev) { cApp = x; cPlugin = plg; cPluginContext = ctx; cResetEvent = rev; }
public string PluginExecute(string sPluginName, string sFileName, string sCommands, string sIncludedXml) { bool bErrors = false; string sResults = ""; IPlugin hPlugin; foreach (IPlugin plugin in App.m_plugins) { hPlugin = plugin; //We add a small ampersand at the start of the name //so we can get shortcut key strokes for it if (plugin.Name.ToLower() == sPluginName.ToLower()) { //Console.Error.Write("{0} {1}", '\x0d', '\x0d'); //Console.WriteLine(DateTime.Now.ToString("yyMMdd-HH:mm") + " W Executing plug-in: {0} for file: {1}", plugin.Name, App.MXGetOnlyFileName(sFileName)); // start worker thread ManualResetEvent manualEvent = new ManualResetEvent(false); PluginContext myContext = new PluginContext(sCommands, sIncludedXml, sResults); if (myContext.sCommands.StartsWith("<![CDATA[")) { myContext.sCommands = myContext.sCommands.Substring("<![CDATA[".Length); myContext.sCommands = myContext.sCommands.Substring(0, myContext.sCommands.Length - "]]>".Length); } myContext.sCommands = myContext.sCommands.Trim(); Worker WorkerClass = new Worker(ref cApp, ref hPlugin, ref myContext, ref manualEvent); Thread thWorker = new Thread(new ThreadStart(WorkerClass.Main)); thWorker.Start(); manualEvent.WaitOne(hPlugin.MaxWorktime * 1000, false); if (myContext.sResults != "") { sResults = myContext.sResults; } else { thWorker.Abort(); bErrors = true; //Console.Error.WriteLine("Results = {0}", myContext.sResults); sResults = "Fatal Error: Plug-In was running longer than allowed (" + string.Format("{0}", hPlugin.MaxWorktime) + "s)"; } break; /* DateTime dFrom, dTo; TimeSpan tSpan; dFrom = DateTime.Now; bool bAbort = false; for (; ; ) { dTo = DateTime.Now; tSpan = -dFrom.Subtract(dTo); if (tSpan.TotalSeconds > hPlugin.MaxWorktime) { bAbort = true; break; } Thread.Sleep(250); if (thWorker.ThreadState == ThreadState.Stopped) { bAbort = false; break; } } break; */ } } return (sResults); }