internal static void GetDataFromFunctionInterface(Assembly loadedFuncAssembly, string fileName) { var types = GetLoadableTypes(loadedFuncAssembly); foreach (var type in types) { var i = type.GetInterface(nameof(IModPlusFunctionForRenga)); if (i != null) { if (Activator.CreateInstance(type) is IModPlusFunctionForRenga function) { var lf = new LoadedFunction { Name = function.Name, LName = Language.GetFunctionLocalName(function.Name, function.LName), ViewTypes = function.ViewTypes, UiLocation = function.UiLocation, ContextMenuShowCase = function.ContextMenuShowCase, IsAddingToMenuBySelf = function.IsAddingToMenuBySelf, Description = Language.GetFunctionShortDescription(function.Name, function.Description), FullDescription = Language.GetFunctionFullDescription(function.Name, function.FullDescription), FunctionAssembly = loadedFuncAssembly }; LoadedFunctions.Add(lf); } break; } } }
/// <summary> /// Получить реализацию интерфейса IRengaFunction из загруженной функции /// </summary> /// <param name="loadedFunction">Загруженная функция</param> private static IRengaFunction GetImplementRengaFunctionFromLoadedFunction(LoadedFunction loadedFunction) { foreach (var t in loadedFunction.FunctionAssembly.GetTypes()) { var c = t.GetInterface(nameof(IRengaFunction)); if (c != null && Activator.CreateInstance(t) is IRengaFunction function) { return(function); } } return(null); }
/// <summary> /// Вызвать метод Start() для функции, которая не строится в меню /// </summary> /// <param name="rengaApplication">The renga application.</param> /// <param name="loadedFunction">Загруженная функция</param> private static void StartFunction(IApplication rengaApplication, LoadedFunction loadedFunction) { var f = GetImplementRengaFunctionFromLoadedFunction(loadedFunction); try { f.Start(); } catch (Exception exception) { rengaApplication.UI.ShowMessageBox(MessageIcon.MessageIcon_Error, "ModPlus", exception.Message + Environment.NewLine + exception.StackTrace); } }
/// <summary> /// Gets the action for function. /// </summary> /// <param name="rengaApplication">The renga application.</param> /// <param name="actionEventSources">The action event sources.</param> /// <param name="loadedFunction">The loaded function.</param> /// <param name="isForContextMenu">if set to <c>true</c> [is for context menu].</param> /// <param name="isForDropDownMenu">if set to <c>true</c> [is for dropdown menu]</param> private static IAction GetActionForFunction( IApplication rengaApplication, List <ActionEventSource> actionEventSources, LoadedFunction loadedFunction, bool isForContextMenu, bool isForDropDownMenu) { var f = GetImplementRengaFunctionFromLoadedFunction(loadedFunction); if (f != null) { var action = rengaApplication.UI.CreateAction(); var extractedImageResource = isForContextMenu || isForDropDownMenu ? ExtractResource(loadedFunction.FunctionAssembly, loadedFunction.Name + "_16x16.png") : ExtractResource(loadedFunction.FunctionAssembly, loadedFunction.Name + "_24x24.png"); if (extractedImageResource != null) { var icon = rengaApplication.UI.CreateImage(); icon.LoadFromData(extractedImageResource, ImageFormat.ImageFormat_PNG); action.Icon = icon; } action.DisplayName = isForContextMenu ? "MP:" + loadedFunction.LName : loadedFunction.LName; var actionEventSource = new ActionEventSource(action); actionEventSource.Triggered += (s, a) => { try { f.Start(); } catch (Exception exception) { rengaApplication.UI.ShowMessageBox(MessageIcon.MessageIcon_Error, "ModPlus", exception.Message + Environment.NewLine + exception.StackTrace); } }; actionEventSources.Add(actionEventSource); return(action); } return(null); }
private static IAction GetActionForButtonInActionPanel(IApplication rengaApplication, List <ActionEventSource> actionEventSources, LoadedFunction loadedFunction) { var f = GetImplementRengaFunctionFromLoadedFunction(loadedFunction); if (f != null) { var action = rengaApplication.UI.CreateAction(); var extractedImageResource = ExtractResource(loadedFunction.FunctionAssembly, loadedFunction.Name + "_24x24.png"); if (extractedImageResource != null) { var icon = rengaApplication.UI.CreateImage(); icon.LoadFromData(extractedImageResource, ImageFormat.ImageFormat_PNG); action.Icon = icon; } action.ToolTip = loadedFunction.LName; var actionEventSource = new ActionEventSource(action); actionEventSource.Triggered += (s, a) => { try { f.Start(); } catch (Exception exception) { rengaApplication.UI.ShowMessageBox(MessageIcon.MessageIcon_Error, "ModPlus", exception.Message + Environment.NewLine + exception.StackTrace); } }; actionEventSources.Add(actionEventSource); return(action); } return(null); }
/// <summary> /// Чтение данных из интерфейса функции /// </summary> /// <param name="loadedFuncAssembly">Load assembly</param> public static void GetDataFromFunctionInterface(Assembly loadedFuncAssembly) { // Есть два интерфейса - старый и новый. Нужно учесть оба var types = GetLoadableTypes(loadedFuncAssembly); foreach (var type in types) { var modplusInterface = type.GetInterface(nameof(IModPlusFunctionInterface)); if (modplusInterface != null) { if (Activator.CreateInstance(type) is IModPlusFunctionInterface function) { var lf = new LoadedFunction { Name = function.Name, LName = function.LName, Description = function.Description, CanAddToRibbon = function.CanAddToRibbon, SmallIconUrl = $"pack://application:,,,/{loadedFuncAssembly.GetName().FullName};component/Resources/{function.Name}_16x16.png", SmallDarkIconUrl = GetSmallDarkIcon(loadedFuncAssembly, function.Name), BigIconUrl = $"pack://application:,,,/{loadedFuncAssembly.GetName().FullName};component/Resources/{function.Name}_32x32.png", BigDarkIconUrl = GetBigDarkIcon(loadedFuncAssembly, function.Name), AvailProductExternalVersion = VersionData.CurrentCadVersion, FullDescription = function.FullDescription, ToolTipHelpImage = !string.IsNullOrEmpty(function.ToolTipHelpImage) ? $"pack://application:,,,/{loadedFuncAssembly.GetName().FullName};component/Resources/Help/{function.ToolTipHelpImage}" : string.Empty, SubFunctionsNames = function.SubFunctionsNames, SubFunctionsLNames = function.SubFunctionsLames, SubDescriptions = function.SubDescriptions, SubFullDescriptions = function.SubFullDescriptions, SubBigIconsUrl = new List<string>(), SubSmallIconsUrl = new List<string>(), SubHelpImages = new List<string>() }; if (function.SubFunctionsNames != null) { foreach (var subFunctionsName in function.SubFunctionsNames) { lf.SubSmallIconsUrl.Add( $"pack://application:,,,/{loadedFuncAssembly.GetName().FullName};component/Resources/{subFunctionsName}_16x16.png"); lf.SubSmallDarkIconsUrl.Add(GetSmallDarkIcon(loadedFuncAssembly, subFunctionsName)); lf.SubBigIconsUrl.Add( $"pack://application:,,,/{loadedFuncAssembly.GetName().FullName};component/Resources/{subFunctionsName}_32x32.png"); lf.SubBigDarkIconsUrl.Add(GetBigDarkIcon(loadedFuncAssembly, subFunctionsName)); } } if (function.SubHelpImages != null) { foreach (var helpImage in function.SubHelpImages) { lf.SubHelpImages.Add( !string.IsNullOrEmpty(helpImage) ? $"pack://application:,,,/{loadedFuncAssembly.GetName().FullName};component/Resources/Help/{helpImage}" : string.Empty); } } LoadedFunctions.Add(lf); } break; } } }