예제 #1
0
 internal PluginMethod(string name, Type discovery, ServerPlugin plugin, ResultConverter result, System.Reflection.MethodInfo method, DataExtractor[] extractors, Description description) : base(discovery, name, description == null ? "" : description.value())
 {
     this._plugin     = plugin;
     this._result     = result;
     this._method     = method;
     this._extractors = extractors;
 }
예제 #2
0
        public override PluginPoint CreateFrom(ServerPlugin plugin, System.Reflection.MethodInfo method, Type discovery)
        {
            ResultConverter result = ResultConverter.Get(method.GenericReturnType);

            Type[]          types           = method.GenericParameterTypes;
            Annotation[][]  annotations     = method.ParameterAnnotations;
            SourceExtractor sourceExtractor = null;

            DataExtractor[] extractors = new DataExtractor[types.Length];
            for (int i = 0; i < types.Length; i++)
            {
                Description description = null;
                Parameter   param       = null;
                Source      source      = null;
                foreach (Annotation annotation in annotations[i])
                {
                    if (annotation is Description)
                    {
                        description = ( Description )annotation;
                    }
                    else if (annotation is Parameter)
                    {
                        param = ( Parameter )annotation;
                    }
                    else if (annotation is Source)
                    {
                        source = ( Source )annotation;
                    }
                }
                if (param != null && source != null)
                {
                    throw new System.InvalidOperationException(string.Format("Method parameter {0:D} of {1} cannot be retrieved as both Parameter and Source", Convert.ToInt32(i), method));
                }
                else if (source != null)
                {
                    if (types[i] != discovery)
                    {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                        throw new System.InvalidOperationException("Source parameter type (" + types[i] + ") must equal the discovery type (" + discovery.FullName + ").");
                    }
                    if (sourceExtractor != null)
                    {
                        throw new System.InvalidOperationException("Server Extension methods may have at most one Source parameter.");
                    }
                    extractors[i] = sourceExtractor = new SourceExtractor(source, description);
                }
                else if (param != null)
                {
                    extractors[i] = ParameterExtractor(types[i], param, description);
                }
                else
                {
                    throw new System.InvalidOperationException("Parameters of Server Extension methods must be annotated as either Source or Parameter.");
                }
            }
            return(new PluginMethod(NameOf(method), discovery, plugin, result, method, extractors, method.getAnnotation(typeof(Description))));
        }
예제 #3
0
        public DefaultPluginManager(LogProvider logProvider)
        {
            IDictionary <string, Pair <ServerPlugin, ServerExtender> > extensions = new Dictionary <string, Pair <ServerPlugin, ServerExtender> >();
            Log log = logProvider.getLog(this.GetType());
            IEnumerable <ServerPlugin> loadedPlugins = ServerPlugin.Load();

            foreach (ServerPlugin plugin in loadedPlugins)
            {
                PluginPointFactory factory = new PluginPointFactoryImpl();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ServerExtender extender = new ServerExtender(factory);
                ServerExtender extender = new ServerExtender(factory);
                try
                {
                    plugin.LoadServerExtender(extender);
                }
                catch (Exception ex) when(ex is Exception || ex is LinkageError)
                {
                    log.Warn("Failed to load plugin [%s]: %s", plugin.ToString(), ex.Message);
                    continue;
                }
                Pair <ServerPlugin, ServerExtender> old = extensions[plugin.Name] = Pair.of(plugin, extender);
                if (old != null)
                {
                    log.Warn(string.Format("Extension naming conflict \"{0}\" between \"{1}\" and \"{2}\"", plugin.Name, old.First().GetType(), plugin.GetType()));
                }
            }
            foreach (Pair <ServerPlugin, ServerExtender> extension in extensions.Values)
            {
                log.Info(string.Format("Loaded server plugin \"{0}\"", extension.First().Name));
                foreach (PluginPoint point in extension.Other().all())
                {
                    log.Info(string.Format("  {0}.{1}: {2}", point.ForType().Name, point.Name(), point.Description));
                }
                this._extensions[extension.First().Name] = extension.Other();
            }
        }
예제 #4
0
 protected internal PluginPoint(Type type, string name, string description)
 {
     this._extendsType = type;
     this._description = string.ReferenceEquals(description, null) ? "" : description;
     this._name        = ServerPlugin.VerifyName(name);
 }