Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IronClient" /> class.
        /// </summary>
        /// <param name="name">Client name</param>
        /// <param name="version">Version of the client</param>
        /// <param name="product">Iron.io product</param>
        /// <param name="host">hostname to use</param>
        /// <param name="port">port number</param>
        /// <param name="projectId">Project identifier available from the HUD</param>
        /// <param name="token">Token available from the HUD</param>
        /// <param name="protocol">Protocol e.g. http https</param>
        /// <param name="apiVersion">Version of the API to use (1,2)</param>
        /// <param name="configFile">Path to a specific JSON configuration file to load</param>
        public IronClient(string name, string version, string product, string host = null, int port = 0, string projectId = null, string token = null, string protocol = null, int apiVersion = 0, string configFile = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Name cannot be null or empty");
            }

            AutoMapper.Mapper.CreateMap <Configuration, Configuration>().ForMember(c => c.Port, opt => opt.Condition(s => s.Port > 0))
            .ForMember(c => c.ApiVersion, opt => opt.Condition(s => s.ApiVersion > 0))
            .ForMember(c => c.Host, opt => opt.Condition(s => !string.IsNullOrEmpty(s.Host)))
            .ForMember(c => c.ProjectId, opt => opt.Condition(s => !string.IsNullOrEmpty(s.ProjectId)))
            .ForMember(c => c.Token, opt => opt.Condition(s => !string.IsNullOrEmpty(s.Token)))
            .ForMember(c => c.Protocol, opt => opt.Condition(s => !string.IsNullOrEmpty(s.Protocol)));

            ConfigurationFactory configFactory = new DefaultConfigurationFactory();

            if (product == "iron_mq")
            {
                configFactory = new MQConfigFactory(configFactory);
            }

            if (product == "iron_worker")
            {
                configFactory = new WorkerConfigFactory(configFactory);
            }

            if (product == "iron_cache")
            {
                configFactory = new CacheConfigFactory(configFactory);
            }

            string homePath = (Environment.OSVersion.Platform == PlatformID.Unix ||
                               Environment.OSVersion.Platform == PlatformID.MacOSX)
            ? Environment.GetEnvironmentVariable("HOME")
            : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");

            configFactory = new JsonConfigFactory(configFactory, System.IO.Path.Combine(homePath, ".iron.json"));
            configFactory = new EnvConfigFactory(configFactory);
            configFactory = new JsonConfigFactory(configFactory, "iron.json");
            configFactory = new JsonConfigFactory(configFactory, configFile);
            configFactory = new ArgsConfigFactory(configFactory, name, version, product, host, port, projectId, token, protocol, apiVersion);

            this.Config = configFactory.GetConfiguartion();

            if (string.IsNullOrEmpty(this.Config.ProjectId))
            {
                throw new Exception("No projectId set. projectId is a required field.");
            }

            if (string.IsNullOrEmpty(this.Config.Token))
            {
                throw new Exception("No token set. token is a required field.");
            }

            this.BuildHeaders();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IronClient" /> class.
        /// </summary>
        /// <param name="name">Client name</param>
        /// <param name="version">Version of the client</param>
        /// <param name="product">Iron.io product</param>
        /// <param name="host">hostname to use</param>
        /// <param name="port">port number</param>
        /// <param name="projectId">Project identifier available from the HUD</param>
        /// <param name="token">Token available from the HUD</param>
        /// <param name="protocol">Protocol e.g. http https</param>
        /// <param name="apiVersion">Version of the API to use (1,2)</param>
        /// <param name="configFile">Path to a specific JSON configuration file to load</param>
        public IronClient(string name, string version, string product, string host = null, int port = 0, string projectId = null, string token = null, string protocol = null, int apiVersion = 0, string configFile = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Name cannot be null or empty");
            }

            AutoMapper.Mapper.CreateMap<Configuration, Configuration>().ForMember(c => c.Port, opt => opt.Condition(s => s.Port > 0))
                                                         .ForMember(c => c.ApiVersion, opt => opt.Condition(s => s.ApiVersion > 0))
                                                         .ForMember(c => c.Host, opt => opt.Condition(s => !string.IsNullOrEmpty(s.Host)))
                                                         .ForMember(c => c.ProjectId, opt => opt.Condition(s => !string.IsNullOrEmpty(s.ProjectId)))
                                                         .ForMember(c => c.Token, opt => opt.Condition(s => !string.IsNullOrEmpty(s.Token)))
                                                         .ForMember(c => c.Protocol, opt => opt.Condition(s => !string.IsNullOrEmpty(s.Protocol)));

            ConfigurationFactory configFactory = new DefaultConfigurationFactory();

            if (product == "iron_mq")
            {
                configFactory = new MQConfigFactory(configFactory);
            }

            if (product == "iron_worker")
            {
                configFactory = new WorkerConfigFactory(configFactory);
            }

            if (product == "iron_cache")
            {
                configFactory = new CacheConfigFactory(configFactory);
            }

            string homePath = (Environment.OSVersion.Platform == PlatformID.Unix ||
                   Environment.OSVersion.Platform == PlatformID.MacOSX)
            ? Environment.GetEnvironmentVariable("HOME")
            : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");

            configFactory = new JsonConfigFactory(configFactory, System.IO.Path.Combine(homePath, ".iron.json"));
            configFactory = new EnvConfigFactory(configFactory);
            configFactory = new JsonConfigFactory(configFactory, "iron.json");
            configFactory = new JsonConfigFactory(configFactory, configFile);
            configFactory = new ArgsConfigFactory(configFactory, name, version, product, host, port, projectId, token, protocol, apiVersion);

            this.Config = configFactory.GetConfiguartion();

            if (string.IsNullOrEmpty(this.Config.ProjectId))
            {
                throw new Exception("No projectId set. projectId is a required field.");
            }

            if (string.IsNullOrEmpty(this.Config.Token))
            {
                throw new Exception("No token set. token is a required field.");
            }

            this.BuildHeaders();
        }