/*public static IList<TabularObject> DeserializeObjects(string json) * { * json = json.Trim(); * if (!(json.StartsWith("{") && json.EndsWith("}"))) return null; // Expect a JSON object * JObject jObj; * * try * { * jObj = JObject.Parse(json); * } * catch (JsonReaderException jex) * { * return null; * } * * var result = new List<TabularObject>(); * * foreach (var type in ObjectMetadata.Creatable) * { * var jArr = jObj[TypeToJson(type)] as JArray; * if(jArr != null) * { * var tomType = ObjectMetadata.ToTOM(type); * foreach (JObject tomObj in jArr) * { * var tomJson = tomObj.ToString(); * var tom = TOM.JsonSerializer.DeserializeObject(tomType, tomJson); * var wrapperObj = ObjectMetadata.CreateFromMetadata(tom) as TabularObject; * wrapperObj.SerializedFrom = tomObj; * result.Add(wrapperObj); * } * } * } * * return result.Count > 0 ? result : null; * }*/ public static string SerializeDB(SerializeOptions options) { var serializedDB = TOM.JsonSerializer.SerializeDatabase(TabularModelHandler.Singleton.Database, new TOM.SerializeOptions() { IgnoreInferredObjects = options.IgnoreInferredObjects, IgnoreTimestamps = options.IgnoreTimestamps, IgnoreInferredProperties = options.IgnoreInferredProperties, SplitMultilineStrings = options.SplitMultilineStrings }); // Hack: Remove \r characters from multiline strings in the BIM: // "1 + 2\r", -> "1 + 2", if (options.SplitMultilineStrings) { serializedDB = serializedDB.Replace("\\r\",\r\n", "\",\r\n"); } return(serializedDB); }
/*public static IList<TabularObject> DeserializeObjects(string json) * { * json = json.Trim(); * if (!(json.StartsWith("{") && json.EndsWith("}"))) return null; // Expect a JSON object * JObject jObj; * * try * { * jObj = JObject.Parse(json); * } * catch (JsonReaderException jex) * { * return null; * } * * var result = new List<TabularObject>(); * * foreach (var type in ObjectMetadata.Creatable) * { * var jArr = jObj[TypeToJson(type)] as JArray; * if(jArr != null) * { * var tomType = ObjectMetadata.ToTOM(type); * foreach (JObject tomObj in jArr) * { * var tomJson = tomObj.ToString(); * var tom = TOM.JsonSerializer.DeserializeObject(tomType, tomJson); * var wrapperObj = ObjectMetadata.CreateFromMetadata(tom) as TabularObject; * wrapperObj.SerializedFrom = tomObj; * result.Add(wrapperObj); * } * } * } * * return result.Count > 0 ? result : null; * }*/ public static string SerializeDB(SerializeOptions options) { var db = TabularModelHandler.Singleton.Database; var serializedDB = TOM.JsonSerializer.SerializeDatabase(db, new TOM.SerializeOptions() { IgnoreInferredObjects = options.IgnoreInferredObjects, IgnoreTimestamps = options.IgnoreTimestamps, IgnoreInferredProperties = options.IgnoreInferredProperties, SplitMultilineStrings = options.SplitMultilineStrings, IncludeRestrictedInformation = db.Model.Annotations.Contains("TabularEditor_SaveSensitive") && db.Model.Annotations["TabularEditor_SaveSensitive"].Value == "1" }); // Hack: Remove \r characters from multiline strings in the BIM: // "1 + 2\r", -> "1 + 2", if (options.SplitMultilineStrings) { serializedDB = serializedDB.Replace("\\r\",\r\n", "\",\r\n"); } return(serializedDB); }