public ScanInfoDTO ClientScanAccount(string username) { try { using (var context = new WinDbEntities()) { var i = context.Users.FirstOrDefault(u => u.Username == username); if (i == null) { throw new Exception("INVALID USERNAME"); } var scanaccDto = new ScanInfoDTO(); scanaccDto.ScanServers = context.SystemConfigs.Where(a => a.KeyConfig == "SBO_SCAN_LINK") .Select(a => a.ValueConfig).ToList(); scanaccDto.Accounts = i.AccScanInUses.Where(a => a.ScanAccount.ServerType == 2).Select( ac => new ScanAccountInfoDTO { Username = ac.ScanAccount.Username, Password = ac.ScanAccount.Password } ).ToList(); return(scanaccDto); } } catch (Exception ex) { Logger.Error(ex); return(new ScanInfoDTO()); } }
public bool Login(string username, string password, eUserType userType, string ip, string mac, string hostname) { try { using (var context = new WinDbEntities()) { var i = context.Users.FirstOrDefault(u => u.Username == username && u.Password == password && u.Type == (byte)userType); if (i == null) { return(false); } i.LoginTraces.Add(new LoginTrace() { Hostname = hostname, IpAddress = ip, MacAddress = mac, TimeLogin = DateTime.Now }); context.SaveChanges(); return(true); } } catch (Exception ex) { Logger.Error(ex); return(false); } }
public SetupBetConfigDTO BetSetupConfig(string username, int type) { try { SetupBetConfigDTO clientConfig = ProcessData.BetClientConfigs[type]; using (var context = new WinDbEntities()) { var i = context.Users.FirstOrDefault(u => u.Username == username); if (i == null) { throw new Exception("INVALID USERNAME"); } clientConfig.SboScanAccounts = i.AccScanInUses.Where(a => a.ScanAccount.ServerType == 2).Select( ac => new ScanAccountInfoDTO { Username = ac.ScanAccount.Username, Password = ac.ScanAccount.Password } ).ToList(); } return(clientConfig); } catch (Exception ex) { Logger.Error(ex); } return(null); }
private void SaveScanConfig() { try { int timeScanLiveIbet; int timeScanLiveSbo; IList <string> ibetScanServers; IList <string> sboScanServers; bool hasFakeIpSbo; using (var context = new WinDbEntities()) { timeScanLiveIbet = Convert.ToInt32(context.SystemConfigs.FirstOrDefault(w => w.KeyConfig == "IBET_TIME_SCAN_LIVE").ValueConfig); timeScanLiveSbo = Convert.ToInt32(context.SystemConfigs.FirstOrDefault(w => w.KeyConfig == "SBO_TIME_SCAN_LIVE").ValueConfig); sboScanServers = context.SystemConfigs.Where(a => a.KeyConfig == "SBO_SCAN_LINK") .Select(a => a.ValueConfig).ToList(); ibetScanServers = context.SystemConfigs.Where(a => a.KeyConfig == "IBET_SCAN_LINK") .Select(a => a.ValueConfig).ToList(); var fakeIpSbo = Convert.ToInt32( context.SystemConfigs.FirstOrDefault(w => w.KeyConfig == "FAKE_IP_SBO").ValueConfig); hasFakeIpSbo = fakeIpSbo == 1; } var sumHub = Convert.ToInt32(ConfigurationManager.AppSettings["SUMHUB"]); using (var context = new WinDbEntities()) { for (int i = 0; i <= sumHub; i++) { SetupScanConfigDTO scanCon = new SetupScanConfigDTO() { TimeScanLiveIbet = timeScanLiveIbet, TimeScanLiveSbo = timeScanLiveSbo, IbetScanServers = ibetScanServers, SboScanServers = sboScanServers, HasFakeIpSbo = hasFakeIpSbo }; string en = "ENDPOINT_ROUTE_SCAN_" + i; scanCon.EndpointRoute = context.SystemConfigs.FirstOrDefault(w => w.KeyConfig == en).ValueConfig; ProcessData.ScanConfigs.Add(scanCon); } } } catch (Exception ex) { Logger.Error(ex); throw; } }
public ScanInfoDTO ClientScanAccountBuyServerType(string username, eServerType serverType) { try { int accType; string linkType; switch (serverType) { case eServerType.Sbo: accType = 2; linkType = "SBO_SCAN_LINK"; break; case eServerType.Ibet: accType = 1; linkType = "IBET_SCAN_LINK"; break; default: accType = 0; linkType = ""; break; } using (var context = new WinDbEntities()) { var i = context.Users.FirstOrDefault(u => u.Username == username); if (i == null) { throw new Exception("INVALID USERNAME"); } var scanaccDto = new ScanInfoDTO(); scanaccDto.ScanServers = context.SystemConfigs.Where(a => a.KeyConfig == linkType) .Select(a => a.ValueConfig).ToList(); scanaccDto.Accounts = i.AccScanInUses.Where(a => a.ScanAccount.ServerType == accType).Select( ac => new ScanAccountInfoDTO { Username = ac.ScanAccount.Username, Password = ac.ScanAccount.Password } ).ToList(); return(scanaccDto); } } catch (Exception ex) { Logger.Error(ex); return(new ScanInfoDTO()); } }
private void ImportScanAcc(byte serverType) { try { OpenFileDialog openFileDialog1 = new OpenFileDialog(); //openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "TXT files|*.txt"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string filename = openFileDialog1.FileName; string[] filelines = File.ReadAllLines(filename); Dictionary <string, string> ibetAccdics = new Dictionary <string, string>(); foreach (var sboScanAcc in filelines) { var a = sboScanAcc.Split(new[] { "<>" }, StringSplitOptions.None); ibetAccdics[a[0]] = a[1]; } using (var context = new WinDbEntities()) { foreach (var o in ibetAccdics) { context.ScanAccounts.Add(new ScanAccount() { ServerType = serverType, Username = o.Key, Password = o.Value, IsBlock = false, IsFree = true, PassChangeVersion = 0 }); } context.SaveChanges(); } MessageBox.Show("DONE!"); } } catch (Exception ex) { Logger.Error(ex); MessageBox.Show("Lổi import data !"); } }
public int RouteType(string username) { try { using (var context = new WinDbEntities()) { return(context.Users.FirstOrDefault(u => u.Username == username).RouteType.Value); } } catch (Exception ex) { Logger.Error(ex); return(int.MaxValue); } }
public string GetKey() { try { using (var context = new WinDbEntities()) { return(context.SystemConfigs.FirstOrDefault(u => u.KeyConfig == "KEY_VALID").ValueConfig); } } catch (Exception ex) { Logger.Error(ex); return(string.Empty); } }
private void btnSubmit_Click(object sender, EventArgs e) { int getSbo = 0; int getIbet = 0; byte userType = (byte)(cbUserType.SelectedIndex + 1); if (userType == 1) { getSbo = (int)numSboScanAcc.Value; } else { getSbo = (int)numSboScanAcc.Value; getIbet = (int)numIbetScanAcc.Value; } if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show("Invalid input user information!"); return; } try { using (var context = new WinDbEntities()) { User u = new User(); u.Username = txtUsername.Text; u.Password = txtPassword.Text; u.Type = userType; var sbo = context.ScanAccounts.OrderBy(x => Guid.NewGuid()).Where(s => !s.IsBlock && s.IsFree && s.ServerType == 2).Take(getSbo); foreach (var sba in sbo) { sba.IsFree = false; u.AccScanInUses.Add(new AccScanInUse { ScanAccount = sba }); } var ibetA = context.ScanAccounts.OrderBy(x => Guid.NewGuid()).Where(s => !s.IsBlock && s.IsFree && s.ServerType == 1).Take(getIbet); foreach (var ibe in ibetA) { ibe.IsFree = false; u.AccScanInUses.Add(new AccScanInUse() { ScanAccount = ibe }); } context.Users.Add(u); context.SaveChanges(); } MessageBox.Show("DONE!"); } catch (Exception ex) { Logger.Error(ex); MessageBox.Show("Add user fail!"); } }
private void SaveBetClientConfig() { try { int timeScanLiveIbet; int timeScanLiveSbo; int timeScanNonLiveIbet; int timeScanNonLiveSbo; bool hasLocalScan; IList <string> sboScanServers; using (var context = new WinDbEntities()) { timeScanLiveIbet = Convert.ToInt32(context.SystemConfigs.FirstOrDefault(w => w.KeyConfig == "IBET_TIME_BET_LIVE").ValueConfig); timeScanLiveSbo = Convert.ToInt32(context.SystemConfigs.FirstOrDefault(w => w.KeyConfig == "SBO_TIME_BET_LIVE").ValueConfig); timeScanNonLiveIbet = Convert.ToInt32(context.SystemConfigs.FirstOrDefault(w => w.KeyConfig == "IBET_TIME_BET_NONLIVE").ValueConfig); timeScanNonLiveSbo = Convert.ToInt32(context.SystemConfigs.FirstOrDefault(w => w.KeyConfig == "SBO_TIME_BET_NONLIVE").ValueConfig); var localScan = Convert.ToInt32( context.SystemConfigs.FirstOrDefault(w => w.KeyConfig == "HAS_LOCAL_SCAN").ValueConfig); hasLocalScan = localScan == 1; sboScanServers = context.SystemConfigs.Where(a => a.KeyConfig == "SBO_SCAN_LINK") .Select(a => a.ValueConfig).ToList(); } var sumHub = Convert.ToInt32(ConfigurationManager.AppSettings["SUMHUB"]); using (var context = new WinDbEntities()) { for (int i = 0; i <= sumHub; i++) { SetupBetConfigDTO s = new SetupBetConfigDTO() { TimeScanLiveIbet = timeScanLiveIbet, TimeScanLiveSbo = timeScanLiveSbo, TimeScanNonLiveIbet = timeScanNonLiveIbet, TimeScanNonLiveSbo = timeScanNonLiveSbo, HasLocalScan = hasLocalScan, SboScanServers = sboScanServers }; string en = "ENDPOINT_ROUTE_BET_" + i; s.EndpointRoute = context.SystemConfigs.FirstOrDefault(w => w.KeyConfig == en).ValueConfig; ProcessData.BetClientConfigs.Add(s); } } } catch (Exception ex) { Logger.Error(ex); throw; } }