public IClient Create(string serverAddress, ClientFormat clientFormat, ClientCredentials clientCredentials) { var restClient = GetRestClient(serverAddress, clientFormat); restClient.SetCredentials(clientCredentials.Username, clientCredentials.Password); restClient.AlwaysSendBasicAuthHeader = true; return new Client(restClient); }
public void GetClientFormat(out string prefix, out string postfix, out string clientFormat) { prefix = Prefix; if (prefix == null) { prefix = string.Empty; } postfix = Postfix; if (postfix == null) { postfix = string.Empty; } clientFormat = ClientFormat; if (clientFormat == null) { clientFormat = string.Empty; } if (!ExtractClientFormat) { /* if (!new System.Text.RegularExpressions.Regex(@"[ndDpcsS]\d*").IsMatch(clientFormat)) * { * clientFormat = string.Empty; * }*/ return; } string[] parts = null; if (string.IsNullOrWhiteSpace(ClientFormat) && !string.IsNullOrWhiteSpace(DataFormatString)) { parts = ClientFormat.Split(new string[] { "{0:", "}" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 1) { clientFormat = parts[1]; if (clientFormat == "s") { clientFormat = "S"; } } } /*if (!new System.Text.RegularExpressions.Regex(@"[ndpc]\d*").IsMatch(clientFormat)) * { * clientFormat = string.Empty; * }*/ if (string.IsNullOrWhiteSpace(ClientFormat) && !string.IsNullOrEmpty(ClientFormat) && !string.IsNullOrWhiteSpace(DataFormatString)) { prefix = parts[0].Replace("{{", "{").Replace("}}", "}"); if (parts.Length > 2) { postfix = parts[2].Replace("{{", "{").Replace("}}", "}"); } } }
private static ServiceClientBase GetRestClient(string serverAddress, ClientFormat clientFormat) { switch (clientFormat) { case ClientFormat.Xml: { return new XmlServiceClient(serverAddress); } default: { return new JsonServiceClient(serverAddress); } } }