public void SaveConfiguration(SlotConfiguration slotConfiguration) { var configs = GetConfigurations(); var config = configs.SingleOrDefault(s => s.Slot == slotConfiguration.Slot); if (config is null) { config = new SlotConfiguration { Slot = slotConfiguration.Slot, ExpirationDate = slotConfiguration.ExpirationDate, RepetitionFrequency = slotConfiguration.RepetitionFrequency }; configs.Add(config); } else { config.ExpirationDate = slotConfiguration.ExpirationDate; config.RepetitionFrequency = slotConfiguration.RepetitionFrequency; } var updatedConfigsJsonString = JsonSerializer.Serialize(configs); File.WriteAllText(configFile, updatedConfigsJsonString); }
/// <summary> /// Setup the slot size /// </summary> /// <param name="size"></param> public void SetSlotQueueSize(int size) { SlotConfiguration slotConfiguration = new SlotConfiguration(); slotConfiguration.ItemName = "SlotSize"; slotConfiguration.ItemValue = size.ToString(); database.GetCollection <SlotConfiguration>("SlotConfiguration").ReplaceOne(c => c.ItemName == "SlotSize", slotConfiguration); }
/// <summary> /// Get the slot spin size /// </summary> /// <returns></returns> public int GetSlotQueueSize() { SlotConfiguration size = database.GetCollection <SlotConfiguration>("SlotConfiguration").Find(c => c.ItemName == "SlotSize").FirstOrDefault(); if (size == null) { SetSlotQueueSize(settings.DefaultSlotSize); return(settings.DefaultSlotSize); } else { return(int.Parse(size.ItemValue)); } }