using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WPF_Sample.Common
{
    public class ServiceUtil
    {

        public static string CreateToken()
        {
            using (var client = new STWS.ServiceRouterClient())
            {
                string tokenKey;
                Guid sharedKey = new Guid(Properties.Settings.Default["WSSharedKey"].ToString());

                STWS.TokenCreate tokenCreate = new STWS.TokenCreate { 
                    CustomerAlias = Properties.Settings.Default["CustomerAlias"].ToString(), 
                    UserName = "wsuser", 
                    UserPass = Properties.Settings.Default["WSPassword"].ToString(),
                    SharedKey = sharedKey
                };
                STWS.TokenCreateRequest request = new STWS.TokenCreateRequest(tokenCreate);

     
                STWS.TokenCreateResponse response = client.TokenCreate(request);
                tokenKey = response.TokenCreateResult;
                
                return tokenKey;
            }
        }


        public static string CreateToken_V2()
        {
            using (var client = new STWS_V2.ServiceRouterClient())
            {
                string tokenKey;
                Guid sharedKey = new Guid(Properties.Settings.Default["WSSharedKey"].ToString());

                STWS_V2.CreateTokenIn input = new STWS_V2.CreateTokenIn
                {
                    CustomerAlias = Properties.Settings.Default["CustomerAlias"].ToString(),
                    UserName = "wsuser",
                    UserPass = Properties.Settings.Default["WSPassword"].ToString(),
                    SharedKey = sharedKey
                };

                STWS_V2.CreateTokenRequest request = new STWS_V2.CreateTokenRequest(input);
                STWS_V2.CreateTokenResponse response = client.CreateToken(request);
                tokenKey = response.CreateTokenResult;

                return tokenKey;
            }
        }



    }
}
