Пример #1
0
        public void Login(string serverIP, string account, string password, bool adjudicatorMode, Action failAction)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(obj =>
            {
                try
                {
                    string ip = obj as string;
                    if (LoginChannel == null)
                    {
                        string ipe = String.Format("{0}:{1}", ip, (int)PortID.LoginLink);
                        //string ipe = String.Format("localhost:{0}", (int)PortID.LoginLink);

                        var binding = new NetTcpBinding(SecurityMode.None);
                        binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                        binding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;
                        binding.OpenTimeout            = TimeSpan.MaxValue;
                        binding.SendTimeout            = TimeSpan.MaxValue;
                        binding.ReceiveTimeout         = TimeSpan.MaxValue;
                        binding.MaxReceivedMessageSize = 1024 * 1024;
                        binding.MaxBufferPoolSize      = 1024 * 1024;

                        var inst     = new InstanceContext(MainForm.Instance.FrmLogin);
                        var endpt    = new EndpointAddress(string.Format("{0}://{1}/LoginService", binding.Scheme, ipe));
                        var fac      = new DuplexChannelFactory <ILoginService>(inst, binding);
                        LoginChannel = fac.CreateChannel(endpt);

                        ((IContextChannel)LoginChannel).OperationTimeout = new TimeSpan(0, 0, 10);
                        ((IContextChannel)LoginChannel).Closed          += new EventHandler(ProxyService_Closed);
                        ((IContextChannel)LoginChannel).Faulted         += new EventHandler(ProxyService_Faulted);
                    }

                    var info = new LoginInfo(account, password)
                    {
                        AdjudicatorMode        = adjudicatorMode,
                        TransServicePort       = DownloadTransmissionService.ServicePort,
                        JudgementConfigFileMD5 = adjudicatorMode ? JudgementSettings.ConfigFileMD5 : ""
                    };
                    LoginChannel.Login(info);
                    ServerIP = ip;
                }
                catch// (Exception ex)
                {
                    LoginChannel = null;
                    if (failAction != null)
                    {
                        failAction();
                    }
                }
            }), serverIP);
        }
Пример #2
0
        public static CookAppPartnerLoginUser CreateInstance(string authCode, string accessToken, int expiredIn, string refreshToken, string scope, string unionId, LoginChannel loginChannel, string partnerKey)
        {
            var now = DateTime.Now;
            var obj = new CookAppPartnerLoginUser
            {
                CreatedBy          = partnerKey,
                CreatedOn          = now,
                ExpiredIn          = expiredIn,
                LoginChannel       = loginChannel,
                PartnerAccessToken = accessToken,
                PartnerAuthCode    = authCode,
                PartnerKey         = partnerKey,
                RefreshToken       = refreshToken,
                Scope     = scope,
                UnionId   = unionId,
                UpdatedBy = partnerKey,
                UpdatedOn = now
            };

            obj.GenerateId();

            return(obj);
        }