示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="serverAddress">Token服务器地址</param>
        /// <param name="serverPort">Token服务器端口</param>
        /// <param name="cert">与服务器交互的客户端证书</param>
        public TokenClient(string serverAddress, int serverPort, X509Certificate2 cert = null)
        {
            _cert = cert;
            if (Keys == null)
            {
                lock (LockObj)
                {
                    if (Keys != null)
                    {
                        return;
                    }

                    CertClient client = new CertClient(serverAddress, serverPort, _cert);
                    client.Write(1);
                    var len = client.ReadInt();
                    Keys = Encoding.UTF8.GetString(client.ReceiveDatas(len)).FromJson <string[]>();
                    Task.Run(() => {
                        try
                        {
                            client.ReadTimeout = 0;
                            client.ReadInt();
                        }
                        catch (Exception)
                        {
                            Keys = null;
                        }
                    });
                }
            }
        }
示例#2
0
        public void GetGatewayShareFile(NetAddress gatewayAddr, string filepath, string localFilePath, X509Certificate2 gatewayClientCert)
        {
            using (var client = new CertClient(gatewayAddr, gatewayClientCert))
            {
                client.WriteServiceData(new GatewayCommand
                {
                    Type    = CommandType.GetShareFile,
                    Content = filepath
                });

                var ret = client.ReadServiceObject <InvokeResult <int?> >();
                if (ret.Success == false)
                {
                    throw new Exception(ret.Error);
                }

                int len  = ret.Data.GetValueOrDefault();
                var data = client.ReceiveDatas(len);

                File.WriteAllBytes(localFilePath, data);
            }
        }