public static Option GetOption(this IMigGateway gateway, string option)
 {
     if (gateway.Options != null)
     {
         return(gateway.Options.Find(o => o.Name == option));
     }
     return(null);
 }
Beispiel #2
0
        /// <summary>
        /// Adds the gateway.
        /// </summary>
        /// <returns>The gateway.</returns>
        /// <param name="className">Class name.</param>
        /// <param name="assemblyName">Assembly name.</param>
        public IMigGateway AddGateway(string className, string assemblyName = "")
        {
            IMigGateway migGateway = GetGateway(className);

            if (migGateway == null)
            {
                try
                {
                    var type = TypeLookup("MIG.Gateways." + className, assemblyName);
                    if (type == null)
                    {
                        Log.Error("Can't find type for Mig Gateway MIG.Gateways.{0} (assemblyName={1})", className, assemblyName);
                        return(null);
                    }
                    migGateway = (IMigGateway)Activator.CreateInstance(type);
                }
                catch (Exception e)
                {
                    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);
        }
        public static void SetOption(this IMigGateway 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);
        }
 public static string GetName(this IMigGateway gateway)
 {
     return(gateway.GetType().Name);
 }