private static Lazy<ServiceProxy> LoadFromConfig(ClientConfig config) { ClientContext.CreateNew(config); if (_commandServiceProxy == null) { var lazyConnection = new Lazy<ServiceProxy>(() => { var contextConfig = ClientContext.Current.Config; var client = WcfClient<ICommandService<object>>.Create(contextConfig.Runtime.Client.GetWcfServiceType(), contextConfig.Runtime.Client.Host, contextConfig.Runtime.Client.Port.ToString(CultureInfo.InvariantCulture), "CommandService"); client.OnFaulted += client_OnFaulted; CurrentContext.Default.Log.Info("Connection Established:" + client.ServerName + " Port:" + client.Port); return new ServiceProxy(client.Contract, config); }); _commandServiceProxy = lazyConnection; } return _commandServiceProxy; }
public static Lazy<ServiceProxy> GetInstance(ClientConfig config) { if (config == null) throw new ArgumentNullException("config"); return LoadFromConfig(config); }
public static void CreateNew(ClientConfig configuration) { if (_current == null) { _current = new ClientContext(configuration); } }
private ClientContext(ClientConfig configuration) { _config = configuration; if (configuration == null) throw new InvalidOperationException( "Current Context could not be initialized. No configuration passed to the context"); var logger = LogFactory.CreateInstance(configuration.Runtime.LogInfo); var cache = CacheFactory.Create(configuration.Caching); cache.ItemRemoved += (sender, args) => Log.Debug("Item removed from cache: " + args.CacheKey + " Reason : " + args.RemoveReason); CurrentContext.CreateDefault(logger, new CommandArgs(string.Empty), cache); }
public static void GetAppConfiguration() { ClientConfig config = new ClientConfig(); config.Runtime.User.Username = "******"; config.Runtime.User.Password = "******"; config.Runtime.Client.Host = "localhost"; config.Runtime.Client.Port = 8880; config.Runtime.Client.Type = EndPointType.HTTP; var commandService = ConnectionFactory.GetInstance(config); var output = commandService.Value.ExecuteCommand("get /app:6 /env:8 /region:8 /server:9"); if (output != null) { var parameters = (List<ConfigurationModel>) output.Data; parameters.ForEach(param => Console.WriteLine(param.ParameterName + "=" + param.ParameterValue)); } Console.WriteLine("Press any key to continue.."); Console.ReadKey(); }
public void TestJsonCreationForClient() { var config = new ClientConfig { Runtime = { LogInfo = new LogElement { ProviderType = "KonfDB.Infrastructure.Logging.Logger, KonfDBC", Parameters = @"-path:konfdb\log.txt" } } }; config.Runtime.Client.Host = "localhost"; config.Runtime.Client.Port = 8085; config.Runtime.Client.Type = EndPointType.TCP; config.Runtime.User.Username = "******"; config.Runtime.User.Password = "******"; config.Caching.Enabled = false; config.Caching.ProviderType = typeof (InMemoryCacheStore).AssemblyQualifiedName; config.Caching.Parameters = "-duration:30 -mode:Absolute"; var configJson = config.ToJson(); var readBack = configJson.FromJsonToObject<ClientConfig>(); Assert.IsNotNull(readBack); }
public ServiceProxy(ICommandService<object> commandService, ClientConfig configuration) { _commandService = commandService; _configuration = configuration; }