コード例 #1
0
        /// <summary>
        /// Implement <see cref="IConfigurationData.GetAdapterConfig"/>
        /// </summary>
        /// <param name="adapterName">The adapter name</param>
        /// <returns>Returns the abstract adapter config data</returns>
        public AdapterConfig GetAdapterConfig(string adapterName)
        {
            AdapterConfig adapter;

            // Gets target adapter type.
            string type = this.GetAdapterAttribute(adapterName,
                                                   "type",
                                                   DefaultSchemaInstance
                                                   );

            // Create proxy for default type adapter.
            if (type.Equals("interactive", StringComparison.CurrentCultureIgnoreCase))
            {
                string adapterTypeName = this.TryGetAdapterAttribute(adapterName, "adaptertype", "");
                adapter = new InteractiveAdapterConfig(adapterName, adapterTypeName);
            }
            // Create proxy for PowerShell script type adapter
            else if (type.Equals("powershell", StringComparison.CurrentCultureIgnoreCase))
            {
                string psdir = this.GetAdapterAttribute(adapterName, "scriptdir", "");
                adapter = new PowerShellAdapterConfig(adapterName, psdir);
            }
            // Create proxy for Shell script type adapter
            else if (type.Equals("shell", StringComparison.CurrentCultureIgnoreCase))
            {
                string scriptdir = this.GetAdapterAttribute(adapterName, "scriptdir", "");
                adapter = new ShellAdapterConfig(adapterName, scriptdir);
            }
            // Create instance for dot net type adapter.
            else if (type.Equals("managed", StringComparison.CurrentCultureIgnoreCase))
            {
                string adapterTypeName         = this.GetAdapterAttribute(adapterName, "adaptertype", "");
                string disablevalidationstring = this.TryGetAdapterAttribute(adapterName, "disablevalidation", "");
                bool   disablevalidation       = false;
                if (!String.IsNullOrEmpty(disablevalidationstring))
                {
                    Boolean.TryParse(disablevalidationstring, out disablevalidation);
                }
                adapter = new ManagedAdapterConfig(adapterName, adapterTypeName, disablevalidation);
            }
            else
            {
                throw new ArgumentException(String.Format("Unsupported adapter type: {0}", type));
            }

            return(adapter);
        }
コード例 #2
0
        /// <summary>
        /// Implement <see cref="IConfigurationData.GetAdapterConfig"/>
        /// </summary>
        /// <param name="adapterName">The adapter name</param>
        /// <returns>Returns the abstract adapter config data</returns>
        public AdapterConfig GetAdapterConfig(string adapterName)
        {
            AdapterConfig adapter;

            // Gets target adapter type.
            string type = this.GetAdapterAttribute(adapterName,
                                                    "type",
                                                    DefaultSchemaInstance
                                                    );

            // Create proxy for default type adapter.
            if (type.Equals("interactive", StringComparison.CurrentCultureIgnoreCase))
            {
                adapter = new InteractiveAdapterConfig(adapterName);
            }

            // Create proxy for command script type adapter.
            else if (type.Equals("script", StringComparison.CurrentCultureIgnoreCase))
            {
                string scriptdir = this.GetAdapterAttribute(adapterName, "scriptdir", "");
                adapter = new ScriptAdapterConfig(adapterName, scriptdir);
            }

            // Create proxy for PowerShell script type adapter
            else if (type.Equals("powershell", StringComparison.CurrentCultureIgnoreCase))
            {
                string psdir = this.GetAdapterAttribute(adapterName, "scriptdir", "");
                adapter = new PowerShellAdapterConfig(adapterName, psdir);
            }

            // Create proxy for PowerShell wrapper adapter
            else if (type.Equals("pswrapper", StringComparison.CurrentCultureIgnoreCase))
            {
                string psfile = this.GetAdapterAttribute(adapterName, "scriptfile", "");
                adapter = new PsWrapperAdapterConfig(adapterName, psfile);
            }

            // Create instance for dot net type adapter.
            else if (type.Equals("managed", StringComparison.CurrentCultureIgnoreCase))
            {
                string adapterTypeName = this.GetAdapterAttribute(adapterName, "adaptertype", "");
                string disablevalidationstring = this.TryGetAdapterAttribute(adapterName, "disablevalidation", "");
                bool disablevalidation = false;
                if (!String.IsNullOrEmpty(disablevalidationstring))
                {
                    Boolean.TryParse(disablevalidationstring, out disablevalidation);
                }
                adapter = new ManagedAdapterConfig(adapterName, adapterTypeName, disablevalidation);
            }
            // Create instance for rpc type adapter.
            else if (type.Equals("rpc", StringComparison.CurrentCultureIgnoreCase))
            {
                string validationSwitch = this.TryGetAdapterAttribute(adapterName, "autovalidate", "");
                string callingConventionString = this.TryGetAdapterAttribute(adapterName, "callingconvention", "");
                string charsetString = this.TryGetAdapterAttribute(adapterName, "charset", "");

                bool autoValidate = true;
                if (!String.IsNullOrEmpty(validationSwitch))
                {
                    autoValidate = Boolean.Parse(validationSwitch);
                }

                //since the specified value has been validated by schema already, no need to re-check if the value is defined in Enum.
                CallingConvention callingConvention = CallingConvention.Winapi; //by default
                if (!String.IsNullOrEmpty(callingConventionString))
                {
                    callingConvention = (CallingConvention)Enum.Parse(typeof(CallingConvention), callingConventionString, true);
                }

                CharSet charset = CharSet.Auto; //by default
                if (!String.IsNullOrEmpty(charsetString))
                {
                    charset = (CharSet)Enum.Parse(typeof(CharSet), charsetString, true);
                }

                adapter = new RpcAdapterConfig(adapterName, type, autoValidate, callingConvention, charset);
            }
            else
            {
                adapter = new CustomAdapterConfig(adapterName, type);
            }

            return adapter;
        }