Example #1
0
        /// <summary>
        /// Adds the gateway.
        /// </summary>
        /// <returns>The gateway.</returns>
        /// <param name="className">Class name.</param>
        /// <param name="assemblyName">Assembly name.</param>
        public MigGateway AddGateway(string className, string assemblyName = "")
        {
            MigGateway migGateway = GetGateway(className);

            if (migGateway == null)
            {
                try
                {
                    var type = TypeLookup("MIG.Gateways." + className, assemblyName);
                    migGateway = (MigGateway)Activator.CreateInstance(type);
                }
                catch (Exception e)
                {
                    MigService.Log.Error(e);
                }
                if (migGateway != null)
                {
                    Log.Debug("Adding Gateway {0}", migGateway.GetName());
                    Gateways.Add(migGateway);
                    migGateway.PreProcessRequest  += Gateway_PreProcessRequest;
                    migGateway.PostProcessRequest += Gateway_PostProcessRequest;
                }
            }
            // Try loading gateway settings from MIG configuration
            var config = configuration.GetGateway(migGateway.GetName());

            if (config == null)
            {
                config      = new Gateway();
                config.Name = migGateway.GetName();
                if (config.Options == null)
                {
                    config.Options = new List <Option>();
                }
                configuration.Gateways.Add(config);
            }
            if (migGateway != null)
            {
                Log.Debug("Setting Gateway options");
                migGateway.Options = config.Options;
                foreach (var opt in configuration.GetGateway(migGateway.GetName()).Options)
                {
                    migGateway.SetOption(opt.Name, opt.Value);
                }
            }
            return(migGateway);
        }
Example #2
0
        public static void SetOption(this MigGateway gateway, string option, string value)
        {
            MigService.Log.Debug("{0}: {1}={2}", gateway.GetName(), option, value);
            var opt = gateway.GetOption(option);

            if (opt == null)
            {
                opt = new Option(option);
                gateway.Options.Add(opt);
            }
            opt.Value = value;
            gateway.OnSetOption(opt);
        }