/// <summary> /// Serialization text on the EntitySet level turns into a JSON array, composed of individual object-per-collection member. /// The output format is lighter-weight than the portable format (no schema). /// </summary> /// <param name="mode"></param> /// <returns></returns> public string GetSerializationText(SerializationMode?mode = null) { StringBuilder sb = new StringBuilder(4096); var actmode = mode.GetValueOrDefault(CEF.CurrentServiceScope.Settings.SerializationMode); var st = new SerializationVisitTracker(); CEF.CurrentServiceScope.ReconcileModifiedState(null); using (var jw = new JsonTextWriter(new StringWriter(sb))) { jw.WriteStartArray(); foreach (var i in this) { var iw = i.AsInfraWrapped(); var rs = iw.GetRowState(); if ((rs != ObjectState.Unchanged && rs != ObjectState.Unlinked) || ((actmode & SerializationMode.OnlyChanged) == 0)) { CEF.CurrentPCTService()?.SaveContents(jw, i, actmode, st); } } jw.WriteEndArray(); } return(sb.ToString()); }
public virtual bool SaveContents(JsonTextWriter tw, SerializationMode mode) { using (new ReaderLock(_lock)) { return((CEF.CurrentPCTService()?.SaveContents(tw, this, mode, new SerializationVisitTracker())).GetValueOrDefault()); } }
public void PopulateFromSerializationText(string json, JsonSerializationSettings?jss = null) { if (jss == null) { jss = new JsonSerializationSettings(); } // Must be an array... if (jss.SerializationType == SerializationType.Array) { if (!Regex.IsMatch(json, @"^\s*\[") || !Regex.IsMatch(json, @"\]\s*$")) { throw new CEFInvalidStateException(InvalidStateType.Serialization, "JSON provided is not an array (must be to deserialize a service scope)."); } } var il = CEF.CurrentPCTService()?.GetItemsFromSerializationText <T>(json, jss); if (il != null) { foreach (var i in il) { this.Add(i); } } }