public static CoreServiceInfo For(string hostName, bool secure, string userName = null, string password = null)
    {
        CoreServiceInfo result = new CoreServiceInfo {
            HostName = hostName, Secure = secure, UserName = userName, Password = password
        };

        result.BindingType = result.HostName == "localhost" ? TcmCoreService.BindingType.netTcp : TcmCoreService.BindingType.basicHttp;
        return(result);
    }
예제 #2
0
    public static CoreServiceClient GetClient(CoreServiceInfo info)
    {
        var client      = new SmarterCoreServiceClient(GetBinding(info.BindingType), GetEndpoint(info.BindingType, info.HostName));
        var credentials = CredentialCache.DefaultNetworkCredentials;

        if (!string.IsNullOrWhiteSpace(info.UserName) && !string.IsNullOrWhiteSpace(info.Password))
        {
            credentials = new NetworkCredential(info.UserName, info.Password);
        }
        client.ChannelFactory.Credentials.Windows.ClientCredential = credentials;
        return(client);
    }
    /// <summary>
    /// Sample values
    /// "localhost"
    /// ":administrator:tridion@tcmserver"
    /// </summary>
    /// <param name="value">a string describing the hostname and optional username/password</param>
    /// <returns></returns>
    public static CoreServiceInfo ParseTridionHost(string value)
    {
        CoreServiceInfo result = new CoreServiceInfo();

        if (!string.IsNullOrWhiteSpace(value) && value.StartsWith(":"))
        {
            Match match = new Regex(":([^:]*):([^@]*)@(.*)").Match(value);
            result.UserName = match.Groups[1].Value;
            result.Password = match.Groups[2].Value;
            result.HostName = match.Groups[3].Value;
        }
        else
        {
            result.HostName = string.IsNullOrWhiteSpace(value) ? "localhost" : value;
        }
        result.BindingType = result.HostName == "localhost" ? TcmCoreService.BindingType.netTcp : TcmCoreService.BindingType.basicHttp;
        //Console.WriteLine(string.Format("CoreServiceInfo: {0}-{1}-{2}-{3}", result.BindingType, result.HostName, result.UserName, result.Password));
        return(result);
    }