internal static void BuildFileInfo(BaseMessage baseMessage, ErrorRecorder errorRecorder) { baseMessage.fileInfo = new FileInfo(); ParseFileMessage(baseMessage, errorRecorder); ParseFileAttrs(baseMessage, errorRecorder); }
internal static void ParseFileAttrs(BaseMessage baseMessage, ErrorRecorder errorRecorder) { try { Dictionary <string, object> attrsDict = Json.ParseObject(baseMessage.attrs); if (attrsDict != null) { if (attrsDict.TryGetValue("rtm", out object rtmAttrs)) { Dictionary <string, object> rtmAttrsDict = (Dictionary <string, object>)rtmAttrs; if (rtmAttrsDict.TryGetValue("type", out object typeText)) { string typeStr = (string)typeText; if (typeStr.Equals("audiomsg")) { baseMessage.fileInfo.isRTMAudio = true; } } if (baseMessage.fileInfo.isRTMAudio) { if (rtmAttrsDict.TryGetValue("lang", out object languageText)) { baseMessage.fileInfo.language = (string)languageText; } if (rtmAttrsDict.TryGetValue("duration", out object durationInt)) { baseMessage.fileInfo.duration = (Int32)Convert.ChangeType(durationInt, TypeCode.Int32); } } } if (attrsDict.TryGetValue("custom", out object attrsInfo)) { try { Dictionary <string, object> userAttrsDict = (Dictionary <string, object>)attrsInfo; baseMessage.attrs = Json.ToString(userAttrsDict); return; } catch (Exception) { try { string userAttrs = (string)attrsInfo; baseMessage.attrs = userAttrs; return; } catch (Exception ex) { if (errorRecorder != null) { errorRecorder.RecordError("Convert user attrs to string type for file attrs error. Full attrs: " + baseMessage.attrs, ex); } } } } } } catch (JsonException e) { if (errorRecorder != null) { errorRecorder.RecordError("Parse file attrs error. Full attrs: " + baseMessage.attrs, e); } } }