示例#1
0
        private void ScanService()
        {
            // Scan once and cache
            if (mServiceActions != null)
            {
                return;
            }
            Console.WriteLine("Scanning Service: " + mService.GetType().FullName);
            mServiceActions = new List <ActionHandler>();

            // Register all actions which have 'GingerAction' attribute
            Type t = mService.GetType();
            var  v = t.GetMethods(); //BindingFlags.Public  BindingFlags.DeclaredOnly);

            foreach (MethodInfo MI in v)
            {
                GingerActionAttribute GAA = (GingerActionAttribute)MI.GetCustomAttribute(typeof(GingerActionAttribute));
                if (GAA != null)
                {
                    ActionHandler AH = new ActionHandler();
                    AH.ServiceActionId = GAA.Id;
                    AH.MethodInfo      = MI;
                    AH.Instance        = mService;
                    mServiceActions.Add(AH);

                    Console.WriteLine("Found Action: " + AH.ServiceActionId);
                }
            }
        }
示例#2
0
        public ObservableList <StandAloneAction> GetStandAloneActions()
        {
            ObservableList <StandAloneAction> list = new ObservableList <StandAloneAction>();

            foreach (PluginService pluginService in GetPluginServices())
            {
                foreach (MethodInfo MI in pluginService.mStandAloneMethods)
                {
                    GingerActionAttribute token = (GingerActionAttribute)Attribute.GetCustomAttribute(MI, typeof(GingerActionAttribute), false);
                    StandAloneAction      DA    = new StandAloneAction();
                    DA.ID = token.Id;
                    // AssemblyName AN = MI.DeclaringType.Assembly.GetName();
                    DA.PluginID    = PluginID; //AN.Name;
                    DA.ServiceID   = pluginService.ServiceId;
                    DA.Description = token.Description;
                    foreach (ParameterInfo PI in MI.GetParameters())
                    {
                        if (PI.ParameterType.Name != nameof(GingerAction))
                        {
                            DA.InputValues.Add(new ActionInputValueInfo()
                            {
                                Param = PI.Name, ParamType = PI.ParameterType
                            });
                        }
                    }
                    list.Add(DA);
                }
            }
            return(list);
        }
示例#3
0
        private void LoadGingerPluginsDLL()
        {
            // We make sure our latest in Ginger is the one to load GingerPlugin DLL so it will not be loaded from the folder of the plugin in case some one copied it too, or we point to debug folder

            // Just dummy does nothing except making sure we load the DLL first from inside Ginger
            GingerActionAttribute PIC = new GingerActionAttribute("ID DUMMY", "Desc DUMMY");
        }
示例#4
0
        List <MethodInfo> GetStandAloneMethods()
        {
            ScanPackage();  // do once !!!!!!!!!!!!!!!!!!!!!!
            if (mStandAloneMethods == null)
            {
                mStandAloneMethods = new List <MethodInfo>();
                foreach (PluginAssemblyInfo asssembly in mAssembliesInfo)
                {
                    IEnumerable <Type> types = from x in asssembly.Assembly.GetTypes() where typeof(IStandAloneAction).IsAssignableFrom(x) select x;
                    foreach (Type t in types)
                    {
                        if (t == typeof(IStandAloneAction))
                        {
                            continue;                                  // we ignore the interface itself
                        }
                        // expecting to get ExcelAction, FileAction, DatabaseAction...
                        MethodInfo[] methods = t.GetMethods();
                        foreach (MethodInfo MI in methods)
                        {
                            //Check if method have token [GingerAction]  else we ignore
                            GingerActionAttribute token = (GingerActionAttribute)Attribute.GetCustomAttribute(MI, typeof(GingerActionAttribute), false);

                            if (token == null)
                            {
                                continue;
                            }

                            mStandAloneMethods.Add(MI);
                        }
                    }
                }
            }
            return(mStandAloneMethods);
        }
