void ConfigureDatabase() { while (true) { string provider = ""; if (string.IsNullOrWhiteSpace(DiceBot.PersonalSettings.EncrConnectionString)) { Console.WriteLine("It seems like this is the first time you're running DiceBot. Please configure a database to store your bets in.\n"); } Console.WriteLine("(1) SQLite (Default)\n(2) MS SQL Server\n(3) MYSQL\n(4) Mongo\n(5) Post Gre\n\nSelect database provider:"); string input = Console.ReadLine(); switch (input) { case "1": default: provider = "SQLite"; break; case "2": provider = "MSSQL"; break; case "3": provider = "MYSQL"; break; case "4": provider = "Mongo"; break; case "5": provider = "PostGRE"; break; } Console.WriteLine("Selected Provider: " + provider); Console.WriteLine("Please provide the following DB settings:"); Console.Write("Data Source (File name or database server): "); string datasource = Console.ReadLine(); string Constring = ""; if (input != "1") { Console.Write("Initial Catalog (Database name):"); string dbname = Console.ReadLine(); Console.Write("DB Username: "******"DB Password: "******"Data Source={0};Initial Catalog={1};User Id={2};Password={3};persist security info=true;", datasource, dbname, Username, Password); DiceBot.PersonalSettings.Provider = provider; } else { Constring = string.Format("Data Source={0};Version=3;Compress=True;", datasource); DiceBot.PersonalSettings.Provider = provider; } Console.WriteLine("Enter a password to encrypt your connection string. You will need to enter it every time you open DiceBot. Leaving it blank will store your connectionstring in plain text."); Console.Write("Password: "******"personalsettings.json"); DiceBot.LoadPersonalSettings("personalsettings.json"); return; } }
public void Start() { DiceBot = new Doormat(); DiceBot.OnSiteBetFinished += DiceBot_OnSiteDiceBetFinished; DiceBot.OnSiteAction += DiceBot_OnSiteAction; DiceBot.OnSiteChat += DiceBot_OnSiteChat; DiceBot.OnSiteError += DiceBot_OnSiteError; DiceBot.OnSiteLoginFinished += DiceBot_OnSiteLoginFinished; DiceBot.OnSiteNotify += DiceBot_OnSiteNotify; DiceBot.OnSiteRegisterFinished += DiceBot_OnSiteRegisterFinished; DiceBot.OnSiteStatsUpdated += DiceBot_OnSiteStatsUpdated; DiceBot.NeedConstringPassword += DiceBot_NeedConstringPassword; DiceBot.NeedKeepassPassword += DiceBot_NeedKeepassPassword; if (File.Exists("personalsettings.json")) { try { DiceBot.LoadPersonalSettings("personalsettings.json"); } catch (Exception e) { Logger.DumpLog(e); } } if (DiceBot.PersonalSettings != null) { if (string.IsNullOrWhiteSpace(DiceBot.PersonalSettings.EncrConnectionString)) { ConfigureDatabase(); } } if (File.Exists("betsettings.json")) { try { DiceBot.LoadBetSettings("betsettings.json"); } catch (Exception e) { Logger.DumpLog(e); } } SelectSite(); PrintCurrentActions(); string Input = Console.ReadLine(); while (Input.ToLower() != "exit") { try { switch (Input.ToLower()) { case "login": Login(); break; case "site": SelectSite(); break; case "currency": SelectCurrency(); break; case "logout": Logout(); break; case "sitestats": PrintSiteStats(); break; case "strategy": Strategy(); break; case "stats": Stats(); break; case "start": Console.Clear(); bets = new List <DiceBet>(); DiceBot.SavePersonalSettings("personalsettings.json"); DiceBot.SaveBetSettings("betsettings.json"); DiceBot.Start(); break; case "stop": DiceBot.StopStrategy("Stop received from console."); break; case "sim": Simulate(); break; case "betsettings": BetSettings(); break; case "personalsettings": PersonalSetting(); break; } } catch (Exception e) { Console.WriteLine(e.Message); } PrintCurrentActions(); if (DiceBot.Running) { this.Input = ""; char CharRead = Console.ReadKey().KeyChar; while (CharRead != '\n' && CharRead != '\r') { this.Input += CharRead; if ((CharRead != '\n' && CharRead != '\r')) { CharRead = Console.ReadKey().KeyChar; } } Input = this.Input; } else { Input = Console.ReadLine(); } } try { DiceBot.SavePersonalSettings("personalsettings.json"); DiceBot.SaveBetSettings("betsettings.json"); DiceBot.CurrentSite.Disconnect(); } catch (Exception e) { Logger.DumpLog(e); } }