public Task <object> CreateInstance(IDictionary <string, object> input) { using (StreamWriter x = File.AppendText("test.txt")) { x.WriteLine(input); foreach (PropertyInfo y in input.GetType().GetProperties()) { x.WriteLine(y.Name); } x.WriteLine(input["OnGameChanged"]); } if (Instance == null) { Logger.LoggingLevel = 6; Instance = new Doormat(); Callbacks = new Dictionary <string, Func <object, Task <object> > >(); Instance.OnGameChanged += Instance_OnGameChanged; Callbacks.Add("OnGameChanged", (Func <object, Task <object> >)input["OnGameChanged"]); Instance.OnSiteAction += Instance_OnSiteAction; Callbacks.Add("OnSiteAction", (Func <object, Task <object> >)input["OnSiteAction"]); Instance.OnSiteChat += Instance_OnSiteChat; Callbacks.Add("OnSiteChat", (Func <object, Task <object> >)input["OnSiteChat"]); Instance.OnSiteBetFinished += Instance_OnSiteDiceBetFinished; Callbacks.Add("OnSiteDiceBetFinished", (Func <object, Task <object> >)input["OnSiteDiceBetFinished"]); Instance.OnSiteError += Instance_OnSiteError; Callbacks.Add("OnSiteError", (Func <object, Task <object> >)input["OnSiteError"]); Instance.OnSiteLoginFinished += Instance_OnSiteLoginFinished; Callbacks.Add("OnSiteLoginFinished", (Func <object, Task <object> >)input["OnSiteLoginFinished"]); Instance.OnSiteNotify += Instance_OnSiteNotify; Callbacks.Add("OnSiteNotify", (Func <object, Task <object> >)input["OnSiteNotify"]); Instance.OnSiteRegisterFinished += Instance_OnSiteRegisterFinished; Callbacks.Add("OnSiteRegisterFinished", (Func <object, Task <object> >)input["OnSiteRegisterFinished"]); Instance.OnSiteStatsUpdated += Instance_OnSiteStatsUpdated; Callbacks.Add("OnSiteStatsUpdated", (Func <object, Task <object> >)input["OnSiteStatsUpdated"]); Instance.LoadPersonalSettings("personalsettings.json"); Instance.LoadBetSettings("betsettings.json"); Instance.CompileSites(); } //Instance.Sites = null; Logger.DumpLog("Finished creating instance, creating task and returning", 6); Task <object> taskA = new Task <object>(() => (Instance)); //taskA.Start(); taskA.RunSynchronously(); Logger.DumpLog("Finished creating instance, returning", 6); return(taskA); }
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); } }