コード例 #1
0
        /// <summary>Updates <paramref name="plugin" /></summary>
        /// <param name="plugin">The plugin to update</param>
        /// <returns></returns>
        private async Task PluginUpdateAsync(LocalPluginPackage <PluginMetadata> plugin)
        {
            bool success = false;

            try
            {
                Status = PluginManagerStatus.Update;

                OperationLogs.Clear();
                PluginMgr.AddLogger(LogOperationOutput);

                using (CancellationTokenSource = new CancellationTokenSource())
                    if ((success = await PluginMgr.UpdatePluginAsync(plugin,
                                                                     plugin.SelectedVersion,
                                                                     EnablePrerelease,
                                                                     CancellationTokenSource.Token)
                                   .ConfigureAwait(true)) == false)
                    {
                        return;
                    }

                await PluginMgr.StartPlugin(PluginInstances.FirstOrDefault(pi => pi.Package == plugin)).ConfigureAwait(true);
            }
            catch (InvalidOperationException ex1) when(ex1.InnerException is NuGetProtocolException)
            {
                success = false;
            }
            catch (InvalidOperationException ex2) when(ex2.InnerException is OperationCanceledException)
            {
                success = true;
            }
            finally
            {
                PluginMgr.RemoveLogger(LogOperationOutput);
                CancellationTokenSource = null;

                Status = success ? PluginManagerStatus.Display : PluginManagerStatus.Update;
            }
        }
コード例 #2
0
 /// <summary>
 ///     Given an instance name string, return the matching instance of IPluginInstance.
 /// </summary>
 /// <param name="instanceName">The name of the instance to find.</param>
 /// <param name="pluginType">The Type of instance to find.</param>
 /// <returns>The instance of IPluginInstance matching the requested InstanceName.</returns>
 public IPluginInstance FindPluginInstance(string instanceName, PluginType pluginType = PluginType.Connector)
 {
     return(PluginInstances.Where(p => p.PluginType == pluginType).Where(p => p.InstanceName == instanceName).FirstOrDefault());
 }
コード例 #3
0
 /// <summary>Removes the plugin from the plugin registry.</summary>
 /// <returns>The plugin.</returns>
 /// <param name="assembly">Assembly.</param>
 public bool RemovePlugin(Assembly assembly) => RemovePlugin(PluginInstances.FirstOrDefault(x => x.GetType().Assembly == assembly));
コード例 #4
0
 /// <summary>
 /// Attempts to get a plugin instance via the name of the plugin.
 /// </summary>
 /// <param name="pluginName">The plugin name to check against.</param>
 /// <returns></returns>
 public IPlugin GetPlugin(string pluginName) => PluginInstances.FirstOrDefault(x => x.PluginName.ToLowerInvariant() == pluginName.ToLowerInvariant());
コード例 #5
0
 /// <summary>
 /// Gets a value indicating whether a specific plugin has been loaded in to
 /// memory or not.
 /// </summary>
 /// <param name="pluginName">The plugin name to check against.</param>
 /// <returns><code>true</code> if the plugin was found. <code>false</code> otherwise.</returns>
 public bool HasPlugin(string pluginName) => PluginInstances.Count(x => x.PluginName.ToLowerInvariant() == pluginName.ToLowerInvariant()) == 1;
