public void Dispose() { if (_commandRef != default) { UtilitiesAPI.CommandEnd(_commandRef); _commandRef = default; } }
public CommandExecutionScope(CommandRef commandRef) { _commandRef = commandRef; if (_commandRef != default) { UtilitiesAPI.CommandBegin(_commandRef); } }
public static int XPluginStart(ref StartParameters parameters) { GlobalContext.StartupPath = Marshal.PtrToStringUTF8(parameters.StartupPath); var pluginPath = Marshal.PtrToStringUTF8(parameters.PluginPath); if (string.IsNullOrEmpty(pluginPath)) { UtilitiesAPI.DebugString("Plugin path is null." + Environment.NewLine); return(0); } var assemblyPath = Path.ChangeExtension(pluginPath, ".dll"); var currentContext = AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly()); if (!_resolverInitialized) { currentContext.ResolvingUnmanagedDll += ResolveUnmanagedDll; _resolverInitialized = true; } _context = new PluginContext(currentContext, assemblyPath); try { var assembly = _context.LoadFromAssemblyPath(assemblyPath); var attr = assembly.GetCustomAttribute <PluginAttribute>(); if (attr == null) { UtilitiesAPI.DebugString($"Plugin assembly {assemblyPath} does not have '{typeof(PluginAttribute).FullName}' attribute defined.{Environment.NewLine}"); return(0); } _plugin = (PluginBase)Activator.CreateInstance(attr.PluginType); WriteUtf8String(_plugin.Name, parameters.Name); WriteUtf8String(_plugin.Signature, parameters.Sig); WriteUtf8String(_plugin.Description, parameters.Desc); GlobalContext.CurrentPlugin = new WeakReference <PluginBase>(_plugin); return(_plugin.Start() ? 1 : 0); } catch (Exception ex) { UtilitiesAPI.DebugString(ex.ToString()); Unload(); return(0); }
public CommandDisposableScope(CommandRef commandRef) { _commandRef = commandRef; UtilitiesAPI.CommandBegin(_commandRef); }