コード例 #1
0
 private string GetChangeManagedNameActionResult(TypeInfo typeInfo,
                                                 ConvType convType, string oldName)
 {
     if (Settings.m_ruleSet != null)
     {
         ICategory           category = TypeCategory.GetInstance();
         TypeInfoMatchTarget target   = null;
         using (TypeAttr attr = typeInfo.GetTypeAttr())
         {
             TypeLibTypes.Interop.TYPEKIND kind = attr.typekind;
             target = new TypeInfoMatchTarget(typeInfo.GetContainingTypeLib(), typeInfo, kind);
         }
         AbstractActionManager actionManager   = RuleEngine.GetActionManager();
         List <Rule>           changeNameRules = Settings.m_ruleSet.GetRule(
             category, ChangeManagedNameActionDef.GetInstance(), target);
         if (changeNameRules.Count != 0)
         {
             if (changeNameRules.Count > 1)
             {
                 Output.WriteWarning(Resource.FormatString("Wrn_RuleMultipleMatch",
                                                           ChangeManagedNameActionDef.GetInstance()),
                                     WarningCode.Wrn_RuleMultipleMatch);
             }
             Rule   changeNameRule = changeNameRules[changeNameRules.Count - 1];
             int    namespaceSplit = oldName.LastIndexOf('.');
             string oldNamespace   = "";
             if (namespaceSplit != -1)
             {
                 oldNamespace = oldName.Substring(0, namespaceSplit + 1);
             }
             return(oldNamespace + (changeNameRule.Action as ChangeManagedNameAction).NewName);
         }
     }
     return(oldName);
 }
コード例 #2
0
ファイル: RuleForm.cs プロジェクト: ARLM-Keller/clr-interop
        public IAction GetAction()
        {
            if (actionComboBox.SelectedItem == null)
            {
                return(null);
            }
            string actionName = actionComboBox.SelectedItem.ToString();

            return(RuleEngine.GetActionManager().CreateAction(actionName));
        }
コード例 #3
0
        private bool RuleEngineResolveRedirection(RuleSet ruleSet, TypeInfo typeInfo,
                                                  out Type convertedType)
        {
            convertedType = null;
            if (ruleSet != null)
            {
                ICategory category = TypeCategory.GetInstance();
                TypeLibTypes.Interop.TYPEKIND typeKind;
                using (TypeAttr attr = typeInfo.GetTypeAttr())
                {
                    typeKind = attr.typekind;
                }
                TypeInfoMatchTarget target = new TypeInfoMatchTarget(typeInfo.GetContainingTypeLib(),
                                                                     typeInfo, typeKind);
                AbstractActionManager actionManager  = RuleEngine.GetActionManager();
                List <Rule>           resolveToRules = ruleSet.GetRule(
                    category, ResolveToActionDef.GetInstance(), target);
                if (resolveToRules.Count != 0)
                {
                    if (resolveToRules.Count > 1)
                    {
                        Output.WriteWarning(Resource.FormatString("Wrn_RuleMultipleMatch",
                                                                  ResolveToActionDef.GetInstance().GetActionName()),
                                            WarningCode.Wrn_RuleMultipleMatch);
                    }
                    Rule resolveToRule =
                        resolveToRules[resolveToRules.Count - 1];

                    ResolveToAction action =
                        resolveToRule.Action as ResolveToAction;
                    try
                    {
                        Assembly assembly = Assembly.ReflectionOnlyLoad(action.AssemblyName);
                        convertedType = assembly.GetType(action.ManagedTypeFullName);
                        return(true);
                    }
                    catch (Exception)
                    {
                        Output.WriteWarning(Resource.FormatString("Wrn_CannotLoadResolveToType",
                                                                  action.ManagedTypeFullName, action.AssemblyName),
                                            WarningCode.Wrn_CannotLoadResolveToType);
                    }
                }
            }
            return(false);
        }
コード例 #4
0
ファイル: RuleForm.cs プロジェクト: ARLM-Keller/clr-interop
        private void actionComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (actionComboBox.SelectedItem == null)
            {
                return;
            }
            string actionName = actionComboBox.SelectedItem as string;
            AbstractActionManager actionManager = RuleEngine.GetActionManager();
            IActionDef            actionDef     = actionManager.GetActionDef(actionName);

            if (actionDef == null)
            {
                return;
            }
            string actionDescription =
                Resource.FormatString("Msg_ActionDescription_" + actionDef.GetActionName());

            textBoxDescription.Text = actionDescription;
            CheckOKButtonEnabled();
        }
コード例 #5
0
        private static string GetActionParamString(IAction action)
        {
            StringBuilder sb        = new StringBuilder();
            IActionDef    actionDef =
                RuleEngine.GetActionManager().GetActionDef(action.GetActionDef().GetActionName());
            List <string> paramNameList = actionDef.GetParameterNames();

            foreach (string paramName in paramNameList)
            {
                if (sb.Length != 0)
                {
                    sb.Append(", ");
                }
                sb.Append(paramName);
                sb.Append("='");
                sb.Append(action.GetParameterValue(paramName));
                sb.Append("'");
            }
            return(sb.ToString());
        }
