예제 #1
0
 public void Dispose()
 {
     if (_commandRef != default)
     {
         UtilitiesAPI.CommandEnd(_commandRef);
         _commandRef = default;
     }
 }
예제 #2
0
 public CommandExecutionScope(CommandRef commandRef)
 {
     _commandRef = commandRef;
     if (_commandRef != default)
     {
         UtilitiesAPI.CommandBegin(_commandRef);
     }
 }
예제 #3
0
        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);
            }
예제 #4
0
 public CommandDisposableScope(CommandRef commandRef)
 {
     _commandRef = commandRef;
     UtilitiesAPI.CommandBegin(_commandRef);
 }