/// <summary> /// Writes FPP Universe file in 2.x json format /// </summary> /// <param name="fileName"></param> /// <returns></returns> public async Task Write2xUniverseFile(string fileName) { var fppStartChannel = 1; FppOutputConfiguration config = new FppOutputConfiguration(); ChannelOutputs channelOutputs = new ChannelOutputs(); config.ChannelOutputs.Add(channelOutputs); foreach (var controller in ControllerExportInfo.Where(x => x.IsActive).OrderBy(x => x.Index)) { if (controller.HasNetworkSupport) { var universes = controller.ControllerNetworkConfiguration.Universes; foreach (var uc in universes) { Universe u = new Universe(); channelOutputs.Universes.Add(u); string ip = string.Empty; if (!uc.IsMultiCast) { //Validate ip address ip = uc.IpAddress?.Address.ToString(); if (ip == null) { ip = string.Empty; } u.Address = ip; } u.Description = controller.Name; u.UniverseType = uc.IsMultiCast?UniverseTypes.E131_Multicast:UniverseTypes.E131_Unicast; u.Active = uc.Active; u.ChannelCount = uc.Size; u.StartChannel = fppStartChannel; u.UniverseId = uc.Universe; fppStartChannel = fppStartChannel + uc.Size; } } else { fppStartChannel = fppStartChannel + controller.Channels; } } using (var writer = new StreamWriter(fileName)) { DefaultContractResolver contractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }; var s = JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings { ContractResolver = contractResolver }); await writer.WriteAsync(s); await writer.FlushAsync(); } }
/// <summary> /// Writes FPP Universe file in 2.x json format /// </summary> /// <param name="fileName"></param> /// <returns></returns> public async Task Write2xUniverseFile(string fileName) { var fppStartChannel = 1; FppOutputConfiguration config = new FppOutputConfiguration(); ChannelOutputs channelOutputs = new ChannelOutputs(); config.ChannelOutputs.Add(channelOutputs); foreach (var controller in ControllerExportInfo.Where(x => x.IsActive).OrderBy(x => x.Index)) { if (controller.HasNetworkSupport) { var universes = controller.ControllerNetworkConfiguration.Universes; string ip = controller.ControllerNetworkConfiguration.IpAddress?.ToString(); if (ip is null) { ip = string.Empty; } switch (controller.ControllerNetworkConfiguration.ProtocolType) { case ProtocolTypes.sACN: var isMulticast = controller.ControllerNetworkConfiguration.TransmissionMethod == TransmissionMethods.Multicast; foreach (var uc in universes) { Universe u = new Universe(); u.Address = ip; u.Description = controller.Name; u.UniverseType = isMulticast ? UniverseTypes.E131_Multicast:UniverseTypes.E131_Unicast; u.Active = uc.Active; u.ChannelCount = uc.Size; u.StartChannel = fppStartChannel; u.UniverseId = uc.UniverseNumber; channelOutputs.Universes.Add(u); fppStartChannel = fppStartChannel + uc.Size; } break; case ProtocolTypes.DDP: { var uc = universes[0]; Universe u = new Universe(); u.Address = ip; u.Description = controller.Name; u.UniverseType = UniverseTypes.DDP_1_Based; u.Active = true; u.ChannelCount = uc.Size; u.StartChannel = fppStartChannel; u.UniverseId = 0; channelOutputs.Universes.Add(u); fppStartChannel = fppStartChannel + uc.Size; } break; default: break; } } //if(controller.hasExportOtherSupport) else { fppStartChannel = fppStartChannel + controller.Channels; } } using (var writer = new StreamWriter(fileName)) { DefaultContractResolver contractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }; var s = JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings { ContractResolver = contractResolver }); await writer.WriteAsync(s); await writer.FlushAsync(); } }