private void CreateNewSubscriptionsConfigurationFile(SubscriptionsConfiguration subscriptionsConfiguration) { var intenralConfig = new SubscriptionsConfigurationInternal(subscriptionsConfiguration); var text = JsonSerializer.Serialize(intenralConfig, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(configFileNew, text, Encoding.UTF8); }
public SubscriptionsConfigurationInternal(SubscriptionsConfiguration subscriptionsConfiguration) { if ((subscriptionsConfiguration.Subscriptions?.Count ?? 0) == 0) { Subscriptions = new List <string>(); } Subscriptions = subscriptionsConfiguration.Subscriptions.Select(x => x.Name).ToList(); }
private void CreateNewSubscriptionsMapFile(SubscriptionsConfiguration subscriptionsConfiguration) { var subscriptions = subscriptionsConfiguration.Subscriptions ?? new List <SubscriptionConfiguration>(); using (var writer = new BinaryWriter(File.Create(mapFileNew), Encoding.UTF8, false)) { foreach (var item in subscriptions) { WriteMapRecord(item, writer); } writer.Flush(); } }
public void Update(SubscriptionsConfiguration subscriptionsConfiguration) { CreateNewSubscriptionsConfigurationFile(subscriptionsConfiguration); CreateNewSubscriptionsMapFile(subscriptionsConfiguration); if (File.Exists(configFile)) { File.Delete(configFile); } if (File.Exists(mapFile)) { File.Delete(mapFile); } File.Move(configFileNew, configFile); File.Move(mapFileNew, mapFile); }
public SubscriptionsConfiguration Read() { var config = new SubscriptionsConfiguration { Subscriptions = new List <SubscriptionConfiguration>() }; if (!File.Exists(mapFile)) { return(config); } using (var reader = new BinaryReader(File.OpenRead(mapFile), Encoding.UTF8, false)) { SubscriptionConfiguration subscriptionConfiguration; while ((subscriptionConfiguration = ReadMapRecord(reader)) != null) { config.Subscriptions.Add(subscriptionConfiguration); } } return(config); }