public static void Save(MasterDivisionRegistry mdr) { using (var fileStream = new FileStream("mdr.json", FileMode.Create)) { using (var writer = JsonReaderWriterFactory.CreateJsonWriter(fileStream, Encoding.UTF8, true, true, " ")) { var settings = new DataContractJsonSerializerSettings(); settings.EmitTypeInformation = EmitTypeInformation.AsNeeded; settings.KnownTypes = new [] { typeof(DIUnit), typeof(MasterDivisionRegistry), typeof(DIHouse), typeof(DIDivision), typeof(DITeam), typeof(DIRoster), typeof(DIUser) }; new DataContractJsonSerializer(typeof(MasterDivisionRegistry), settings).WriteObject(writer, mdr); } } }
public CalendarScheduler(DiscordSocketClient discord, MasterDivisionRegistry mdr) { _discord = discord; _mdr = mdr; _timer = new Timer(); _timer.Interval = 10000; _timer.Elapsed += CalendarLoop; _timer.Enabled = true; var postTimer = new Timer(); postTimer.Interval = 10000; postTimer.Elapsed += (sender, evt) => { postTimer.Enabled = false; foreach (var guild in _discord.Guilds) { if (!ScheduledPosts.ContainsKey(guild.Id)) { ScheduledPosts.Add(guild.Id, new Queue <Func <Task> >()); } if (ScheduledPosts[guild.Id].Count() == 0) { continue; } ScheduledPosts[guild.Id].Dequeue().Invoke().GetAwaiter().GetResult(); } postTimer.Enabled = true; }; postTimer.Enabled = true; }