public static void ExperimentalPartReceived(ClientStructure client, ShareProgressExperimentalPartMsgData data) { LunaLog.Debug($"Experimental part received: {data.PartName} Count: {data.Count}"); //send the experimental part to all other clients MessageQueuer.RelayMessage <ShareProgressSrvMsg>(client, data); ScenarioDataUpdater.WriteExperimentalPartDataToFile(data); }
/// <summary> /// We received a experimental part message so update the scenario file accordingly /// </summary> public static void WriteExperimentalPartDataToFile(ShareProgressExperimentalPartMsgData experimentalPartMsg) { Task.Run(() => { lock (Semaphore.GetOrAdd("ResearchAndDevelopment", new object())) { if (!ScenarioStoreSystem.CurrentScenarios.TryGetValue("ResearchAndDevelopment", out var scenario)) { return; } var expPartNode = scenario.GetNode("ExpParts"); if (expPartNode == null && experimentalPartMsg.Count > 0) { scenario.AddNode(new ConfigNode("ExpParts", scenario)); expPartNode = scenario.GetNode("ExpParts"); } var specificExpPart = expPartNode?.Value.GetValue(experimentalPartMsg.PartName); if (specificExpPart == null) { var newVal = new CfgNodeValue <string, string>(experimentalPartMsg.PartName, experimentalPartMsg.Count.ToString(CultureInfo.InvariantCulture)); expPartNode?.Value.CreateValue(newVal); } else { if (experimentalPartMsg.Count == 0) { expPartNode.Value.RemoveValue(specificExpPart.Value); } else { specificExpPart.Value = experimentalPartMsg.Count.ToString(CultureInfo.InvariantCulture); } } if (expPartNode?.Value.GetAllValues().Count == 0) { scenario.RemoveNode(expPartNode.Value); } } }); }