Exemple #1
0
 public PluginInstance(
     int sourceIndex, Assembly asm, Type plugType, IAasxPluginInterface plugObj, string[] args)
 {
     this.SourceIndex = sourceIndex;
     this.asm         = asm;
     this.plugType    = plugType;
     this.plugObj     = plugObj;
     this.args        = args;
 }
Exemple #2
0
        public static void TryActivatePlugins(List <OptionsInformation.PluginDllInfo> pluginDll)
        {
            for (int index = 0; index < pluginDll.Count; index++)
            {
                try
                {
                    Log.Info("Trying load .dll at {0}", pluginDll[index].Path);

                    // make full path
                    var fullfn = System.IO.Path.GetFullPath(pluginDll[index].Path);

                    // Note: use LoadFrom instead of LoadFile, insane:
                    // https://stackoverflow.com/questions/36075829/
                    // assembly-loadfile-look-dependencies-in-location-of-executeable
                    var asm = Assembly.LoadFrom(fullfn);

                    var tp = asm.GetType("AasxIntegrationBase.AasxPlugin");
                    if (tp == null)
                    {
                        Log.Error("Cannot find class AasxIntegrationBase.AasxPlugin within .dll.");
                        continue;
                    }

                    // create instance using late binding
                    IAasxPluginInterface ob = (IAasxPluginInterface)Activator.CreateInstance(tp);
                    if (ob == null)
                    {
                        Log.Error("Cannot create instance from class AasxIntegrationBase.AasxPlugin within .dll.");
                        continue;
                    }

                    // create plugin
                    var pi = PluginInstance.CreateNew(index, asm, tp, ob, pluginDll[index].Args);
                    if (pi == null)
                    {
                        Log.Error(
                            "Cannot invoke methods within instance from " +
                            "class AasxIntegrationBase.AasxPlugin within .dll.");
                        continue;
                    }

                    // init plug-in
                    var singleArg = new object[] { pluginDll[index].Args };
                    pi.BasicInvokeMethod("InitPlugin", singleArg);

                    // adding
                    Log.Info(".. adding plugin {0}", pi.name);
                    LoadedPlugins.Add(pi.name, pi);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, $"Trying activate plugin index {index}");
                }
            }
        }
Exemple #3
0
            public static PluginInstance CreateNew(
                int sourceIndex, Assembly asm, Type plugType, IAasxPluginInterface plugObj, string[] args)
            {
                var pi = new PluginInstance(sourceIndex, asm, plugType, plugObj, args);

                pi.name    = pi.GetName();
                pi.actions = pi.ListActions();
                if (pi.name == null || pi.actions == null || pi.actions.Length < 1)
                {
                    return(null);
                }
                return(pi);
            }