public static bool UpdateJsonTemplate(string _jsonFilePath, ObservableCollection <GeneralDisplayData> _roleOSBuild) { filePath = _jsonFilePath; try { root = JObject.Parse(File.ReadAllText(_jsonFilePath)); } catch (Exception e) { log.ErrorFormat("Parse Json File error, {0}", e); return(false); } List <BuildConfigure_ViewModel> _buildsList = new List <BuildConfigure_ViewModel>(); var tmp = _roleOSBuild.Select(r => { Role_OSBuild_ViewModel rovm = r.CValue as Role_OSBuild_ViewModel; if (rovm == null) { log.Debug("Convert to Role_OSBuild_ViewModel error"); return(r); } UpdateRoleOS(rovm); if (!_buildsList.Contains(rovm._SelectedBuild) && rovm._SelectedBuild != null) { _buildsList.Add(rovm._SelectedBuild); } return(r); }).ToArray(); UpdateBuilds(_buildsList); string laciPath = GetLACIPath(_buildsList); log.InfoFormat("the laci install path is {0}", laciPath); // a bug here. if user do not specify the laci path and we need this packet, it will failed // when we invoke our sequence. Currently, we don't notify user. maybe later will show it up. if (string.IsNullOrEmpty(laciPath)) { log.ErrorFormat("we cannot get the laciPath from selected builds"); } else { var laciJson = root["Environment"]["Workflow"]["Sequences"] .Where(t => t["Data"] != null) .FirstOrDefault() as JObject; laciJson["Data"]["LACIINSTALLPATH"] = laciPath; //UpdatejsonPath("$.Environment.Workflow.Sequences[2].Data", "LACIINSTALLPATH", laciPath); } File.WriteAllText(filePath, root.ToString()); return(true); }
private static void UpdateRoleOS(Role_OSBuild_ViewModel rovm) { var tmp = root["Environment"]["Roles"].Where(t => t["Settings"]["HostType"].ToString() == "AsfManaged" && (t["Role"].ToString() == rovm.RoleName || t["Role"].ToString() == "DC-1")).Select(e => { e["Settings"]["TemplateName"] = rovm._SelectedOS.TemplateName; return(e); }).ToArray(); JToken targetObj = root["Environment"]["Workflow"]["Sequences"].Where(t => t["Data"] != null).FirstOrDefault(); if (rovm.RoleName != "DC-1") { targetObj["Data"]["PRODUCT_VERSION_" + rovm.RoleName.Remove(rovm.RoleName.IndexOf('-'), 1)] = rovm.SelectedBuild; } else { targetObj["Data"]["PRODUCT_VERSION_DOMAINCONTROLLER"] = rovm.SelectedBuild; } }