Пример #1
0
        public GingerNode(object gingerServiceObject)
        {
            mService = gingerServiceObject;

            GingerServiceAttribute attr = (GingerServiceAttribute)Attribute.GetCustomAttribute(mService.GetType(), typeof(GingerServiceAttribute), false);

            mServiceID = attr.Id;
        }
Пример #2
0
        public GingerNode(IGingerService service)
        {
            mService = service;

            GingerServiceAttribute attr = (GingerServiceAttribute)Attribute.GetCustomAttribute(mService.GetType(), typeof(GingerServiceAttribute), false);

            mServiceID = attr.Id;
        }
Пример #3
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);
        }
Пример #4
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);
                    }
                }
            }
        }
Пример #5
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);
                    }
                }
            }
        }