public void SetNewPalantirEndpoint(ObservedGuild guild) { abort = false; PalantirEndpoint = guild; Dataflow = new Thread(new ThreadStart(ObserveLobbies)); Dataflow.Name = "Dataflow GuildID " + guild.GuildID; }
public void LoadConnections() { PalantirDbContext Database = new PalantirDbContext(); PalantirTethers = new List <Tether>(); foreach (PalantirEntity palantirEntity in Database.Palantiri) { Tether tether; ObservedGuild guild = JsonConvert.DeserializeObject <ObservedGuild>(palantirEntity.Palantir); if (Database.GuildSettings.Any(s => s.GuildID == guild.GuildID)) { tether = new Tether(guild, JsonConvert.DeserializeObject <GuildSettings>(Database.GuildSettings.FirstOrDefault(s => s.GuildID == guild.GuildID).Settings)); } else { tether = new Tether(guild); } PalantirTethers.Add(tether); } PalantirMembers = new List <Member>(); foreach (MemberEntity memberEntity in Database.Members) { PalantirMembers.Add(JsonConvert.DeserializeObject <Member>(memberEntity.Member)); } Database.Dispose(); }
public Tether(ObservedGuild guild, GuildSettings settings) { abort = false; PalantirEndpoint = guild; PalantirSettings = settings; Dataflow = new Thread(new ThreadStart(ObserveLobbies)); Dataflow.Name = "Dataflow GuildID " + guild.GuildID; }
public Tether(ObservedGuild guild) { abort = false; PalantirEndpoint = guild; PalantirSettings = new GuildSettings { Header = "```fix\nCurrently playing skribbl.io```", IdleMessage = "Seems like no-one is playing :( \nAsk some friends to join or go solo!\n\n ", Timezone = 0, ShowAnimatedEmojis = true, ShowRefreshed = false, ShowToken = true, WaitingMessages = { } }; Dataflow = new Thread(new ThreadStart(ObserveLobbies)); Dataflow.Name = "Dataflow GuildID " + guild.GuildID; }
public void SavePalantiri(ObservedGuild guild) { bool newGuild = true; PalantirDbContext Database = new PalantirDbContext(); // If guild of new palantir has already an active palantir, close tether, replace palantir and reopen tether PalantirTethers.ForEach((t) => { if (t.PalantirEndpoint.GuildID == guild.GuildID) { string oldToken = t.PalantirEndpoint.ObserveToken; // update tether t.StopDataflow(); t.SetNewPalantirEndpoint(guild); t.EstablishDataflow(); newGuild = false; // Console.WriteLine("Change token from " + oldToken + " to " + guild.ObserveToken); // update db entry Database.Palantiri.Remove(Database.Palantiri.FirstOrDefault(p => p.Token == oldToken)); PalantirEntity entity = new PalantirEntity(); entity.Palantir = JsonConvert.SerializeObject(guild); entity.Token = guild.ObserveToken; Database.Palantiri.Add(entity); Database.SaveChanges(); } }); if (newGuild) { // add tether Tether tether = new Tether(guild); tether.EstablishDataflow(); PalantirTethers.Add(tether); // Add db entry PalantirEntity entity = new PalantirEntity(); entity.Token = guild.ObserveToken; entity.Palantir = JsonConvert.SerializeObject(guild); Database.Palantiri.Add(entity); Database.SaveChanges(); } Database.Dispose(); UpdateMemberGuilds(); }
public void RemovePalantiri(ObservedGuild guild) { // remove tether PalantirTethers.Remove(PalantirTethers.Find(t => t.PalantirEndpoint.ObserveToken == guild.ObserveToken)); // remove palantir from db PalantirDbContext context = new PalantirDbContext(); PalantirEntity e = context.Palantiri.FirstOrDefault(ptr => ptr.Token == guild.ObserveToken); context.Palantiri.Remove(e); try { context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } context.Dispose(); // restart string op = "sudo service palantir restart".Bash(); //Environment.Exit(0); //UpdateMemberGuilds(); }