コード例 #6
0
ファイル: RuleForm.cs プロジェクト: ARLM-Keller/clr-interop
        private void categoryComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (categoryComboBox.SelectedItem == null)
            {
                return;
            }
            string categoryName = categoryComboBox.SelectedItem as string;
            AbstractCategoryManager categoryManager = RuleEngine.GetCategoryManager();
            ICategory             category          = categoryManager.GetCategory(categoryName);
            AbstractActionManager actionManager     = RuleEngine.GetActionManager();
            List <IActionDef>     actionDefList     =
                actionManager.GetPossibleActionDefList(category);

            actionComboBox.Items.Clear();
            foreach (IActionDef actionDef in actionDefList)
            {
                actionComboBox.Items.Add(actionDef.GetActionName());
            }
            actionComboBox.SelectedIndex = -1;
            CheckOKButtonEnabled();
        }
コード例 #7
0
        public static TreeNode GetActionTreeNode(IAction action)
        {
            TreeNode actionNode = new TreeNode();

            actionNode.Text = ACTION_NODE_TEXT + " : " + action.GetActionDef().GetActionName();
            if (!action.IsInitialized)
            {
                actionNode.Text += " <" + Resource.FormatString("Msg_EditUninitializedActionTip") + ">";
            }
            actionNode.Tag = action;

            IActionDef actionDef =
                RuleEngine.GetActionManager().GetActionDef(action.GetActionDef().GetActionName());
            List <string> paramNameList = actionDef.GetParameterNames();

            foreach (string paramName in paramNameList)
            {
                TreeNode      actionParameterNode = new TreeNode();
                StringBuilder sb = new StringBuilder();
                sb.Append(paramName);
                sb.Append(" = '");
                if (action.IsInitialized)
                {
                    sb.Append(action.GetParameterValue(paramName));
                }
                else
                {
                    sb.Append(TreeNodeConstants.Uninitialized_Value);
                }
                sb.Append("'");
                actionParameterNode.Text = sb.ToString();
                actionParameterNode.Tag  = action;
                SetRuleTreeNodeImage(actionParameterNode);
                actionNode.Nodes.Add(actionParameterNode);
            }

            SetRuleTreeNodeImage(actionNode);
            return(actionNode);
        }
コード例 #8
0
        protected void DefineType(ConverterInfo info, TypeInfo typeInfo, bool dealWithAlias)
        {
            m_info     = info;
            m_typeInfo = typeInfo;

            if (dealWithAlias)
            {
                m_nonAliasedTypeInfo = ConvCommon.GetAlias(typeInfo);
            }
            else
            {
                m_nonAliasedTypeInfo = typeInfo;
            }

            try
            {
                OnDefineType();

                //
                // Emit SuppressUnmanagedCodeSecurityAttribute for /unsafe switch
                //
                if ((m_info.Settings.m_flags & TypeLibImporterFlags.UnsafeInterfaces) != 0)
                {
                    if (ConvType != ConvType.ClassInterface && ConvType != ConvType.EventInterface)
                    {
                        m_typeBuilder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForSuppressUnmanagedCodeSecurity());
                    }
                }

                // Rule Engine AddAttributeAction
                if (m_info.Settings.m_ruleSet != null)
                {
                    ICategory           category = TypeCategory.GetInstance();
                    TypeInfoMatchTarget target   = null;
                    using (TypeAttr attr = m_typeInfo.GetTypeAttr())
                    {
                        TypeLibTypes.Interop.TYPEKIND kind = attr.typekind;
                        target = new TypeInfoMatchTarget(m_typeInfo.GetContainingTypeLib(), m_typeInfo, kind);
                    }
                    AbstractActionManager actionManager     = RuleEngine.GetActionManager();
                    List <Rule>           addAttributeRules = m_info.Settings.m_ruleSet.GetRule(
                        category, AddAttributeActionDef.GetInstance(), target);
                    foreach (Rule rule in addAttributeRules)
                    {
                        AddAttributeAction addAttributeAction = rule.Action as AddAttributeAction;
                        ConstructorInfo    attributeCtor;
                        byte[]             blob;
                        bool success = true;
                        if (addAttributeAction.GetCustomAttribute(out attributeCtor, out blob))
                        {
                            try
                            {
                                m_typeBuilder.SetCustomAttribute(attributeCtor, blob);
                            }
                            catch (Exception)
                            {
                                success = false;
                            }
                        }
                        else
                        {
                            success = false;
                        }
                        if (!success)
                        {
                            string name = m_typeInfo.GetDocumentation();
                            string msg  = Resource.FormatString("Wrn_AddCustomAttributeFailed",
                                                                addAttributeAction.TypeName, name);
                            m_info.ReportEvent(WarningCode.Wrn_AddCustomAttributeFailed, msg);
                        }
                    }
                }
            }
            catch (ReflectionTypeLoadException)
            {
                throw; // Fatal failure. Throw
            }
            catch (TlbImpResolveRefFailWrapperException)
            {
                throw; // Fatal failure. Throw
            }
            catch (TlbImpGeneralException)
            {
                throw; // Fatal failure. Throw
            }
            catch (Exception)
            {
                string name = String.Empty;
                if (m_typeInfo != null)
                {
                    try
                    {
                        name = m_typeInfo.GetDocumentation();
                    }
                    catch (Exception)
                    {
                    }
                }

                if (name != String.Empty)
                {
                    string msg = Resource.FormatString("Wrn_InvalidTypeInfo", name);
                    m_info.ReportEvent(WarningCode.Wrn_InvalidTypeInfo, msg);
                }
                else
                {
                    string msg = Resource.FormatString("Wrn_InvalidTypeInfo_Unnamed");
                    m_info.ReportEvent(WarningCode.Wrn_InvalidTypeInfo_Unnamed, msg);
                }

                // When failure, try to create the type anyway
                if (m_typeBuilder != null)
                {
                    m_type = m_typeBuilder.CreateType();
                }
            }
        }