/// <summary> /// Parse complex settings JSON for translation /// </summary> /// <param name="CRMDataList"></param> /// <returns></returns> public static List <CRMDataObject> ParseComplexJson(List <CRMDataObject> CRMDataList) { List <CRMDataObject> newCRMDataList = new List <CRMDataObject>(); foreach (var CRMObject in CRMDataList) { List <ComplexJson> dataListJson = ParseComplexJsonToObjects(CRMObject.Value); //gets only the english foreach (var jsonData in dataListJson.Where(c => c.LCID == 1033)) { CRMDataObject temObj = new CRMDataObject( CRMObject.EntityName, CRMObject.GUID, jsonData.Value, "", CRMObject.FieldName); //replaces the path to irish jsonData.Path = ReplaceLastOccurrence(jsonData.Path, "0", "1"); temObj.ValueIE = GetJsonObjectValue(jsonData.Path, CRMObject); temObj.Path = jsonData.Path; temObj.ComplexJson = CRMObject.Value; newCRMDataList.Add(temObj); } //irish with no english value foreach (var jsonData in dataListJson.Where(c => c.LCID == 1046)) { CRMDataObject temObj = new CRMDataObject( CRMObject.EntityName, CRMObject.GUID, string.Empty, jsonData.Value, CRMObject.FieldName); //skip english value check for column overrides if (jsonData.Path.StartsWith("ColumnOverrides")) { temObj.Path = jsonData.Path; temObj.ComplexJson = CRMObject.Value; newCRMDataList.Add(temObj); continue; } else { //check english value is emppty string englishPath = ReplaceLastOccurrence(jsonData.Path, "1", "0"); string enValue = GetJsonObjectValue(englishPath, CRMObject); if (string.IsNullOrEmpty(enValue)) { temObj.Path = jsonData.Path; temObj.ComplexJson = CRMObject.Value; newCRMDataList.Add(temObj); } } } } return(newCRMDataList); }
private static CRMDataObject ParseJsonValueToCRMObject(List <string> jsonValueList, CRMDataObject crmData) { //insert the json data into crmdataObjects so it can be exported to excel if (jsonValueList.Count <= 0) { return(null); } CRMDataObject tempObj = new CRMDataObject(); tempObj.EntityName = crmData.EntityName; tempObj.GUID = crmData.GUID; tempObj.Value = jsonValueList.First(); tempObj.FieldName = crmData.FieldName; if (jsonValueList.Count > 1) { tempObj.ValueIE = jsonValueList[1]; } return(tempObj); }
private static string GetJsonObjectValue(string irishPath, CRMDataObject CRMObject) { JToken dataToken = JToken.Parse(CRMObject.Value); return(dataToken.SelectToken(irishPath + ".Value").ToString()); }