コード例 #1
0
        private void HqServerInit()
        {
            if (pubServerIPCache != string.Empty && CommonUtils.TelnetPort(pubServerIPCache, AASClient.TDFData.DataCache.ServerPort))
            {
                AASClient.TDFData.DataCache.ServerIP = pubServerIPCache;
            }
            else
            {
                string ip = Program.AASServiceClient.GetDataServerIP();
                if (string.IsNullOrEmpty(ip))
                {
                    TDFData.DataSourceConfig.IsUseTDFData = false;
                }
                else
                {
                    if (ip.Contains(System.Environment.NewLine))
                    {
                        string[] arr = ip.Split(new[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var item in arr)
                        {
                            if (CommonUtils.TelnetPort(item, AASClient.TDFData.DataCache.ServerPort))
                            {
                                AASClient.TDFData.DataCache.ServerIP = item;
                                if (this.AppConfig.AppSettings.Settings.AllKeys.Contains(pubServerName))
                                {
                                    if (item.Equals(Cryptor.MD5Decrypt(this.AppConfig.AppSettings.Settings[pubServerName].Value)))
                                    {
                                        break;
                                    }
                                    this.AppConfig.AppSettings.Settings[pubServerName].Value = Cryptor.MD5Encrypt(item);
                                }
                                else
                                {
                                    this.AppConfig.AppSettings.Settings.Add(pubServerName, Cryptor.MD5Encrypt(item));
                                }

                                this.AppConfig.Save(ConfigurationSaveMode.Modified);
                                ConfigurationManager.RefreshSection("appSettings");
                                break;
                            }
                            Thread.Sleep(100);
                        }
                    }
                    else
                    {
                        if (CommonUtils.TelnetPort(ip, AASClient.TDFData.DataCache.ServerPort))
                        {
                            AASClient.TDFData.DataCache.ServerIP = ip;
                        }
                    }
                }
            }
            if (AASClient.TDFData.DataCache.ServerIP == string.Empty)
            {
                TDFData.DataSourceConfig.IsUseTDFData = false;
            }
        }
コード例 #2
0
        private void button登录_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox服务器.Text.Length == 0)
                {
                    MessageBox.Show("请输入登陆服务器IP!");
                    return;
                }

                //string server = string.IsNullOrEmpty(serverIP) ? textBox服务器.Text : serverIP;

                Program.EndpointAddress = new EndpointAddress(new Uri(string.Format("net.tcp://{0}:{1}/", textBox服务器.Text, Program.Port)), EndpointIdentity.CreateDnsIdentity("localhost"));
                //if (Program.Port == "808")
                //{

                //}
                //else
                //{
                //    Program.EndpointAddress = new EndpointAddress(new Uri(string.Format("net.tcp://{0}/", textBox服务器.Text)), EndpointIdentity.CreateDnsIdentity("localhost"));
                //}


                Program.AASServiceClient = new AASServiceReference.AASServiceClient(Program.callbackInstance, Program.NetTcpBinding, Program.EndpointAddress);

                //Program.EndpointAddress = new EndpointAddress(new Uri(string.Format("http://{0}/", server)), EndpointIdentity.CreateDnsIdentity("localhost"));
                //Program.AASServiceClient = new AASServiceReference.AASServiceClient(Program.callbackInstance, Program.WSDualHttpBinding, Program.EndpointAddress);


                Program.AASServiceClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
                Program.AASServiceClient.ClientCredentials.UserName.UserName = this.comboBox用户名.Text;
                Program.AASServiceClient.ClientCredentials.UserName.Password = this.textBox密码.Text + "\t" + this.MAC;


                Program.Current平台用户 = Program.AASServiceClient.QuerySingleUser(Program.Version)[0];
                Program.LoginInfoCache(textBox服务器.Text, this.comboBox用户名.Text, this.textBox密码.Text);
                //优先获取缓存的分发服务器地址
                //pubServerIPCache = "192.168.1.28";
                if (pubServerIPCache != string.Empty && CommonUtils.TelnetPort(pubServerIPCache, AASClient.TDFData.DataCache.ServerPort))
                {
                    AASClient.TDFData.DataCache.ServerIP = pubServerIPCache;
                }
                else
                {
                    string ip = Program.AASServiceClient.GetDataServerIP();
                    if (string.IsNullOrEmpty(ip))
                    {
                        TDFData.DataSourceConfig.IsUseTDFData = false;
                    }
                    else
                    {
                        if (ip.Contains(System.Environment.NewLine))
                        {
                            string[] arr = ip.Split(new[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var item in arr)
                            {
                                if (CommonUtils.TelnetPort(item, AASClient.TDFData.DataCache.ServerPort))
                                {
                                    AASClient.TDFData.DataCache.ServerIP = item;
                                    if (this.AppConfig.AppSettings.Settings.AllKeys.Contains(pubServerName))
                                    {
                                        if (item.Equals(Cryptor.MD5Decrypt(this.AppConfig.AppSettings.Settings[pubServerName].Value)))
                                        {
                                            break;
                                        }
                                        this.AppConfig.AppSettings.Settings[pubServerName].Value = Cryptor.MD5Encrypt(item);
                                    }
                                    else
                                    {
                                        this.AppConfig.AppSettings.Settings.Add(pubServerName, Cryptor.MD5Encrypt(item));
                                    }

                                    this.AppConfig.Save(ConfigurationSaveMode.Modified);
                                    System.Configuration.ConfigurationManager.RefreshSection("appSettings");
                                    break;
                                }
                                Thread.Sleep(100);
                            }
                        }
                        else
                        {
                            if (CommonUtils.TelnetPort(ip, AASClient.TDFData.DataCache.ServerPort))
                            {
                                AASClient.TDFData.DataCache.ServerIP = ip;
                            }
                        }
                    }
                }
                if (AASClient.TDFData.DataCache.ServerIP == string.Empty)
                {
                    MessageBox.Show("行情服务器IP为空!");
                    TDFData.DataSourceConfig.IsUseTDFData = false;
                }

                //MessageBox.Show(AASClient.TDFData.DataCache.ServerIP);
                ICommunicationObject ICommunicationObject1 = Program.AASServiceClient as ICommunicationObject;
                ICommunicationObject1.Faulted += ICommunicationObject1_Faulted;
                ICommunicationObject1.Closed  += ICommunicationObject1_Closed;



                if (this.checkBox记住密码.Checked)
                {
                    if (this.AppConfig.AppSettings.Settings.AllKeys.Contains(this.comboBox用户名.Text))
                    {
                        this.AppConfig.AppSettings.Settings[this.comboBox用户名.Text].Value = this.textBox服务器.Text + "," + Cryptor.MD5Encrypt(this.textBox密码.Text);
                    }
                    else
                    {
                        this.AppConfig.AppSettings.Settings.Add(this.comboBox用户名.Text, this.textBox服务器.Text + "," + Cryptor.MD5Encrypt(this.textBox密码.Text));
                    }
                    this.AppConfig.Save(ConfigurationSaveMode.Modified);
                    System.Configuration.ConfigurationManager.RefreshSection("appSettings");
                }
                else
                {
                    if (this.AppConfig.AppSettings.Settings.AllKeys.Contains(this.comboBox用户名.Text))
                    {
                        this.AppConfig.AppSettings.Settings.Remove(this.comboBox用户名.Text);
                        this.AppConfig.Save(ConfigurationSaveMode.Modified);
                        System.Configuration.ConfigurationManager.RefreshSection("appSettings");
                    }
                }

                Directory.CreateDirectory(Program.Current平台用户.用户名);

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (MessageSecurityException ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "MessageSecurityException - InnerException");
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "MessageSecurityException");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name);
            }
        }