Пример #1
0
        private static void UpdateParamsType(ActPlugIn actPlugIn)
        {
            List <ActionInputValueInfo> paramsList = WorkSpace.Instance.PlugInsManager.GetActionEditInfo(actPlugIn.PluginId, actPlugIn.ServiceId, actPlugIn.ActionId);

            foreach (ActInputValue AP in actPlugIn.InputValues)
            {
                ActionInputValueInfo actionInputValueInfo = (from x in paramsList where x.Param == AP.Param select x).SingleOrDefault();
                AP.ParamType = actionInputValueInfo.ParamType;
            }
        }
Пример #2
0
        private void SetActionInputsControls()
        {
            List <ActionInputValueInfo> actionInputsDetails = WorkSpace.Instance.PlugInsManager.GetActionEditInfo(mAct.PluginId, mAct.ServiceId, mAct.ActionId);

            foreach (ActInputValue param in mAct.InputValues)
            {
                ActionInputValueInfo actionInputValueInfo = (from x in actionInputsDetails where x.Param == param.Param select x).SingleOrDefault();
                // update the type based on the info json of the plugin
                param.ParamType = actionInputValueInfo.ParamType;

                // Add ActionInputValueUserControl for the param value to edit
                ActionInputValueUserControl actionInputValueUserControl = new ActionInputValueUserControl(Context.GetAsContext(mAct.Context), param, actionInputValueInfo.ParamAttrs);
                DockPanel.SetDock(actionInputValueUserControl, Dock.Top);
                actionInputValueUserControl.Margin = new Thickness(0, 10, 0, 0);
                xActionInputControlsPnl.Children.Add(actionInputValueUserControl);
            }
        }
Пример #3
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);
                    }
                }
            }
        }