示例#5
0
        List <PluginService> GetPluginServices()
        {
            ScanPackage();  // do once !!!!!!!!!!!!!!!!!!!!!!
            if (mPluginServices == null)
            {
                mPluginServices = new List <PluginService>();
                foreach (PluginAssemblyInfo asssembly in mAssembliesInfo)
                {
                    IEnumerable <Type> types = from x in asssembly.Assembly.GetTypes() where typeof(IGingerService).IsAssignableFrom(x) select x;
                    foreach (Type t in types)
                    {
                        GingerServiceAttribute gingerServiceAttribute = (GingerServiceAttribute)Attribute.GetCustomAttribute(t, typeof(GingerServiceAttribute), false);
                        PluginService          pluginService          = new PluginService()
                        {
                            ServiceId = gingerServiceAttribute.Id
                        };
                        // expecting to get ExcelAction, FileAction, DatabaseAction...
                        MethodInfo[] methods = t.GetMethods();
                        foreach (MethodInfo MI in methods)
                        {
                            //Check if method have token [GingerAction]  else we ignore
                            GingerActionAttribute token = (GingerActionAttribute)Attribute.GetCustomAttribute(MI, typeof(GingerActionAttribute), false);

                            if (token == null)
                            {
                                continue;
                            }

                            pluginService.mStandAloneMethods.Add(MI);
                        }
                        mPluginServices.Add(pluginService);
                    }
                }
            }
            return(mPluginServices);
        }
示例#6
0
        public ActionHandler GetStandAloneActionHandler(string id)
        {
            if (!Isloaded)
            {
                ScanPackage();
            }
            foreach (MethodInfo MI in GetStandAloneMethods())
            {
                GingerActionAttribute token = (GingerActionAttribute)Attribute.GetCustomAttribute(MI, typeof(GingerActionAttribute), false);
                if (token.ID == id)
                {
                    ActionHandler AH = new ActionHandler();
                    AH.ID         = id;
                    AH.MethodInfo = MI;

                    //TODO: create on demand nad cache to 1
                    AH.Instance     = MI.DeclaringType.Assembly.CreateInstance(MI.DeclaringType.FullName); // !!!!!!!!!!!!
                    AH.GingerAction = new GingerAction(id);
                    // do we need the params?
                    return(AH);
                }
            }
            return(null);
        }