コード例 #6
0
        private void LoadModule(IConfig config, string modulename)
        {
            string[] modulenameparts = modulename.Split(new char[] { ':' }, 2, StringSplitOptions.None);
            if (modulenameparts.Length < 2)
            {
                m_Log.FatalFormat("Invalid Module in section {0}: {1}", config.Name, modulename);
                throw new ConfigurationErrorException();
            }
            string   assemblyname = Path.Combine(InstallationBinPath, "plugins/" + modulenameparts[0] + ".dll");
            Assembly assembly;

            try
            {
                assembly = Assembly.LoadFrom(assemblyname);
            }
            catch
            {
                m_Log.FatalFormat("Failed to load module {0}", assemblyname);
                throw new ConfigurationErrorException();
            }

            InterfaceVersionAttribute loadedVersion = GetInterfaceVersion(assembly);

            if (loadedVersion.Version != m_OwnInterfaceVersion.Version)
            {
                m_Log.FatalFormat("Failed to load module {0}: interface version mismatch: {2} != {1}", assemblyname, m_OwnInterfaceVersion, loadedVersion);
                throw new ConfigurationErrorException();
            }

            /* try to load class from assembly */
            Type t;

            try
            {
                t = FindPluginInAssembly(assembly, modulenameparts[1]);
            }
            catch (Exception e)
            {
                m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}", assemblyname, modulenameparts[1], e.Message);
                throw new ConfigurationErrorException();
            }

            if (t == null)
            {
                m_Log.FatalFormat("Failed to load factory for {1} in module {0}: factory not found", assemblyname, modulenameparts[1]);
                throw new ConfigurationErrorException();
            }

            Type[] interfaces = t.GetInterfaces();
            /* check type inheritance first */
            if (interfaces.Contains(typeof(IPlugin)))
            {
                ConstructorInfo ci;
                if ((ci = t.GetConstructor(new Type[] { typeof(IConfig) })) != null)
                {
                    try
                    {
                        PluginInstances.Add(config.Name, (IPlugin)ci.Invoke(new object[] { config }));
                    }
                    catch (TargetInvocationException e)
                    {
#if DEBUG
                        if (e.InnerException != null)
                        {
                            m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}: {3}\n{4}", assemblyname, modulenameparts[1], e.InnerException.GetType().FullName, e.InnerException.Message, e.InnerException.StackTrace);
                        }
                        else
                        {
                            m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}: {3}\n{4}", assemblyname, modulenameparts[1], e.GetType().FullName, e.Message, e.StackTrace);
                        }
#else
                        if (e.InnerException != null)
                        {
                            m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}: {3}", assemblyname, modulenameparts[1], e.InnerException.GetType().FullName, e.InnerException.Message);
                        }
                        else
                        {
                            m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}: {3}", assemblyname, modulenameparts[1], e.GetType().FullName, e.Message);
                        }
#endif
                        throw new ConfigurationErrorException();
                    }
                }
                else if ((ci = t.GetConstructor(new Type[] { typeof(ConfigurationLoader), typeof(IConfig) })) != null)
                {
                    try
                    {
                        PluginInstances.Add(config.Name, (IPlugin)ci.Invoke(new object[] { this, config }));
                    }
                    catch (TargetInvocationException e)
                    {
                        if (e.InnerException != null)
                        {
                            m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}: {3}", assemblyname, modulenameparts[1], e.InnerException.GetType().FullName, e.InnerException.Message);
                        }
                        else
                        {
                            m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}: {3}", assemblyname, modulenameparts[1], e.GetType().FullName, e.Message);
                        }
                        throw new ConfigurationErrorException();
                    }
                }
                else if ((ci = t.GetConstructor(new Type[] { typeof(ConfigurationLoader) })) != null)
                {
                    try
                    {
                        PluginInstances.Add(config.Name, (IPlugin)ci.Invoke(new object[] { this }));
                    }
                    catch (TargetInvocationException e)
                    {
                        if (e.InnerException != null)
                        {
                            m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}: {3}", assemblyname, modulenameparts[1], e.InnerException.GetType().FullName, e.InnerException.Message);
                        }
                        else
                        {
                            m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}: {3}", assemblyname, modulenameparts[1], e.GetType().FullName, e.Message);
                        }
                        throw new ConfigurationErrorException();
                    }
                }
                else if ((ci = t.GetConstructor(Type.EmptyTypes)) != null)
                {
                    try
                    {
                        PluginInstances.Add(config.Name, (IPlugin)ci.Invoke(new object[0]));
                    }
                    catch (TargetInvocationException e)
                    {
                        if (e.InnerException != null)
                        {
                            m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}: {3}", assemblyname, modulenameparts[1], e.InnerException.GetType().FullName, e.InnerException.Message);
                        }
                        else
                        {
                            m_Log.FatalFormat("Failed to load factory for {1} in module {0}: {2}: {3}", assemblyname, modulenameparts[1], e.GetType().FullName, e.Message);
                        }
                        throw new ConfigurationErrorException();
                    }
                }
                else
                {
                    m_Log.FatalFormat("Failed to load factory for {1} in module {0}: plugin does not have a suitable constructor", assemblyname, modulenameparts[1]);
                    throw new ConfigurationErrorException();
                }
            }
            else
            {
                m_Log.FatalFormat("Failed to load factory for {1} in module {0}: not a factory", assemblyname, modulenameparts[1]);
                throw new ConfigurationErrorException();
            }
        }