/// <summary> /// Called after the plugin process has been started, and connection has been made with /// this Plugin Manager instance Always call this base method if it is inherited. /// </summary> /// <param name="pluginInstance">The connected plugin instance</param> /// <param name="plugin">The connected plugin service</param> protected virtual void OnPluginConnected(TPluginInstance pluginInstance, IPlugin plugin) { LogTo.Information($"Connected {pluginInstance.Denomination} {pluginInstance.Package.Id}."); UISynchronizationContext.Send(_ => { pluginInstance.OnConnected(plugin); }, null); }
/// <summary> /// Attempts to update plugin <paramref name="packageId" />. If no /// <paramref name="version" /> is specified, the latest available version will be installed. /// </summary> /// <param name="packageId">The plugin package id to update</param> /// <param name="version">Optional version to install</param> /// <param name="allowPrereleaseVersions">Whether to include pre-release versions</param> /// <param name="cancellationToken"></param> /// <returns>Success of operation</returns> /// <exception cref="ArgumentException"><paramref name="packageId" /> is empty</exception> /// <exception cref="ArgumentException">Plugin <paramref name="packageId" /> is not installed</exception> /// <exception cref="ArgumentNullException"></exception> public async Task <bool> UpdatePluginAsync( string packageId, NuGetVersion version = null, bool allowPrereleaseVersions = false, CancellationToken cancellationToken = default) { var pluginInstance = AllPlugins.FirstOrDefault(pi => pi.Package.Id == packageId); if (await StopPlugin(pluginInstance) == false) { LogAdapter.Warning($"Failed to stop plugin {packageId}, aborting update."); return(false); } using (await PMLock.WriterLockAsync()) { var success = await PackageManager.UpdateAsync( packageId, version, allowPrereleaseVersions, cancellationToken); UISynchronizationContext.Send(() => PackageManager.FindInstalledPluginById(packageId)?.RaiseVersionChanged()); return(success); } }
private void DoPrint(IBackgroundTaskContext context) { try { if (_selectPresentationsInformations == null || _selectPresentationsInformations.Count == 0) { return; } Thread.Sleep(20); BackgroundTaskReportStatus(context, "Dicom打印开始", 0); Thread.Sleep(10); BackgroundTaskReportStatus(context, "开始处理图像...", 0); Thread.Sleep(10); //UISynchronizationContext.Send(DoImageProcess, null); DoImageProcess(null); if (_selectPresentationsInformations.Count == 0) { BackgroundTaskReportStatus(context, "处理图像处理结果为0", 0); return; } BackgroundTaskReportStatus(context, "开始向打印机发送图像", 0); Thread.Sleep(10); PrintScu scu = new PrintScu(); DicomPrintProgressUpdate progressUpdate = new DicomPrintProgressUpdate(); progressUpdate.dicomPrintManager = this; progressUpdate.printScu = scu; progressUpdate.Task = context; scu.ProgressUpdated += progressUpdate.Update; _dicomPrintSession = new DicomPrintSession(DicomPrinter, new SelectPresentationsInformationsCollection(_selectPresentationsInformations)); PrintScu.FilmSession filmSession = DicomPrintSession.GetFilmSession(_dicomPrintSession.SelectPresentationsCollection, _dicomPrintSession.DicomPrinter.Config); DicomState dicomState = scu.Print("MacroAETile", _dicomPrintSession.DicomPrinter.AETitle, _dicomPrintSession.DicomPrinter.Host, _dicomPrintSession.DicomPrinter.Port, filmSession); scu.Join(); if (dicomState == DicomState.Success) { //UpDicomPrintStatus(context); if (_dicomPrintComponent != null) { UISynchronizationContext.Send(_dicomPrintComponent.PrintedDeleteImage, this); } } } catch (Exception e) { Platform.Log(LogLevel.Debug, e); BackgroundTaskReportStatus(context, e.Message, 100); } if (_studyInstanceUid != null) { _studyInstanceUid.Clear(); _studyInstanceUid = null; } GC.Collect(); }
/// <summary> /// Call passed delegate in UIThread Context if available /// </summary> /// <param name="del"></param> /// <param name="value"></param> public static void CallMethodInUISynchronizationContext(SendOrPostCallback del, object value) { if (del != null) { if (UISynchronizationContext != null) { UISynchronizationContext.Send(new System.Threading.SendOrPostCallback(del), value); } else { del(value); } } }
/// <summary> /// Invokes the specified action on the UI thread. Blocking. /// Active message pump required. /// </summary> /// <param name="action">the action to run on UI thread</param> /// <param name="exclusively">avoid overlap with ExecuteOnSameThread</param> private static void InvokeOnUIThread(ThreadStart action, bool exclusively) { if (action == null) { return; } // Run directly if no UI context or if already on UI thread if (OnMainUiThreadOrNoUiContext) { action(); return; } Exception caughtException = null; bool finished = false; // Looping may be necessary to run exclusively while (!finished) { // Wait for the UI Thread UISynchronizationContext.Send(delegate { // If the action is to be run exclusively and if ExecuteOnSameThread is already running, then wait if (exclusively && inExecuteOnSameThread) { return; } try { action(); } catch (Exception exception) { SaveStackTrace(exception); caughtException = exception; } finally { finished = true; } }, null); // We can only get here if we are running exclusively and if ExecuteOnSameThread was running. // Wait for ExecuteOnSameThread to finish if (!finished) { executeOnSameThreadComplete.WaitOne(); } } if (caughtException == null) { return; } // FB25127 - if a UnhandledThreadException handler is present use that rather than // rethrowing the exception. if (UnhandledThreadException != null) { UnhandledThreadException(caughtException); } else { throw caughtException; } }