示例#7
0
        void LoadPluginServicesFromDll()
        {
            if (mServices == null)                                    // Done only once
            {
                mServices = new ObservableList <PluginServiceInfo>(); // Move down !!!!!!!!!!!!!!!
                foreach (PluginAssemblyInfo pluginAssemblyInfo in mAssembliesInfo)
                {
                    var types2 = pluginAssemblyInfo.Assembly.GetExportedTypes();
                    IEnumerable <Type> types = from x in pluginAssemblyInfo.Assembly.GetTypes() where x.GetCustomAttribute(typeof(GingerServiceAttribute)) != null select x;
                    foreach (Type type in types)
                    {
                        GingerServiceAttribute gingerServiceAttribute = (GingerServiceAttribute)Attribute.GetCustomAttribute(type, typeof(GingerServiceAttribute), false);
                        bool IsServiceSession = typeof(IServiceSession).IsAssignableFrom(type);
                        // if service impl IServiceSession then mark it so we know we need and agent Start/Stop
                        // if it is not session , then all actions are stand alone

                        PluginServiceInfo pluginServiceInfo = new PluginServiceInfo()
                        {
                            ServiceId = gingerServiceAttribute.Id, IsSession = IsServiceSession
                        };
                        // expecting to get ExcelAction, FileAction, DatabaseAction...
                        MethodInfo[] methods    = type.GetMethods();
                        Type[]       interfaces = type.GetInterfaces();
                        foreach (MethodInfo MI in methods)
                        {
                            //Check if method have token [GingerAction] or is is of interface else we ignore
                            GingerActionAttribute gingerActionAttr = (GingerActionAttribute)Attribute.GetCustomAttribute(MI, typeof(GingerActionAttribute), false);

                            if (gingerActionAttr == null && !MI.IsVirtual)   // Virtual if it is interface
                            {
                                continue;
                            }


                            PluginServiceActionInfo action = new PluginServiceActionInfo();

                            if (gingerActionAttr != null)
                            {
                                action.ActionId    = gingerActionAttr.Id;
                                action.Description = gingerActionAttr.Description;
                            }
                            else
                            {
                                // Check if the method is from interface
                                if (MI.IsVirtual)
                                {
                                    foreach (Type serviceInterface in interfaces)
                                    {
                                        /// !!!!!!!!!!!!! see new style and remove !!!!!!!!!!!!!!!!
                                        // Not sure if we need to list all method if they come from interface !!!!!!!!!!!!!! need to list only the interface

                                        //check if marked with [GingerInterface]
                                        GingerInterfaceAttribute gingerInterfaceAttr = (GingerInterfaceAttribute)Attribute.GetCustomAttribute(serviceInterface, typeof(GingerInterfaceAttribute), false);

                                        if (gingerInterfaceAttr != null)
                                        {
                                            var mm = serviceInterface.GetMethod(MI.Name);
                                            if (mm != null)
                                            {
                                                // Get the action id and desc from the interface
                                                action.Interface = serviceInterface.FullName;

                                                GingerActionAttribute interfaceGAAttr = (GingerActionAttribute)Attribute.GetCustomAttribute(mm, typeof(GingerActionAttribute), false);
                                                if (interfaceGAAttr == null)
                                                {
                                                    // no GA attr then ignore
                                                    continue;
                                                }
                                                else
                                                {
                                                    action.ActionId    = interfaceGAAttr.Id;
                                                    action.Description = interfaceGAAttr.Description;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (string.IsNullOrEmpty(action.ActionId))
                            {
                                continue;
                            }

                            foreach (ParameterInfo PI in MI.GetParameters())
                            {
                                if (PI.ParameterType.Name == nameof(IGingerAction))
                                {
                                    continue;
                                }

                                ActionInputValueInfo actionInputValueInfo = new ActionInputValueInfo()
                                {
                                    Param = PI.Name, ParamType = PI.ParameterType
                                };
                                actionInputValueInfo.ParamAttrs = new List <Attribute>();
                                action.InputValues.Add(actionInputValueInfo);

                                // Add Ginger param properties

                                Attribute[] attrs = Attribute.GetCustomAttributes(PI, typeof(Attribute), false);


                                // var v = PI.CustomAttributes; - not good
                                foreach (Attribute attribute in attrs)
                                {
                                    actionInputValueInfo.ParamAttrs.Add(attribute);
                                }
                            }


                            pluginServiceInfo.Actions.Add(action);
                        }

                        // Get all interfaces which are marked with attr 'GingerInterface'
                        foreach (Type PluginInterface in interfaces)
                        {
                            // decide if we need Feature for service and/or Interfaces seperate
                            // ServiceFeatureAttribute gingerInterfaceAttr = (ServiceFeatureAttribute)Attribute.GetCustomAttribute(PluginInterface, typeof(ServiceFeatureAttribute), true);
                            GingerInterfaceAttribute gingerInterfaceAttr = (GingerInterfaceAttribute)Attribute.GetCustomAttribute(PluginInterface, typeof(GingerInterfaceAttribute), true);

                            if (gingerInterfaceAttr != null)
                            {
                                pluginServiceInfo.Interfaces.Add(gingerInterfaceAttr.Id);
                            }
                        }

                        MemberInfo[] members = type.GetMembers();

                        foreach (MemberInfo mi in members)
                        {
                            if (Attribute.GetCustomAttribute(mi, typeof(ServiceConfigurationAttribute), false) is ServiceConfigurationAttribute mconfig)
                            {
                                PluginServiceConfigInfo Config = new  PluginServiceConfigInfo();
                                Config.Name        = mconfig.Name;
                                Config.Description = mconfig.Description;
                                Config.Type        = mconfig.GetType().Name;
                                // Config.DefaultValue = mconfig.DefaultValue?.ToString();

                                if (Attribute.GetCustomAttribute(mi, typeof(ValidValueAttribute), false) is ValidValueAttribute validValues)
                                {
                                    foreach (var val in validValues.ValidValue)
                                    {
                                        Config.OptionalValues.Add(val.ToString());
                                    }
                                }
                                if (Attribute.GetCustomAttribute(mi, typeof(DefaultAttribute), false) is DefaultAttribute DefaultValue)
                                {
                                    Config.DefaultValue = DefaultValue == null ? string.Empty : DefaultValue.ToString();
                                }

                                pluginServiceInfo.Configs.Add(Config);
                            }
                        }
                        mServices.Add(pluginServiceInfo);
                    }
                }
            }
        }
示例#8
0
        void LoadPluginServicesFromDll()
        {
            if (mServices == null)
            {
                mServices = new ObservableList <PluginServiceInfo>();
                foreach (PluginAssemblyInfo asssembly in mAssembliesInfo)
                {
                    IEnumerable <Type> types = from x in asssembly.Assembly.GetTypes() where x.GetCustomAttribute(typeof(GingerServiceAttribute)) != null select x;
                    foreach (Type type in types)
                    {
                        GingerServiceAttribute gingerServiceAttribute = (GingerServiceAttribute)Attribute.GetCustomAttribute(type, typeof(GingerServiceAttribute), false);
                        bool IsServiceSession = typeof(IServiceSession).IsAssignableFrom(type);
                        // if service impl IServiceSession then mark it so we know we need and agent Start/Stop
                        // if it is not session , then all actions are stand alone

                        PluginServiceInfo pluginServiceInfo = new PluginServiceInfo()
                        {
                            ServiceId = gingerServiceAttribute.Id, IsSession = IsServiceSession
                        };
                        // expecting to get ExcelAction, FileAction, DatabaseAction...
                        MethodInfo[] methods    = type.GetMethods();
                        Type[]       interfaces = type.GetInterfaces();
                        foreach (MethodInfo MI in methods)
                        {
                            //Check if method have token [GingerAction] or is is of interface else we ignore
                            GingerActionAttribute gingerActionAttr = (GingerActionAttribute)Attribute.GetCustomAttribute(MI, typeof(GingerActionAttribute), false);

                            if (gingerActionAttr == null && !MI.IsVirtual)   // Virtual if it is interface
                            {
                                continue;
                            }

                            PluginServiceActionInfo action = new PluginServiceActionInfo();

                            if (gingerActionAttr != null)
                            {
                                action.ActionId    = gingerActionAttr.Id;
                                action.Description = gingerActionAttr.Description;
                            }
                            else
                            {
                                // Check if the method is from interface
                                if (MI.IsVirtual)
                                {
                                    foreach (Type serviceInterface in interfaces)
                                    {
                                        //check if marked with [GingerInterface]
                                        GingerInterfaceAttribute gingerInterfaceAttr = (GingerInterfaceAttribute)Attribute.GetCustomAttribute(serviceInterface, typeof(GingerInterfaceAttribute), false);

                                        if (gingerInterfaceAttr != null)
                                        {
                                            var mm = serviceInterface.GetMethod(MI.Name);
                                            if (mm != null)
                                            {
                                                // Get the action id and desc from the interface
                                                action.Interface = serviceInterface.FullName;

                                                GingerActionAttribute interfaceGAAttr = (GingerActionAttribute)Attribute.GetCustomAttribute(mm, typeof(GingerActionAttribute), false);
                                                if (interfaceGAAttr == null)
                                                {
                                                    // no GA attr then ignore
                                                    continue;
                                                }
                                                else
                                                {
                                                    action.ActionId    = interfaceGAAttr.Id;
                                                    action.Description = interfaceGAAttr.Description;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (string.IsNullOrEmpty(action.ActionId))
                            {
                                continue;
                            }

                            foreach (ParameterInfo PI in MI.GetParameters())
                            {
                                if (PI.ParameterType.Name != nameof(IGingerAction))
                                {
                                    action.InputValues.Add(new ActionInputValueInfo()
                                    {
                                        Param = PI.Name, ParamType = PI.ParameterType
                                    });
                                }
                            }
                            pluginServiceInfo.Actions.Add(action);
                        }
                        mServices.Add(pluginServiceInfo);
                    }
                }
            }
        }