private static long Hash(JToken content, IFieldDescriptor field_desc) { //TODO conflict resolve string str; string hashimport = field_desc.GetAttributeValue(Consts.c_KW_HashImport); string cellidkey = field_desc.GetAttributeValue(Consts.c_KW_CellIdKey); if ((cellidkey != null && field_desc.Type == Consts.c_Type_Guid) || (hashimport == Consts.c_KW_Guid)) { str = ((Guid)content).ToString(); } else if ((cellidkey != null && field_desc.Type == Consts.c_Type_DateTime) || (hashimport == Consts.c_KW_DateTime)) { str = ((DateTime)content).ToString("s");//XXX issue #226 } else { str = content.ToString(); } //TODO what if we're hashing a whole struct to cell id? how do we normalize? return(Trinity.Core.Lib.HashHelper.HashString2Int64(str)); }
public ICell ImportEntity(string type, string content, long?parent_id = null) { var fields = parser.CsvSplit(content); if (fields.Count != m_fieldNames.Count) { throw new ImporterException("Invalid record. The number of a field ({0}) must equal to {1}: {2}", fields.Count, m_fieldNames.Count, content); } var jsonObj = new JObject(); var fieldDescDict = GetFieldDescriptors(type); IFieldDescriptor fieldDesc = null; for (int colIndex = 0; colIndex < m_fieldNames.Count; colIndex++) { var fieldName = m_fieldNames[colIndex]; string fieldValue = fields[colIndex]; if (fieldValue == null || !fieldDescDict.TryGetValue(fieldName, out fieldDesc)) { // Ignore this field if it's value is null or could not find the descriptor. continue; } string csvArraySplitBy = fieldDesc.GetAttributeValue(Consts.c_KW_CsvArray); if (fieldValue == null || csvArraySplitBy == null) { jsonObj[fieldName] = fieldValue; } else { var elements = fieldValue.Split(csvArraySplitBy.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var jsonArray = new JArray(); foreach (var elem in elements) { jsonArray.Add(elem); } jsonObj[fieldName] = jsonArray; } } return(m_jsonImporter.ImportEntity(type, jsonObj.ToString(), parent_id)); }