/// <summary> /// serialize object in a temp file and return a JSON message for data exchange in named pipes /// </summary> public static string savePayload(IpcOperationType type, object data) { string tempFilePath = null; if (data != null) { tempFilePath = Path.GetTempFileName(); File.WriteAllText(tempFilePath, JsonUtils.Serialize(data)); } IpcMessageStore msg = new IpcMessageStore() { type = (int)type, tempFilePath = tempFilePath }; return(JsonUtils.Serialize(msg)); }
/// <summary> /// deserialize object based on JSON message /// </summary> public static T getPayload <T>(string jsonMsg) { try { IpcMessageStore msg = JsonUtils.Deserialize <IpcMessageStore>(jsonMsg); if (string.IsNullOrEmpty(msg.tempFilePath)) { return(default(T)); } T obj = JsonUtils.Deserialize <T>(File.ReadAllText(msg.tempFilePath)); File.Delete(msg.tempFilePath); return(obj); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(default(T)); } }